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" |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 21 | #include "arch/arm/jni_frame_arm.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 22 | #include "art_method-inl.h" |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 23 | #include "base/bit_utils.h" |
| 24 | #include "base/bit_utils_iterator.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 25 | #include "class_table.h" |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 26 | #include "code_generator_utils.h" |
| 27 | #include "common_arm.h" |
| 28 | #include "compiled_method.h" |
| 29 | #include "entrypoints/quick/quick_entrypoints.h" |
| 30 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 31 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 32 | #include "heap_poisoning.h" |
Nicolas Geoffray | 8b8d93d | 2020-09-17 14:30:01 +0100 | [diff] [blame] | 33 | #include "interpreter/mterp/nterp.h" |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 34 | #include "intrinsics.h" |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 35 | #include "intrinsics_arm_vixl.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 36 | #include "linker/linker_patch.h" |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 37 | #include "mirror/array-inl.h" |
| 38 | #include "mirror/class-inl.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 39 | #include "scoped_thread_state_change-inl.h" |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 40 | #include "thread.h" |
| 41 | #include "utils/arm/assembler_arm_vixl.h" |
| 42 | #include "utils/arm/managed_register_arm.h" |
| 43 | #include "utils/assembler.h" |
| 44 | #include "utils/stack_checks.h" |
| 45 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 46 | namespace art { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 47 | namespace arm { |
| 48 | |
| 49 | namespace vixl32 = vixl::aarch32; |
| 50 | using namespace vixl32; // NOLINT(build/namespaces) |
| 51 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 52 | using helpers::DRegisterFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 53 | using helpers::HighRegisterFrom; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 54 | using helpers::InputDRegisterAt; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 55 | using helpers::InputOperandAt; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 56 | using helpers::InputRegister; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 57 | using helpers::InputRegisterAt; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 58 | using helpers::InputSRegisterAt; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 59 | using helpers::InputVRegister; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 60 | using helpers::InputVRegisterAt; |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 61 | using helpers::Int32ConstantFrom; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 62 | using helpers::Int64ConstantFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 63 | using helpers::LocationFrom; |
| 64 | using helpers::LowRegisterFrom; |
| 65 | using helpers::LowSRegisterFrom; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 66 | using helpers::OperandFrom; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 67 | using helpers::OutputRegister; |
| 68 | using helpers::OutputSRegister; |
| 69 | using helpers::OutputVRegister; |
| 70 | using helpers::RegisterFrom; |
| 71 | using helpers::SRegisterFrom; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 72 | using helpers::Uint64ConstantFrom; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 73 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 74 | using vixl::EmissionCheckScope; |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 75 | using vixl::ExactAssemblyScope; |
| 76 | using vixl::CodeBufferCheckScope; |
| 77 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 78 | using RegisterList = vixl32::RegisterList; |
| 79 | |
| 80 | static bool ExpectedPairLayout(Location location) { |
| 81 | // We expected this for both core and fpu register pairs. |
| 82 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 83 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 84 | // Use a local definition to prevent copying mistakes. |
| 85 | static constexpr size_t kArmWordSize = static_cast<size_t>(kArmPointerSize); |
| 86 | static constexpr size_t kArmBitsPerWord = kArmWordSize * kBitsPerByte; |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 87 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 88 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 89 | // Reference load (except object array loads) is using LDR Rt, [Rn, #offset] which can handle |
| 90 | // 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] | 91 | // 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] | 92 | // the offset explicitly. |
| 93 | constexpr uint32_t kReferenceLoadMinFarOffset = 4 * KB; |
| 94 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 95 | // Using a base helps identify when we hit Marking Register check breakpoints. |
| 96 | constexpr int kMarkingRegisterCheckBreakCodeBaseCode = 0x10; |
| 97 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 98 | #ifdef __ |
| 99 | #error "ARM Codegen VIXL macro-assembler macro already defined." |
| 100 | #endif |
| 101 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 102 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 103 | #define __ down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()-> // NOLINT |
| 104 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
| 105 | |
| 106 | // Marker that code is yet to be, and must, be implemented. |
| 107 | #define TODO_VIXL32(level) LOG(level) << __PRETTY_FUNCTION__ << " unimplemented " |
| 108 | |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 109 | static inline bool CanEmitNarrowLdr(vixl32::Register rt, vixl32::Register rn, uint32_t offset) { |
| 110 | return rt.IsLow() && rn.IsLow() && offset < 32u; |
| 111 | } |
| 112 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 113 | class EmitAdrCode { |
| 114 | public: |
| 115 | EmitAdrCode(ArmVIXLMacroAssembler* assembler, vixl32::Register rd, vixl32::Label* label) |
| 116 | : assembler_(assembler), rd_(rd), label_(label) { |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 117 | DCHECK(!assembler->AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 118 | adr_location_ = assembler->GetCursorOffset(); |
| 119 | assembler->adr(EncodingSize(Wide), rd, label); |
| 120 | } |
| 121 | |
| 122 | ~EmitAdrCode() { |
| 123 | DCHECK(label_->IsBound()); |
| 124 | // The ADR emitted by the assembler does not set the Thumb mode bit we need. |
| 125 | // TODO: Maybe extend VIXL to allow ADR for return address? |
| 126 | uint8_t* raw_adr = assembler_->GetBuffer()->GetOffsetAddress<uint8_t*>(adr_location_); |
| 127 | // Expecting ADR encoding T3 with `(offset & 1) == 0`. |
| 128 | DCHECK_EQ(raw_adr[1] & 0xfbu, 0xf2u); // Check bits 24-31, except 26. |
| 129 | DCHECK_EQ(raw_adr[0] & 0xffu, 0x0fu); // Check bits 16-23. |
| 130 | DCHECK_EQ(raw_adr[3] & 0x8fu, rd_.GetCode()); // Check bits 8-11 and 15. |
| 131 | DCHECK_EQ(raw_adr[2] & 0x01u, 0x00u); // Check bit 0, i.e. the `offset & 1`. |
| 132 | // Add the Thumb mode bit. |
| 133 | raw_adr[2] |= 0x01u; |
| 134 | } |
| 135 | |
| 136 | private: |
| 137 | ArmVIXLMacroAssembler* const assembler_; |
| 138 | vixl32::Register rd_; |
| 139 | vixl32::Label* const label_; |
| 140 | int32_t adr_location_; |
| 141 | }; |
| 142 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 143 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 144 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 145 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 146 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 147 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 148 | // that the the kPrimNot result register is the same as the first argument register. |
| 149 | return caller_saves; |
| 150 | } |
| 151 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 152 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 153 | // for each live D registers they treat two corresponding S registers as live ones. |
| 154 | // |
| 155 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 156 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 157 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 158 | // - decreasing code size |
| 159 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 160 | // restored and then used in regular non SlowPath code as D register. |
| 161 | // |
| 162 | // For the following example (v means the S register is live): |
| 163 | // D names: | D0 | D1 | D2 | D4 | ... |
| 164 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 165 | // Live? | | v | v | v | v | v | v | | ... |
| 166 | // |
| 167 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 168 | // as D registers. |
| 169 | // |
| 170 | // TODO(VIXL): All this code should be unnecessary once the VIXL AArch32 backend provides helpers |
| 171 | // for lists of floating-point registers. |
| 172 | static size_t SaveContiguousSRegisterList(size_t first, |
| 173 | size_t last, |
| 174 | CodeGenerator* codegen, |
| 175 | size_t stack_offset) { |
| 176 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 177 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 178 | DCHECK_LE(first, last); |
| 179 | if ((first == last) && (first == 0)) { |
| 180 | __ Vstr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 181 | return stack_offset + kSRegSizeInBytes; |
| 182 | } |
| 183 | if (first % 2 == 1) { |
| 184 | __ Vstr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 185 | stack_offset += kSRegSizeInBytes; |
| 186 | } |
| 187 | |
| 188 | bool save_last = false; |
| 189 | if (last % 2 == 0) { |
| 190 | save_last = true; |
| 191 | --last; |
| 192 | } |
| 193 | |
| 194 | if (first < last) { |
| 195 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 196 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 197 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 198 | |
| 199 | if (number_of_d_regs == 1) { |
| 200 | __ Vstr(d_reg, MemOperand(sp, stack_offset)); |
| 201 | } else if (number_of_d_regs > 1) { |
| 202 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 203 | vixl32::Register base = sp; |
| 204 | if (stack_offset != 0) { |
| 205 | base = temps.Acquire(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 206 | __ Add(base, sp, Operand::From(stack_offset)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 207 | } |
| 208 | __ Vstm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 209 | } |
| 210 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 211 | } |
| 212 | |
| 213 | if (save_last) { |
| 214 | __ Vstr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 215 | stack_offset += kSRegSizeInBytes; |
| 216 | } |
| 217 | |
| 218 | return stack_offset; |
| 219 | } |
| 220 | |
| 221 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 222 | size_t last, |
| 223 | CodeGenerator* codegen, |
| 224 | size_t stack_offset) { |
| 225 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 226 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 227 | DCHECK_LE(first, last); |
| 228 | if ((first == last) && (first == 0)) { |
| 229 | __ Vldr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 230 | return stack_offset + kSRegSizeInBytes; |
| 231 | } |
| 232 | if (first % 2 == 1) { |
| 233 | __ Vldr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 234 | stack_offset += kSRegSizeInBytes; |
| 235 | } |
| 236 | |
| 237 | bool restore_last = false; |
| 238 | if (last % 2 == 0) { |
| 239 | restore_last = true; |
| 240 | --last; |
| 241 | } |
| 242 | |
| 243 | if (first < last) { |
| 244 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 245 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 246 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 247 | if (number_of_d_regs == 1) { |
| 248 | __ Vldr(d_reg, MemOperand(sp, stack_offset)); |
| 249 | } else if (number_of_d_regs > 1) { |
| 250 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 251 | vixl32::Register base = sp; |
| 252 | if (stack_offset != 0) { |
| 253 | base = temps.Acquire(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 254 | __ Add(base, sp, Operand::From(stack_offset)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 255 | } |
| 256 | __ Vldm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 257 | } |
| 258 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 259 | } |
| 260 | |
| 261 | if (restore_last) { |
| 262 | __ Vldr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 263 | stack_offset += kSRegSizeInBytes; |
| 264 | } |
| 265 | |
| 266 | return stack_offset; |
| 267 | } |
| 268 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 269 | static LoadOperandType GetLoadOperandType(DataType::Type type) { |
| 270 | switch (type) { |
| 271 | case DataType::Type::kReference: |
| 272 | return kLoadWord; |
| 273 | case DataType::Type::kBool: |
| 274 | case DataType::Type::kUint8: |
| 275 | return kLoadUnsignedByte; |
| 276 | case DataType::Type::kInt8: |
| 277 | return kLoadSignedByte; |
| 278 | case DataType::Type::kUint16: |
| 279 | return kLoadUnsignedHalfword; |
| 280 | case DataType::Type::kInt16: |
| 281 | return kLoadSignedHalfword; |
| 282 | case DataType::Type::kInt32: |
| 283 | return kLoadWord; |
| 284 | case DataType::Type::kInt64: |
| 285 | return kLoadWordPair; |
| 286 | case DataType::Type::kFloat32: |
| 287 | return kLoadSWord; |
| 288 | case DataType::Type::kFloat64: |
| 289 | return kLoadDWord; |
| 290 | default: |
| 291 | LOG(FATAL) << "Unreachable type " << type; |
| 292 | UNREACHABLE(); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | static StoreOperandType GetStoreOperandType(DataType::Type type) { |
| 297 | switch (type) { |
| 298 | case DataType::Type::kReference: |
| 299 | return kStoreWord; |
| 300 | case DataType::Type::kBool: |
| 301 | case DataType::Type::kUint8: |
| 302 | case DataType::Type::kInt8: |
| 303 | return kStoreByte; |
| 304 | case DataType::Type::kUint16: |
| 305 | case DataType::Type::kInt16: |
| 306 | return kStoreHalfword; |
| 307 | case DataType::Type::kInt32: |
| 308 | return kStoreWord; |
| 309 | case DataType::Type::kInt64: |
| 310 | return kStoreWordPair; |
| 311 | case DataType::Type::kFloat32: |
| 312 | return kStoreSWord; |
| 313 | case DataType::Type::kFloat64: |
| 314 | return kStoreDWord; |
| 315 | default: |
| 316 | LOG(FATAL) << "Unreachable type " << type; |
| 317 | UNREACHABLE(); |
| 318 | } |
| 319 | } |
| 320 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 321 | void SlowPathCodeARMVIXL::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 322 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 323 | size_t orig_offset = stack_offset; |
| 324 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 325 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 326 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 327 | // If the register holds an object, update the stack mask. |
| 328 | if (locations->RegisterContainsObject(i)) { |
| 329 | locations->SetStackBit(stack_offset / kVRegSize); |
| 330 | } |
| 331 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 332 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 333 | saved_core_stack_offsets_[i] = stack_offset; |
| 334 | stack_offset += kArmWordSize; |
| 335 | } |
| 336 | |
| 337 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 338 | arm_codegen->GetAssembler()->StoreRegisterList(core_spills, orig_offset); |
| 339 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 340 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 341 | orig_offset = stack_offset; |
| 342 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 343 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 344 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 345 | stack_offset += kArmWordSize; |
| 346 | } |
| 347 | |
| 348 | stack_offset = orig_offset; |
| 349 | while (fp_spills != 0u) { |
| 350 | uint32_t begin = CTZ(fp_spills); |
| 351 | uint32_t tmp = fp_spills + (1u << begin); |
| 352 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 353 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 354 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 355 | } |
| 356 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 357 | } |
| 358 | |
| 359 | void SlowPathCodeARMVIXL::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 360 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 361 | size_t orig_offset = stack_offset; |
| 362 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 363 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 364 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 365 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 366 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 367 | stack_offset += kArmWordSize; |
| 368 | } |
| 369 | |
| 370 | // TODO(VIXL): Check the coherency of stack_offset after this with a test. |
| 371 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 372 | arm_codegen->GetAssembler()->LoadRegisterList(core_spills, orig_offset); |
| 373 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 374 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 375 | while (fp_spills != 0u) { |
| 376 | uint32_t begin = CTZ(fp_spills); |
| 377 | uint32_t tmp = fp_spills + (1u << begin); |
| 378 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 379 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 380 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 381 | } |
| 382 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 383 | } |
| 384 | |
| 385 | class NullCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 386 | public: |
| 387 | explicit NullCheckSlowPathARMVIXL(HNullCheck* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 388 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 389 | void EmitNativeCode(CodeGenerator* codegen) override { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 390 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 391 | __ Bind(GetEntryLabel()); |
| 392 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 393 | // Live registers will be restored in the catch block if caught. |
| 394 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 395 | } |
| 396 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 397 | instruction_, |
| 398 | instruction_->GetDexPc(), |
| 399 | this); |
| 400 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 401 | } |
| 402 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 403 | bool IsFatal() const override { return true; } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 404 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 405 | const char* GetDescription() const override { return "NullCheckSlowPathARMVIXL"; } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 406 | |
| 407 | private: |
| 408 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARMVIXL); |
| 409 | }; |
| 410 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 411 | class DivZeroCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 412 | public: |
| 413 | explicit DivZeroCheckSlowPathARMVIXL(HDivZeroCheck* instruction) |
| 414 | : SlowPathCodeARMVIXL(instruction) {} |
| 415 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 416 | void EmitNativeCode(CodeGenerator* codegen) override { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 417 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 418 | __ Bind(GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 419 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 420 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 421 | } |
| 422 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 423 | bool IsFatal() const override { return true; } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 424 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 425 | const char* GetDescription() const override { return "DivZeroCheckSlowPathARMVIXL"; } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 426 | |
| 427 | private: |
| 428 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARMVIXL); |
| 429 | }; |
| 430 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 431 | class SuspendCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 432 | public: |
| 433 | SuspendCheckSlowPathARMVIXL(HSuspendCheck* instruction, HBasicBlock* successor) |
| 434 | : SlowPathCodeARMVIXL(instruction), successor_(successor) {} |
| 435 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 436 | void EmitNativeCode(CodeGenerator* codegen) override { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 437 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 438 | __ Bind(GetEntryLabel()); |
| 439 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| 440 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| 441 | if (successor_ == nullptr) { |
| 442 | __ B(GetReturnLabel()); |
| 443 | } else { |
| 444 | __ B(arm_codegen->GetLabelOf(successor_)); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | vixl32::Label* GetReturnLabel() { |
| 449 | DCHECK(successor_ == nullptr); |
| 450 | return &return_label_; |
| 451 | } |
| 452 | |
| 453 | HBasicBlock* GetSuccessor() const { |
| 454 | return successor_; |
| 455 | } |
| 456 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 457 | const char* GetDescription() const override { return "SuspendCheckSlowPathARMVIXL"; } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 458 | |
| 459 | private: |
| 460 | // If not null, the block to branch to after the suspend check. |
| 461 | HBasicBlock* const successor_; |
| 462 | |
| 463 | // If `successor_` is null, the label to branch to after the suspend check. |
| 464 | vixl32::Label return_label_; |
| 465 | |
| 466 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARMVIXL); |
| 467 | }; |
| 468 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 469 | class BoundsCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 470 | public: |
| 471 | explicit BoundsCheckSlowPathARMVIXL(HBoundsCheck* instruction) |
| 472 | : SlowPathCodeARMVIXL(instruction) {} |
| 473 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 474 | void EmitNativeCode(CodeGenerator* codegen) override { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 475 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 476 | LocationSummary* locations = instruction_->GetLocations(); |
| 477 | |
| 478 | __ Bind(GetEntryLabel()); |
| 479 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 480 | // Live registers will be restored in the catch block if caught. |
| 481 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 482 | } |
| 483 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 484 | // move resolver. |
| 485 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 486 | codegen->EmitParallelMoves( |
| 487 | locations->InAt(0), |
| 488 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 489 | DataType::Type::kInt32, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 490 | locations->InAt(1), |
| 491 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 492 | DataType::Type::kInt32); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 493 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 494 | ? kQuickThrowStringBounds |
| 495 | : kQuickThrowArrayBounds; |
| 496 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| 497 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| 498 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 499 | } |
| 500 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 501 | bool IsFatal() const override { return true; } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 502 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 503 | const char* GetDescription() const override { return "BoundsCheckSlowPathARMVIXL"; } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 504 | |
| 505 | private: |
| 506 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARMVIXL); |
| 507 | }; |
| 508 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 509 | class LoadClassSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 510 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 511 | LoadClassSlowPathARMVIXL(HLoadClass* cls, HInstruction* at) |
| 512 | : SlowPathCodeARMVIXL(at), cls_(cls) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 513 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 514 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 515 | } |
| 516 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 517 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 518 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 519 | Location out = locations->Out(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 520 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 521 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 522 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 523 | |
| 524 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 525 | __ Bind(GetEntryLabel()); |
| 526 | SaveLiveRegisters(codegen, locations); |
| 527 | |
| 528 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 529 | if (must_resolve_type) { |
| 530 | DCHECK(IsSameDexFile(cls_->GetDexFile(), arm_codegen->GetGraph()->GetDexFile())); |
| 531 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 532 | __ Mov(calling_convention.GetRegisterAt(0), type_index.index_); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 533 | if (cls_->NeedsAccessCheck()) { |
| 534 | CheckEntrypointTypes<kQuickResolveTypeAndVerifyAccess, void*, uint32_t>(); |
| 535 | arm_codegen->InvokeRuntime(kQuickResolveTypeAndVerifyAccess, instruction_, dex_pc, this); |
| 536 | } else { |
| 537 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| 538 | arm_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 539 | } |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 540 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 541 | } else { |
| 542 | DCHECK(must_do_clinit); |
| 543 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 544 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), source); |
| 545 | } |
| 546 | if (must_do_clinit) { |
| 547 | arm_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 548 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | // Move the class to the desired location. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 552 | if (out.IsValid()) { |
| 553 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 554 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 555 | } |
| 556 | RestoreLiveRegisters(codegen, locations); |
| 557 | __ B(GetExitLabel()); |
| 558 | } |
| 559 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 560 | const char* GetDescription() const override { return "LoadClassSlowPathARMVIXL"; } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 561 | |
| 562 | private: |
| 563 | // The class this slow path will load. |
| 564 | HLoadClass* const cls_; |
| 565 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 566 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARMVIXL); |
| 567 | }; |
| 568 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 569 | class LoadStringSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 570 | public: |
| 571 | explicit LoadStringSlowPathARMVIXL(HLoadString* instruction) |
| 572 | : SlowPathCodeARMVIXL(instruction) {} |
| 573 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 574 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 575 | DCHECK(instruction_->IsLoadString()); |
| 576 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 577 | LocationSummary* locations = instruction_->GetLocations(); |
| 578 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 579 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 580 | |
| 581 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 582 | __ Bind(GetEntryLabel()); |
| 583 | SaveLiveRegisters(codegen, locations); |
| 584 | |
| 585 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 586 | __ Mov(calling_convention.GetRegisterAt(0), string_index.index_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 587 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 588 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 589 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 590 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 591 | RestoreLiveRegisters(codegen, locations); |
| 592 | |
| 593 | __ B(GetExitLabel()); |
| 594 | } |
| 595 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 596 | const char* GetDescription() const override { return "LoadStringSlowPathARMVIXL"; } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 597 | |
| 598 | private: |
| 599 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARMVIXL); |
| 600 | }; |
| 601 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 602 | class TypeCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 603 | public: |
| 604 | TypeCheckSlowPathARMVIXL(HInstruction* instruction, bool is_fatal) |
| 605 | : SlowPathCodeARMVIXL(instruction), is_fatal_(is_fatal) {} |
| 606 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 607 | void EmitNativeCode(CodeGenerator* codegen) override { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 608 | LocationSummary* locations = instruction_->GetLocations(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 609 | DCHECK(instruction_->IsCheckCast() |
| 610 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 611 | |
| 612 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 613 | __ Bind(GetEntryLabel()); |
| 614 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 615 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 616 | SaveLiveRegisters(codegen, locations); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 620 | // move resolver. |
| 621 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 622 | |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 623 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 624 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 625 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 626 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 627 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 628 | DataType::Type::kReference); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 629 | if (instruction_->IsInstanceOf()) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 630 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
| 631 | instruction_, |
| 632 | instruction_->GetDexPc(), |
| 633 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 634 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 635 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 636 | } else { |
| 637 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 638 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 639 | instruction_, |
| 640 | instruction_->GetDexPc(), |
| 641 | this); |
| 642 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | if (!is_fatal_) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 646 | RestoreLiveRegisters(codegen, locations); |
| 647 | __ B(GetExitLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 651 | const char* GetDescription() const override { return "TypeCheckSlowPathARMVIXL"; } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 652 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 653 | bool IsFatal() const override { return is_fatal_; } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 654 | |
| 655 | private: |
| 656 | const bool is_fatal_; |
| 657 | |
| 658 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARMVIXL); |
| 659 | }; |
| 660 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 661 | class DeoptimizationSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 662 | public: |
| 663 | explicit DeoptimizationSlowPathARMVIXL(HDeoptimize* instruction) |
| 664 | : SlowPathCodeARMVIXL(instruction) {} |
| 665 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 666 | void EmitNativeCode(CodeGenerator* codegen) override { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 667 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 668 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 669 | LocationSummary* locations = instruction_->GetLocations(); |
| 670 | SaveLiveRegisters(codegen, locations); |
| 671 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 672 | __ Mov(calling_convention.GetRegisterAt(0), |
| 673 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| 674 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 675 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 676 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 677 | } |
| 678 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 679 | const char* GetDescription() const override { return "DeoptimizationSlowPathARMVIXL"; } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 680 | |
| 681 | private: |
| 682 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARMVIXL); |
| 683 | }; |
| 684 | |
| 685 | class ArraySetSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 686 | public: |
| 687 | explicit ArraySetSlowPathARMVIXL(HInstruction* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 688 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 689 | void EmitNativeCode(CodeGenerator* codegen) override { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 690 | LocationSummary* locations = instruction_->GetLocations(); |
| 691 | __ Bind(GetEntryLabel()); |
| 692 | SaveLiveRegisters(codegen, locations); |
| 693 | |
| 694 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 695 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 696 | parallel_move.AddMove( |
| 697 | locations->InAt(0), |
| 698 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 699 | DataType::Type::kReference, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 700 | nullptr); |
| 701 | parallel_move.AddMove( |
| 702 | locations->InAt(1), |
| 703 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 704 | DataType::Type::kInt32, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 705 | nullptr); |
| 706 | parallel_move.AddMove( |
| 707 | locations->InAt(2), |
| 708 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 709 | DataType::Type::kReference, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 710 | nullptr); |
| 711 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 712 | |
| 713 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 714 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 715 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 716 | RestoreLiveRegisters(codegen, locations); |
| 717 | __ B(GetExitLabel()); |
| 718 | } |
| 719 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 720 | const char* GetDescription() const override { return "ArraySetSlowPathARMVIXL"; } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 721 | |
| 722 | private: |
| 723 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARMVIXL); |
| 724 | }; |
| 725 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 726 | // Slow path generating a read barrier for a heap reference. |
| 727 | class ReadBarrierForHeapReferenceSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 728 | public: |
| 729 | ReadBarrierForHeapReferenceSlowPathARMVIXL(HInstruction* instruction, |
| 730 | Location out, |
| 731 | Location ref, |
| 732 | Location obj, |
| 733 | uint32_t offset, |
| 734 | Location index) |
| 735 | : SlowPathCodeARMVIXL(instruction), |
| 736 | out_(out), |
| 737 | ref_(ref), |
| 738 | obj_(obj), |
| 739 | offset_(offset), |
| 740 | index_(index) { |
| 741 | DCHECK(kEmitCompilerReadBarrier); |
| 742 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 743 | // has been overwritten by (or after) the heap object reference load |
| 744 | // to be instrumented, e.g.: |
| 745 | // |
| 746 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 747 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 748 | // |
| 749 | // In that case, we have lost the information about the original |
| 750 | // object, and the emitted read barrier cannot work properly. |
| 751 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 752 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 753 | } |
| 754 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 755 | void EmitNativeCode(CodeGenerator* codegen) override { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 756 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 757 | LocationSummary* locations = instruction_->GetLocations(); |
| 758 | vixl32::Register reg_out = RegisterFrom(out_); |
| 759 | DCHECK(locations->CanCall()); |
| 760 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 761 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 762 | instruction_->IsStaticFieldGet() || |
| 763 | instruction_->IsArrayGet() || |
| 764 | instruction_->IsInstanceOf() || |
| 765 | instruction_->IsCheckCast() || |
Vladimir Marko | 94d2c81 | 2020-11-05 10:04:45 +0000 | [diff] [blame] | 766 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 767 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 768 | << instruction_->DebugName(); |
| 769 | // The read barrier instrumentation of object ArrayGet |
| 770 | // instructions does not support the HIntermediateAddress |
| 771 | // instruction. |
| 772 | DCHECK(!(instruction_->IsArrayGet() && |
| 773 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 774 | |
| 775 | __ Bind(GetEntryLabel()); |
| 776 | SaveLiveRegisters(codegen, locations); |
| 777 | |
| 778 | // We may have to change the index's value, but as `index_` is a |
| 779 | // constant member (like other "inputs" of this slow path), |
| 780 | // introduce a copy of it, `index`. |
| 781 | Location index = index_; |
| 782 | if (index_.IsValid()) { |
| 783 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 784 | if (instruction_->IsArrayGet()) { |
| 785 | // Compute the actual memory offset and store it in `index`. |
| 786 | vixl32::Register index_reg = RegisterFrom(index_); |
| 787 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg.GetCode())); |
| 788 | if (codegen->IsCoreCalleeSaveRegister(index_reg.GetCode())) { |
| 789 | // We are about to change the value of `index_reg` (see the |
Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 790 | // calls to art::arm::ArmVIXLMacroAssembler::Lsl and |
| 791 | // art::arm::ArmVIXLMacroAssembler::Add below), but it has |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 792 | // not been saved by the previous call to |
| 793 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 794 | // callee-save register -- |
| 795 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 796 | // callee-save registers, as it has been designed with the |
| 797 | // assumption that callee-save registers are supposed to be |
| 798 | // handled by the called function. So, as a callee-save |
| 799 | // register, `index_reg` _would_ eventually be saved onto |
| 800 | // the stack, but it would be too late: we would have |
| 801 | // changed its value earlier. Therefore, we manually save |
| 802 | // it here into another freely available register, |
| 803 | // `free_reg`, chosen of course among the caller-save |
| 804 | // registers (as a callee-save `free_reg` register would |
| 805 | // exhibit the same problem). |
| 806 | // |
| 807 | // Note we could have requested a temporary register from |
| 808 | // the register allocator instead; but we prefer not to, as |
| 809 | // this is a slow path, and we know we can find a |
| 810 | // caller-save register that is available. |
| 811 | vixl32::Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 812 | __ Mov(free_reg, index_reg); |
| 813 | index_reg = free_reg; |
| 814 | index = LocationFrom(index_reg); |
| 815 | } else { |
| 816 | // The initial register stored in `index_` has already been |
| 817 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 818 | // (as it is not a callee-save register), so we can freely |
| 819 | // use it. |
| 820 | } |
| 821 | // Shifting the index value contained in `index_reg` by the scale |
| 822 | // factor (2) cannot overflow in practice, as the runtime is |
| 823 | // unable to allocate object arrays with a size larger than |
| 824 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 825 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 826 | static_assert( |
| 827 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 828 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 829 | __ Add(index_reg, index_reg, offset_); |
| 830 | } else { |
| 831 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 832 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 833 | // (as in the case of ArrayGet), as it is actually an offset |
| 834 | // to an object field within an object. |
| 835 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 836 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 837 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 838 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 839 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 840 | DCHECK_EQ(offset_, 0U); |
| 841 | DCHECK(index_.IsRegisterPair()); |
| 842 | // UnsafeGet's offset location is a register pair, the low |
| 843 | // part contains the correct offset. |
| 844 | index = index_.ToLow(); |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | // We're moving two or three locations to locations that could |
| 849 | // overlap, so we need a parallel move resolver. |
| 850 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 851 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 852 | parallel_move.AddMove(ref_, |
| 853 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 854 | DataType::Type::kReference, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 855 | nullptr); |
| 856 | parallel_move.AddMove(obj_, |
| 857 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 858 | DataType::Type::kReference, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 859 | nullptr); |
| 860 | if (index.IsValid()) { |
| 861 | parallel_move.AddMove(index, |
| 862 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 863 | DataType::Type::kInt32, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 864 | nullptr); |
| 865 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 866 | } else { |
| 867 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 868 | __ Mov(calling_convention.GetRegisterAt(2), offset_); |
| 869 | } |
| 870 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| 871 | CheckEntrypointTypes< |
| 872 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 873 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 874 | |
| 875 | RestoreLiveRegisters(codegen, locations); |
| 876 | __ B(GetExitLabel()); |
| 877 | } |
| 878 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 879 | const char* GetDescription() const override { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 880 | return "ReadBarrierForHeapReferenceSlowPathARMVIXL"; |
| 881 | } |
| 882 | |
| 883 | private: |
| 884 | vixl32::Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 885 | uint32_t ref = RegisterFrom(ref_).GetCode(); |
| 886 | uint32_t obj = RegisterFrom(obj_).GetCode(); |
| 887 | for (uint32_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 888 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 889 | return vixl32::Register(i); |
| 890 | } |
| 891 | } |
| 892 | // We shall never fail to find a free caller-save register, as |
| 893 | // there are more than two core caller-save registers on ARM |
| 894 | // (meaning it is possible to find one which is different from |
| 895 | // `ref` and `obj`). |
| 896 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 897 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 898 | UNREACHABLE(); |
| 899 | } |
| 900 | |
| 901 | const Location out_; |
| 902 | const Location ref_; |
| 903 | const Location obj_; |
| 904 | const uint32_t offset_; |
| 905 | // An additional location containing an index to an array. |
| 906 | // Only used for HArrayGet and the UnsafeGetObject & |
| 907 | // UnsafeGetObjectVolatile intrinsics. |
| 908 | const Location index_; |
| 909 | |
| 910 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARMVIXL); |
| 911 | }; |
| 912 | |
| 913 | // Slow path generating a read barrier for a GC root. |
| 914 | class ReadBarrierForRootSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 915 | public: |
| 916 | ReadBarrierForRootSlowPathARMVIXL(HInstruction* instruction, Location out, Location root) |
| 917 | : SlowPathCodeARMVIXL(instruction), out_(out), root_(root) { |
| 918 | DCHECK(kEmitCompilerReadBarrier); |
| 919 | } |
| 920 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 921 | void EmitNativeCode(CodeGenerator* codegen) override { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 922 | LocationSummary* locations = instruction_->GetLocations(); |
| 923 | vixl32::Register reg_out = RegisterFrom(out_); |
| 924 | DCHECK(locations->CanCall()); |
| 925 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 926 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 927 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 928 | << instruction_->DebugName(); |
| 929 | |
| 930 | __ Bind(GetEntryLabel()); |
| 931 | SaveLiveRegisters(codegen, locations); |
| 932 | |
| 933 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 934 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 935 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), root_); |
| 936 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 937 | instruction_, |
| 938 | instruction_->GetDexPc(), |
| 939 | this); |
| 940 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 941 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 942 | |
| 943 | RestoreLiveRegisters(codegen, locations); |
| 944 | __ B(GetExitLabel()); |
| 945 | } |
| 946 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 947 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathARMVIXL"; } |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 948 | |
| 949 | private: |
| 950 | const Location out_; |
| 951 | const Location root_; |
| 952 | |
| 953 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARMVIXL); |
| 954 | }; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 955 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 956 | inline vixl32::Condition ARMCondition(IfCondition cond) { |
| 957 | switch (cond) { |
| 958 | case kCondEQ: return eq; |
| 959 | case kCondNE: return ne; |
| 960 | case kCondLT: return lt; |
| 961 | case kCondLE: return le; |
| 962 | case kCondGT: return gt; |
| 963 | case kCondGE: return ge; |
| 964 | case kCondB: return lo; |
| 965 | case kCondBE: return ls; |
| 966 | case kCondA: return hi; |
| 967 | case kCondAE: return hs; |
| 968 | } |
| 969 | LOG(FATAL) << "Unreachable"; |
| 970 | UNREACHABLE(); |
| 971 | } |
| 972 | |
| 973 | // Maps signed condition to unsigned condition. |
| 974 | inline vixl32::Condition ARMUnsignedCondition(IfCondition cond) { |
| 975 | switch (cond) { |
| 976 | case kCondEQ: return eq; |
| 977 | case kCondNE: return ne; |
| 978 | // Signed to unsigned. |
| 979 | case kCondLT: return lo; |
| 980 | case kCondLE: return ls; |
| 981 | case kCondGT: return hi; |
| 982 | case kCondGE: return hs; |
| 983 | // Unsigned remain unchanged. |
| 984 | case kCondB: return lo; |
| 985 | case kCondBE: return ls; |
| 986 | case kCondA: return hi; |
| 987 | case kCondAE: return hs; |
| 988 | } |
| 989 | LOG(FATAL) << "Unreachable"; |
| 990 | UNREACHABLE(); |
| 991 | } |
| 992 | |
| 993 | inline vixl32::Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 994 | // The ARM condition codes can express all the necessary branches, see the |
| 995 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 996 | // There is no dex instruction or HIR that would need the missing conditions |
| 997 | // "equal or unordered" or "not equal". |
| 998 | switch (cond) { |
| 999 | case kCondEQ: return eq; |
| 1000 | case kCondNE: return ne /* unordered */; |
| 1001 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 1002 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 1003 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 1004 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 1005 | default: |
| 1006 | LOG(FATAL) << "UNREACHABLE"; |
| 1007 | UNREACHABLE(); |
| 1008 | } |
| 1009 | } |
| 1010 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1011 | inline ShiftType ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1012 | switch (op_kind) { |
| 1013 | case HDataProcWithShifterOp::kASR: return ShiftType::ASR; |
| 1014 | case HDataProcWithShifterOp::kLSL: return ShiftType::LSL; |
| 1015 | case HDataProcWithShifterOp::kLSR: return ShiftType::LSR; |
| 1016 | default: |
| 1017 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1018 | UNREACHABLE(); |
| 1019 | } |
| 1020 | } |
| 1021 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1022 | void CodeGeneratorARMVIXL::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 1023 | stream << vixl32::Register(reg); |
| 1024 | } |
| 1025 | |
| 1026 | void CodeGeneratorARMVIXL::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 1027 | stream << vixl32::SRegister(reg); |
| 1028 | } |
| 1029 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1030 | const ArmInstructionSetFeatures& CodeGeneratorARMVIXL::GetInstructionSetFeatures() const { |
| 1031 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArmInstructionSetFeatures(); |
| 1032 | } |
| 1033 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1034 | static uint32_t ComputeSRegisterListMask(const SRegisterList& regs) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1035 | uint32_t mask = 0; |
| 1036 | for (uint32_t i = regs.GetFirstSRegister().GetCode(); |
| 1037 | i <= regs.GetLastSRegister().GetCode(); |
| 1038 | ++i) { |
| 1039 | mask |= (1 << i); |
| 1040 | } |
| 1041 | return mask; |
| 1042 | } |
| 1043 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1044 | // Saves the register in the stack. Returns the size taken on stack. |
| 1045 | size_t CodeGeneratorARMVIXL::SaveCoreRegister(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 | // Restores the register from the stack. Returns the size taken on stack. |
| 1052 | size_t CodeGeneratorARMVIXL::RestoreCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1053 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1054 | TODO_VIXL32(FATAL); |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1055 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | size_t CodeGeneratorARMVIXL::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1059 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1060 | TODO_VIXL32(FATAL); |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1061 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | size_t CodeGeneratorARMVIXL::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1065 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1066 | TODO_VIXL32(FATAL); |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1067 | UNREACHABLE(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 1068 | } |
| 1069 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1070 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1071 | vixl32::Register out, |
| 1072 | vixl32::Register first, |
| 1073 | const Operand& second, |
| 1074 | CodeGeneratorARMVIXL* codegen) { |
| 1075 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1076 | const Operand in = kind == HInstruction::kAnd |
| 1077 | ? Operand(0) |
| 1078 | : Operand(first); |
| 1079 | |
| 1080 | __ Mov(out, in); |
| 1081 | } else { |
| 1082 | switch (kind) { |
| 1083 | case HInstruction::kAdd: |
| 1084 | __ Add(out, first, second); |
| 1085 | break; |
| 1086 | case HInstruction::kAnd: |
| 1087 | __ And(out, first, second); |
| 1088 | break; |
| 1089 | case HInstruction::kOr: |
| 1090 | __ Orr(out, first, second); |
| 1091 | break; |
| 1092 | case HInstruction::kSub: |
| 1093 | __ Sub(out, first, second); |
| 1094 | break; |
| 1095 | case HInstruction::kXor: |
| 1096 | __ Eor(out, first, second); |
| 1097 | break; |
| 1098 | default: |
| 1099 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1100 | UNREACHABLE(); |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1106 | const Location& out, |
| 1107 | const Location& first, |
| 1108 | const Operand& second_lo, |
| 1109 | const Operand& second_hi, |
| 1110 | CodeGeneratorARMVIXL* codegen) { |
| 1111 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1112 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1113 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1114 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1115 | |
| 1116 | if (kind == HInstruction::kAdd) { |
| 1117 | __ Adds(out_lo, first_lo, second_lo); |
| 1118 | __ Adc(out_hi, first_hi, second_hi); |
| 1119 | } else if (kind == HInstruction::kSub) { |
| 1120 | __ Subs(out_lo, first_lo, second_lo); |
| 1121 | __ Sbc(out_hi, first_hi, second_hi); |
| 1122 | } else { |
| 1123 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1124 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | static Operand GetShifterOperand(vixl32::Register rm, ShiftType shift, uint32_t shift_imm) { |
| 1129 | return shift_imm == 0 ? Operand(rm) : Operand(rm, shift, shift_imm); |
| 1130 | } |
| 1131 | |
| 1132 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, |
| 1133 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1134 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1135 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1136 | |
| 1137 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1138 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1139 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1140 | const Location first = locations->InAt(0); |
| 1141 | const Location second = locations->InAt(1); |
| 1142 | const Location out = locations->Out(); |
| 1143 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1144 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1145 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1146 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1147 | const vixl32::Register second_hi = HighRegisterFrom(second); |
| 1148 | const vixl32::Register second_lo = LowRegisterFrom(second); |
| 1149 | const ShiftType shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1150 | |
| 1151 | if (shift_value >= 32) { |
| 1152 | if (shift == ShiftType::LSL) { |
| 1153 | GenerateDataProcInstruction(kind, |
| 1154 | out_hi, |
| 1155 | first_hi, |
| 1156 | Operand(second_lo, ShiftType::LSL, shift_value - 32), |
| 1157 | codegen); |
| 1158 | GenerateDataProcInstruction(kind, out_lo, first_lo, 0, codegen); |
| 1159 | } else if (shift == ShiftType::ASR) { |
| 1160 | GenerateDataProc(kind, |
| 1161 | out, |
| 1162 | first, |
| 1163 | GetShifterOperand(second_hi, ShiftType::ASR, shift_value - 32), |
| 1164 | Operand(second_hi, ShiftType::ASR, 31), |
| 1165 | codegen); |
| 1166 | } else { |
| 1167 | DCHECK_EQ(shift, ShiftType::LSR); |
| 1168 | GenerateDataProc(kind, |
| 1169 | out, |
| 1170 | first, |
| 1171 | GetShifterOperand(second_hi, ShiftType::LSR, shift_value - 32), |
| 1172 | 0, |
| 1173 | codegen); |
| 1174 | } |
| 1175 | } else { |
| 1176 | DCHECK_GT(shift_value, 1U); |
| 1177 | DCHECK_LT(shift_value, 32U); |
| 1178 | |
| 1179 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1180 | |
| 1181 | if (shift == ShiftType::LSL) { |
| 1182 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1183 | // Location::kOutputOverlap; not applicable to other cases. |
| 1184 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1185 | GenerateDataProcInstruction(kind, |
| 1186 | out_hi, |
| 1187 | first_hi, |
| 1188 | Operand(second_hi, ShiftType::LSL, shift_value), |
| 1189 | codegen); |
| 1190 | GenerateDataProcInstruction(kind, |
| 1191 | out_hi, |
| 1192 | out_hi, |
| 1193 | Operand(second_lo, ShiftType::LSR, 32 - shift_value), |
| 1194 | codegen); |
| 1195 | GenerateDataProcInstruction(kind, |
| 1196 | out_lo, |
| 1197 | first_lo, |
| 1198 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1199 | codegen); |
| 1200 | } else { |
| 1201 | const vixl32::Register temp = temps.Acquire(); |
| 1202 | |
| 1203 | __ Lsl(temp, second_hi, shift_value); |
| 1204 | __ Orr(temp, temp, Operand(second_lo, ShiftType::LSR, 32 - shift_value)); |
| 1205 | GenerateDataProc(kind, |
| 1206 | out, |
| 1207 | first, |
| 1208 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1209 | temp, |
| 1210 | codegen); |
| 1211 | } |
| 1212 | } else { |
| 1213 | DCHECK(shift == ShiftType::ASR || shift == ShiftType::LSR); |
| 1214 | |
| 1215 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1216 | // Location::kOutputOverlap; not applicable to other cases. |
| 1217 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1218 | GenerateDataProcInstruction(kind, |
| 1219 | out_lo, |
| 1220 | first_lo, |
| 1221 | Operand(second_lo, ShiftType::LSR, shift_value), |
| 1222 | codegen); |
| 1223 | GenerateDataProcInstruction(kind, |
| 1224 | out_lo, |
| 1225 | out_lo, |
| 1226 | Operand(second_hi, ShiftType::LSL, 32 - shift_value), |
| 1227 | codegen); |
| 1228 | GenerateDataProcInstruction(kind, |
| 1229 | out_hi, |
| 1230 | first_hi, |
| 1231 | Operand(second_hi, shift, shift_value), |
| 1232 | codegen); |
| 1233 | } else { |
| 1234 | const vixl32::Register temp = temps.Acquire(); |
| 1235 | |
| 1236 | __ Lsr(temp, second_lo, shift_value); |
| 1237 | __ Orr(temp, temp, Operand(second_hi, ShiftType::LSL, 32 - shift_value)); |
| 1238 | GenerateDataProc(kind, |
| 1239 | out, |
| 1240 | first, |
| 1241 | temp, |
| 1242 | Operand(second_hi, shift, shift_value), |
| 1243 | codegen); |
| 1244 | } |
| 1245 | } |
| 1246 | } |
| 1247 | } |
| 1248 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1249 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARMVIXL* codegen) { |
| 1250 | const Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1251 | if (rhs_loc.IsConstant()) { |
| 1252 | // 0.0 is the only immediate that can be encoded directly in |
| 1253 | // a VCMP instruction. |
| 1254 | // |
| 1255 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1256 | // specify that in a floating-point comparison, positive zero |
| 1257 | // and negative zero are considered equal, so we can use the |
| 1258 | // literal 0.0 for both cases here. |
| 1259 | // |
| 1260 | // Note however that some methods (Float.equal, Float.compare, |
| 1261 | // Float.compareTo, Double.equal, Double.compare, |
| 1262 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1263 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1264 | // -0.0. So if we ever translate calls to these methods into a |
| 1265 | // HCompare instruction, we must handle the -0.0 case with |
| 1266 | // care here. |
| 1267 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1268 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1269 | const DataType::Type type = instruction->InputAt(0)->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1270 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1271 | if (type == DataType::Type::kFloat32) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1272 | __ Vcmp(F32, InputSRegisterAt(instruction, 0), 0.0); |
| 1273 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1274 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1275 | __ Vcmp(F64, InputDRegisterAt(instruction, 0), 0.0); |
| 1276 | } |
| 1277 | } else { |
| 1278 | __ Vcmp(InputVRegisterAt(instruction, 0), InputVRegisterAt(instruction, 1)); |
| 1279 | } |
| 1280 | } |
| 1281 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1282 | static int64_t AdjustConstantForCondition(int64_t value, |
| 1283 | IfCondition* condition, |
| 1284 | IfCondition* opposite) { |
| 1285 | if (value == 1) { |
| 1286 | if (*condition == kCondB) { |
| 1287 | value = 0; |
| 1288 | *condition = kCondEQ; |
| 1289 | *opposite = kCondNE; |
| 1290 | } else if (*condition == kCondAE) { |
| 1291 | value = 0; |
| 1292 | *condition = kCondNE; |
| 1293 | *opposite = kCondEQ; |
| 1294 | } |
| 1295 | } else if (value == -1) { |
| 1296 | if (*condition == kCondGT) { |
| 1297 | value = 0; |
| 1298 | *condition = kCondGE; |
| 1299 | *opposite = kCondLT; |
| 1300 | } else if (*condition == kCondLE) { |
| 1301 | value = 0; |
| 1302 | *condition = kCondLT; |
| 1303 | *opposite = kCondGE; |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | return value; |
| 1308 | } |
| 1309 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1310 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTestConstant( |
| 1311 | HCondition* condition, |
| 1312 | bool invert, |
| 1313 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1314 | DCHECK_EQ(condition->GetLeft()->GetType(), DataType::Type::kInt64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1315 | |
| 1316 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1317 | IfCondition cond = condition->GetCondition(); |
| 1318 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1319 | |
| 1320 | if (invert) { |
| 1321 | std::swap(cond, opposite); |
| 1322 | } |
| 1323 | |
| 1324 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1325 | const Location left = locations->InAt(0); |
| 1326 | const Location right = locations->InAt(1); |
| 1327 | |
| 1328 | DCHECK(right.IsConstant()); |
| 1329 | |
| 1330 | const vixl32::Register left_high = HighRegisterFrom(left); |
| 1331 | const vixl32::Register left_low = LowRegisterFrom(left); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1332 | int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), &cond, &opposite); |
| 1333 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1334 | |
| 1335 | // Comparisons against 0 are common enough to deserve special attention. |
| 1336 | if (value == 0) { |
| 1337 | switch (cond) { |
| 1338 | case kCondNE: |
| 1339 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 1340 | case kCondA: |
| 1341 | ret = std::make_pair(ne, eq); |
| 1342 | FALLTHROUGH_INTENDED; |
| 1343 | case kCondEQ: |
| 1344 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 1345 | case kCondBE: |
| 1346 | __ Orrs(temps.Acquire(), left_low, left_high); |
| 1347 | return ret; |
| 1348 | case kCondLT: |
| 1349 | case kCondGE: |
| 1350 | __ Cmp(left_high, 0); |
| 1351 | return std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| 1352 | // Trivially true or false. |
| 1353 | case kCondB: |
| 1354 | ret = std::make_pair(ne, eq); |
| 1355 | FALLTHROUGH_INTENDED; |
| 1356 | case kCondAE: |
| 1357 | __ Cmp(left_low, left_low); |
| 1358 | return ret; |
| 1359 | default: |
| 1360 | break; |
| 1361 | } |
| 1362 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1363 | |
| 1364 | switch (cond) { |
| 1365 | case kCondEQ: |
| 1366 | case kCondNE: |
| 1367 | case kCondB: |
| 1368 | case kCondBE: |
| 1369 | case kCondA: |
| 1370 | case kCondAE: { |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1371 | const uint32_t value_low = Low32Bits(value); |
| 1372 | Operand operand_low(value_low); |
| 1373 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1374 | __ Cmp(left_high, High32Bits(value)); |
| 1375 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1376 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1377 | // we must ensure that the operands corresponding to the least significant |
| 1378 | // halves of the inputs fit into a 16-bit CMP encoding. |
| 1379 | if (!left_low.IsLow() || !IsUint<8>(value_low)) { |
| 1380 | operand_low = Operand(temps.Acquire()); |
| 1381 | __ Mov(LeaveFlags, operand_low.GetBaseRegister(), value_low); |
| 1382 | } |
| 1383 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1384 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1385 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1386 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1387 | CodeBufferCheckScope::kExactSize); |
| 1388 | |
| 1389 | __ it(eq); |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1390 | __ cmp(eq, left_low, operand_low); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1391 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1392 | break; |
| 1393 | } |
| 1394 | case kCondLE: |
| 1395 | case kCondGT: |
| 1396 | // Trivially true or false. |
| 1397 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1398 | __ Cmp(left_low, left_low); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1399 | 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] | 1400 | break; |
| 1401 | } |
| 1402 | |
| 1403 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1404 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1405 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1406 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1407 | } else { |
| 1408 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1409 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1410 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1411 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | value++; |
| 1415 | FALLTHROUGH_INTENDED; |
| 1416 | case kCondGE: |
| 1417 | case kCondLT: { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1418 | __ Cmp(left_low, Low32Bits(value)); |
| 1419 | __ Sbcs(temps.Acquire(), left_high, High32Bits(value)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1420 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1421 | break; |
| 1422 | } |
| 1423 | default: |
| 1424 | LOG(FATAL) << "Unreachable"; |
| 1425 | UNREACHABLE(); |
| 1426 | } |
| 1427 | |
| 1428 | return ret; |
| 1429 | } |
| 1430 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1431 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTest( |
| 1432 | HCondition* condition, |
| 1433 | bool invert, |
| 1434 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1435 | DCHECK_EQ(condition->GetLeft()->GetType(), DataType::Type::kInt64); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1436 | |
| 1437 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1438 | IfCondition cond = condition->GetCondition(); |
| 1439 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1440 | |
| 1441 | if (invert) { |
| 1442 | std::swap(cond, opposite); |
| 1443 | } |
| 1444 | |
| 1445 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1446 | Location left = locations->InAt(0); |
| 1447 | Location right = locations->InAt(1); |
| 1448 | |
| 1449 | DCHECK(right.IsRegisterPair()); |
| 1450 | |
| 1451 | switch (cond) { |
| 1452 | case kCondEQ: |
| 1453 | case kCondNE: |
| 1454 | case kCondB: |
| 1455 | case kCondBE: |
| 1456 | case kCondA: |
| 1457 | case kCondAE: { |
| 1458 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); |
| 1459 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1460 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1461 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1462 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1463 | CodeBufferCheckScope::kExactSize); |
| 1464 | |
| 1465 | __ it(eq); |
| 1466 | __ cmp(eq, LowRegisterFrom(left), LowRegisterFrom(right)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1467 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1468 | break; |
| 1469 | } |
| 1470 | case kCondLE: |
| 1471 | case kCondGT: |
| 1472 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1473 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1474 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1475 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1476 | } else { |
| 1477 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1478 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1479 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1480 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | std::swap(left, right); |
| 1484 | FALLTHROUGH_INTENDED; |
| 1485 | case kCondGE: |
| 1486 | case kCondLT: { |
| 1487 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1488 | |
| 1489 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); |
| 1490 | __ Sbcs(temps.Acquire(), HighRegisterFrom(left), HighRegisterFrom(right)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1491 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1492 | break; |
| 1493 | } |
| 1494 | default: |
| 1495 | LOG(FATAL) << "Unreachable"; |
| 1496 | UNREACHABLE(); |
| 1497 | } |
| 1498 | |
| 1499 | return ret; |
| 1500 | } |
| 1501 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1502 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateTest(HCondition* condition, |
| 1503 | bool invert, |
| 1504 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1505 | const DataType::Type type = condition->GetLeft()->GetType(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1506 | IfCondition cond = condition->GetCondition(); |
| 1507 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1508 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1509 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1510 | if (invert) { |
| 1511 | std::swap(cond, opposite); |
| 1512 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1513 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1514 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1515 | ret = condition->GetLocations()->InAt(1).IsConstant() |
| 1516 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 1517 | : GenerateLongTest(condition, invert, codegen); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1518 | } else if (DataType::IsFloatingPointType(type)) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1519 | GenerateVcmp(condition, codegen); |
| 1520 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 1521 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 1522 | ARMFPCondition(opposite, condition->IsGtBias())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1523 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1524 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1525 | __ Cmp(InputRegisterAt(condition, 0), InputOperandAt(condition, 1)); |
| 1526 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | return ret; |
| 1530 | } |
| 1531 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1532 | static void GenerateConditionGeneric(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1533 | const vixl32::Register out = OutputRegister(cond); |
| 1534 | const auto condition = GenerateTest(cond, false, codegen); |
| 1535 | |
| 1536 | __ Mov(LeaveFlags, out, 0); |
| 1537 | |
| 1538 | if (out.IsLow()) { |
| 1539 | // We use the scope because of the IT block that follows. |
| 1540 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1541 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1542 | CodeBufferCheckScope::kExactSize); |
| 1543 | |
| 1544 | __ it(condition.first); |
| 1545 | __ mov(condition.first, out, 1); |
| 1546 | } else { |
| 1547 | vixl32::Label done_label; |
| 1548 | vixl32::Label* const final_label = codegen->GetFinalLabel(cond, &done_label); |
| 1549 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1550 | __ B(condition.second, final_label, /* is_far_target= */ false); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1551 | __ Mov(out, 1); |
| 1552 | |
| 1553 | if (done_label.IsReferenced()) { |
| 1554 | __ Bind(&done_label); |
| 1555 | } |
| 1556 | } |
| 1557 | } |
| 1558 | |
| 1559 | static void GenerateEqualLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1560 | DCHECK_EQ(cond->GetLeft()->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1561 | |
| 1562 | const LocationSummary* const locations = cond->GetLocations(); |
| 1563 | IfCondition condition = cond->GetCondition(); |
| 1564 | const vixl32::Register out = OutputRegister(cond); |
| 1565 | const Location left = locations->InAt(0); |
| 1566 | const Location right = locations->InAt(1); |
| 1567 | vixl32::Register left_high = HighRegisterFrom(left); |
| 1568 | vixl32::Register left_low = LowRegisterFrom(left); |
| 1569 | vixl32::Register temp; |
| 1570 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1571 | |
| 1572 | if (right.IsConstant()) { |
| 1573 | IfCondition opposite = cond->GetOppositeCondition(); |
| 1574 | const int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), |
| 1575 | &condition, |
| 1576 | &opposite); |
| 1577 | Operand right_high = High32Bits(value); |
| 1578 | Operand right_low = Low32Bits(value); |
| 1579 | |
| 1580 | // The output uses Location::kNoOutputOverlap. |
| 1581 | if (out.Is(left_high)) { |
| 1582 | std::swap(left_low, left_high); |
| 1583 | std::swap(right_low, right_high); |
| 1584 | } |
| 1585 | |
| 1586 | __ Sub(out, left_low, right_low); |
| 1587 | temp = temps.Acquire(); |
| 1588 | __ Sub(temp, left_high, right_high); |
| 1589 | } else { |
| 1590 | DCHECK(right.IsRegisterPair()); |
| 1591 | temp = temps.Acquire(); |
| 1592 | __ Sub(temp, left_high, HighRegisterFrom(right)); |
| 1593 | __ Sub(out, left_low, LowRegisterFrom(right)); |
| 1594 | } |
| 1595 | |
| 1596 | // Need to check after calling AdjustConstantForCondition(). |
| 1597 | DCHECK(condition == kCondEQ || condition == kCondNE) << condition; |
| 1598 | |
| 1599 | if (condition == kCondNE && out.IsLow()) { |
| 1600 | __ Orrs(out, out, temp); |
| 1601 | |
| 1602 | // We use the scope because of the IT block that follows. |
| 1603 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1604 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1605 | CodeBufferCheckScope::kExactSize); |
| 1606 | |
| 1607 | __ it(ne); |
| 1608 | __ mov(ne, out, 1); |
| 1609 | } else { |
| 1610 | __ Orr(out, out, temp); |
| 1611 | codegen->GenerateConditionWithZero(condition, out, out, temp); |
| 1612 | } |
| 1613 | } |
| 1614 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1615 | static void GenerateConditionLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1616 | DCHECK_EQ(cond->GetLeft()->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1617 | |
| 1618 | const LocationSummary* const locations = cond->GetLocations(); |
| 1619 | IfCondition condition = cond->GetCondition(); |
| 1620 | const vixl32::Register out = OutputRegister(cond); |
| 1621 | const Location left = locations->InAt(0); |
| 1622 | const Location right = locations->InAt(1); |
| 1623 | |
| 1624 | if (right.IsConstant()) { |
| 1625 | IfCondition opposite = cond->GetOppositeCondition(); |
| 1626 | |
| 1627 | // Comparisons against 0 are common enough to deserve special attention. |
| 1628 | if (AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite) == 0) { |
| 1629 | switch (condition) { |
| 1630 | case kCondNE: |
| 1631 | case kCondA: |
| 1632 | if (out.IsLow()) { |
| 1633 | // We only care if both input registers are 0 or not. |
| 1634 | __ Orrs(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 1635 | |
| 1636 | // We use the scope because of the IT block that follows. |
| 1637 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1638 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1639 | CodeBufferCheckScope::kExactSize); |
| 1640 | |
| 1641 | __ it(ne); |
| 1642 | __ mov(ne, out, 1); |
| 1643 | return; |
| 1644 | } |
| 1645 | |
| 1646 | FALLTHROUGH_INTENDED; |
| 1647 | case kCondEQ: |
| 1648 | case kCondBE: |
| 1649 | // We only care if both input registers are 0 or not. |
| 1650 | __ Orr(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 1651 | codegen->GenerateConditionWithZero(condition, out, out); |
| 1652 | return; |
| 1653 | case kCondLT: |
| 1654 | case kCondGE: |
| 1655 | // We only care about the sign bit. |
| 1656 | FALLTHROUGH_INTENDED; |
| 1657 | case kCondAE: |
| 1658 | case kCondB: |
| 1659 | codegen->GenerateConditionWithZero(condition, out, HighRegisterFrom(left)); |
| 1660 | return; |
| 1661 | case kCondLE: |
| 1662 | case kCondGT: |
| 1663 | default: |
| 1664 | break; |
| 1665 | } |
| 1666 | } |
| 1667 | } |
| 1668 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1669 | // If `out` is a low register, then the GenerateConditionGeneric() |
| 1670 | // function generates a shorter code sequence that is still branchless. |
| 1671 | if ((condition == kCondEQ || condition == kCondNE) && !out.IsLow()) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1672 | GenerateEqualLong(cond, codegen); |
| 1673 | return; |
| 1674 | } |
| 1675 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1676 | GenerateConditionGeneric(cond, codegen); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1677 | } |
| 1678 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 1679 | static void GenerateConditionIntegralOrNonPrimitive(HCondition* cond, |
| 1680 | CodeGeneratorARMVIXL* codegen) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1681 | const DataType::Type type = cond->GetLeft()->GetType(); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1682 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1683 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1684 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1685 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1686 | GenerateConditionLong(cond, codegen); |
| 1687 | return; |
| 1688 | } |
| 1689 | |
| 1690 | IfCondition condition = cond->GetCondition(); |
| 1691 | vixl32::Register in = InputRegisterAt(cond, 0); |
| 1692 | const vixl32::Register out = OutputRegister(cond); |
| 1693 | const Location right = cond->GetLocations()->InAt(1); |
| 1694 | int64_t value; |
| 1695 | |
| 1696 | if (right.IsConstant()) { |
| 1697 | IfCondition opposite = cond->GetOppositeCondition(); |
| 1698 | |
| 1699 | value = AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite); |
| 1700 | |
| 1701 | // Comparisons against 0 are common enough to deserve special attention. |
| 1702 | if (value == 0) { |
| 1703 | switch (condition) { |
| 1704 | case kCondNE: |
| 1705 | case kCondA: |
| 1706 | if (out.IsLow() && out.Is(in)) { |
| 1707 | __ Cmp(out, 0); |
| 1708 | |
| 1709 | // We use the scope because of the IT block that follows. |
| 1710 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1711 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1712 | CodeBufferCheckScope::kExactSize); |
| 1713 | |
| 1714 | __ it(ne); |
| 1715 | __ mov(ne, out, 1); |
| 1716 | return; |
| 1717 | } |
| 1718 | |
| 1719 | FALLTHROUGH_INTENDED; |
| 1720 | case kCondEQ: |
| 1721 | case kCondBE: |
| 1722 | case kCondLT: |
| 1723 | case kCondGE: |
| 1724 | case kCondAE: |
| 1725 | case kCondB: |
| 1726 | codegen->GenerateConditionWithZero(condition, out, in); |
| 1727 | return; |
| 1728 | case kCondLE: |
| 1729 | case kCondGT: |
| 1730 | default: |
| 1731 | break; |
| 1732 | } |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | if (condition == kCondEQ || condition == kCondNE) { |
| 1737 | Operand operand(0); |
| 1738 | |
| 1739 | if (right.IsConstant()) { |
| 1740 | operand = Operand::From(value); |
| 1741 | } else if (out.Is(RegisterFrom(right))) { |
| 1742 | // Avoid 32-bit instructions if possible. |
| 1743 | operand = InputOperandAt(cond, 0); |
| 1744 | in = RegisterFrom(right); |
| 1745 | } else { |
| 1746 | operand = InputOperandAt(cond, 1); |
| 1747 | } |
| 1748 | |
| 1749 | if (condition == kCondNE && out.IsLow()) { |
| 1750 | __ Subs(out, in, operand); |
| 1751 | |
| 1752 | // We use the scope because of the IT block that follows. |
| 1753 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1754 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1755 | CodeBufferCheckScope::kExactSize); |
| 1756 | |
| 1757 | __ it(ne); |
| 1758 | __ mov(ne, out, 1); |
| 1759 | } else { |
| 1760 | __ Sub(out, in, operand); |
| 1761 | codegen->GenerateConditionWithZero(condition, out, out); |
| 1762 | } |
| 1763 | |
| 1764 | return; |
| 1765 | } |
| 1766 | |
| 1767 | GenerateConditionGeneric(cond, codegen); |
| 1768 | } |
| 1769 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1770 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1771 | const DataType::Type type = constant->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1772 | bool ret = false; |
| 1773 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1774 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1775 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1776 | if (type == DataType::Type::kInt64) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1777 | const uint64_t value = Uint64ConstantFrom(constant); |
| 1778 | |
| 1779 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 1780 | } else { |
| 1781 | ret = IsUint<8>(Int32ConstantFrom(constant)); |
| 1782 | } |
| 1783 | |
| 1784 | return ret; |
| 1785 | } |
| 1786 | |
| 1787 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1788 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1789 | |
| 1790 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 1791 | return Location::ConstantLocation(constant->AsConstant()); |
| 1792 | } |
| 1793 | |
| 1794 | return Location::RequiresRegister(); |
| 1795 | } |
| 1796 | |
| 1797 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 1798 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1799 | // we check that we are not dealing with floating-point output (there is no |
| 1800 | // 16-bit VMOV encoding). |
| 1801 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 1802 | return false; |
| 1803 | } |
| 1804 | |
| 1805 | // For constants, we also check that the output is in one or two low registers, |
| 1806 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 1807 | // MOV encoding can be used. |
| 1808 | if (src.IsConstant()) { |
| 1809 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 1810 | return false; |
| 1811 | } |
| 1812 | |
| 1813 | if (out.IsRegister()) { |
| 1814 | if (!RegisterFrom(out).IsLow()) { |
| 1815 | return false; |
| 1816 | } |
| 1817 | } else { |
| 1818 | DCHECK(out.IsRegisterPair()); |
| 1819 | |
| 1820 | if (!HighRegisterFrom(out).IsLow()) { |
| 1821 | return false; |
| 1822 | } |
| 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | return true; |
| 1827 | } |
| 1828 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1829 | #undef __ |
| 1830 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1831 | vixl32::Label* CodeGeneratorARMVIXL::GetFinalLabel(HInstruction* instruction, |
| 1832 | vixl32::Label* final_label) { |
| 1833 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 1834 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1835 | |
| 1836 | const HBasicBlock* const block = instruction->GetBlock(); |
| 1837 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 1838 | HInstruction* const next = instruction->GetNext(); |
| 1839 | |
| 1840 | // Avoid a branch to a branch. |
| 1841 | if (next->IsGoto() && (info == nullptr || |
| 1842 | !info->IsBackEdge(*block) || |
| 1843 | !info->HasSuspendCheck())) { |
| 1844 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 1845 | } |
| 1846 | |
| 1847 | return final_label; |
| 1848 | } |
| 1849 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1850 | CodeGeneratorARMVIXL::CodeGeneratorARMVIXL(HGraph* graph, |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1851 | const CompilerOptions& compiler_options, |
| 1852 | OptimizingCompilerStats* stats) |
| 1853 | : CodeGenerator(graph, |
| 1854 | kNumberOfCoreRegisters, |
| 1855 | kNumberOfSRegisters, |
| 1856 | kNumberOfRegisterPairs, |
| 1857 | kCoreCalleeSaves.GetList(), |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1858 | ComputeSRegisterListMask(kFpuCalleeSaves), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1859 | compiler_options, |
| 1860 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1861 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1862 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1863 | location_builder_(graph, this), |
| 1864 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1865 | move_resolver_(graph->GetAllocator(), this), |
| 1866 | assembler_(graph->GetAllocator()), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1867 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1868 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1869 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1870 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 1871 | public_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1872 | package_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1873 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1874 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1875 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1876 | call_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1877 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1878 | uint32_literals_(std::less<uint32_t>(), |
| 1879 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 1880 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1881 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 1882 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1883 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1884 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 1885 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1886 | // Always save the LR register to mimic Quick. |
| 1887 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 1888 | // Give D30 and D31 as scratch register to VIXL. The register allocator only works on |
| 1889 | // S0-S31, which alias to D0-D15. |
| 1890 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d31); |
| 1891 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d30); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1892 | } |
| 1893 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1894 | void JumpTableARMVIXL::EmitTable(CodeGeneratorARMVIXL* codegen) { |
| 1895 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 1896 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 1897 | |
| 1898 | // 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] | 1899 | // underlying code buffer and we have generated a jump table of the right size, using |
| 1900 | // codegen->GetVIXLAssembler()->GetBuffer().Align(); |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1901 | ExactAssemblyScope aas(codegen->GetVIXLAssembler(), |
| 1902 | num_entries * sizeof(int32_t), |
| 1903 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1904 | // TODO(VIXL): Check that using lower case bind is fine here. |
| 1905 | codegen->GetVIXLAssembler()->bind(&table_start_); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1906 | for (uint32_t i = 0; i < num_entries; i++) { |
| 1907 | codegen->GetVIXLAssembler()->place(bb_addresses_[i].get()); |
| 1908 | } |
| 1909 | } |
| 1910 | |
| 1911 | void JumpTableARMVIXL::FixTable(CodeGeneratorARMVIXL* codegen) { |
| 1912 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 1913 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 1914 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1915 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 1916 | for (uint32_t i = 0; i < num_entries; i++) { |
| 1917 | vixl32::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 1918 | DCHECK(target_label->IsBound()); |
| 1919 | int32_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| 1920 | // When doing BX to address we need to have lower bit set to 1 in T32. |
| 1921 | if (codegen->GetVIXLAssembler()->IsUsingT32()) { |
| 1922 | jump_offset++; |
| 1923 | } |
| 1924 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 1925 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1926 | |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 1927 | bb_addresses_[i].get()->UpdateValue(jump_offset, codegen->GetVIXLAssembler()->GetBuffer()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1928 | } |
| 1929 | } |
| 1930 | |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1931 | void CodeGeneratorARMVIXL::FixJumpTables() { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1932 | for (auto&& jump_table : jump_tables_) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1933 | jump_table->FixTable(this); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1934 | } |
| 1935 | } |
| 1936 | |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 1937 | #define __ reinterpret_cast<ArmVIXLAssembler*>(GetAssembler())->GetVIXLAssembler()-> // NOLINT |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1938 | |
| 1939 | void CodeGeneratorARMVIXL::Finalize(CodeAllocator* allocator) { |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1940 | FixJumpTables(); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1941 | |
| 1942 | // Emit JIT baker read barrier slow paths. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 1943 | DCHECK(GetCompilerOptions().IsJitCompiler() || jit_baker_read_barrier_slow_paths_.empty()); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1944 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 1945 | uint32_t encoded_data = entry.first; |
| 1946 | vixl::aarch32::Label* slow_path_entry = &entry.second.label; |
| 1947 | __ Bind(slow_path_entry); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1948 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name= */ nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1949 | } |
| 1950 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1951 | GetAssembler()->FinalizeCode(); |
| 1952 | CodeGenerator::Finalize(allocator); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1953 | |
| 1954 | // Verify Baker read barrier linker patches. |
| 1955 | if (kIsDebugBuild) { |
| 1956 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 1957 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 1958 | DCHECK(info.label.IsBound()); |
| 1959 | uint32_t literal_offset = info.label.GetLocation(); |
| 1960 | DCHECK_ALIGNED(literal_offset, 2u); |
| 1961 | |
| 1962 | auto GetInsn16 = [&code](uint32_t offset) { |
| 1963 | DCHECK_ALIGNED(offset, 2u); |
| 1964 | return (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 1965 | (static_cast<uint32_t>(code[offset + 1]) << 8); |
| 1966 | }; |
| 1967 | auto GetInsn32 = [=](uint32_t offset) { |
| 1968 | return (GetInsn16(offset) << 16) + (GetInsn16(offset + 2u) << 0); |
| 1969 | }; |
| 1970 | |
| 1971 | uint32_t encoded_data = info.custom_data; |
| 1972 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 1973 | // Check that the next instruction matches the expected LDR. |
| 1974 | switch (kind) { |
| 1975 | case BakerReadBarrierKind::kField: { |
| 1976 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 1977 | if (width == BakerReadBarrierWidth::kWide) { |
| 1978 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1979 | uint32_t next_insn = GetInsn32(literal_offset + 4u); |
| 1980 | // LDR (immediate), encoding T3, with correct base_reg. |
| 1981 | CheckValidReg((next_insn >> 12) & 0xfu); // Check destination register. |
| 1982 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1983 | CHECK_EQ(next_insn & 0xffff0000u, 0xf8d00000u | (base_reg << 16)); |
| 1984 | } else { |
| 1985 | DCHECK_GE(code.size() - literal_offset, 6u); |
| 1986 | uint32_t next_insn = GetInsn16(literal_offset + 4u); |
| 1987 | // LDR (immediate), encoding T1, with correct base_reg. |
| 1988 | CheckValidReg(next_insn & 0x7u); // Check destination register. |
| 1989 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1990 | CHECK_EQ(next_insn & 0xf838u, 0x6800u | (base_reg << 3)); |
| 1991 | } |
| 1992 | break; |
| 1993 | } |
| 1994 | case BakerReadBarrierKind::kArray: { |
| 1995 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1996 | uint32_t next_insn = GetInsn32(literal_offset + 4u); |
| 1997 | // LDR (register) with correct base_reg, S=1 and option=011 (LDR Wt, [Xn, Xm, LSL #2]). |
| 1998 | CheckValidReg((next_insn >> 12) & 0xfu); // Check destination register. |
| 1999 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2000 | CHECK_EQ(next_insn & 0xffff0ff0u, 0xf8500020u | (base_reg << 16)); |
| 2001 | CheckValidReg(next_insn & 0xf); // Check index register |
| 2002 | break; |
| 2003 | } |
| 2004 | case BakerReadBarrierKind::kGcRoot: { |
| 2005 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 2006 | if (width == BakerReadBarrierWidth::kWide) { |
| 2007 | DCHECK_GE(literal_offset, 4u); |
| 2008 | uint32_t prev_insn = GetInsn32(literal_offset - 4u); |
Vladimir Marko | f28be43 | 2018-08-14 12:20:51 +0000 | [diff] [blame] | 2009 | // LDR (immediate), encoding T3, with correct root_reg. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2010 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | f28be43 | 2018-08-14 12:20:51 +0000 | [diff] [blame] | 2011 | CHECK_EQ(prev_insn & 0xfff0f000u, 0xf8d00000u | (root_reg << 12)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2012 | } else { |
| 2013 | DCHECK_GE(literal_offset, 2u); |
| 2014 | uint32_t prev_insn = GetInsn16(literal_offset - 2u); |
| 2015 | // LDR (immediate), encoding T1, with correct root_reg. |
| 2016 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2017 | CHECK_EQ(prev_insn & 0xf807u, 0x6800u | root_reg); |
| 2018 | } |
| 2019 | break; |
| 2020 | } |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 2021 | case BakerReadBarrierKind::kUnsafeCas: { |
| 2022 | DCHECK_GE(literal_offset, 4u); |
| 2023 | uint32_t prev_insn = GetInsn32(literal_offset - 4u); |
| 2024 | // ADD (register), encoding T3, with correct root_reg. |
| 2025 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2026 | CHECK_EQ(prev_insn & 0xfff0fff0u, 0xeb000000u | (root_reg << 8)); |
| 2027 | break; |
| 2028 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2029 | default: |
| 2030 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 2031 | UNREACHABLE(); |
| 2032 | } |
| 2033 | } |
| 2034 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | void CodeGeneratorARMVIXL::SetupBlockedRegisters() const { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2038 | // Stack register, LR and PC are always reserved. |
| 2039 | blocked_core_registers_[SP] = true; |
| 2040 | blocked_core_registers_[LR] = true; |
| 2041 | blocked_core_registers_[PC] = true; |
| 2042 | |
Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 2043 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2044 | // Reserve marking register. |
| 2045 | blocked_core_registers_[MR] = true; |
| 2046 | } |
| 2047 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2048 | // Reserve thread register. |
| 2049 | blocked_core_registers_[TR] = true; |
| 2050 | |
| 2051 | // Reserve temp register. |
| 2052 | blocked_core_registers_[IP] = true; |
| 2053 | |
| 2054 | if (GetGraph()->IsDebuggable()) { |
| 2055 | // Stubs do not save callee-save floating point registers. If the graph |
| 2056 | // is debuggable, we need to deal with these registers differently. For |
| 2057 | // now, just block them. |
| 2058 | for (uint32_t i = kFpuCalleeSaves.GetFirstSRegister().GetCode(); |
| 2059 | i <= kFpuCalleeSaves.GetLastSRegister().GetCode(); |
| 2060 | ++i) { |
| 2061 | blocked_fpu_registers_[i] = true; |
| 2062 | } |
| 2063 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2064 | } |
| 2065 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2066 | InstructionCodeGeneratorARMVIXL::InstructionCodeGeneratorARMVIXL(HGraph* graph, |
| 2067 | CodeGeneratorARMVIXL* codegen) |
| 2068 | : InstructionCodeGenerator(graph, codegen), |
| 2069 | assembler_(codegen->GetAssembler()), |
| 2070 | codegen_(codegen) {} |
| 2071 | |
| 2072 | void CodeGeneratorARMVIXL::ComputeSpillMask() { |
| 2073 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
Vladimir Marko | 460f054 | 2019-07-04 14:02:08 +0100 | [diff] [blame] | 2074 | DCHECK_NE(core_spill_mask_ & (1u << kLrCode), 0u) |
| 2075 | << "At least the return address register must be saved"; |
| 2076 | // 16-bit PUSH/POP (T1) can save/restore just the LR/PC. |
| 2077 | DCHECK(GetVIXLAssembler()->IsUsingT32()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2078 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2079 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2080 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2081 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2082 | // but in the range. |
| 2083 | if (fpu_spill_mask_ != 0) { |
| 2084 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2085 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2086 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2087 | fpu_spill_mask_ |= (1 << i); |
| 2088 | } |
| 2089 | } |
| 2090 | } |
| 2091 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2092 | void CodeGeneratorARMVIXL::MaybeIncrementHotness(bool is_frame_entry) { |
| 2093 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 2094 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2095 | vixl32::Register temp = temps.Acquire(); |
| 2096 | static_assert(ArtMethod::MaxCounter() == 0xFFFF, "asm is probably wrong"); |
| 2097 | if (!is_frame_entry) { |
| 2098 | __ Push(vixl32::Register(kMethodRegister)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2099 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2100 | GetAssembler()->LoadFromOffset(kLoadWord, kMethodRegister, sp, kArmWordSize); |
| 2101 | } |
| 2102 | // Load with zero extend to clear the high bits for integer overflow check. |
| 2103 | __ Ldrh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 2104 | __ Add(temp, temp, 1); |
| 2105 | // Subtract one if the counter would overflow. |
| 2106 | __ Sub(temp, temp, Operand(temp, ShiftType::LSR, 16)); |
| 2107 | __ Strh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 2108 | if (!is_frame_entry) { |
| 2109 | __ Pop(vixl32::Register(kMethodRegister)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2110 | GetAssembler()->cfi().AdjustCFAOffset(-static_cast<int>(kArmWordSize)); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2111 | } |
| 2112 | } |
| 2113 | |
| 2114 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 2115 | ScopedProfilingInfoUse spiu( |
| 2116 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 2117 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2118 | if (info != nullptr) { |
| 2119 | uint32_t address = reinterpret_cast32<uint32_t>(info); |
| 2120 | vixl::aarch32::Label done; |
| 2121 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2122 | temps.Exclude(ip); |
| 2123 | if (!is_frame_entry) { |
| 2124 | __ Push(r4); // Will be used as temporary. For frame entry, r4 is always available. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2125 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2126 | } |
| 2127 | __ Mov(r4, address); |
| 2128 | __ Ldrh(ip, MemOperand(r4, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 2129 | __ Add(ip, ip, 1); |
Nicolas Geoffray | 8b8d93d | 2020-09-17 14:30:01 +0100 | [diff] [blame] | 2130 | instruction_visitor_.GenerateAndConst(ip, ip, interpreter::kTieredHotnessMask); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2131 | __ Strh(ip, MemOperand(r4, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 2132 | if (!is_frame_entry) { |
| 2133 | __ Pop(r4); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2134 | GetAssembler()->cfi().AdjustCFAOffset(-static_cast<int>(kArmWordSize)); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2135 | } |
| 2136 | __ Lsls(ip, ip, 16); |
| 2137 | __ B(ne, &done); |
| 2138 | uint32_t entry_point_offset = |
| 2139 | GetThreadOffset<kArmPointerSize>(kQuickCompileOptimized).Int32Value(); |
| 2140 | if (HasEmptyFrame()) { |
| 2141 | CHECK(is_frame_entry); |
| 2142 | // For leaf methods, we need to spill lr and r0. Also spill r1 and r2 for |
| 2143 | // alignment. |
| 2144 | uint32_t core_spill_mask = |
| 2145 | (1 << lr.GetCode()) | (1 << r0.GetCode()) | (1 << r1.GetCode()) | (1 << r2.GetCode()); |
| 2146 | __ Push(RegisterList(core_spill_mask)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2147 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask)); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2148 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2149 | __ Blx(lr); |
| 2150 | __ Pop(RegisterList(core_spill_mask)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2151 | GetAssembler()->cfi().AdjustCFAOffset( |
| 2152 | -static_cast<int>(kArmWordSize) * POPCOUNT(core_spill_mask)); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2153 | } else { |
| 2154 | if (!RequiresCurrentMethod()) { |
| 2155 | CHECK(is_frame_entry); |
| 2156 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 2157 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2158 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2159 | __ Blx(lr); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2160 | } |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2161 | __ Bind(&done); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2162 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2163 | } |
| 2164 | } |
| 2165 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2166 | void CodeGeneratorARMVIXL::GenerateFrameEntry() { |
| 2167 | bool skip_overflow_check = |
| 2168 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
| 2169 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| 2170 | __ Bind(&frame_entry_label_); |
| 2171 | |
| 2172 | if (HasEmptyFrame()) { |
David Srbecky | 3002184 | 2019-02-13 14:19:36 +0000 | [diff] [blame] | 2173 | // Ensure that the CFI opcode list is not empty. |
| 2174 | GetAssembler()->cfi().Nop(); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2175 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2176 | return; |
| 2177 | } |
| 2178 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2179 | if (!skip_overflow_check) { |
xueliang.zhong | 1004955 | 2018-01-31 17:10:36 +0000 | [diff] [blame] | 2180 | // Using r4 instead of IP saves 2 bytes. |
Nicolas Geoffray | 1a4f3ca | 2018-01-25 14:07:15 +0000 | [diff] [blame] | 2181 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
xueliang.zhong | 1004955 | 2018-01-31 17:10:36 +0000 | [diff] [blame] | 2182 | vixl32::Register temp; |
| 2183 | // TODO: Remove this check when R4 is made a callee-save register |
| 2184 | // in ART compiled code (b/72801708). Currently we need to make |
| 2185 | // sure r4 is not blocked, e.g. in special purpose |
| 2186 | // TestCodeGeneratorARMVIXL; also asserting that r4 is available |
| 2187 | // here. |
| 2188 | if (!blocked_core_registers_[R4]) { |
| 2189 | for (vixl32::Register reg : kParameterCoreRegistersVIXL) { |
| 2190 | DCHECK(!reg.Is(r4)); |
| 2191 | } |
| 2192 | DCHECK(!kCoreCalleeSaves.Includes(r4)); |
| 2193 | temp = r4; |
| 2194 | } else { |
| 2195 | temp = temps.Acquire(); |
| 2196 | } |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 2197 | __ Sub(temp, sp, Operand::From(GetStackOverflowReservedBytes(InstructionSet::kArm))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2198 | // The load must immediately precede RecordPcInfo. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2199 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2200 | vixl32::kMaxInstructionSizeInBytes, |
| 2201 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2202 | __ ldr(temp, MemOperand(temp)); |
| 2203 | RecordPcInfo(nullptr, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2204 | } |
| 2205 | |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2206 | uint32_t frame_size = GetFrameSize(); |
| 2207 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 2208 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 2209 | if ((fpu_spill_mask_ == 0u || IsPowerOfTwo(fpu_spill_mask_)) && |
| 2210 | core_spills_offset <= 3u * kArmWordSize) { |
| 2211 | // Do a single PUSH for core registers including the method and up to two |
| 2212 | // filler registers. Then store the single FP spill if any. |
| 2213 | // (The worst case is when the method is not required and we actually |
| 2214 | // store 3 extra registers but they are stored in the same properly |
| 2215 | // aligned 16-byte chunk where we're already writing anyway.) |
| 2216 | DCHECK_EQ(kMethodRegister.GetCode(), 0u); |
| 2217 | uint32_t extra_regs = MaxInt<uint32_t>(core_spills_offset / kArmWordSize); |
| 2218 | DCHECK_LT(MostSignificantBit(extra_regs), LeastSignificantBit(core_spill_mask_)); |
| 2219 | __ Push(RegisterList(core_spill_mask_ | extra_regs)); |
| 2220 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
| 2221 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2222 | core_spills_offset, |
| 2223 | core_spill_mask_, |
| 2224 | kArmWordSize); |
| 2225 | if (fpu_spill_mask_ != 0u) { |
| 2226 | DCHECK(IsPowerOfTwo(fpu_spill_mask_)); |
| 2227 | vixl::aarch32::SRegister sreg(LeastSignificantBit(fpu_spill_mask_)); |
| 2228 | GetAssembler()->StoreSToOffset(sreg, sp, fp_spills_offset); |
| 2229 | GetAssembler()->cfi().RelOffset(DWARFReg(sreg), /*offset=*/ fp_spills_offset); |
| 2230 | } |
| 2231 | } else { |
| 2232 | __ Push(RegisterList(core_spill_mask_)); |
| 2233 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2234 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2235 | /*offset=*/ 0, |
| 2236 | core_spill_mask_, |
| 2237 | kArmWordSize); |
| 2238 | if (fpu_spill_mask_ != 0) { |
| 2239 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2240 | |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2241 | // Check that list is contiguous. |
| 2242 | 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] | 2243 | |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2244 | __ Vpush(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2245 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
| 2246 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(s0), |
| 2247 | /*offset=*/ 0, |
| 2248 | fpu_spill_mask_, |
| 2249 | kArmWordSize); |
| 2250 | } |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2251 | |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2252 | // Adjust SP and save the current method if we need it. Note that we do |
| 2253 | // not save the method in HCurrentMethod, as the instruction might have |
| 2254 | // been removed in the SSA graph. |
| 2255 | if (RequiresCurrentMethod() && fp_spills_offset <= 3 * kArmWordSize) { |
| 2256 | DCHECK_EQ(kMethodRegister.GetCode(), 0u); |
| 2257 | __ Push(RegisterList(MaxInt<uint32_t>(fp_spills_offset / kArmWordSize))); |
| 2258 | GetAssembler()->cfi().AdjustCFAOffset(fp_spills_offset); |
| 2259 | } else { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2260 | IncreaseFrame(fp_spills_offset); |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2261 | if (RequiresCurrentMethod()) { |
| 2262 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 2263 | } |
| 2264 | } |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2265 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 2266 | |
| 2267 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2268 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2269 | vixl32::Register temp = temps.Acquire(); |
| 2270 | // Initialize should_deoptimize flag to 0. |
| 2271 | __ Mov(temp, 0); |
| 2272 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2273 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 2274 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2275 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2276 | MaybeGenerateMarkingRegisterCheck(/* code= */ 1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | void CodeGeneratorARMVIXL::GenerateFrameExit() { |
| 2280 | if (HasEmptyFrame()) { |
| 2281 | __ Bx(lr); |
| 2282 | return; |
| 2283 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2284 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2285 | // Pop LR into PC to return. |
| 2286 | DCHECK_NE(core_spill_mask_ & (1 << kLrCode), 0U); |
| 2287 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << kLrCode))) | 1 << kPcCode; |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2288 | |
| 2289 | uint32_t frame_size = GetFrameSize(); |
| 2290 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 2291 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 2292 | if ((fpu_spill_mask_ == 0u || IsPowerOfTwo(fpu_spill_mask_)) && |
| 2293 | // r4 is blocked by TestCodeGeneratorARMVIXL used by some tests. |
| 2294 | core_spills_offset <= (blocked_core_registers_[r4.GetCode()] ? 2u : 3u) * kArmWordSize) { |
| 2295 | // Load the FP spill if any and then do a single POP including the method |
| 2296 | // and up to two filler registers. If we have no FP spills, this also has |
| 2297 | // the advantage that we do not need to emit CFI directives. |
| 2298 | if (fpu_spill_mask_ != 0u) { |
| 2299 | DCHECK(IsPowerOfTwo(fpu_spill_mask_)); |
| 2300 | vixl::aarch32::SRegister sreg(LeastSignificantBit(fpu_spill_mask_)); |
| 2301 | GetAssembler()->cfi().RememberState(); |
| 2302 | GetAssembler()->LoadSFromOffset(sreg, sp, fp_spills_offset); |
| 2303 | GetAssembler()->cfi().Restore(DWARFReg(sreg)); |
| 2304 | } |
| 2305 | // Clobber registers r2-r4 as they are caller-save in ART managed ABI and |
| 2306 | // never hold the return value. |
| 2307 | uint32_t extra_regs = MaxInt<uint32_t>(core_spills_offset / kArmWordSize) << r2.GetCode(); |
| 2308 | DCHECK_EQ(extra_regs & kCoreCalleeSaves.GetList(), 0u); |
| 2309 | DCHECK_LT(MostSignificantBit(extra_regs), LeastSignificantBit(pop_mask)); |
| 2310 | __ Pop(RegisterList(pop_mask | extra_regs)); |
| 2311 | if (fpu_spill_mask_ != 0u) { |
| 2312 | GetAssembler()->cfi().RestoreState(); |
| 2313 | } |
| 2314 | } else { |
| 2315 | GetAssembler()->cfi().RememberState(); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2316 | DecreaseFrame(fp_spills_offset); |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2317 | if (fpu_spill_mask_ != 0) { |
| 2318 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2319 | |
| 2320 | // Check that list is contiguous. |
| 2321 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2322 | |
| 2323 | __ Vpop(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2324 | GetAssembler()->cfi().AdjustCFAOffset( |
| 2325 | -static_cast<int>(kArmWordSize) * POPCOUNT(fpu_spill_mask_)); |
| 2326 | GetAssembler()->cfi().RestoreMany(DWARFReg(vixl32::SRegister(0)), fpu_spill_mask_); |
| 2327 | } |
| 2328 | __ Pop(RegisterList(pop_mask)); |
| 2329 | GetAssembler()->cfi().RestoreState(); |
| 2330 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| 2331 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | void CodeGeneratorARMVIXL::Bind(HBasicBlock* block) { |
| 2335 | __ Bind(GetLabelOf(block)); |
| 2336 | } |
| 2337 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2338 | Location InvokeDexCallingConventionVisitorARMVIXL::GetNextLocation(DataType::Type type) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2339 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2340 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2341 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2342 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2343 | case DataType::Type::kInt8: |
| 2344 | case DataType::Type::kUint16: |
| 2345 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2346 | case DataType::Type::kInt32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2347 | uint32_t index = gp_index_++; |
| 2348 | uint32_t stack_index = stack_index_++; |
| 2349 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2350 | return LocationFrom(calling_convention.GetRegisterAt(index)); |
| 2351 | } else { |
| 2352 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2353 | } |
| 2354 | } |
| 2355 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2356 | case DataType::Type::kInt64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2357 | uint32_t index = gp_index_; |
| 2358 | uint32_t stack_index = stack_index_; |
| 2359 | gp_index_ += 2; |
| 2360 | stack_index_ += 2; |
| 2361 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2362 | if (calling_convention.GetRegisterAt(index).Is(r1)) { |
| 2363 | // Skip R1, and use R2_R3 instead. |
| 2364 | gp_index_++; |
| 2365 | index++; |
| 2366 | } |
| 2367 | } |
| 2368 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2369 | DCHECK_EQ(calling_convention.GetRegisterAt(index).GetCode() + 1, |
| 2370 | calling_convention.GetRegisterAt(index + 1).GetCode()); |
| 2371 | |
| 2372 | return LocationFrom(calling_convention.GetRegisterAt(index), |
| 2373 | calling_convention.GetRegisterAt(index + 1)); |
| 2374 | } else { |
| 2375 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2376 | } |
| 2377 | } |
| 2378 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2379 | case DataType::Type::kFloat32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2380 | uint32_t stack_index = stack_index_++; |
| 2381 | if (float_index_ % 2 == 0) { |
| 2382 | float_index_ = std::max(double_index_, float_index_); |
| 2383 | } |
| 2384 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2385 | return LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2386 | } else { |
| 2387 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2388 | } |
| 2389 | } |
| 2390 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2391 | case DataType::Type::kFloat64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2392 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2393 | uint32_t stack_index = stack_index_; |
| 2394 | stack_index_ += 2; |
| 2395 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2396 | uint32_t index = double_index_; |
| 2397 | double_index_ += 2; |
| 2398 | Location result = LocationFrom( |
| 2399 | calling_convention.GetFpuRegisterAt(index), |
| 2400 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 2401 | DCHECK(ExpectedPairLayout(result)); |
| 2402 | return result; |
| 2403 | } else { |
| 2404 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2405 | } |
| 2406 | } |
| 2407 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2408 | case DataType::Type::kUint32: |
| 2409 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2410 | case DataType::Type::kVoid: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2411 | LOG(FATAL) << "Unexpected parameter type " << type; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 2412 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2413 | } |
| 2414 | return Location::NoLocation(); |
| 2415 | } |
| 2416 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2417 | Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(DataType::Type type) const { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2418 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2419 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2420 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2421 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2422 | case DataType::Type::kInt8: |
| 2423 | case DataType::Type::kUint16: |
| 2424 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2425 | case DataType::Type::kUint32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2426 | case DataType::Type::kInt32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2427 | return LocationFrom(r0); |
| 2428 | } |
| 2429 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2430 | case DataType::Type::kFloat32: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2431 | return LocationFrom(s0); |
| 2432 | } |
| 2433 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2434 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2435 | case DataType::Type::kInt64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2436 | return LocationFrom(r0, r1); |
| 2437 | } |
| 2438 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2439 | case DataType::Type::kFloat64: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2440 | return LocationFrom(s0, s1); |
| 2441 | } |
| 2442 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2443 | case DataType::Type::kVoid: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2444 | return Location::NoLocation(); |
| 2445 | } |
| 2446 | |
| 2447 | UNREACHABLE(); |
| 2448 | } |
| 2449 | |
| 2450 | Location InvokeDexCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 2451 | return LocationFrom(kMethodRegister); |
| 2452 | } |
| 2453 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2454 | Location CriticalNativeCallingConventionVisitorARMVIXL::GetNextLocation(DataType::Type type) { |
| 2455 | DCHECK_NE(type, DataType::Type::kReference); |
| 2456 | |
| 2457 | // Native ABI uses the same registers as managed, except that the method register r0 |
| 2458 | // is a normal argument. |
| 2459 | Location location = Location::NoLocation(); |
| 2460 | if (DataType::Is64BitType(type)) { |
| 2461 | gpr_index_ = RoundUp(gpr_index_, 2u); |
| 2462 | stack_offset_ = RoundUp(stack_offset_, 2 * kFramePointerSize); |
| 2463 | if (gpr_index_ < 1u + kParameterCoreRegistersLengthVIXL) { |
| 2464 | location = LocationFrom(gpr_index_ == 0u ? r0 : kParameterCoreRegistersVIXL[gpr_index_ - 1u], |
| 2465 | kParameterCoreRegistersVIXL[gpr_index_]); |
| 2466 | gpr_index_ += 2u; |
| 2467 | } |
| 2468 | } else { |
| 2469 | if (gpr_index_ < 1u + kParameterCoreRegistersLengthVIXL) { |
| 2470 | location = LocationFrom(gpr_index_ == 0u ? r0 : kParameterCoreRegistersVIXL[gpr_index_ - 1u]); |
| 2471 | ++gpr_index_; |
| 2472 | } |
| 2473 | } |
| 2474 | if (location.IsInvalid()) { |
| 2475 | if (DataType::Is64BitType(type)) { |
| 2476 | location = Location::DoubleStackSlot(stack_offset_); |
| 2477 | stack_offset_ += 2 * kFramePointerSize; |
| 2478 | } else { |
| 2479 | location = Location::StackSlot(stack_offset_); |
| 2480 | stack_offset_ += kFramePointerSize; |
| 2481 | } |
| 2482 | |
| 2483 | if (for_register_allocation_) { |
| 2484 | location = Location::Any(); |
| 2485 | } |
| 2486 | } |
| 2487 | return location; |
| 2488 | } |
| 2489 | |
| 2490 | Location CriticalNativeCallingConventionVisitorARMVIXL::GetReturnLocation(DataType::Type type) |
| 2491 | const { |
| 2492 | // We perform conversion to the managed ABI return register after the call if needed. |
| 2493 | InvokeDexCallingConventionVisitorARMVIXL dex_calling_convention; |
| 2494 | return dex_calling_convention.GetReturnLocation(type); |
| 2495 | } |
| 2496 | |
| 2497 | Location CriticalNativeCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 2498 | // Pass the method in the hidden argument R4. |
| 2499 | return Location::RegisterLocation(R4); |
| 2500 | } |
| 2501 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2502 | void CodeGeneratorARMVIXL::Move32(Location destination, Location source) { |
| 2503 | if (source.Equals(destination)) { |
| 2504 | return; |
| 2505 | } |
| 2506 | if (destination.IsRegister()) { |
| 2507 | if (source.IsRegister()) { |
| 2508 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 2509 | } else if (source.IsFpuRegister()) { |
| 2510 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| 2511 | } else { |
| 2512 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2513 | RegisterFrom(destination), |
| 2514 | sp, |
| 2515 | source.GetStackIndex()); |
| 2516 | } |
| 2517 | } else if (destination.IsFpuRegister()) { |
| 2518 | if (source.IsRegister()) { |
| 2519 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| 2520 | } else if (source.IsFpuRegister()) { |
| 2521 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 2522 | } else { |
| 2523 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 2524 | } |
| 2525 | } else { |
| 2526 | DCHECK(destination.IsStackSlot()) << destination; |
| 2527 | if (source.IsRegister()) { |
| 2528 | GetAssembler()->StoreToOffset(kStoreWord, |
| 2529 | RegisterFrom(source), |
| 2530 | sp, |
| 2531 | destination.GetStackIndex()); |
| 2532 | } else if (source.IsFpuRegister()) { |
| 2533 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 2534 | } else { |
| 2535 | DCHECK(source.IsStackSlot()) << source; |
| 2536 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2537 | vixl32::Register temp = temps.Acquire(); |
| 2538 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 2539 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 2540 | } |
| 2541 | } |
| 2542 | } |
| 2543 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2544 | void CodeGeneratorARMVIXL::MoveConstant(Location location, int32_t value) { |
| 2545 | DCHECK(location.IsRegister()); |
| 2546 | __ Mov(RegisterFrom(location), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2547 | } |
| 2548 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2549 | void CodeGeneratorARMVIXL::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2550 | // TODO(VIXL): Maybe refactor to have the 'move' implementation here and use it in |
| 2551 | // `ParallelMoveResolverARMVIXL::EmitMove`, as is done in the `arm64` backend. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2552 | HParallelMove move(GetGraph()->GetAllocator()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2553 | move.AddMove(src, dst, dst_type, nullptr); |
| 2554 | GetMoveResolver()->EmitNativeCode(&move); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2555 | } |
| 2556 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2557 | void CodeGeneratorARMVIXL::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2558 | if (location.IsRegister()) { |
| 2559 | locations->AddTemp(location); |
| 2560 | } else if (location.IsRegisterPair()) { |
| 2561 | locations->AddTemp(LocationFrom(LowRegisterFrom(location))); |
| 2562 | locations->AddTemp(LocationFrom(HighRegisterFrom(location))); |
| 2563 | } else { |
| 2564 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2565 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | void CodeGeneratorARMVIXL::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2569 | HInstruction* instruction, |
| 2570 | uint32_t dex_pc, |
| 2571 | SlowPathCode* slow_path) { |
| 2572 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 2573 | |
| 2574 | ThreadOffset32 entrypoint_offset = GetThreadOffset<kArmPointerSize>(entrypoint); |
| 2575 | // Reduce code size for AOT by using shared trampolines for slow path runtime calls across the |
| 2576 | // entire oat file. This adds an extra branch and we do not want to slow down the main path. |
| 2577 | // For JIT, thunk sharing is per-method, so the gains would be smaller or even negative. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 2578 | if (slow_path == nullptr || GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 2579 | __ Ldr(lr, MemOperand(tr, entrypoint_offset.Int32Value())); |
| 2580 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 2581 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 2582 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2583 | vixl32::k16BitT32InstructionSizeInBytes, |
| 2584 | CodeBufferCheckScope::kExactSize); |
| 2585 | __ blx(lr); |
| 2586 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2587 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2588 | } |
| 2589 | } else { |
| 2590 | // Ensure the pc position is recorded immediately after the `bl` instruction. |
| 2591 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2592 | vixl32::k32BitT32InstructionSizeInBytes, |
| 2593 | CodeBufferCheckScope::kExactSize); |
| 2594 | EmitEntrypointThunkCall(entrypoint_offset); |
| 2595 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2596 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2597 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2598 | } |
| 2599 | } |
| 2600 | |
| 2601 | void CodeGeneratorARMVIXL::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2602 | HInstruction* instruction, |
| 2603 | SlowPathCode* slow_path) { |
| 2604 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2605 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2606 | __ Blx(lr); |
| 2607 | } |
| 2608 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2609 | void InstructionCodeGeneratorARMVIXL::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2610 | if (successor->IsExitBlock()) { |
| 2611 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 2612 | return; // no code needed |
| 2613 | } |
| 2614 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2615 | HBasicBlock* block = got->GetBlock(); |
| 2616 | HInstruction* previous = got->GetPrevious(); |
| 2617 | HLoopInformation* info = block->GetLoopInformation(); |
| 2618 | |
| 2619 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 2620 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2621 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2622 | return; |
| 2623 | } |
| 2624 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2625 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2626 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 2); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2627 | } |
| 2628 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2629 | __ B(codegen_->GetLabelOf(successor)); |
| 2630 | } |
| 2631 | } |
| 2632 | |
| 2633 | void LocationsBuilderARMVIXL::VisitGoto(HGoto* got) { |
| 2634 | got->SetLocations(nullptr); |
| 2635 | } |
| 2636 | |
| 2637 | void InstructionCodeGeneratorARMVIXL::VisitGoto(HGoto* got) { |
| 2638 | HandleGoto(got, got->GetSuccessor()); |
| 2639 | } |
| 2640 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2641 | void LocationsBuilderARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2642 | try_boundary->SetLocations(nullptr); |
| 2643 | } |
| 2644 | |
| 2645 | void InstructionCodeGeneratorARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2646 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2647 | if (!successor->IsExitBlock()) { |
| 2648 | HandleGoto(try_boundary, successor); |
| 2649 | } |
| 2650 | } |
| 2651 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2652 | void LocationsBuilderARMVIXL::VisitExit(HExit* exit) { |
| 2653 | exit->SetLocations(nullptr); |
| 2654 | } |
| 2655 | |
| 2656 | void InstructionCodeGeneratorARMVIXL::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2657 | } |
| 2658 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2659 | void InstructionCodeGeneratorARMVIXL::GenerateCompareTestAndBranch(HCondition* condition, |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2660 | vixl32::Label* true_target, |
| 2661 | vixl32::Label* false_target, |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2662 | bool is_far_target) { |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2663 | if (true_target == false_target) { |
| 2664 | DCHECK(true_target != nullptr); |
| 2665 | __ B(true_target); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2666 | return; |
| 2667 | } |
| 2668 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2669 | vixl32::Label* non_fallthrough_target; |
| 2670 | bool invert; |
| 2671 | bool emit_both_branches; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2672 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2673 | if (true_target == nullptr) { |
| 2674 | // The true target is fallthrough. |
| 2675 | DCHECK(false_target != nullptr); |
| 2676 | non_fallthrough_target = false_target; |
| 2677 | invert = true; |
| 2678 | emit_both_branches = false; |
| 2679 | } else { |
| 2680 | non_fallthrough_target = true_target; |
| 2681 | invert = false; |
| 2682 | // Either the false target is fallthrough, or there is no fallthrough |
| 2683 | // and both branches must be emitted. |
| 2684 | emit_both_branches = (false_target != nullptr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2685 | } |
| 2686 | |
Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2687 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2688 | |
| 2689 | __ B(cond.first, non_fallthrough_target, is_far_target); |
| 2690 | |
| 2691 | if (emit_both_branches) { |
| 2692 | // No target falls through, we need to branch. |
| 2693 | __ B(false_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2694 | } |
| 2695 | } |
| 2696 | |
| 2697 | void InstructionCodeGeneratorARMVIXL::GenerateTestAndBranch(HInstruction* instruction, |
| 2698 | size_t condition_input_index, |
| 2699 | vixl32::Label* true_target, |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2700 | vixl32::Label* false_target, |
| 2701 | bool far_target) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2702 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2703 | |
| 2704 | if (true_target == nullptr && false_target == nullptr) { |
| 2705 | // Nothing to do. The code always falls through. |
| 2706 | return; |
| 2707 | } else if (cond->IsIntConstant()) { |
| 2708 | // Constant condition, statically compared against "true" (integer value 1). |
| 2709 | if (cond->AsIntConstant()->IsTrue()) { |
| 2710 | if (true_target != nullptr) { |
| 2711 | __ B(true_target); |
| 2712 | } |
| 2713 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2714 | DCHECK(cond->AsIntConstant()->IsFalse()) << Int32ConstantFrom(cond); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2715 | if (false_target != nullptr) { |
| 2716 | __ B(false_target); |
| 2717 | } |
| 2718 | } |
| 2719 | return; |
| 2720 | } |
| 2721 | |
| 2722 | // The following code generates these patterns: |
| 2723 | // (1) true_target == nullptr && false_target != nullptr |
| 2724 | // - opposite condition true => branch to false_target |
| 2725 | // (2) true_target != nullptr && false_target == nullptr |
| 2726 | // - condition true => branch to true_target |
| 2727 | // (3) true_target != nullptr && false_target != nullptr |
| 2728 | // - condition true => branch to true_target |
| 2729 | // - branch to false_target |
| 2730 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2731 | // Condition has been materialized, compare the output to 0. |
| 2732 | if (kIsDebugBuild) { |
| 2733 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2734 | DCHECK(cond_val.IsRegister()); |
| 2735 | } |
| 2736 | if (true_target == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2737 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, condition_input_index), |
| 2738 | false_target, |
| 2739 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2740 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2741 | __ CompareAndBranchIfNonZero(InputRegisterAt(instruction, condition_input_index), |
| 2742 | true_target, |
| 2743 | far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2744 | } |
| 2745 | } else { |
| 2746 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2747 | // its condition as the branch condition. |
| 2748 | HCondition* condition = cond->AsCondition(); |
| 2749 | |
| 2750 | // If this is a long or FP comparison that has been folded into |
| 2751 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2752 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 2753 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2754 | GenerateCompareTestAndBranch(condition, true_target, false_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2755 | return; |
| 2756 | } |
| 2757 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2758 | vixl32::Label* non_fallthrough_target; |
| 2759 | vixl32::Condition arm_cond = vixl32::Condition::None(); |
| 2760 | const vixl32::Register left = InputRegisterAt(cond, 0); |
| 2761 | const Operand right = InputOperandAt(cond, 1); |
| 2762 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2763 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2764 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2765 | non_fallthrough_target = false_target; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2766 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2767 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2768 | non_fallthrough_target = true_target; |
| 2769 | } |
| 2770 | |
| 2771 | if (right.IsImmediate() && right.GetImmediate() == 0 && (arm_cond.Is(ne) || arm_cond.Is(eq))) { |
| 2772 | if (arm_cond.Is(eq)) { |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2773 | __ CompareAndBranchIfZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2774 | } else { |
| 2775 | DCHECK(arm_cond.Is(ne)); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2776 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target, far_target); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2777 | } |
| 2778 | } else { |
| 2779 | __ Cmp(left, right); |
Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2780 | __ B(arm_cond, non_fallthrough_target, far_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2781 | } |
| 2782 | } |
| 2783 | |
| 2784 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2785 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2786 | if (true_target != nullptr && false_target != nullptr) { |
| 2787 | __ B(false_target); |
| 2788 | } |
| 2789 | } |
| 2790 | |
| 2791 | void LocationsBuilderARMVIXL::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2792 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2793 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| 2794 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | void InstructionCodeGeneratorARMVIXL::VisitIf(HIf* if_instr) { |
| 2799 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2800 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2801 | vixl32::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2802 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2803 | vixl32::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2804 | nullptr : codegen_->GetLabelOf(false_successor); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2805 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2806 | } |
| 2807 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2808 | void LocationsBuilderARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2809 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2810 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 2811 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 2812 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2813 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 2814 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2815 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| 2816 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | void InstructionCodeGeneratorARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2821 | SlowPathCodeARMVIXL* slow_path = |
| 2822 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARMVIXL>(deoptimize); |
| 2823 | GenerateTestAndBranch(deoptimize, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2824 | /* condition_input_index= */ 0, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2825 | slow_path->GetEntryLabel(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2826 | /* false_target= */ nullptr); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2827 | } |
| 2828 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2829 | void LocationsBuilderARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2830 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2831 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2832 | locations->SetOut(Location::RequiresRegister()); |
| 2833 | } |
| 2834 | |
| 2835 | void InstructionCodeGeneratorARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2836 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2837 | OutputRegister(flag), |
| 2838 | sp, |
| 2839 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2840 | } |
| 2841 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2842 | void LocationsBuilderARMVIXL::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2843 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2844 | const bool is_floating_point = DataType::IsFloatingPointType(select->GetType()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2845 | |
| 2846 | if (is_floating_point) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2847 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2848 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2849 | } else { |
| 2850 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2851 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2852 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2853 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2854 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2855 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 2856 | // The code generator handles overlap with the values, but not with the condition. |
| 2857 | locations->SetOut(Location::SameAsFirstInput()); |
| 2858 | } else if (is_floating_point) { |
| 2859 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2860 | } else { |
| 2861 | if (!locations->InAt(1).IsConstant()) { |
| 2862 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 2863 | } |
| 2864 | |
| 2865 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2866 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | void InstructionCodeGeneratorARMVIXL::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2870 | HInstruction* const condition = select->GetCondition(); |
| 2871 | const LocationSummary* const locations = select->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2872 | const DataType::Type type = select->GetType(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2873 | const Location first = locations->InAt(0); |
| 2874 | const Location out = locations->Out(); |
| 2875 | const Location second = locations->InAt(1); |
Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2876 | |
| 2877 | // In the unlucky case the output of this instruction overlaps |
| 2878 | // with an input of an "emitted-at-use-site" condition, and |
| 2879 | // the output of this instruction is not one of its inputs, we'll |
| 2880 | // need to fallback to branches instead of conditional ARM instructions. |
| 2881 | bool output_overlaps_with_condition_inputs = |
| 2882 | !IsBooleanValueOrMaterializedCondition(condition) && |
| 2883 | !out.Equals(first) && |
| 2884 | !out.Equals(second) && |
| 2885 | (condition->GetLocations()->InAt(0).Equals(out) || |
| 2886 | condition->GetLocations()->InAt(1).Equals(out)); |
| 2887 | DCHECK(!output_overlaps_with_condition_inputs || condition->IsCondition()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2888 | Location src; |
| 2889 | |
| 2890 | if (condition->IsIntConstant()) { |
| 2891 | if (condition->AsIntConstant()->IsFalse()) { |
| 2892 | src = first; |
| 2893 | } else { |
| 2894 | src = second; |
| 2895 | } |
| 2896 | |
| 2897 | codegen_->MoveLocation(out, src, type); |
| 2898 | return; |
| 2899 | } |
| 2900 | |
Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2901 | if (!DataType::IsFloatingPointType(type) && !output_overlaps_with_condition_inputs) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2902 | bool invert = false; |
| 2903 | |
| 2904 | if (out.Equals(second)) { |
| 2905 | src = first; |
| 2906 | invert = true; |
| 2907 | } else if (out.Equals(first)) { |
| 2908 | src = second; |
| 2909 | } else if (second.IsConstant()) { |
| 2910 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 2911 | src = second; |
| 2912 | } else if (first.IsConstant()) { |
| 2913 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 2914 | src = first; |
| 2915 | invert = true; |
| 2916 | } else { |
| 2917 | src = second; |
| 2918 | } |
| 2919 | |
| 2920 | if (CanGenerateConditionalMove(out, src)) { |
| 2921 | if (!out.Equals(first) && !out.Equals(second)) { |
| 2922 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 2923 | } |
| 2924 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2925 | std::pair<vixl32::Condition, vixl32::Condition> cond(eq, ne); |
| 2926 | |
| 2927 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 2928 | __ Cmp(InputRegisterAt(select, 2), 0); |
| 2929 | cond = invert ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
| 2930 | } else { |
| 2931 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 2932 | } |
| 2933 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2934 | const size_t instr_count = out.IsRegisterPair() ? 4 : 2; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2935 | // We use the scope because of the IT block that follows. |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2936 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 2937 | instr_count * vixl32::k16BitT32InstructionSizeInBytes, |
| 2938 | CodeBufferCheckScope::kExactSize); |
| 2939 | |
| 2940 | if (out.IsRegister()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2941 | __ it(cond.first); |
| 2942 | __ mov(cond.first, RegisterFrom(out), OperandFrom(src, type)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2943 | } else { |
| 2944 | DCHECK(out.IsRegisterPair()); |
| 2945 | |
| 2946 | Operand operand_high(0); |
| 2947 | Operand operand_low(0); |
| 2948 | |
| 2949 | if (src.IsConstant()) { |
| 2950 | const int64_t value = Int64ConstantFrom(src); |
| 2951 | |
| 2952 | operand_high = High32Bits(value); |
| 2953 | operand_low = Low32Bits(value); |
| 2954 | } else { |
| 2955 | DCHECK(src.IsRegisterPair()); |
| 2956 | operand_high = HighRegisterFrom(src); |
| 2957 | operand_low = LowRegisterFrom(src); |
| 2958 | } |
| 2959 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2960 | __ it(cond.first); |
| 2961 | __ mov(cond.first, LowRegisterFrom(out), operand_low); |
| 2962 | __ it(cond.first); |
| 2963 | __ mov(cond.first, HighRegisterFrom(out), operand_high); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | return; |
| 2967 | } |
| 2968 | } |
| 2969 | |
| 2970 | vixl32::Label* false_target = nullptr; |
| 2971 | vixl32::Label* true_target = nullptr; |
| 2972 | vixl32::Label select_end; |
Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2973 | vixl32::Label other_case; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2974 | vixl32::Label* const target = codegen_->GetFinalLabel(select, &select_end); |
| 2975 | |
| 2976 | if (out.Equals(second)) { |
| 2977 | true_target = target; |
| 2978 | src = first; |
| 2979 | } else { |
| 2980 | false_target = target; |
| 2981 | src = second; |
| 2982 | |
| 2983 | if (!out.Equals(first)) { |
Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2984 | if (output_overlaps_with_condition_inputs) { |
| 2985 | false_target = &other_case; |
| 2986 | } else { |
| 2987 | codegen_->MoveLocation(out, first, type); |
| 2988 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2989 | } |
| 2990 | } |
| 2991 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2992 | GenerateTestAndBranch(select, 2, true_target, false_target, /* far_target= */ false); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2993 | codegen_->MoveLocation(out, src, type); |
Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2994 | if (output_overlaps_with_condition_inputs) { |
| 2995 | __ B(target); |
| 2996 | __ Bind(&other_case); |
| 2997 | codegen_->MoveLocation(out, first, type); |
| 2998 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2999 | |
| 3000 | if (select_end.IsReferenced()) { |
| 3001 | __ Bind(&select_end); |
| 3002 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3003 | } |
| 3004 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3005 | void LocationsBuilderARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3006 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 3007 | } |
| 3008 | |
| 3009 | void InstructionCodeGeneratorARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3010 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| 3011 | } |
| 3012 | |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3013 | void CodeGeneratorARMVIXL::IncreaseFrame(size_t adjustment) { |
| 3014 | __ Claim(adjustment); |
| 3015 | GetAssembler()->cfi().AdjustCFAOffset(adjustment); |
| 3016 | } |
| 3017 | |
| 3018 | void CodeGeneratorARMVIXL::DecreaseFrame(size_t adjustment) { |
| 3019 | __ Drop(adjustment); |
| 3020 | GetAssembler()->cfi().AdjustCFAOffset(-adjustment); |
| 3021 | } |
| 3022 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3023 | void CodeGeneratorARMVIXL::GenerateNop() { |
| 3024 | __ Nop(); |
| 3025 | } |
| 3026 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3027 | // `temp` is an extra temporary register that is used for some conditions; |
| 3028 | // callers may not specify it, in which case the method will use a scratch |
| 3029 | // register instead. |
| 3030 | void CodeGeneratorARMVIXL::GenerateConditionWithZero(IfCondition condition, |
| 3031 | vixl32::Register out, |
| 3032 | vixl32::Register in, |
| 3033 | vixl32::Register temp) { |
| 3034 | switch (condition) { |
| 3035 | case kCondEQ: |
| 3036 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 3037 | case kCondBE: |
| 3038 | if (!temp.IsValid() || (out.IsLow() && !out.Is(in))) { |
| 3039 | temp = out; |
| 3040 | } |
| 3041 | |
| 3042 | // Avoid 32-bit instructions if possible; note that `in` and `temp` must be |
| 3043 | // different as well. |
| 3044 | if (in.IsLow() && temp.IsLow() && !in.Is(temp)) { |
| 3045 | // temp = - in; only 0 sets the carry flag. |
| 3046 | __ Rsbs(temp, in, 0); |
| 3047 | |
| 3048 | if (out.Is(in)) { |
| 3049 | std::swap(in, temp); |
| 3050 | } |
| 3051 | |
| 3052 | // out = - in + in + carry = carry |
| 3053 | __ Adc(out, temp, in); |
| 3054 | } else { |
| 3055 | // If `in` is 0, then it has 32 leading zeros, and less than that otherwise. |
| 3056 | __ Clz(out, in); |
| 3057 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 3058 | // the same operation on 32 yields 1. |
| 3059 | __ Lsr(out, out, 5); |
| 3060 | } |
| 3061 | |
| 3062 | break; |
| 3063 | case kCondNE: |
| 3064 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 3065 | case kCondA: { |
| 3066 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3067 | |
| 3068 | if (out.Is(in)) { |
| 3069 | if (!temp.IsValid() || in.Is(temp)) { |
| 3070 | temp = temps.Acquire(); |
| 3071 | } |
| 3072 | } else if (!temp.IsValid() || !temp.IsLow()) { |
| 3073 | temp = out; |
| 3074 | } |
| 3075 | |
| 3076 | // temp = in - 1; only 0 does not set the carry flag. |
| 3077 | __ Subs(temp, in, 1); |
| 3078 | // out = in + ~temp + carry = in + (-(in - 1) - 1) + carry = in - in + 1 - 1 + carry = carry |
| 3079 | __ Sbc(out, in, temp); |
| 3080 | break; |
| 3081 | } |
| 3082 | case kCondGE: |
| 3083 | __ Mvn(out, in); |
| 3084 | in = out; |
| 3085 | FALLTHROUGH_INTENDED; |
| 3086 | case kCondLT: |
| 3087 | // We only care about the sign bit. |
| 3088 | __ Lsr(out, in, 31); |
| 3089 | break; |
| 3090 | case kCondAE: |
| 3091 | // Trivially true. |
| 3092 | __ Mov(out, 1); |
| 3093 | break; |
| 3094 | case kCondB: |
| 3095 | // Trivially false. |
| 3096 | __ Mov(out, 0); |
| 3097 | break; |
| 3098 | default: |
| 3099 | LOG(FATAL) << "Unexpected condition " << condition; |
| 3100 | UNREACHABLE(); |
| 3101 | } |
| 3102 | } |
| 3103 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3104 | void LocationsBuilderARMVIXL::HandleCondition(HCondition* cond) { |
| 3105 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3106 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 3107 | const DataType::Type type = cond->InputAt(0)->GetType(); |
| 3108 | if (DataType::IsFloatingPointType(type)) { |
| 3109 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3110 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
| 3111 | } else { |
| 3112 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3113 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 3114 | } |
| 3115 | if (!cond->IsEmittedAtUseSite()) { |
| 3116 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3117 | } |
| 3118 | } |
| 3119 | |
| 3120 | void InstructionCodeGeneratorARMVIXL::HandleCondition(HCondition* cond) { |
| 3121 | if (cond->IsEmittedAtUseSite()) { |
| 3122 | return; |
| 3123 | } |
| 3124 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3125 | const DataType::Type type = cond->GetLeft()->GetType(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3126 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3127 | if (DataType::IsFloatingPointType(type)) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3128 | GenerateConditionGeneric(cond, codegen_); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3129 | return; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3130 | } |
| 3131 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3132 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3133 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3134 | const IfCondition condition = cond->GetCondition(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3135 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3136 | // A condition with only one boolean input, or two boolean inputs without being equality or |
| 3137 | // inequality results from transformations done by the instruction simplifier, and is handled |
| 3138 | // as a regular condition with integral inputs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3139 | if (type == DataType::Type::kBool && |
| 3140 | cond->GetRight()->GetType() == DataType::Type::kBool && |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3141 | (condition == kCondEQ || condition == kCondNE)) { |
| 3142 | vixl32::Register left = InputRegisterAt(cond, 0); |
| 3143 | const vixl32::Register out = OutputRegister(cond); |
| 3144 | const Location right_loc = cond->GetLocations()->InAt(1); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3145 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3146 | // The constant case is handled by the instruction simplifier. |
| 3147 | DCHECK(!right_loc.IsConstant()); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3148 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3149 | vixl32::Register right = RegisterFrom(right_loc); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3150 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3151 | // Avoid 32-bit instructions if possible. |
| 3152 | if (out.Is(right)) { |
| 3153 | std::swap(left, right); |
| 3154 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3155 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3156 | __ Eor(out, left, right); |
| 3157 | |
| 3158 | if (condition == kCondEQ) { |
| 3159 | __ Eor(out, out, 1); |
| 3160 | } |
| 3161 | |
| 3162 | return; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3163 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 3164 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3165 | GenerateConditionIntegralOrNonPrimitive(cond, codegen_); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | void LocationsBuilderARMVIXL::VisitEqual(HEqual* comp) { |
| 3169 | HandleCondition(comp); |
| 3170 | } |
| 3171 | |
| 3172 | void InstructionCodeGeneratorARMVIXL::VisitEqual(HEqual* comp) { |
| 3173 | HandleCondition(comp); |
| 3174 | } |
| 3175 | |
| 3176 | void LocationsBuilderARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3177 | HandleCondition(comp); |
| 3178 | } |
| 3179 | |
| 3180 | void InstructionCodeGeneratorARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3181 | HandleCondition(comp); |
| 3182 | } |
| 3183 | |
| 3184 | void LocationsBuilderARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3185 | HandleCondition(comp); |
| 3186 | } |
| 3187 | |
| 3188 | void InstructionCodeGeneratorARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3189 | HandleCondition(comp); |
| 3190 | } |
| 3191 | |
| 3192 | void LocationsBuilderARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3193 | HandleCondition(comp); |
| 3194 | } |
| 3195 | |
| 3196 | void InstructionCodeGeneratorARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3197 | HandleCondition(comp); |
| 3198 | } |
| 3199 | |
| 3200 | void LocationsBuilderARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3201 | HandleCondition(comp); |
| 3202 | } |
| 3203 | |
| 3204 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3205 | HandleCondition(comp); |
| 3206 | } |
| 3207 | |
| 3208 | void LocationsBuilderARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3209 | HandleCondition(comp); |
| 3210 | } |
| 3211 | |
| 3212 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3213 | HandleCondition(comp); |
| 3214 | } |
| 3215 | |
| 3216 | void LocationsBuilderARMVIXL::VisitBelow(HBelow* comp) { |
| 3217 | HandleCondition(comp); |
| 3218 | } |
| 3219 | |
| 3220 | void InstructionCodeGeneratorARMVIXL::VisitBelow(HBelow* comp) { |
| 3221 | HandleCondition(comp); |
| 3222 | } |
| 3223 | |
| 3224 | void LocationsBuilderARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3225 | HandleCondition(comp); |
| 3226 | } |
| 3227 | |
| 3228 | void InstructionCodeGeneratorARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3229 | HandleCondition(comp); |
| 3230 | } |
| 3231 | |
| 3232 | void LocationsBuilderARMVIXL::VisitAbove(HAbove* comp) { |
| 3233 | HandleCondition(comp); |
| 3234 | } |
| 3235 | |
| 3236 | void InstructionCodeGeneratorARMVIXL::VisitAbove(HAbove* comp) { |
| 3237 | HandleCondition(comp); |
| 3238 | } |
| 3239 | |
| 3240 | void LocationsBuilderARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3241 | HandleCondition(comp); |
| 3242 | } |
| 3243 | |
| 3244 | void InstructionCodeGeneratorARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3245 | HandleCondition(comp); |
| 3246 | } |
| 3247 | |
| 3248 | void LocationsBuilderARMVIXL::VisitIntConstant(HIntConstant* constant) { |
| 3249 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3250 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3251 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3252 | } |
| 3253 | |
| 3254 | void InstructionCodeGeneratorARMVIXL::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 3255 | // Will be generated at use site. |
| 3256 | } |
| 3257 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3258 | void LocationsBuilderARMVIXL::VisitNullConstant(HNullConstant* constant) { |
| 3259 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3260 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3261 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3262 | } |
| 3263 | |
| 3264 | void InstructionCodeGeneratorARMVIXL::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 3265 | // Will be generated at use site. |
| 3266 | } |
| 3267 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3268 | void LocationsBuilderARMVIXL::VisitLongConstant(HLongConstant* constant) { |
| 3269 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3270 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3271 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3272 | } |
| 3273 | |
| 3274 | void InstructionCodeGeneratorARMVIXL::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 3275 | // Will be generated at use site. |
| 3276 | } |
| 3277 | |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3278 | void LocationsBuilderARMVIXL::VisitFloatConstant(HFloatConstant* constant) { |
| 3279 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3280 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3281 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3282 | } |
| 3283 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3284 | void InstructionCodeGeneratorARMVIXL::VisitFloatConstant( |
| 3285 | HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3286 | // Will be generated at use site. |
| 3287 | } |
| 3288 | |
| 3289 | void LocationsBuilderARMVIXL::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3290 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3291 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3292 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3293 | } |
| 3294 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3295 | void InstructionCodeGeneratorARMVIXL::VisitDoubleConstant( |
| 3296 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3297 | // Will be generated at use site. |
| 3298 | } |
| 3299 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3300 | void LocationsBuilderARMVIXL::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3301 | constructor_fence->SetLocations(nullptr); |
| 3302 | } |
| 3303 | |
| 3304 | void InstructionCodeGeneratorARMVIXL::VisitConstructorFence( |
| 3305 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3306 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3307 | } |
| 3308 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3309 | void LocationsBuilderARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3310 | memory_barrier->SetLocations(nullptr); |
| 3311 | } |
| 3312 | |
| 3313 | void InstructionCodeGeneratorARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3314 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3315 | } |
| 3316 | |
| 3317 | void LocationsBuilderARMVIXL::VisitReturnVoid(HReturnVoid* ret) { |
| 3318 | ret->SetLocations(nullptr); |
| 3319 | } |
| 3320 | |
| 3321 | void InstructionCodeGeneratorARMVIXL::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3322 | codegen_->GenerateFrameExit(); |
| 3323 | } |
| 3324 | |
| 3325 | void LocationsBuilderARMVIXL::VisitReturn(HReturn* ret) { |
| 3326 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3327 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3328 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
| 3329 | } |
| 3330 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 3331 | void InstructionCodeGeneratorARMVIXL::VisitReturn(HReturn* ret) { |
| 3332 | if (GetGraph()->IsCompilingOsr()) { |
| 3333 | // To simplify callers of an OSR method, we put the return value in both |
| 3334 | // floating point and core registers. |
| 3335 | switch (ret->InputAt(0)->GetType()) { |
| 3336 | case DataType::Type::kFloat32: |
| 3337 | __ Vmov(r0, s0); |
| 3338 | break; |
| 3339 | case DataType::Type::kFloat64: |
| 3340 | __ Vmov(r0, r1, d0); |
| 3341 | break; |
| 3342 | default: |
| 3343 | break; |
| 3344 | } |
| 3345 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3346 | codegen_->GenerateFrameExit(); |
| 3347 | } |
| 3348 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3349 | void LocationsBuilderARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3350 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3351 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3352 | // the method_idx. |
| 3353 | HandleInvoke(invoke); |
| 3354 | } |
| 3355 | |
| 3356 | void InstructionCodeGeneratorARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3357 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3358 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 3); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3359 | } |
| 3360 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3361 | void LocationsBuilderARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3362 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3363 | // art::PrepareForRegisterAllocation. |
| 3364 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3365 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3366 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3367 | if (intrinsic.TryDispatch(invoke)) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3368 | return; |
| 3369 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3370 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 3371 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 3372 | CriticalNativeCallingConventionVisitorARMVIXL calling_convention_visitor( |
| 3373 | /*for_register_allocation=*/ true); |
| 3374 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3375 | } else { |
| 3376 | HandleInvoke(invoke); |
| 3377 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3378 | } |
| 3379 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3380 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARMVIXL* codegen) { |
| 3381 | if (invoke->GetLocations()->Intrinsified()) { |
| 3382 | IntrinsicCodeGeneratorARMVIXL intrinsic(codegen); |
| 3383 | intrinsic.Dispatch(invoke); |
| 3384 | return true; |
| 3385 | } |
| 3386 | return false; |
| 3387 | } |
| 3388 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3389 | void InstructionCodeGeneratorARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3390 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3391 | // art::PrepareForRegisterAllocation. |
| 3392 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3393 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3394 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3395 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 4); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3396 | return; |
| 3397 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3398 | |
| 3399 | LocationSummary* locations = invoke->GetLocations(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3400 | codegen_->GenerateStaticOrDirectCall( |
| 3401 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3402 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3403 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 5); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3404 | } |
| 3405 | |
| 3406 | void LocationsBuilderARMVIXL::HandleInvoke(HInvoke* invoke) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3407 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3408 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3409 | } |
| 3410 | |
| 3411 | void LocationsBuilderARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3412 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3413 | if (intrinsic.TryDispatch(invoke)) { |
| 3414 | return; |
| 3415 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3416 | |
| 3417 | HandleInvoke(invoke); |
| 3418 | } |
| 3419 | |
| 3420 | void InstructionCodeGeneratorARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3421 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3422 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 6); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3423 | return; |
| 3424 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3425 | |
| 3426 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3427 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3428 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3429 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 7); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3430 | } |
| 3431 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3432 | void LocationsBuilderARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3433 | HandleInvoke(invoke); |
| 3434 | // Add the hidden argument. |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 3435 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 3436 | // We cannot request r12 as it's blocked by the register allocator. |
| 3437 | invoke->GetLocations()->SetInAt(invoke->GetNumberOfArguments() - 1, Location::Any()); |
| 3438 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3439 | } |
| 3440 | |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3441 | void CodeGeneratorARMVIXL::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 3442 | vixl32::Register klass) { |
| 3443 | DCHECK_EQ(r0.GetCode(), klass.GetCode()); |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 3444 | // We know the destination of an intrinsic, so no need to record inline |
| 3445 | // caches. |
| 3446 | if (!instruction->GetLocations()->Intrinsified() && |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 3447 | GetGraph()->IsCompilingBaseline() && |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 3448 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3449 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 3450 | ScopedProfilingInfoUse spiu( |
| 3451 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 3452 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 3453 | if (info != nullptr) { |
| 3454 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 3455 | uint32_t address = reinterpret_cast32<uint32_t>(cache); |
| 3456 | vixl32::Label done; |
| 3457 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3458 | temps.Exclude(ip); |
| 3459 | __ Mov(r4, address); |
| 3460 | __ Ldr(ip, MemOperand(r4, InlineCache::ClassesOffset().Int32Value())); |
| 3461 | // Fast path for a monomorphic cache. |
| 3462 | __ Cmp(klass, ip); |
| 3463 | __ B(eq, &done, /* is_far_target= */ false); |
| 3464 | InvokeRuntime(kQuickUpdateInlineCache, instruction, instruction->GetDexPc()); |
| 3465 | __ Bind(&done); |
| 3466 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3467 | } |
| 3468 | } |
| 3469 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3470 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3471 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 3472 | LocationSummary* locations = invoke->GetLocations(); |
| 3473 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3474 | Location receiver = locations->InAt(0); |
| 3475 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3476 | |
| 3477 | DCHECK(!receiver.IsStackSlot()); |
| 3478 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3479 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 3480 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3481 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 3482 | vixl32::kMaxInstructionSizeInBytes, |
| 3483 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3484 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 3485 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 3486 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3487 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3488 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3489 | // emit a read barrier for the previous class reference load. |
| 3490 | // However this is not required in practice, as this is an |
| 3491 | // intermediate/temporary reference and because the current |
| 3492 | // concurrent copying collector keeps the from-space memory |
| 3493 | // intact/accessible until the end of the marking phase (the |
| 3494 | // concurrent copying collector may not in the future). |
| 3495 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3496 | |
| 3497 | // If we're compiling baseline, update the inline cache. |
| 3498 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 3499 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3500 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3501 | temp, |
| 3502 | temp, |
| 3503 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3504 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3505 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 3506 | invoke->GetImtIndex(), kArmPointerSize)); |
| 3507 | // temp = temp->GetImtEntryAt(method_offset); |
| 3508 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3509 | uint32_t entry_point = |
| 3510 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 3511 | // LR = temp->GetEntryPoint(); |
| 3512 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 3513 | |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3514 | { |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 3515 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 3516 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 3517 | Location hidden_reg = Location::RegisterLocation(r12.GetCode()); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3518 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 3519 | // so it checks if the application is using them (by passing them to the macro assembler |
| 3520 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 3521 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 3522 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 3523 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 3524 | // (to materialize the constant), since the destination register becomes available for such use |
| 3525 | // internally for the duration of the macro instruction. |
| 3526 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 3527 | temps.Exclude(RegisterFrom(hidden_reg)); |
| 3528 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 3529 | Location current_method = locations->InAt(invoke->GetNumberOfArguments() - 1); |
| 3530 | if (current_method.IsStackSlot()) { |
| 3531 | GetAssembler()->LoadFromOffset( |
| 3532 | kLoadWord, RegisterFrom(hidden_reg), sp, current_method.GetStackIndex()); |
| 3533 | } else { |
| 3534 | __ Mov(RegisterFrom(hidden_reg), RegisterFrom(current_method)); |
| 3535 | } |
| 3536 | } else { |
| 3537 | codegen_->LoadMethod(invoke->GetHiddenArgumentLoadKind(), hidden_reg, invoke); |
| 3538 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3539 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3540 | { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3541 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 3542 | // 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] | 3543 | ExactAssemblyScope aas(GetVIXLAssembler(), |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3544 | vixl32::k16BitT32InstructionSizeInBytes, |
| 3545 | CodeBufferCheckScope::kExactSize); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3546 | // LR(); |
| 3547 | __ blx(lr); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3548 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3549 | DCHECK(!codegen_->IsLeafMethod()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3550 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3551 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3552 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 8); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3553 | } |
| 3554 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3555 | void LocationsBuilderARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3556 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3557 | if (intrinsic.TryDispatch(invoke)) { |
| 3558 | return; |
| 3559 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3560 | HandleInvoke(invoke); |
| 3561 | } |
| 3562 | |
| 3563 | void InstructionCodeGeneratorARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3564 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3565 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 9); |
| 3566 | return; |
| 3567 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3568 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3569 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 10); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3570 | } |
| 3571 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 3572 | void LocationsBuilderARMVIXL::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 3573 | HandleInvoke(invoke); |
| 3574 | } |
| 3575 | |
| 3576 | void InstructionCodeGeneratorARMVIXL::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 3577 | codegen_->GenerateInvokeCustomCall(invoke); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3578 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 11); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 3579 | } |
| 3580 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3581 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 3582 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3583 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3584 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3585 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3586 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3587 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3588 | break; |
| 3589 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3590 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3591 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3592 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3593 | break; |
| 3594 | } |
| 3595 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3596 | case DataType::Type::kFloat32: |
| 3597 | case DataType::Type::kFloat64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3598 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3599 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3600 | break; |
| 3601 | |
| 3602 | default: |
| 3603 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3604 | } |
| 3605 | } |
| 3606 | |
| 3607 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 3608 | LocationSummary* locations = neg->GetLocations(); |
| 3609 | Location out = locations->Out(); |
| 3610 | Location in = locations->InAt(0); |
| 3611 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3612 | case DataType::Type::kInt32: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3613 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 3614 | break; |
| 3615 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3616 | case DataType::Type::kInt64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3617 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3618 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 3619 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3620 | // instruction here, as it does not exist in the Thumb-2 |
| 3621 | // instruction set. We use the following approach |
| 3622 | // using SBC and SUB instead. |
| 3623 | // |
| 3624 | // out.hi = -C |
| 3625 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 3626 | // out.hi = out.hi - in.hi |
| 3627 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 3628 | break; |
| 3629 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3630 | case DataType::Type::kFloat32: |
| 3631 | case DataType::Type::kFloat64: |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3632 | __ Vneg(OutputVRegister(neg), InputVRegister(neg)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3633 | break; |
| 3634 | |
| 3635 | default: |
| 3636 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3637 | } |
| 3638 | } |
| 3639 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3640 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3641 | DataType::Type result_type = conversion->GetResultType(); |
| 3642 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3643 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3644 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3645 | |
| 3646 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3647 | // rely on a call to the runtime. |
| 3648 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3649 | (((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 3650 | && result_type == DataType::Type::kInt64) |
| 3651 | || (input_type == DataType::Type::kInt64 && result_type == DataType::Type::kFloat32)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3652 | ? LocationSummary::kCallOnMainOnly |
| 3653 | : LocationSummary::kNoCall; |
| 3654 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3655 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3656 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3657 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3658 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3659 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3660 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3661 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3662 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 3663 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3664 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3665 | break; |
| 3666 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3667 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3668 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3669 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3670 | locations->SetInAt(0, Location::Any()); |
| 3671 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3672 | break; |
| 3673 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3674 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3675 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3676 | locations->SetOut(Location::RequiresRegister()); |
| 3677 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3678 | break; |
| 3679 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3680 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3681 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3682 | locations->SetOut(Location::RequiresRegister()); |
| 3683 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3684 | break; |
| 3685 | |
| 3686 | default: |
| 3687 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3688 | << " to " << result_type; |
| 3689 | } |
| 3690 | break; |
| 3691 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3692 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3693 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3694 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3695 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3696 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3697 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3698 | case DataType::Type::kInt16: |
| 3699 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3700 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3701 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3702 | break; |
| 3703 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3704 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3705 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3706 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3707 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3708 | break; |
| 3709 | } |
| 3710 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3711 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3712 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3713 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 3714 | calling_convention.GetFpuRegisterAt(1))); |
| 3715 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3716 | break; |
| 3717 | } |
| 3718 | |
| 3719 | default: |
| 3720 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3721 | << " to " << result_type; |
| 3722 | } |
| 3723 | break; |
| 3724 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3725 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3726 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3727 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3728 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3729 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3730 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3731 | case DataType::Type::kInt16: |
| 3732 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3733 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3734 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3735 | break; |
| 3736 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3737 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3738 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3739 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 3740 | calling_convention.GetRegisterAt(1))); |
| 3741 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3742 | break; |
| 3743 | } |
| 3744 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3745 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3746 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3747 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3748 | break; |
| 3749 | |
| 3750 | default: |
| 3751 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3752 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3753 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3754 | break; |
| 3755 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3756 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3757 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3758 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3759 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3760 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3761 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3762 | case DataType::Type::kInt16: |
| 3763 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3764 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3765 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3766 | break; |
| 3767 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3768 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3769 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3770 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3771 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3772 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3773 | break; |
| 3774 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3775 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3776 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3777 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3778 | break; |
| 3779 | |
| 3780 | default: |
| 3781 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3782 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3783 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3784 | break; |
| 3785 | |
| 3786 | default: |
| 3787 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3788 | << " to " << result_type; |
| 3789 | } |
| 3790 | } |
| 3791 | |
| 3792 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3793 | LocationSummary* locations = conversion->GetLocations(); |
| 3794 | Location out = locations->Out(); |
| 3795 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3796 | DataType::Type result_type = conversion->GetResultType(); |
| 3797 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3798 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3799 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3800 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3801 | case DataType::Type::kUint8: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3802 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3803 | case DataType::Type::kInt8: |
| 3804 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3805 | case DataType::Type::kInt16: |
| 3806 | case DataType::Type::kInt32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3807 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3808 | break; |
| 3809 | case DataType::Type::kInt64: |
| 3810 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3811 | break; |
| 3812 | |
| 3813 | default: |
| 3814 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3815 | << " to " << result_type; |
| 3816 | } |
| 3817 | break; |
| 3818 | |
| 3819 | case DataType::Type::kInt8: |
| 3820 | switch (input_type) { |
| 3821 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3822 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3823 | case DataType::Type::kInt16: |
| 3824 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3825 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3826 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3827 | case DataType::Type::kInt64: |
| 3828 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3829 | break; |
| 3830 | |
| 3831 | default: |
| 3832 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3833 | << " to " << result_type; |
| 3834 | } |
| 3835 | break; |
| 3836 | |
| 3837 | case DataType::Type::kUint16: |
| 3838 | switch (input_type) { |
| 3839 | case DataType::Type::kInt8: |
| 3840 | case DataType::Type::kInt16: |
| 3841 | case DataType::Type::kInt32: |
| 3842 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3843 | break; |
| 3844 | case DataType::Type::kInt64: |
| 3845 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3846 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3847 | |
| 3848 | default: |
| 3849 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3850 | << " to " << result_type; |
| 3851 | } |
| 3852 | break; |
| 3853 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3854 | case DataType::Type::kInt16: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3855 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3856 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3857 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3858 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3859 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3860 | case DataType::Type::kInt64: |
| 3861 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3862 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3863 | |
| 3864 | default: |
| 3865 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3866 | << " to " << result_type; |
| 3867 | } |
| 3868 | break; |
| 3869 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3870 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3871 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3872 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3873 | DCHECK(out.IsRegister()); |
| 3874 | if (in.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3875 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3876 | } else if (in.IsDoubleStackSlot()) { |
| 3877 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3878 | OutputRegister(conversion), |
| 3879 | sp, |
| 3880 | in.GetStackIndex()); |
| 3881 | } else { |
| 3882 | DCHECK(in.IsConstant()); |
| 3883 | DCHECK(in.GetConstant()->IsLongConstant()); |
Vladimir Marko | ba1a48e | 2017-04-13 11:50:14 +0100 | [diff] [blame] | 3884 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3885 | __ Mov(OutputRegister(conversion), static_cast<int32_t>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3886 | } |
| 3887 | break; |
| 3888 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3889 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3890 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3891 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3892 | __ Vmov(OutputRegister(conversion), temp); |
| 3893 | break; |
| 3894 | } |
| 3895 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3896 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3897 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3898 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3899 | __ Vmov(OutputRegister(conversion), temp_s); |
| 3900 | break; |
| 3901 | } |
| 3902 | |
| 3903 | default: |
| 3904 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3905 | << " to " << result_type; |
| 3906 | } |
| 3907 | break; |
| 3908 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3909 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3910 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3911 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3912 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3913 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3914 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3915 | case DataType::Type::kInt16: |
| 3916 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3917 | DCHECK(out.IsRegisterPair()); |
| 3918 | DCHECK(in.IsRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3919 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3920 | // Sign extension. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3921 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3922 | break; |
| 3923 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3924 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3925 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 3926 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 3927 | break; |
| 3928 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3929 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3930 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 3931 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 3932 | break; |
| 3933 | |
| 3934 | default: |
| 3935 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3936 | << " to " << result_type; |
| 3937 | } |
| 3938 | break; |
| 3939 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3940 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3941 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3942 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3943 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3944 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3945 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3946 | case DataType::Type::kInt16: |
| 3947 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3948 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3949 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3950 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3951 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3952 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3953 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 3954 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 3955 | break; |
| 3956 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3957 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3958 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3959 | break; |
| 3960 | |
| 3961 | default: |
| 3962 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3963 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3964 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3965 | break; |
| 3966 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3967 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3968 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3969 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3970 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3971 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3972 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3973 | case DataType::Type::kInt16: |
| 3974 | case DataType::Type::kInt32: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3975 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3976 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3977 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3978 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3979 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3980 | vixl32::Register low = LowRegisterFrom(in); |
| 3981 | vixl32::Register high = HighRegisterFrom(in); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3982 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3983 | vixl32::DRegister out_d = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3984 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3985 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3986 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3987 | |
| 3988 | // temp_d = int-to-double(high) |
| 3989 | __ Vmov(temp_s, high); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3990 | __ Vcvt(F64, S32, temp_d, temp_s); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3991 | // constant_d = k2Pow32EncodingForDouble |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3992 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3993 | // out_d = unsigned-to-double(low) |
| 3994 | __ Vmov(out_s, low); |
| 3995 | __ Vcvt(F64, U32, out_d, out_s); |
| 3996 | // out_d += temp_d * constant_d |
| 3997 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 3998 | break; |
| 3999 | } |
| 4000 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4001 | case DataType::Type::kFloat32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 4002 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4003 | break; |
| 4004 | |
| 4005 | default: |
| 4006 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4007 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 4008 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4009 | break; |
| 4010 | |
| 4011 | default: |
| 4012 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4013 | << " to " << result_type; |
| 4014 | } |
| 4015 | } |
| 4016 | |
| 4017 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 4018 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4019 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4020 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4021 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4022 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4023 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 4024 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4025 | break; |
| 4026 | } |
| 4027 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4028 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4029 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4030 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4031 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4032 | break; |
| 4033 | } |
| 4034 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4035 | case DataType::Type::kFloat32: |
| 4036 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4037 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4038 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4039 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4040 | break; |
| 4041 | } |
| 4042 | |
| 4043 | default: |
| 4044 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4045 | } |
| 4046 | } |
| 4047 | |
| 4048 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 4049 | LocationSummary* locations = add->GetLocations(); |
| 4050 | Location out = locations->Out(); |
| 4051 | Location first = locations->InAt(0); |
| 4052 | Location second = locations->InAt(1); |
| 4053 | |
| 4054 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4055 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4056 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 4057 | } |
| 4058 | break; |
| 4059 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4060 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4061 | if (second.IsConstant()) { |
| 4062 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4063 | GenerateAddLongConst(out, first, value); |
| 4064 | } else { |
| 4065 | DCHECK(second.IsRegisterPair()); |
| 4066 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4067 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4068 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4069 | break; |
| 4070 | } |
| 4071 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4072 | case DataType::Type::kFloat32: |
| 4073 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4074 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4075 | break; |
| 4076 | |
| 4077 | default: |
| 4078 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4079 | } |
| 4080 | } |
| 4081 | |
| 4082 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 4083 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4084 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4085 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4086 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4087 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4088 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 4089 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4090 | break; |
| 4091 | } |
| 4092 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4093 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4094 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4095 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4096 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4097 | break; |
| 4098 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4099 | case DataType::Type::kFloat32: |
| 4100 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4101 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4102 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4103 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4104 | break; |
| 4105 | } |
| 4106 | default: |
| 4107 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4108 | } |
| 4109 | } |
| 4110 | |
| 4111 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 4112 | LocationSummary* locations = sub->GetLocations(); |
| 4113 | Location out = locations->Out(); |
| 4114 | Location first = locations->InAt(0); |
| 4115 | Location second = locations->InAt(1); |
| 4116 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4117 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4118 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4119 | break; |
| 4120 | } |
| 4121 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4122 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4123 | if (second.IsConstant()) { |
| 4124 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4125 | GenerateAddLongConst(out, first, -value); |
| 4126 | } else { |
| 4127 | DCHECK(second.IsRegisterPair()); |
| 4128 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4129 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4130 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4131 | break; |
| 4132 | } |
| 4133 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4134 | case DataType::Type::kFloat32: |
| 4135 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4136 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4137 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4138 | |
| 4139 | default: |
| 4140 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4141 | } |
| 4142 | } |
| 4143 | |
| 4144 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 4145 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4146 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4147 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4148 | case DataType::Type::kInt32: |
| 4149 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4150 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4151 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4152 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4153 | break; |
| 4154 | } |
| 4155 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4156 | case DataType::Type::kFloat32: |
| 4157 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4158 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4159 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4160 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4161 | break; |
| 4162 | } |
| 4163 | |
| 4164 | default: |
| 4165 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4166 | } |
| 4167 | } |
| 4168 | |
| 4169 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 4170 | LocationSummary* locations = mul->GetLocations(); |
| 4171 | Location out = locations->Out(); |
| 4172 | Location first = locations->InAt(0); |
| 4173 | Location second = locations->InAt(1); |
| 4174 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4175 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4176 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4177 | break; |
| 4178 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4179 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4180 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 4181 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 4182 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 4183 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 4184 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 4185 | vixl32::Register in2_lo = LowRegisterFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4186 | |
| 4187 | // Extra checks to protect caused by the existence of R1_R2. |
| 4188 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4189 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4190 | DCHECK(!out_hi.Is(in1_lo)); |
| 4191 | DCHECK(!out_hi.Is(in2_lo)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4192 | |
| 4193 | // input: in1 - 64 bits, in2 - 64 bits |
| 4194 | // output: out |
| 4195 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4196 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4197 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4198 | |
| 4199 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4200 | vixl32::Register temp = temps.Acquire(); |
| 4201 | // temp <- in1.lo * in2.hi |
| 4202 | __ Mul(temp, in1_lo, in2_hi); |
| 4203 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4204 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 4205 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4206 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 4207 | // 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] | 4208 | __ Add(out_hi, out_hi, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4209 | break; |
| 4210 | } |
| 4211 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4212 | case DataType::Type::kFloat32: |
| 4213 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4214 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4215 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4216 | |
| 4217 | default: |
| 4218 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4219 | } |
| 4220 | } |
| 4221 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4222 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4223 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4224 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4225 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4226 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4227 | DCHECK(second.IsConstant()); |
| 4228 | |
| 4229 | vixl32::Register out = OutputRegister(instruction); |
| 4230 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4231 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4232 | DCHECK(imm == 1 || imm == -1); |
| 4233 | |
| 4234 | if (instruction->IsRem()) { |
| 4235 | __ Mov(out, 0); |
| 4236 | } else { |
| 4237 | if (imm == 1) { |
| 4238 | __ Mov(out, dividend); |
| 4239 | } else { |
| 4240 | __ Rsb(out, dividend, 0); |
| 4241 | } |
| 4242 | } |
| 4243 | } |
| 4244 | |
| 4245 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4246 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4247 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4248 | |
| 4249 | LocationSummary* locations = instruction->GetLocations(); |
| 4250 | Location second = locations->InAt(1); |
| 4251 | DCHECK(second.IsConstant()); |
| 4252 | |
| 4253 | vixl32::Register out = OutputRegister(instruction); |
| 4254 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4255 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4256 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 4257 | int ctz_imm = CTZ(abs_imm); |
| 4258 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4259 | auto generate_div_code = [this, imm, ctz_imm](vixl32::Register out, vixl32::Register in) { |
| 4260 | __ Asr(out, in, ctz_imm); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4261 | if (imm < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4262 | __ Rsb(out, out, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4263 | } |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4264 | }; |
| 4265 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4266 | if (HasNonNegativeOrMinIntInputAt(instruction, 0)) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4267 | // No need to adjust the result for non-negative dividends or the INT32_MIN dividend. |
| 4268 | // NOTE: The generated code for HDiv/HRem correctly works for the INT32_MIN dividend: |
| 4269 | // imm == 2 |
| 4270 | // HDiv |
| 4271 | // add out, dividend(0x80000000), dividend(0x80000000), lsr #31 => out = 0x80000001 |
| 4272 | // asr out, out(0x80000001), #1 => out = 0xc0000000 |
| 4273 | // This is the same as 'asr out, dividend(0x80000000), #1' |
| 4274 | // |
| 4275 | // imm > 2 |
| 4276 | // HDiv |
| 4277 | // asr out, dividend(0x80000000), #31 => out = -1 |
| 4278 | // add out, dividend(0x80000000), out(-1), lsr #(32 - ctz_imm) => out = 0b10..01..1, |
| 4279 | // where the number of the rightmost 1s is ctz_imm. |
| 4280 | // asr out, out(0b10..01..1), #ctz_imm => out = 0b1..10..0, where the number of the |
| 4281 | // leftmost 1s is ctz_imm + 1. |
| 4282 | // This is the same as 'asr out, dividend(0x80000000), #ctz_imm'. |
| 4283 | // |
| 4284 | // imm == INT32_MIN |
| 4285 | // HDiv |
| 4286 | // asr out, dividend(0x80000000), #31 => out = -1 |
| 4287 | // add out, dividend(0x80000000), out(-1), lsr #1 => out = 0xc0000000 |
| 4288 | // asr out, out(0xc0000000), #31 => out = -1 |
| 4289 | // rsb out, out(-1), #0 => out = 1 |
| 4290 | // This is the same as |
| 4291 | // asr out, dividend(0x80000000), #31 |
| 4292 | // rsb out, out, #0 |
| 4293 | // |
| 4294 | // |
| 4295 | // INT_MIN % imm must be 0 for any imm of power 2. 'and' and 'ubfx' work only with bits |
| 4296 | // 0..30 of a dividend. For INT32_MIN those bits are zeros. So 'and' and 'ubfx' always |
| 4297 | // produce zero. |
| 4298 | if (instruction->IsDiv()) { |
| 4299 | generate_div_code(out, dividend); |
| 4300 | } else { |
| 4301 | if (GetVIXLAssembler()->IsModifiedImmediate(abs_imm - 1)) { |
| 4302 | __ And(out, dividend, abs_imm - 1); |
| 4303 | } else { |
| 4304 | __ Ubfx(out, dividend, 0, ctz_imm); |
| 4305 | } |
| 4306 | return; |
| 4307 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4308 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4309 | vixl32::Register add_right_input = dividend; |
| 4310 | if (ctz_imm > 1) { |
| 4311 | __ Asr(out, dividend, 31); |
| 4312 | add_right_input = out; |
| 4313 | } |
| 4314 | __ Add(out, dividend, Operand(add_right_input, vixl32::LSR, 32 - ctz_imm)); |
| 4315 | |
| 4316 | if (instruction->IsDiv()) { |
| 4317 | generate_div_code(out, out); |
| 4318 | } else { |
| 4319 | __ Bfc(out, 0, ctz_imm); |
| 4320 | __ Sub(out, dividend, out); |
| 4321 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4322 | } |
| 4323 | } |
| 4324 | |
| 4325 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4326 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4327 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4328 | |
| 4329 | LocationSummary* locations = instruction->GetLocations(); |
| 4330 | Location second = locations->InAt(1); |
| 4331 | DCHECK(second.IsConstant()); |
| 4332 | |
| 4333 | vixl32::Register out = OutputRegister(instruction); |
| 4334 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4335 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 4336 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4337 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4338 | |
| 4339 | int64_t magic; |
| 4340 | int shift; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4341 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4342 | |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 4343 | auto generate_unsigned_div_code =[this, magic, shift](vixl32::Register out, |
| 4344 | vixl32::Register dividend, |
| 4345 | vixl32::Register temp1, |
| 4346 | vixl32::Register temp2) { |
| 4347 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4348 | __ Mov(temp1, static_cast<int32_t>(magic)); |
| 4349 | if (magic > 0 && shift == 0) { |
| 4350 | __ Smull(temp2, out, dividend, temp1); |
| 4351 | } else { |
| 4352 | __ Smull(temp2, temp1, dividend, temp1); |
| 4353 | if (magic < 0) { |
| 4354 | // The negative magic M = static_cast<int>(m) means that the multiplier m is greater |
| 4355 | // than INT32_MAX. In such a case shift is never 0. |
| 4356 | // Proof: |
| 4357 | // m = (2^p + d - 2^p % d) / d, where p = 32 + shift, d > 2 |
| 4358 | // |
| 4359 | // If shift == 0, m = (2^32 + d - 2^32 % d) / d = |
| 4360 | // = (2^32 + d - (2^32 - (2^32 / d) * d)) / d = |
| 4361 | // = (d + (2^32 / d) * d) / d = 1 + (2^32 / d), here '/' is the integer division. |
| 4362 | // |
| 4363 | // 1 + (2^32 / d) is decreasing when d is increasing. |
| 4364 | // The maximum is 1 431 655 766, when d == 3. This value is less than INT32_MAX. |
| 4365 | // the minimum is 3, when d = 2^31 -1. |
| 4366 | // So for all values of d in [3, INT32_MAX] m with p == 32 is in [3, INT32_MAX) and |
| 4367 | // is never less than 0. |
| 4368 | __ Add(temp1, temp1, dividend); |
| 4369 | } |
| 4370 | DCHECK_NE(shift, 0); |
| 4371 | __ Lsr(out, temp1, shift); |
| 4372 | } |
| 4373 | }; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4374 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4375 | if (imm > 0 && HasNonNegativeInputAt(instruction, 0)) { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 4376 | // No need to adjust the result for a non-negative dividend and a positive divisor. |
| 4377 | if (instruction->IsDiv()) { |
| 4378 | generate_unsigned_div_code(out, dividend, temp1, temp2); |
| 4379 | } else { |
| 4380 | generate_unsigned_div_code(temp1, dividend, temp1, temp2); |
| 4381 | __ Mov(temp2, imm); |
| 4382 | __ Mls(out, temp1, temp2, dividend); |
| 4383 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4384 | } else { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 4385 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4386 | __ Mov(temp1, static_cast<int32_t>(magic)); |
| 4387 | __ Smull(temp2, temp1, dividend, temp1); |
| 4388 | |
| 4389 | if (imm > 0 && magic < 0) { |
| 4390 | __ Add(temp1, temp1, dividend); |
| 4391 | } else if (imm < 0 && magic > 0) { |
| 4392 | __ Sub(temp1, temp1, dividend); |
| 4393 | } |
| 4394 | |
| 4395 | if (shift != 0) { |
| 4396 | __ Asr(temp1, temp1, shift); |
| 4397 | } |
| 4398 | |
| 4399 | if (instruction->IsDiv()) { |
| 4400 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4401 | } else { |
| 4402 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4403 | // TODO: Strength reduction for mls. |
| 4404 | __ Mov(temp2, imm); |
| 4405 | __ Mls(out, temp1, temp2, dividend); |
| 4406 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4407 | } |
| 4408 | } |
| 4409 | |
| 4410 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 4411 | HBinaryOperation* instruction) { |
| 4412 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4413 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4414 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4415 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4416 | DCHECK(second.IsConstant()); |
| 4417 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4418 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4419 | if (imm == 0) { |
| 4420 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4421 | } else if (imm == 1 || imm == -1) { |
| 4422 | DivRemOneOrMinusOne(instruction); |
| 4423 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4424 | DivRemByPowerOfTwo(instruction); |
| 4425 | } else { |
| 4426 | DCHECK(imm <= -2 || imm >= 2); |
| 4427 | GenerateDivRemWithAnyConstant(instruction); |
| 4428 | } |
| 4429 | } |
| 4430 | |
| 4431 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 4432 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4433 | if (div->GetResultType() == DataType::Type::kInt64) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4434 | // pLdiv runtime call. |
| 4435 | call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4436 | } else if (div->GetResultType() == DataType::Type::kInt32 && div->InputAt(1)->IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4437 | // sdiv will be replaced by other instruction sequence. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4438 | } else if (div->GetResultType() == DataType::Type::kInt32 && |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4439 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4440 | // pIdivmod runtime call. |
| 4441 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4442 | } |
| 4443 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4444 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4445 | |
| 4446 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4447 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4448 | if (div->InputAt(1)->IsConstant()) { |
| 4449 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4450 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4451 | int32_t value = Int32ConstantFrom(div->InputAt(1)); |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4452 | Location::OutputOverlap out_overlaps = Location::kNoOutputOverlap; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4453 | if (value == 1 || value == 0 || value == -1) { |
| 4454 | // No temp register required. |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4455 | } else if (IsPowerOfTwo(AbsOrMin(value)) && |
| 4456 | value != 2 && |
| 4457 | value != -2 && |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4458 | !HasNonNegativeOrMinIntInputAt(div, 0)) { |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4459 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 4460 | out_overlaps = Location::kOutputOverlap; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4461 | } else { |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4462 | locations->AddRegisterTemps(2); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4463 | } |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4464 | locations->SetOut(Location::RequiresRegister(), out_overlaps); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4465 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4466 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4467 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4468 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4469 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4470 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4471 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4472 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4473 | // 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] | 4474 | // we only need the former. |
| 4475 | locations->SetOut(LocationFrom(r0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4476 | } |
| 4477 | break; |
| 4478 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4479 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4480 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4481 | locations->SetInAt(0, LocationFrom( |
| 4482 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4483 | locations->SetInAt(1, LocationFrom( |
| 4484 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4485 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4486 | break; |
| 4487 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4488 | case DataType::Type::kFloat32: |
| 4489 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4490 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4491 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4492 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4493 | break; |
| 4494 | } |
| 4495 | |
| 4496 | default: |
| 4497 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4498 | } |
| 4499 | } |
| 4500 | |
| 4501 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4502 | Location lhs = div->GetLocations()->InAt(0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4503 | Location rhs = div->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4504 | |
| 4505 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4506 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4507 | if (rhs.IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4508 | GenerateDivRemConstantIntegral(div); |
| 4509 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4510 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 4511 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4512 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4513 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 4514 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 4515 | DCHECK(r0.Is(OutputRegister(div))); |
| 4516 | |
| 4517 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 4518 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4519 | } |
| 4520 | break; |
| 4521 | } |
| 4522 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4523 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4524 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4525 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 4526 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 4527 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 4528 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 4529 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 4530 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 4531 | |
| 4532 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 4533 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4534 | break; |
| 4535 | } |
| 4536 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4537 | case DataType::Type::kFloat32: |
| 4538 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4539 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4540 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4541 | |
| 4542 | default: |
| 4543 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4544 | } |
| 4545 | } |
| 4546 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4547 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4548 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4549 | |
| 4550 | // Most remainders are implemented in the runtime. |
| 4551 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4552 | if (rem->GetResultType() == DataType::Type::kInt32 && rem->InputAt(1)->IsConstant()) { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4553 | // sdiv will be replaced by other instruction sequence. |
| 4554 | call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4555 | } else if ((rem->GetResultType() == DataType::Type::kInt32) |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4556 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4557 | // Have hardware divide instruction for int, do it with three instructions. |
| 4558 | call_kind = LocationSummary::kNoCall; |
| 4559 | } |
| 4560 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4561 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4562 | |
| 4563 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4564 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4565 | if (rem->InputAt(1)->IsConstant()) { |
| 4566 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4567 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4568 | int32_t value = Int32ConstantFrom(rem->InputAt(1)); |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4569 | Location::OutputOverlap out_overlaps = Location::kNoOutputOverlap; |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4570 | if (value == 1 || value == 0 || value == -1) { |
| 4571 | // No temp register required. |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4572 | } else if (IsPowerOfTwo(AbsOrMin(value)) && !HasNonNegativeOrMinIntInputAt(rem, 0)) { |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4573 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 4574 | out_overlaps = Location::kOutputOverlap; |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4575 | } else { |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4576 | locations->AddRegisterTemps(2); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4577 | } |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4578 | locations->SetOut(Location::RequiresRegister(), out_overlaps); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4579 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4580 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4581 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4582 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4583 | locations->AddTemp(Location::RequiresRegister()); |
| 4584 | } else { |
| 4585 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4586 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4587 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4588 | // 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] | 4589 | // we only need the latter. |
| 4590 | locations->SetOut(LocationFrom(r1)); |
| 4591 | } |
| 4592 | break; |
| 4593 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4594 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4595 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4596 | locations->SetInAt(0, LocationFrom( |
| 4597 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4598 | locations->SetInAt(1, LocationFrom( |
| 4599 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4600 | // The runtime helper puts the output in R2,R3. |
| 4601 | locations->SetOut(LocationFrom(r2, r3)); |
| 4602 | break; |
| 4603 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4604 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4605 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4606 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4607 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4608 | locations->SetOut(LocationFrom(s0)); |
| 4609 | break; |
| 4610 | } |
| 4611 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4612 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4613 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4614 | locations->SetInAt(0, LocationFrom( |
| 4615 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4616 | locations->SetInAt(1, LocationFrom( |
| 4617 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4618 | locations->SetOut(LocationFrom(s0, s1)); |
| 4619 | break; |
| 4620 | } |
| 4621 | |
| 4622 | default: |
| 4623 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4624 | } |
| 4625 | } |
| 4626 | |
| 4627 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 4628 | LocationSummary* locations = rem->GetLocations(); |
| 4629 | Location second = locations->InAt(1); |
| 4630 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4631 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4632 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4633 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4634 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 4635 | vixl32::Register out_reg = OutputRegister(rem); |
| 4636 | if (second.IsConstant()) { |
| 4637 | GenerateDivRemConstantIntegral(rem); |
| 4638 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4639 | vixl32::Register reg2 = RegisterFrom(second); |
| 4640 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4641 | |
| 4642 | // temp = reg1 / reg2 (integer division) |
| 4643 | // dest = reg1 - temp * reg2 |
| 4644 | __ Sdiv(temp, reg1, reg2); |
| 4645 | __ Mls(out_reg, temp, reg2, reg1); |
| 4646 | } else { |
| 4647 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4648 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 4649 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 4650 | DCHECK(out_reg.Is(r1)); |
| 4651 | |
| 4652 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 4653 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 4654 | } |
| 4655 | break; |
| 4656 | } |
| 4657 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4658 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4659 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 4660 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 4661 | break; |
| 4662 | } |
| 4663 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4664 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4665 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 4666 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4667 | break; |
| 4668 | } |
| 4669 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4670 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4671 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 4672 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4673 | break; |
| 4674 | } |
| 4675 | |
| 4676 | default: |
| 4677 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4678 | } |
| 4679 | } |
| 4680 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4681 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4682 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4683 | switch (minmax->GetResultType()) { |
| 4684 | case DataType::Type::kInt32: |
| 4685 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4686 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4687 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4688 | break; |
| 4689 | case DataType::Type::kInt64: |
| 4690 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4691 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4692 | locations->SetOut(Location::SameAsFirstInput()); |
| 4693 | break; |
| 4694 | case DataType::Type::kFloat32: |
| 4695 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4696 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4697 | locations->SetOut(Location::SameAsFirstInput()); |
| 4698 | locations->AddTemp(Location::RequiresRegister()); |
| 4699 | break; |
| 4700 | case DataType::Type::kFloat64: |
| 4701 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4702 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4703 | locations->SetOut(Location::SameAsFirstInput()); |
| 4704 | break; |
| 4705 | default: |
| 4706 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4707 | } |
| 4708 | } |
| 4709 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4710 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxInt(LocationSummary* locations, bool is_min) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4711 | Location op1_loc = locations->InAt(0); |
| 4712 | Location op2_loc = locations->InAt(1); |
| 4713 | Location out_loc = locations->Out(); |
| 4714 | |
| 4715 | vixl32::Register op1 = RegisterFrom(op1_loc); |
| 4716 | vixl32::Register op2 = RegisterFrom(op2_loc); |
| 4717 | vixl32::Register out = RegisterFrom(out_loc); |
| 4718 | |
| 4719 | __ Cmp(op1, op2); |
| 4720 | |
| 4721 | { |
| 4722 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 4723 | 3 * kMaxInstructionSizeInBytes, |
| 4724 | CodeBufferCheckScope::kMaximumSize); |
| 4725 | |
| 4726 | __ ite(is_min ? lt : gt); |
| 4727 | __ mov(is_min ? lt : gt, out, op1); |
| 4728 | __ mov(is_min ? ge : le, out, op2); |
| 4729 | } |
| 4730 | } |
| 4731 | |
| 4732 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxLong(LocationSummary* locations, bool is_min) { |
| 4733 | Location op1_loc = locations->InAt(0); |
| 4734 | Location op2_loc = locations->InAt(1); |
| 4735 | Location out_loc = locations->Out(); |
| 4736 | |
| 4737 | // Optimization: don't generate any code if inputs are the same. |
| 4738 | if (op1_loc.Equals(op2_loc)) { |
| 4739 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder. |
| 4740 | return; |
| 4741 | } |
| 4742 | |
| 4743 | vixl32::Register op1_lo = LowRegisterFrom(op1_loc); |
| 4744 | vixl32::Register op1_hi = HighRegisterFrom(op1_loc); |
| 4745 | vixl32::Register op2_lo = LowRegisterFrom(op2_loc); |
| 4746 | vixl32::Register op2_hi = HighRegisterFrom(op2_loc); |
| 4747 | vixl32::Register out_lo = LowRegisterFrom(out_loc); |
| 4748 | vixl32::Register out_hi = HighRegisterFrom(out_loc); |
| 4749 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4750 | const vixl32::Register temp = temps.Acquire(); |
| 4751 | |
| 4752 | DCHECK(op1_lo.Is(out_lo)); |
| 4753 | DCHECK(op1_hi.Is(out_hi)); |
| 4754 | |
| 4755 | // Compare op1 >= op2, or op1 < op2. |
| 4756 | __ Cmp(out_lo, op2_lo); |
| 4757 | __ Sbcs(temp, out_hi, op2_hi); |
| 4758 | |
| 4759 | // Now GE/LT condition code is correct for the long comparison. |
| 4760 | { |
| 4761 | vixl32::ConditionType cond = is_min ? ge : lt; |
| 4762 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4763 | 3 * kMaxInstructionSizeInBytes, |
| 4764 | CodeBufferCheckScope::kMaximumSize); |
| 4765 | __ itt(cond); |
| 4766 | __ mov(cond, out_lo, op2_lo); |
| 4767 | __ mov(cond, out_hi, op2_hi); |
| 4768 | } |
| 4769 | } |
| 4770 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4771 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxFloat(HInstruction* minmax, bool is_min) { |
| 4772 | LocationSummary* locations = minmax->GetLocations(); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4773 | Location op1_loc = locations->InAt(0); |
| 4774 | Location op2_loc = locations->InAt(1); |
| 4775 | Location out_loc = locations->Out(); |
| 4776 | |
| 4777 | // Optimization: don't generate any code if inputs are the same. |
| 4778 | if (op1_loc.Equals(op2_loc)) { |
| 4779 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder. |
| 4780 | return; |
| 4781 | } |
| 4782 | |
| 4783 | vixl32::SRegister op1 = SRegisterFrom(op1_loc); |
| 4784 | vixl32::SRegister op2 = SRegisterFrom(op2_loc); |
| 4785 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 4786 | |
| 4787 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4788 | const vixl32::Register temp1 = temps.Acquire(); |
| 4789 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(0)); |
| 4790 | vixl32::Label nan, done; |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4791 | vixl32::Label* final_label = codegen_->GetFinalLabel(minmax, &done); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4792 | |
| 4793 | DCHECK(op1.Is(out)); |
| 4794 | |
| 4795 | __ Vcmp(op1, op2); |
| 4796 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4797 | __ 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] | 4798 | |
| 4799 | // op1 <> op2 |
| 4800 | vixl32::ConditionType cond = is_min ? gt : lt; |
| 4801 | { |
| 4802 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4803 | 2 * kMaxInstructionSizeInBytes, |
| 4804 | CodeBufferCheckScope::kMaximumSize); |
| 4805 | __ it(cond); |
| 4806 | __ vmov(cond, F32, out, op2); |
| 4807 | } |
| 4808 | // for <>(not equal), we've done min/max calculation. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4809 | __ B(ne, final_label, /* is_far_target= */ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4810 | |
| 4811 | // handle op1 == op2, max(+0.0,-0.0), min(+0.0,-0.0). |
| 4812 | __ Vmov(temp1, op1); |
| 4813 | __ Vmov(temp2, op2); |
| 4814 | if (is_min) { |
| 4815 | __ Orr(temp1, temp1, temp2); |
| 4816 | } else { |
| 4817 | __ And(temp1, temp1, temp2); |
| 4818 | } |
| 4819 | __ Vmov(out, temp1); |
| 4820 | __ B(final_label); |
| 4821 | |
| 4822 | // handle NaN input. |
| 4823 | __ Bind(&nan); |
| 4824 | __ Movt(temp1, High16Bits(kNanFloat)); // 0x7FC0xxxx is a NaN. |
| 4825 | __ Vmov(out, temp1); |
| 4826 | |
| 4827 | if (done.IsReferenced()) { |
| 4828 | __ Bind(&done); |
| 4829 | } |
| 4830 | } |
| 4831 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4832 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxDouble(HInstruction* minmax, bool is_min) { |
| 4833 | LocationSummary* locations = minmax->GetLocations(); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4834 | Location op1_loc = locations->InAt(0); |
| 4835 | Location op2_loc = locations->InAt(1); |
| 4836 | Location out_loc = locations->Out(); |
| 4837 | |
| 4838 | // Optimization: don't generate any code if inputs are the same. |
| 4839 | if (op1_loc.Equals(op2_loc)) { |
| 4840 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in. |
| 4841 | return; |
| 4842 | } |
| 4843 | |
| 4844 | vixl32::DRegister op1 = DRegisterFrom(op1_loc); |
| 4845 | vixl32::DRegister op2 = DRegisterFrom(op2_loc); |
| 4846 | vixl32::DRegister out = DRegisterFrom(out_loc); |
| 4847 | vixl32::Label handle_nan_eq, done; |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4848 | vixl32::Label* final_label = codegen_->GetFinalLabel(minmax, &done); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4849 | |
| 4850 | DCHECK(op1.Is(out)); |
| 4851 | |
| 4852 | __ Vcmp(op1, op2); |
| 4853 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4854 | __ 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] | 4855 | |
| 4856 | // op1 <> op2 |
| 4857 | vixl32::ConditionType cond = is_min ? gt : lt; |
| 4858 | { |
| 4859 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4860 | 2 * kMaxInstructionSizeInBytes, |
| 4861 | CodeBufferCheckScope::kMaximumSize); |
| 4862 | __ it(cond); |
| 4863 | __ vmov(cond, F64, out, op2); |
| 4864 | } |
| 4865 | // for <>(not equal), we've done min/max calculation. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4866 | __ B(ne, final_label, /* is_far_target= */ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4867 | |
| 4868 | // handle op1 == op2, max(+0.0,-0.0). |
| 4869 | if (!is_min) { |
| 4870 | __ Vand(F64, out, op1, op2); |
| 4871 | __ B(final_label); |
| 4872 | } |
| 4873 | |
| 4874 | // handle op1 == op2, min(+0.0,-0.0), NaN input. |
| 4875 | __ Bind(&handle_nan_eq); |
| 4876 | __ Vorr(F64, out, op1, op2); // assemble op1/-0.0/NaN. |
| 4877 | |
| 4878 | if (done.IsReferenced()) { |
| 4879 | __ Bind(&done); |
| 4880 | } |
| 4881 | } |
| 4882 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4883 | void InstructionCodeGeneratorARMVIXL::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4884 | DataType::Type type = minmax->GetResultType(); |
| 4885 | switch (type) { |
| 4886 | case DataType::Type::kInt32: |
| 4887 | GenerateMinMaxInt(minmax->GetLocations(), is_min); |
| 4888 | break; |
| 4889 | case DataType::Type::kInt64: |
| 4890 | GenerateMinMaxLong(minmax->GetLocations(), is_min); |
| 4891 | break; |
| 4892 | case DataType::Type::kFloat32: |
| 4893 | GenerateMinMaxFloat(minmax, is_min); |
| 4894 | break; |
| 4895 | case DataType::Type::kFloat64: |
| 4896 | GenerateMinMaxDouble(minmax, is_min); |
| 4897 | break; |
| 4898 | default: |
| 4899 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4900 | } |
| 4901 | } |
| 4902 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4903 | void LocationsBuilderARMVIXL::VisitMin(HMin* min) { |
| 4904 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4905 | } |
| 4906 | |
| 4907 | void InstructionCodeGeneratorARMVIXL::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4908 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4909 | } |
| 4910 | |
| 4911 | void LocationsBuilderARMVIXL::VisitMax(HMax* max) { |
| 4912 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4913 | } |
| 4914 | |
| 4915 | void InstructionCodeGeneratorARMVIXL::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4916 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4917 | } |
| 4918 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4919 | void LocationsBuilderARMVIXL::VisitAbs(HAbs* abs) { |
| 4920 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4921 | switch (abs->GetResultType()) { |
| 4922 | case DataType::Type::kInt32: |
| 4923 | case DataType::Type::kInt64: |
| 4924 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4925 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4926 | locations->AddTemp(Location::RequiresRegister()); |
| 4927 | break; |
| 4928 | case DataType::Type::kFloat32: |
| 4929 | case DataType::Type::kFloat64: |
| 4930 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4931 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4932 | break; |
| 4933 | default: |
| 4934 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 4935 | } |
| 4936 | } |
| 4937 | |
| 4938 | void InstructionCodeGeneratorARMVIXL::VisitAbs(HAbs* abs) { |
| 4939 | LocationSummary* locations = abs->GetLocations(); |
| 4940 | switch (abs->GetResultType()) { |
| 4941 | case DataType::Type::kInt32: { |
| 4942 | vixl32::Register in_reg = RegisterFrom(locations->InAt(0)); |
| 4943 | vixl32::Register out_reg = RegisterFrom(locations->Out()); |
| 4944 | vixl32::Register mask = RegisterFrom(locations->GetTemp(0)); |
| 4945 | __ Asr(mask, in_reg, 31); |
| 4946 | __ Add(out_reg, in_reg, mask); |
| 4947 | __ Eor(out_reg, out_reg, mask); |
| 4948 | break; |
| 4949 | } |
| 4950 | case DataType::Type::kInt64: { |
| 4951 | Location in = locations->InAt(0); |
| 4952 | vixl32::Register in_reg_lo = LowRegisterFrom(in); |
| 4953 | vixl32::Register in_reg_hi = HighRegisterFrom(in); |
| 4954 | Location output = locations->Out(); |
| 4955 | vixl32::Register out_reg_lo = LowRegisterFrom(output); |
| 4956 | vixl32::Register out_reg_hi = HighRegisterFrom(output); |
| 4957 | DCHECK(!out_reg_lo.Is(in_reg_hi)) << "Diagonal overlap unexpected."; |
| 4958 | vixl32::Register mask = RegisterFrom(locations->GetTemp(0)); |
| 4959 | __ Asr(mask, in_reg_hi, 31); |
| 4960 | __ Adds(out_reg_lo, in_reg_lo, mask); |
| 4961 | __ Adc(out_reg_hi, in_reg_hi, mask); |
| 4962 | __ Eor(out_reg_lo, out_reg_lo, mask); |
| 4963 | __ Eor(out_reg_hi, out_reg_hi, mask); |
| 4964 | break; |
| 4965 | } |
| 4966 | case DataType::Type::kFloat32: |
| 4967 | case DataType::Type::kFloat64: |
| 4968 | __ Vabs(OutputVRegister(abs), InputVRegisterAt(abs, 0)); |
| 4969 | break; |
| 4970 | default: |
| 4971 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 4972 | } |
| 4973 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4974 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4975 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 4976 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4977 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 4981 | DivZeroCheckSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4982 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARMVIXL(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4983 | codegen_->AddSlowPath(slow_path); |
| 4984 | |
| 4985 | LocationSummary* locations = instruction->GetLocations(); |
| 4986 | Location value = locations->InAt(0); |
| 4987 | |
| 4988 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4989 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4990 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4991 | case DataType::Type::kInt8: |
| 4992 | case DataType::Type::kUint16: |
| 4993 | case DataType::Type::kInt16: |
| 4994 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4995 | if (value.IsRegister()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 4996 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4997 | } else { |
| 4998 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4999 | if (Int32ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5000 | __ B(slow_path->GetEntryLabel()); |
| 5001 | } |
| 5002 | } |
| 5003 | break; |
| 5004 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5005 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5006 | if (value.IsRegisterPair()) { |
| 5007 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5008 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5009 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5010 | __ B(eq, slow_path->GetEntryLabel()); |
| 5011 | } else { |
| 5012 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5013 | if (Int64ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5014 | __ B(slow_path->GetEntryLabel()); |
| 5015 | } |
| 5016 | } |
| 5017 | break; |
| 5018 | } |
| 5019 | default: |
| 5020 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 5021 | } |
| 5022 | } |
| 5023 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5024 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 5025 | LocationSummary* locations = ror->GetLocations(); |
| 5026 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 5027 | Location rhs = locations->InAt(1); |
| 5028 | vixl32::Register out = OutputRegister(ror); |
| 5029 | |
| 5030 | if (rhs.IsConstant()) { |
| 5031 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 5032 | // so map all rotations to a +ve. equivalent in that range. |
| 5033 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 5034 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 5035 | if (rot) { |
| 5036 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 5037 | // (e.g. left by 2 bits == right by 30.) |
| 5038 | __ Ror(out, in, rot); |
| 5039 | } else if (!out.Is(in)) { |
| 5040 | __ Mov(out, in); |
| 5041 | } |
| 5042 | } else { |
| 5043 | __ Ror(out, in, RegisterFrom(rhs)); |
| 5044 | } |
| 5045 | } |
| 5046 | |
| 5047 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 5048 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 5049 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 5050 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 5051 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 5052 | LocationSummary* locations = ror->GetLocations(); |
| 5053 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 5054 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 5055 | Location rhs = locations->InAt(1); |
| 5056 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 5057 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 5058 | |
| 5059 | if (rhs.IsConstant()) { |
| 5060 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 5061 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 5062 | rot &= kMaxLongShiftDistance; |
| 5063 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 5064 | // logic below to a simple pair of binary orr. |
| 5065 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 5066 | if (rot >= kArmBitsPerWord) { |
| 5067 | rot -= kArmBitsPerWord; |
| 5068 | std::swap(in_reg_hi, in_reg_lo); |
| 5069 | } |
| 5070 | // Rotate, or mov to out for zero or word size rotations. |
| 5071 | if (rot != 0u) { |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5072 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5073 | __ 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] | 5074 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5075 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 5076 | } else { |
| 5077 | __ Mov(out_reg_lo, in_reg_lo); |
| 5078 | __ Mov(out_reg_hi, in_reg_hi); |
| 5079 | } |
| 5080 | } else { |
| 5081 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 5082 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 5083 | vixl32::Label end; |
| 5084 | vixl32::Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5085 | vixl32::Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5086 | |
| 5087 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 5088 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 5089 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5090 | __ B(cc, &shift_by_32_plus_shift_right, /* is_far_target= */ false); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5091 | |
| 5092 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 5093 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 5094 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 5095 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 5096 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 5097 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 5098 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 5099 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5100 | __ B(final_label); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5101 | |
| 5102 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 5103 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 5104 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 5105 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 5106 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 5107 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 5108 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 5109 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 5110 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 5111 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5112 | if (end.IsReferenced()) { |
| 5113 | __ Bind(&end); |
| 5114 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5115 | } |
| 5116 | } |
| 5117 | |
| 5118 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 5119 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5120 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5121 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5122 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5123 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5124 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 5125 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5126 | break; |
| 5127 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5128 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5129 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5130 | if (ror->InputAt(1)->IsConstant()) { |
| 5131 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 5132 | } else { |
| 5133 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5134 | locations->AddTemp(Location::RequiresRegister()); |
| 5135 | locations->AddTemp(Location::RequiresRegister()); |
| 5136 | } |
| 5137 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5138 | break; |
| 5139 | } |
| 5140 | default: |
| 5141 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 5142 | } |
| 5143 | } |
| 5144 | |
| 5145 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5146 | DataType::Type type = ror->GetResultType(); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5147 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5148 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5149 | HandleIntegerRotate(ror); |
| 5150 | break; |
| 5151 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5152 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5153 | HandleLongRotate(ror); |
| 5154 | break; |
| 5155 | } |
| 5156 | default: |
| 5157 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5158 | UNREACHABLE(); |
| 5159 | } |
| 5160 | } |
| 5161 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5162 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 5163 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5164 | |
| 5165 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5166 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5167 | |
| 5168 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5169 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5170 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5171 | if (op->InputAt(1)->IsConstant()) { |
| 5172 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5173 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5174 | } else { |
| 5175 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5176 | // Make the output overlap, as it will be used to hold the masked |
| 5177 | // second input. |
| 5178 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5179 | } |
| 5180 | break; |
| 5181 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5182 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5183 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5184 | if (op->InputAt(1)->IsConstant()) { |
| 5185 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5186 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 5187 | // don't clash with high registers which the register allocator currently guarantees. |
| 5188 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5189 | } else { |
| 5190 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5191 | locations->AddTemp(Location::RequiresRegister()); |
| 5192 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5193 | } |
| 5194 | break; |
| 5195 | } |
| 5196 | default: |
| 5197 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 5198 | } |
| 5199 | } |
| 5200 | |
| 5201 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 5202 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5203 | |
| 5204 | LocationSummary* locations = op->GetLocations(); |
| 5205 | Location out = locations->Out(); |
| 5206 | Location first = locations->InAt(0); |
| 5207 | Location second = locations->InAt(1); |
| 5208 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5209 | DataType::Type type = op->GetResultType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5210 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5211 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5212 | vixl32::Register out_reg = OutputRegister(op); |
| 5213 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 5214 | if (second.IsRegister()) { |
| 5215 | vixl32::Register second_reg = RegisterFrom(second); |
| 5216 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 5217 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 5218 | if (op->IsShl()) { |
| 5219 | __ Lsl(out_reg, first_reg, out_reg); |
| 5220 | } else if (op->IsShr()) { |
| 5221 | __ Asr(out_reg, first_reg, out_reg); |
| 5222 | } else { |
| 5223 | __ Lsr(out_reg, first_reg, out_reg); |
| 5224 | } |
| 5225 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5226 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5227 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 5228 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 5229 | __ Mov(out_reg, first_reg); |
| 5230 | } else if (op->IsShl()) { |
| 5231 | __ Lsl(out_reg, first_reg, shift_value); |
| 5232 | } else if (op->IsShr()) { |
| 5233 | __ Asr(out_reg, first_reg, shift_value); |
| 5234 | } else { |
| 5235 | __ Lsr(out_reg, first_reg, shift_value); |
| 5236 | } |
| 5237 | } |
| 5238 | break; |
| 5239 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5240 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5241 | vixl32::Register o_h = HighRegisterFrom(out); |
| 5242 | vixl32::Register o_l = LowRegisterFrom(out); |
| 5243 | |
| 5244 | vixl32::Register high = HighRegisterFrom(first); |
| 5245 | vixl32::Register low = LowRegisterFrom(first); |
| 5246 | |
| 5247 | if (second.IsRegister()) { |
| 5248 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5249 | |
| 5250 | vixl32::Register second_reg = RegisterFrom(second); |
| 5251 | |
| 5252 | if (op->IsShl()) { |
| 5253 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 5254 | // Shift the high part |
| 5255 | __ Lsl(o_h, high, o_l); |
| 5256 | // Shift the low part and `or` what overflew on the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5257 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5258 | __ Lsr(temp, low, temp); |
| 5259 | __ Orr(o_h, o_h, temp); |
| 5260 | // If the shift is > 32 bits, override the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5261 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5262 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5263 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5264 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5265 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5266 | __ it(pl); |
| 5267 | __ lsl(pl, o_h, low, temp); |
| 5268 | } |
| 5269 | // Shift the low part |
| 5270 | __ Lsl(o_l, low, o_l); |
| 5271 | } else if (op->IsShr()) { |
| 5272 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5273 | // Shift the low part |
| 5274 | __ Lsr(o_l, low, o_h); |
| 5275 | // Shift the high part and `or` what underflew on the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5276 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5277 | __ Lsl(temp, high, temp); |
| 5278 | __ Orr(o_l, o_l, temp); |
| 5279 | // If the shift is > 32 bits, override the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5280 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5281 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5282 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5283 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5284 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5285 | __ it(pl); |
| 5286 | __ asr(pl, o_l, high, temp); |
| 5287 | } |
| 5288 | // Shift the high part |
| 5289 | __ Asr(o_h, high, o_h); |
| 5290 | } else { |
| 5291 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5292 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 5293 | __ Lsr(o_l, low, o_h); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5294 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5295 | __ Lsl(temp, high, temp); |
| 5296 | __ Orr(o_l, o_l, temp); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5297 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5298 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5299 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5300 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5301 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5302 | __ it(pl); |
| 5303 | __ lsr(pl, o_l, high, temp); |
| 5304 | } |
| 5305 | __ Lsr(o_h, high, o_h); |
| 5306 | } |
| 5307 | } else { |
| 5308 | // Register allocator doesn't create partial overlap. |
| 5309 | DCHECK(!o_l.Is(high)); |
| 5310 | DCHECK(!o_h.Is(low)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5311 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5312 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 5313 | if (shift_value > 32) { |
| 5314 | if (op->IsShl()) { |
| 5315 | __ Lsl(o_h, low, shift_value - 32); |
| 5316 | __ Mov(o_l, 0); |
| 5317 | } else if (op->IsShr()) { |
| 5318 | __ Asr(o_l, high, shift_value - 32); |
| 5319 | __ Asr(o_h, high, 31); |
| 5320 | } else { |
| 5321 | __ Lsr(o_l, high, shift_value - 32); |
| 5322 | __ Mov(o_h, 0); |
| 5323 | } |
| 5324 | } else if (shift_value == 32) { |
| 5325 | if (op->IsShl()) { |
| 5326 | __ Mov(o_h, low); |
| 5327 | __ Mov(o_l, 0); |
| 5328 | } else if (op->IsShr()) { |
| 5329 | __ Mov(o_l, high); |
| 5330 | __ Asr(o_h, high, 31); |
| 5331 | } else { |
| 5332 | __ Mov(o_l, high); |
| 5333 | __ Mov(o_h, 0); |
| 5334 | } |
| 5335 | } else if (shift_value == 1) { |
| 5336 | if (op->IsShl()) { |
| 5337 | __ Lsls(o_l, low, 1); |
| 5338 | __ Adc(o_h, high, high); |
| 5339 | } else if (op->IsShr()) { |
| 5340 | __ Asrs(o_h, high, 1); |
| 5341 | __ Rrx(o_l, low); |
| 5342 | } else { |
| 5343 | __ Lsrs(o_h, high, 1); |
| 5344 | __ Rrx(o_l, low); |
| 5345 | } |
Nicolas Geoffray | 9b195cc | 2019-04-02 08:29:00 +0100 | [diff] [blame] | 5346 | } else if (shift_value == 0) { |
| 5347 | __ Mov(o_l, low); |
| 5348 | __ Mov(o_h, high); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5349 | } else { |
Nicolas Geoffray | 9b195cc | 2019-04-02 08:29:00 +0100 | [diff] [blame] | 5350 | DCHECK(0 < shift_value && shift_value < 32) << shift_value; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5351 | if (op->IsShl()) { |
| 5352 | __ Lsl(o_h, high, shift_value); |
| 5353 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 5354 | __ Lsl(o_l, low, shift_value); |
| 5355 | } else if (op->IsShr()) { |
| 5356 | __ Lsr(o_l, low, shift_value); |
| 5357 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5358 | __ Asr(o_h, high, shift_value); |
| 5359 | } else { |
| 5360 | __ Lsr(o_l, low, shift_value); |
| 5361 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5362 | __ Lsr(o_h, high, shift_value); |
| 5363 | } |
| 5364 | } |
| 5365 | } |
| 5366 | break; |
| 5367 | } |
| 5368 | default: |
| 5369 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5370 | UNREACHABLE(); |
| 5371 | } |
| 5372 | } |
| 5373 | |
| 5374 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 5375 | HandleShift(shl); |
| 5376 | } |
| 5377 | |
| 5378 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 5379 | HandleShift(shl); |
| 5380 | } |
| 5381 | |
| 5382 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 5383 | HandleShift(shr); |
| 5384 | } |
| 5385 | |
| 5386 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 5387 | HandleShift(shr); |
| 5388 | } |
| 5389 | |
| 5390 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 5391 | HandleShift(ushr); |
| 5392 | } |
| 5393 | |
| 5394 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 5395 | HandleShift(ushr); |
| 5396 | } |
| 5397 | |
| 5398 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5399 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5400 | instruction, LocationSummary::kCallOnMainOnly); |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5401 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5402 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5403 | locations->SetOut(LocationFrom(r0)); |
| 5404 | } |
| 5405 | |
| 5406 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5407 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5408 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 5409 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 12); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5413 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5414 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5415 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5416 | locations->SetOut(LocationFrom(r0)); |
Nicolas Geoffray | 8c7c4f1 | 2017-01-26 10:13:11 +0000 | [diff] [blame] | 5417 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5418 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5419 | } |
| 5420 | |
| 5421 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5422 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5423 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5424 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5425 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5426 | DCHECK(!codegen_->IsLeafMethod()); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 5427 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 13); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5428 | } |
| 5429 | |
| 5430 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 5431 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5432 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5433 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5434 | if (location.IsStackSlot()) { |
| 5435 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5436 | } else if (location.IsDoubleStackSlot()) { |
| 5437 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5438 | } |
| 5439 | locations->SetOut(location); |
| 5440 | } |
| 5441 | |
| 5442 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 5443 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 5444 | // Nothing to do, the parameter is already at its location. |
| 5445 | } |
| 5446 | |
| 5447 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5448 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5449 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5450 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 5451 | } |
| 5452 | |
| 5453 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 5454 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5455 | // Nothing to do, the method is already at its location. |
| 5456 | } |
| 5457 | |
| 5458 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 5459 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5460 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5461 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5462 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5463 | } |
| 5464 | |
| 5465 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 5466 | LocationSummary* locations = not_->GetLocations(); |
| 5467 | Location out = locations->Out(); |
| 5468 | Location in = locations->InAt(0); |
| 5469 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5470 | case DataType::Type::kInt32: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5471 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 5472 | break; |
| 5473 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5474 | case DataType::Type::kInt64: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5475 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 5476 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 5477 | break; |
| 5478 | |
| 5479 | default: |
| 5480 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5481 | } |
| 5482 | } |
| 5483 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5484 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5485 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5486 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5487 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5488 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5489 | } |
| 5490 | |
| 5491 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5492 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 5493 | } |
| 5494 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5495 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 5496 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5497 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5498 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5499 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5500 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5501 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5502 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5503 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5504 | case DataType::Type::kInt32: |
| 5505 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5506 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5507 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5508 | // Output overlaps because it is written before doing the low comparison. |
| 5509 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5510 | break; |
| 5511 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5512 | case DataType::Type::kFloat32: |
| 5513 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5514 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5515 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 5516 | locations->SetOut(Location::RequiresRegister()); |
| 5517 | break; |
| 5518 | } |
| 5519 | default: |
| 5520 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5521 | } |
| 5522 | } |
| 5523 | |
| 5524 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 5525 | LocationSummary* locations = compare->GetLocations(); |
| 5526 | vixl32::Register out = OutputRegister(compare); |
| 5527 | Location left = locations->InAt(0); |
| 5528 | Location right = locations->InAt(1); |
| 5529 | |
| 5530 | vixl32::Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5531 | vixl32::Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5532 | DataType::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 5533 | vixl32::Condition less_cond = vixl32::Condition::None(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5534 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5535 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5536 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5537 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5538 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5539 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5540 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5541 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 5542 | __ Mov(out, 0); |
| 5543 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 5544 | less_cond = lt; |
| 5545 | break; |
| 5546 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5547 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5548 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5549 | __ B(lt, &less, /* is_far_target= */ false); |
| 5550 | __ B(gt, &greater, /* is_far_target= */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5551 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 5552 | __ Mov(out, 0); |
| 5553 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 5554 | less_cond = lo; |
| 5555 | break; |
| 5556 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5557 | case DataType::Type::kFloat32: |
| 5558 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5559 | __ Mov(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5560 | GenerateVcmp(compare, codegen_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5561 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 5562 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 5563 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 5564 | break; |
| 5565 | } |
| 5566 | default: |
| 5567 | LOG(FATAL) << "Unexpected compare type " << type; |
| 5568 | UNREACHABLE(); |
| 5569 | } |
| 5570 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5571 | __ B(eq, final_label, /* is_far_target= */ false); |
| 5572 | __ B(less_cond, &less, /* is_far_target= */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5573 | |
| 5574 | __ Bind(&greater); |
| 5575 | __ Mov(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5576 | __ B(final_label); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5577 | |
| 5578 | __ Bind(&less); |
| 5579 | __ Mov(out, -1); |
| 5580 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5581 | if (done.IsReferenced()) { |
| 5582 | __ Bind(&done); |
| 5583 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5584 | } |
| 5585 | |
| 5586 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 5587 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5588 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5589 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 5590 | locations->SetInAt(i, Location::Any()); |
| 5591 | } |
| 5592 | locations->SetOut(Location::Any()); |
| 5593 | } |
| 5594 | |
| 5595 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5596 | LOG(FATAL) << "Unreachable"; |
| 5597 | } |
| 5598 | |
| 5599 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5600 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5601 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 5602 | switch (kind) { |
| 5603 | case MemBarrierKind::kAnyStore: |
| 5604 | case MemBarrierKind::kLoadAny: |
| 5605 | case MemBarrierKind::kAnyAny: { |
| 5606 | flavor = DmbOptions::ISH; |
| 5607 | break; |
| 5608 | } |
| 5609 | case MemBarrierKind::kStoreStore: { |
| 5610 | flavor = DmbOptions::ISHST; |
| 5611 | break; |
| 5612 | } |
| 5613 | default: |
| 5614 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5615 | } |
| 5616 | __ Dmb(flavor); |
| 5617 | } |
| 5618 | |
| 5619 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 5620 | uint32_t offset, |
| 5621 | vixl32::Register out_lo, |
| 5622 | vixl32::Register out_hi) { |
| 5623 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5624 | if (offset != 0) { |
| 5625 | vixl32::Register temp = temps.Acquire(); |
| 5626 | __ Add(temp, addr, offset); |
| 5627 | addr = temp; |
| 5628 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5629 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5630 | } |
| 5631 | |
| 5632 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 5633 | uint32_t offset, |
| 5634 | vixl32::Register value_lo, |
| 5635 | vixl32::Register value_hi, |
| 5636 | vixl32::Register temp1, |
| 5637 | vixl32::Register temp2, |
| 5638 | HInstruction* instruction) { |
| 5639 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5640 | vixl32::Label fail; |
| 5641 | if (offset != 0) { |
| 5642 | vixl32::Register temp = temps.Acquire(); |
| 5643 | __ Add(temp, addr, offset); |
| 5644 | addr = temp; |
| 5645 | } |
| 5646 | __ Bind(&fail); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5647 | { |
| 5648 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5649 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5650 | vixl32::kMaxInstructionSizeInBytes, |
| 5651 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5652 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5653 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5654 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 5655 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5656 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5657 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5658 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5659 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5660 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5661 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 5662 | HInstruction* instruction, const FieldInfo& field_info) { |
| 5663 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5664 | |
| 5665 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5666 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5667 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5668 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5669 | DataType::Type field_type = field_info.GetFieldType(); |
| 5670 | if (DataType::IsFloatingPointType(field_type)) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5671 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5672 | } else { |
| 5673 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5674 | } |
| 5675 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5676 | 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] | 5677 | bool generate_volatile = field_info.IsVolatile() |
| 5678 | && is_wide |
| 5679 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5680 | bool needs_write_barrier = |
| 5681 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5682 | // Temporary registers for the write barrier. |
| 5683 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 5684 | if (needs_write_barrier) { |
| 5685 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 5686 | locations->AddTemp(Location::RequiresRegister()); |
| 5687 | } else if (generate_volatile) { |
| 5688 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5689 | // - registers need to be consecutive |
| 5690 | // - the first register should be even but not R14. |
| 5691 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5692 | // revisit this if we ever enable ARM encoding. |
| 5693 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5694 | |
| 5695 | locations->AddTemp(Location::RequiresRegister()); |
| 5696 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5697 | if (field_type == DataType::Type::kFloat64) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5698 | // For doubles we need two more registers to copy the value. |
| 5699 | locations->AddTemp(LocationFrom(r2)); |
| 5700 | locations->AddTemp(LocationFrom(r3)); |
| 5701 | } |
| 5702 | } |
| 5703 | } |
| 5704 | |
| 5705 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 5706 | const FieldInfo& field_info, |
| 5707 | bool value_can_be_null) { |
| 5708 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5709 | |
| 5710 | LocationSummary* locations = instruction->GetLocations(); |
| 5711 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5712 | Location value = locations->InAt(1); |
| 5713 | |
| 5714 | bool is_volatile = field_info.IsVolatile(); |
| 5715 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5716 | DataType::Type field_type = field_info.GetFieldType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5717 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5718 | bool needs_write_barrier = |
| 5719 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5720 | |
| 5721 | if (is_volatile) { |
| 5722 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5723 | } |
| 5724 | |
| 5725 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5726 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5727 | case DataType::Type::kUint8: |
| 5728 | case DataType::Type::kInt8: |
| 5729 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5730 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5731 | case DataType::Type::kInt32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5732 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5733 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5734 | StoreOperandType operand_type = GetStoreOperandType(field_type); |
| 5735 | GetAssembler()->StoreToOffset(operand_type, RegisterFrom(value), base, offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5736 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5737 | break; |
| 5738 | } |
| 5739 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5740 | case DataType::Type::kReference: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5741 | vixl32::Register value_reg = RegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5742 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5743 | // Note that in the case where `value` is a null reference, |
| 5744 | // we do not enter this block, as a null reference does not |
| 5745 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5746 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5747 | value_reg = RegisterFrom(locations->GetTemp(0)); |
| 5748 | __ Mov(value_reg, RegisterFrom(value)); |
| 5749 | GetAssembler()->PoisonHeapReference(value_reg); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5750 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5751 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5752 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5753 | GetAssembler()->StoreToOffset(kStoreWord, value_reg, base, offset); |
| 5754 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5755 | break; |
| 5756 | } |
| 5757 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5758 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5759 | if (is_volatile && !atomic_ldrd_strd) { |
| 5760 | GenerateWideAtomicStore(base, |
| 5761 | offset, |
| 5762 | LowRegisterFrom(value), |
| 5763 | HighRegisterFrom(value), |
| 5764 | RegisterFrom(locations->GetTemp(0)), |
| 5765 | RegisterFrom(locations->GetTemp(1)), |
| 5766 | instruction); |
| 5767 | } else { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5768 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5769 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5770 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 5771 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5772 | } |
| 5773 | break; |
| 5774 | } |
| 5775 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5776 | case DataType::Type::kFloat32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5777 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5778 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5779 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5780 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5781 | break; |
| 5782 | } |
| 5783 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5784 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5785 | vixl32::DRegister value_reg = DRegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5786 | if (is_volatile && !atomic_ldrd_strd) { |
| 5787 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 5788 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 5789 | |
| 5790 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 5791 | |
| 5792 | GenerateWideAtomicStore(base, |
| 5793 | offset, |
| 5794 | value_reg_lo, |
| 5795 | value_reg_hi, |
| 5796 | RegisterFrom(locations->GetTemp(2)), |
| 5797 | RegisterFrom(locations->GetTemp(3)), |
| 5798 | instruction); |
| 5799 | } else { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5800 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5801 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5802 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 5803 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5804 | } |
| 5805 | break; |
| 5806 | } |
| 5807 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5808 | case DataType::Type::kUint32: |
| 5809 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5810 | case DataType::Type::kVoid: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5811 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5812 | UNREACHABLE(); |
| 5813 | } |
| 5814 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5815 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5816 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5817 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 5818 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 5819 | } |
| 5820 | |
| 5821 | if (is_volatile) { |
| 5822 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5823 | } |
| 5824 | } |
| 5825 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5826 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5827 | const FieldInfo& field_info) { |
| 5828 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5829 | |
| 5830 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5831 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == DataType::Type::kReference); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5832 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5833 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5834 | object_field_get_with_read_barrier |
| 5835 | ? LocationSummary::kCallOnSlowPath |
| 5836 | : LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5837 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5838 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5839 | } |
| 5840 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5841 | |
| 5842 | bool volatile_for_double = field_info.IsVolatile() |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5843 | && (field_info.GetFieldType() == DataType::Type::kFloat64) |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5844 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5845 | // The output overlaps in case of volatile long: we don't want the |
| 5846 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5847 | // object's location. Likewise, in the case of an object field get |
| 5848 | // with read barriers enabled, we do not want the load to overwrite |
| 5849 | // 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] | 5850 | bool overlap = |
| 5851 | (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) || |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5852 | object_field_get_with_read_barrier; |
| 5853 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5854 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5855 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5856 | } else { |
| 5857 | locations->SetOut(Location::RequiresRegister(), |
| 5858 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5859 | } |
| 5860 | if (volatile_for_double) { |
| 5861 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5862 | // - registers need to be consecutive |
| 5863 | // - the first register should be even but not R14. |
| 5864 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5865 | // revisit this if we ever enable ARM encoding. |
| 5866 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5867 | locations->AddTemp(Location::RequiresRegister()); |
| 5868 | locations->AddTemp(Location::RequiresRegister()); |
| 5869 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 5870 | // We need a temporary register for the read barrier load in |
| 5871 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier() |
| 5872 | // only if the offset is too big. |
| 5873 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5874 | locations->AddTemp(Location::RequiresRegister()); |
| 5875 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5876 | } |
| 5877 | } |
| 5878 | |
| 5879 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5880 | DCHECK(DataType::IsFloatingPointType(input->GetType())) << input->GetType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5881 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5882 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5883 | return Location::ConstantLocation(input->AsConstant()); |
| 5884 | } else { |
| 5885 | return Location::RequiresFpuRegister(); |
| 5886 | } |
| 5887 | } |
| 5888 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5889 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5890 | Opcode opcode) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5891 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5892 | if (constant->IsConstant() && |
| 5893 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5894 | return Location::ConstantLocation(constant->AsConstant()); |
| 5895 | } |
| 5896 | return Location::RequiresRegister(); |
| 5897 | } |
| 5898 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5899 | static bool CanEncode32BitConstantAsImmediate( |
| 5900 | CodeGeneratorARMVIXL* codegen, |
| 5901 | uint32_t value, |
| 5902 | Opcode opcode, |
| 5903 | vixl32::FlagsUpdate flags_update = vixl32::FlagsUpdate::DontCare) { |
| 5904 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
| 5905 | if (assembler->ShifterOperandCanHold(opcode, value, flags_update)) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5906 | return true; |
| 5907 | } |
| 5908 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5909 | uint32_t neg_value = 0; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5910 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5911 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5912 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5913 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5914 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5915 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5916 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5917 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5918 | default: |
| 5919 | return false; |
| 5920 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5921 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5922 | if (assembler->ShifterOperandCanHold(neg_opcode, neg_value, flags_update)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5923 | return true; |
| 5924 | } |
| 5925 | |
| 5926 | return opcode == AND && IsPowerOfTwo(value + 1); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5927 | } |
| 5928 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5929 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, Opcode opcode) { |
| 5930 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5931 | if (DataType::Is64BitType(input_cst->GetType())) { |
| 5932 | Opcode high_opcode = opcode; |
| 5933 | vixl32::FlagsUpdate low_flags_update = vixl32::FlagsUpdate::DontCare; |
| 5934 | switch (opcode) { |
| 5935 | case SUB: |
| 5936 | // Flip the operation to an ADD. |
| 5937 | value = -value; |
| 5938 | opcode = ADD; |
| 5939 | FALLTHROUGH_INTENDED; |
| 5940 | case ADD: |
| 5941 | if (Low32Bits(value) == 0u) { |
| 5942 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), opcode); |
| 5943 | } |
| 5944 | high_opcode = ADC; |
| 5945 | low_flags_update = vixl32::FlagsUpdate::SetFlags; |
| 5946 | break; |
| 5947 | default: |
| 5948 | break; |
| 5949 | } |
| 5950 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), high_opcode) && |
| 5951 | CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode, low_flags_update); |
| 5952 | } else { |
| 5953 | return CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode); |
| 5954 | } |
| 5955 | } |
| 5956 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5957 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5958 | const FieldInfo& field_info) { |
| 5959 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5960 | |
| 5961 | LocationSummary* locations = instruction->GetLocations(); |
| 5962 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5963 | Location out = locations->Out(); |
| 5964 | bool is_volatile = field_info.IsVolatile(); |
| 5965 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5966 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5967 | DataType::Type load_type = instruction->GetType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5968 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5969 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5970 | switch (load_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5971 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5972 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5973 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5974 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5975 | case DataType::Type::kInt16: |
| 5976 | case DataType::Type::kInt32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5977 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5978 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5979 | LoadOperandType operand_type = GetLoadOperandType(load_type); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5980 | GetAssembler()->LoadFromOffset(operand_type, RegisterFrom(out), base, offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5981 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5982 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5983 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5984 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5985 | case DataType::Type::kReference: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5986 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5987 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 5988 | Location maybe_temp = (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location(); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5989 | // Note that a potential implicit null check is handled in this |
| 5990 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier call. |
| 5991 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5992 | instruction, out, base, offset, maybe_temp, /* needs_null_check= */ true); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5993 | if (is_volatile) { |
| 5994 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5995 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5996 | } else { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5997 | { |
| 5998 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5999 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6000 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
| 6001 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6002 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6003 | if (is_volatile) { |
| 6004 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6005 | } |
| 6006 | // If read barriers are enabled, emit read barriers other than |
| 6007 | // Baker's using a slow path (and also unpoison the loaded |
| 6008 | // reference, if heap poisoning is enabled). |
| 6009 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, locations->InAt(0), offset); |
| 6010 | } |
| 6011 | break; |
| 6012 | } |
| 6013 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6014 | case DataType::Type::kInt64: { |
| 6015 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6016 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6017 | if (is_volatile && !atomic_ldrd_strd) { |
| 6018 | GenerateWideAtomicLoad(base, offset, LowRegisterFrom(out), HighRegisterFrom(out)); |
| 6019 | } else { |
| 6020 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out), base, offset); |
| 6021 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6022 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6023 | break; |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6024 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6025 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6026 | case DataType::Type::kFloat32: { |
| 6027 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6028 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6029 | GetAssembler()->LoadSFromOffset(SRegisterFrom(out), base, offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6030 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6031 | break; |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6032 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6033 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6034 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6035 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6036 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6037 | vixl32::DRegister out_dreg = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6038 | if (is_volatile && !atomic_ldrd_strd) { |
| 6039 | vixl32::Register lo = RegisterFrom(locations->GetTemp(0)); |
| 6040 | vixl32::Register hi = RegisterFrom(locations->GetTemp(1)); |
| 6041 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6042 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6043 | __ Vmov(out_dreg, lo, hi); |
| 6044 | } else { |
| 6045 | GetAssembler()->LoadDFromOffset(out_dreg, base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6046 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6047 | } |
| 6048 | break; |
| 6049 | } |
| 6050 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6051 | case DataType::Type::kUint32: |
| 6052 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6053 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6054 | LOG(FATAL) << "Unreachable type " << load_type; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6055 | UNREACHABLE(); |
| 6056 | } |
| 6057 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6058 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6059 | if (load_type == DataType::Type::kReference) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6060 | // Memory barriers, in the case of references, are also handled |
| 6061 | // in the previous switch statement. |
| 6062 | } else { |
| 6063 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6064 | } |
| 6065 | } |
| 6066 | } |
| 6067 | |
| 6068 | void LocationsBuilderARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6069 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6070 | } |
| 6071 | |
| 6072 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6073 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 6074 | } |
| 6075 | |
| 6076 | void LocationsBuilderARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6077 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6078 | } |
| 6079 | |
| 6080 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6081 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6082 | } |
| 6083 | |
| 6084 | void LocationsBuilderARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6085 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6086 | } |
| 6087 | |
| 6088 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6089 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6090 | } |
| 6091 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6092 | void LocationsBuilderARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6093 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6094 | } |
| 6095 | |
| 6096 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6097 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 6098 | } |
| 6099 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 6100 | void LocationsBuilderARMVIXL::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6101 | codegen_->CreateStringBuilderAppendLocations(instruction, LocationFrom(r0)); |
| 6102 | } |
| 6103 | |
| 6104 | void InstructionCodeGeneratorARMVIXL::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6105 | __ Mov(r0, instruction->GetFormat()->GetValue()); |
| 6106 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 6107 | } |
| 6108 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6109 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 6110 | HUnresolvedInstanceFieldGet* instruction) { |
| 6111 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6112 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6113 | instruction, instruction->GetFieldType(), calling_convention); |
| 6114 | } |
| 6115 | |
| 6116 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 6117 | HUnresolvedInstanceFieldGet* instruction) { |
| 6118 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6119 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6120 | instruction->GetFieldType(), |
| 6121 | instruction->GetFieldIndex(), |
| 6122 | instruction->GetDexPc(), |
| 6123 | calling_convention); |
| 6124 | } |
| 6125 | |
| 6126 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 6127 | HUnresolvedInstanceFieldSet* instruction) { |
| 6128 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6129 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6130 | instruction, instruction->GetFieldType(), calling_convention); |
| 6131 | } |
| 6132 | |
| 6133 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 6134 | HUnresolvedInstanceFieldSet* instruction) { |
| 6135 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6136 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6137 | instruction->GetFieldType(), |
| 6138 | instruction->GetFieldIndex(), |
| 6139 | instruction->GetDexPc(), |
| 6140 | calling_convention); |
| 6141 | } |
| 6142 | |
| 6143 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldGet( |
| 6144 | HUnresolvedStaticFieldGet* instruction) { |
| 6145 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6146 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6147 | instruction, instruction->GetFieldType(), calling_convention); |
| 6148 | } |
| 6149 | |
| 6150 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldGet( |
| 6151 | HUnresolvedStaticFieldGet* instruction) { |
| 6152 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6153 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6154 | instruction->GetFieldType(), |
| 6155 | instruction->GetFieldIndex(), |
| 6156 | instruction->GetDexPc(), |
| 6157 | calling_convention); |
| 6158 | } |
| 6159 | |
| 6160 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldSet( |
| 6161 | HUnresolvedStaticFieldSet* instruction) { |
| 6162 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6163 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6164 | instruction, instruction->GetFieldType(), calling_convention); |
| 6165 | } |
| 6166 | |
| 6167 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldSet( |
| 6168 | HUnresolvedStaticFieldSet* instruction) { |
| 6169 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6170 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6171 | instruction->GetFieldType(), |
| 6172 | instruction->GetFieldIndex(), |
| 6173 | instruction->GetDexPc(), |
| 6174 | calling_convention); |
| 6175 | } |
| 6176 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6177 | void LocationsBuilderARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6178 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6179 | locations->SetInAt(0, Location::RequiresRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6180 | } |
| 6181 | |
| 6182 | void CodeGeneratorARMVIXL::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6183 | if (CanMoveNullCheckToUser(instruction)) { |
| 6184 | return; |
| 6185 | } |
| 6186 | |
| 6187 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6188 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6189 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6190 | vixl32::kMaxInstructionSizeInBytes, |
| 6191 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6192 | __ ldr(temps.Acquire(), MemOperand(InputRegisterAt(instruction, 0))); |
| 6193 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 6194 | } |
| 6195 | |
| 6196 | void CodeGeneratorARMVIXL::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 6197 | NullCheckSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6198 | new (GetScopedAllocator()) NullCheckSlowPathARMVIXL(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6199 | AddSlowPath(slow_path); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6200 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | void InstructionCodeGeneratorARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| 6204 | codegen_->GenerateNullCheck(instruction); |
| 6205 | } |
| 6206 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6207 | void CodeGeneratorARMVIXL::LoadFromShiftedRegOffset(DataType::Type type, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6208 | Location out_loc, |
| 6209 | vixl32::Register base, |
| 6210 | vixl32::Register reg_index, |
| 6211 | vixl32::Condition cond) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6212 | uint32_t shift_count = DataType::SizeShift(type); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6213 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 6214 | |
| 6215 | switch (type) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6216 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6217 | case DataType::Type::kUint8: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6218 | __ Ldrb(cond, RegisterFrom(out_loc), mem_address); |
| 6219 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6220 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6221 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 6222 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6223 | case DataType::Type::kUint16: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6224 | __ Ldrh(cond, RegisterFrom(out_loc), mem_address); |
| 6225 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6226 | case DataType::Type::kInt16: |
| 6227 | __ Ldrsh(cond, RegisterFrom(out_loc), mem_address); |
| 6228 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6229 | case DataType::Type::kReference: |
| 6230 | case DataType::Type::kInt32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6231 | __ Ldr(cond, RegisterFrom(out_loc), mem_address); |
| 6232 | break; |
| 6233 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6234 | case DataType::Type::kInt64: |
| 6235 | case DataType::Type::kFloat32: |
| 6236 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6237 | default: |
| 6238 | LOG(FATAL) << "Unreachable type " << type; |
| 6239 | UNREACHABLE(); |
| 6240 | } |
| 6241 | } |
| 6242 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6243 | void CodeGeneratorARMVIXL::StoreToShiftedRegOffset(DataType::Type type, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6244 | Location loc, |
| 6245 | vixl32::Register base, |
| 6246 | vixl32::Register reg_index, |
| 6247 | vixl32::Condition cond) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6248 | uint32_t shift_count = DataType::SizeShift(type); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6249 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 6250 | |
| 6251 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6252 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6253 | case DataType::Type::kUint8: |
| 6254 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6255 | __ Strb(cond, RegisterFrom(loc), mem_address); |
| 6256 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6257 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6258 | case DataType::Type::kInt16: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6259 | __ Strh(cond, RegisterFrom(loc), mem_address); |
| 6260 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6261 | case DataType::Type::kReference: |
| 6262 | case DataType::Type::kInt32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6263 | __ Str(cond, RegisterFrom(loc), mem_address); |
| 6264 | break; |
| 6265 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6266 | case DataType::Type::kInt64: |
| 6267 | case DataType::Type::kFloat32: |
| 6268 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6269 | default: |
| 6270 | LOG(FATAL) << "Unreachable type " << type; |
| 6271 | UNREACHABLE(); |
| 6272 | } |
| 6273 | } |
| 6274 | |
| 6275 | void LocationsBuilderARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| 6276 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6277 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6278 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6279 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 6280 | object_array_get_with_read_barrier |
| 6281 | ? LocationSummary::kCallOnSlowPath |
| 6282 | : LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6283 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6284 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6285 | } |
| 6286 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6287 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6288 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6289 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6290 | } else { |
| 6291 | // The output overlaps in the case of an object array get with |
| 6292 | // read barriers enabled: we do not want the move to overwrite the |
| 6293 | // array's location, as we need it to emit the read barrier. |
| 6294 | locations->SetOut( |
| 6295 | Location::RequiresRegister(), |
| 6296 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 6297 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6298 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6299 | if (instruction->GetIndex()->IsConstant()) { |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6300 | // Array loads with constant index are treated as field loads. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6301 | // We need a temporary register for the read barrier load in |
| 6302 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier() |
| 6303 | // only if the offset is too big. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6304 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 6305 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6306 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6307 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6308 | locations->AddTemp(Location::RequiresRegister()); |
| 6309 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6310 | } else { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6311 | // We need a non-scratch temporary for the array data pointer in |
| 6312 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(). |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6313 | locations->AddTemp(Location::RequiresRegister()); |
| 6314 | } |
| 6315 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6316 | // Also need a temporary for String compression feature. |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6317 | locations->AddTemp(Location::RequiresRegister()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6318 | } |
| 6319 | } |
| 6320 | |
| 6321 | void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6322 | LocationSummary* locations = instruction->GetLocations(); |
| 6323 | Location obj_loc = locations->InAt(0); |
| 6324 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6325 | Location index = locations->InAt(1); |
| 6326 | Location out_loc = locations->Out(); |
| 6327 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6328 | DataType::Type type = instruction->GetType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6329 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 6330 | instruction->IsStringCharAt(); |
| 6331 | HInstruction* array_instr = instruction->GetArray(); |
| 6332 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6333 | |
| 6334 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6335 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6336 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6337 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6338 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6339 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6340 | case DataType::Type::kInt32: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6341 | vixl32::Register length; |
| 6342 | if (maybe_compressed_char_at) { |
| 6343 | length = RegisterFrom(locations->GetTemp(0)); |
| 6344 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6345 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6346 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6347 | GetAssembler()->LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 6348 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6349 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6350 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6351 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6352 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6353 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6354 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6355 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6356 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6357 | "Expecting 0=compressed, 1=uncompressed"); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6358 | __ B(cs, &uncompressed_load, /* is_far_target= */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6359 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, |
| 6360 | RegisterFrom(out_loc), |
| 6361 | obj, |
| 6362 | data_offset + const_index); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6363 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6364 | __ Bind(&uncompressed_load); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6365 | GetAssembler()->LoadFromOffset(GetLoadOperandType(DataType::Type::kUint16), |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6366 | RegisterFrom(out_loc), |
| 6367 | obj, |
| 6368 | data_offset + (const_index << 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6369 | if (done.IsReferenced()) { |
| 6370 | __ Bind(&done); |
| 6371 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6372 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6373 | uint32_t full_offset = data_offset + (const_index << DataType::SizeShift(type)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6374 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6375 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6376 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6377 | LoadOperandType load_type = GetLoadOperandType(type); |
| 6378 | GetAssembler()->LoadFromOffset(load_type, RegisterFrom(out_loc), obj, full_offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6379 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6380 | } |
| 6381 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6382 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6383 | vixl32::Register temp = temps.Acquire(); |
| 6384 | |
| 6385 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6386 | // We do not need to compute the intermediate address from the array: the |
| 6387 | // input instruction has done it already. See the comment in |
| 6388 | // `TryExtractArrayAccessAddress()`. |
| 6389 | if (kIsDebugBuild) { |
| 6390 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6391 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6392 | } |
| 6393 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6394 | } else { |
| 6395 | __ Add(temp, obj, data_offset); |
| 6396 | } |
| 6397 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6398 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6399 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6400 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6401 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6402 | "Expecting 0=compressed, 1=uncompressed"); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6403 | __ B(cs, &uncompressed_load, /* is_far_target= */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6404 | __ Ldrb(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 0)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6405 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6406 | __ Bind(&uncompressed_load); |
| 6407 | __ Ldrh(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6408 | if (done.IsReferenced()) { |
| 6409 | __ Bind(&done); |
| 6410 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6411 | } else { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6412 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6413 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6414 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6415 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6416 | } |
| 6417 | } |
| 6418 | break; |
| 6419 | } |
| 6420 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6421 | case DataType::Type::kReference: { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6422 | // The read barrier instrumentation of object ArrayGet |
| 6423 | // instructions does not support the HIntermediateAddress |
| 6424 | // instruction. |
| 6425 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 6426 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6427 | static_assert( |
| 6428 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6429 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6430 | // /* HeapReference<Object> */ out = |
| 6431 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6432 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6433 | // Note that a potential implicit null check is handled in this |
| 6434 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6435 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 6436 | if (index.IsConstant()) { |
| 6437 | // 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] | 6438 | Location maybe_temp = |
| 6439 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6440 | data_offset += Int32ConstantFrom(index) << DataType::SizeShift(type); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6441 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6442 | out_loc, |
| 6443 | obj, |
| 6444 | data_offset, |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 6445 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6446 | /* needs_null_check= */ false); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6447 | } else { |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 6448 | Location temp = locations->GetTemp(0); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6449 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6450 | out_loc, obj, data_offset, index, temp, /* needs_null_check= */ false); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6451 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6452 | } else { |
| 6453 | vixl32::Register out = OutputRegister(instruction); |
| 6454 | if (index.IsConstant()) { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6455 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| 6456 | { |
| 6457 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6458 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6459 | GetAssembler()->LoadFromOffset(kLoadWord, out, obj, offset); |
| 6460 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6461 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6462 | // If read barriers are enabled, emit read barriers other than |
| 6463 | // Baker's using a slow path (and also unpoison the loaded |
| 6464 | // reference, if heap poisoning is enabled). |
| 6465 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6466 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6467 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6468 | vixl32::Register temp = temps.Acquire(); |
| 6469 | |
| 6470 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6471 | // We do not need to compute the intermediate address from the array: the |
| 6472 | // input instruction has done it already. See the comment in |
| 6473 | // `TryExtractArrayAccessAddress()`. |
| 6474 | if (kIsDebugBuild) { |
| 6475 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6476 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6477 | } |
| 6478 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6479 | } else { |
| 6480 | __ Add(temp, obj, data_offset); |
| 6481 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6482 | { |
| 6483 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6484 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6485 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| 6486 | temps.Close(); |
| 6487 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6488 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6489 | // If read barriers are enabled, emit read barriers other than |
| 6490 | // Baker's using a slow path (and also unpoison the loaded |
| 6491 | // reference, if heap poisoning is enabled). |
| 6492 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6493 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6494 | } |
| 6495 | } |
| 6496 | break; |
| 6497 | } |
| 6498 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6499 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6500 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6501 | // As two macro instructions can be emitted the max size is doubled. |
| 6502 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6503 | if (index.IsConstant()) { |
| 6504 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6505 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6506 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), obj, offset); |
| 6507 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6508 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6509 | vixl32::Register temp = temps.Acquire(); |
| 6510 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6511 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), temp, data_offset); |
| 6512 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6513 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6514 | break; |
| 6515 | } |
| 6516 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6517 | case DataType::Type::kFloat32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6518 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6519 | // As two macro instructions can be emitted the max size is doubled. |
| 6520 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6521 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 6522 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6523 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6524 | GetAssembler()->LoadSFromOffset(out, obj, offset); |
| 6525 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6526 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6527 | vixl32::Register temp = temps.Acquire(); |
| 6528 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6529 | GetAssembler()->LoadSFromOffset(out, temp, data_offset); |
| 6530 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6531 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6532 | break; |
| 6533 | } |
| 6534 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6535 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6536 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6537 | // As two macro instructions can be emitted the max size is doubled. |
| 6538 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6539 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6540 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6541 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), obj, offset); |
| 6542 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6543 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6544 | vixl32::Register temp = temps.Acquire(); |
| 6545 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6546 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), temp, data_offset); |
| 6547 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6548 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6549 | break; |
| 6550 | } |
| 6551 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6552 | case DataType::Type::kUint32: |
| 6553 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6554 | case DataType::Type::kVoid: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6555 | LOG(FATAL) << "Unreachable type " << type; |
| 6556 | UNREACHABLE(); |
| 6557 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6558 | } |
| 6559 | |
| 6560 | void LocationsBuilderARMVIXL::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6561 | DataType::Type value_type = instruction->GetComponentType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6562 | |
| 6563 | bool needs_write_barrier = |
| 6564 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6565 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6566 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6567 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6568 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6569 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6570 | |
| 6571 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6572 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6573 | if (DataType::IsFloatingPointType(value_type)) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6574 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 6575 | } else { |
| 6576 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6577 | } |
| 6578 | if (needs_write_barrier) { |
| 6579 | // Temporary registers for the write barrier. |
| 6580 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6581 | locations->AddTemp(Location::RequiresRegister()); |
| 6582 | } |
| 6583 | } |
| 6584 | |
| 6585 | void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6586 | LocationSummary* locations = instruction->GetLocations(); |
| 6587 | vixl32::Register array = InputRegisterAt(instruction, 0); |
| 6588 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6589 | DataType::Type value_type = instruction->GetComponentType(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6590 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6591 | bool needs_write_barrier = |
| 6592 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6593 | uint32_t data_offset = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6594 | mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6595 | Location value_loc = locations->InAt(2); |
| 6596 | HInstruction* array_instr = instruction->GetArray(); |
| 6597 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6598 | |
| 6599 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6600 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6601 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6602 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6603 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6604 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6605 | case DataType::Type::kInt32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6606 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6607 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6608 | uint32_t full_offset = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6609 | data_offset + (const_index << DataType::SizeShift(value_type)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6610 | StoreOperandType store_type = GetStoreOperandType(value_type); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6611 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6612 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6613 | GetAssembler()->StoreToOffset(store_type, RegisterFrom(value_loc), array, full_offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6614 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6615 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6616 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6617 | vixl32::Register temp = temps.Acquire(); |
| 6618 | |
| 6619 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6620 | // We do not need to compute the intermediate address from the array: the |
| 6621 | // input instruction has done it already. See the comment in |
| 6622 | // `TryExtractArrayAccessAddress()`. |
| 6623 | if (kIsDebugBuild) { |
| 6624 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6625 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6626 | } |
| 6627 | temp = array; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6628 | } else { |
| 6629 | __ Add(temp, array, data_offset); |
| 6630 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6631 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6632 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6633 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6634 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6635 | } |
| 6636 | break; |
| 6637 | } |
| 6638 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6639 | case DataType::Type::kReference: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6640 | vixl32::Register value = RegisterFrom(value_loc); |
| 6641 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6642 | // See the comment in instruction_simplifier_shared.cc. |
| 6643 | DCHECK(!has_intermediate_address); |
| 6644 | |
| 6645 | if (instruction->InputAt(2)->IsNullConstant()) { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6646 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6647 | // As two macro instructions can be emitted the max size is doubled. |
| 6648 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6649 | // Just setting null. |
| 6650 | if (index.IsConstant()) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6651 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6652 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6653 | } else { |
| 6654 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6655 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6656 | vixl32::Register temp = temps.Acquire(); |
| 6657 | __ Add(temp, array, data_offset); |
| 6658 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6659 | } |
| 6660 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6661 | DCHECK(!needs_write_barrier); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6662 | DCHECK(!needs_type_check); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6663 | break; |
| 6664 | } |
| 6665 | |
| 6666 | DCHECK(needs_write_barrier); |
| 6667 | Location temp1_loc = locations->GetTemp(0); |
| 6668 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 6669 | Location temp2_loc = locations->GetTemp(1); |
| 6670 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6671 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6672 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 6673 | vixl32::Label do_store; |
| 6674 | if (can_value_be_null) { |
| 6675 | __ CompareAndBranchIfZero(value, &do_store, /* is_far_target= */ false); |
| 6676 | } |
| 6677 | |
| 6678 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 6679 | if (needs_type_check) { |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6680 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARMVIXL(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6681 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6682 | |
| 6683 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6684 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6685 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6686 | |
| 6687 | // Note that when read barriers are enabled, the type checks |
| 6688 | // are performed without read barriers. This is fine, even in |
| 6689 | // the case where a class object is in the from-space after |
| 6690 | // the flip, as a comparison involving such a type would not |
| 6691 | // produce a false positive; it may of course produce a false |
| 6692 | // negative, in which case we would take the ArraySet slow |
| 6693 | // path. |
| 6694 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6695 | { |
| 6696 | // Ensure we record the pc position immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6697 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6698 | vixl32::kMaxInstructionSizeInBytes, |
| 6699 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6700 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6701 | __ ldr(temp1, MemOperand(array, class_offset)); |
| 6702 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6703 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6704 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6705 | |
| 6706 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6707 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6708 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6709 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6710 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6711 | // nor `temp2`, as we are comparing two poisoned references. |
| 6712 | __ Cmp(temp1, temp2); |
| 6713 | |
| 6714 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6715 | vixl32::Label do_put; |
| 6716 | __ B(eq, &do_put, /* is_far_target= */ false); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6717 | // If heap poisoning is enabled, the `temp1` reference has |
| 6718 | // not been unpoisoned yet; unpoison it now. |
| 6719 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6720 | |
| 6721 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6722 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6723 | // If heap poisoning is enabled, no need to unpoison |
| 6724 | // `temp1`, as we are comparing against null below. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6725 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6726 | __ Bind(&do_put); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6727 | } else { |
| 6728 | __ B(ne, slow_path->GetEntryLabel()); |
| 6729 | } |
| 6730 | } |
| 6731 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6732 | codegen_->MarkGCCard(temp1, temp2, array, value, /* can_be_null= */ false); |
| 6733 | |
| 6734 | if (can_value_be_null) { |
| 6735 | DCHECK(do_store.IsReferenced()); |
| 6736 | __ Bind(&do_store); |
| 6737 | } |
| 6738 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6739 | vixl32::Register source = value; |
| 6740 | if (kPoisonHeapReferences) { |
| 6741 | // Note that in the case where `value` is a null reference, |
| 6742 | // we do not enter this block, as a null reference does not |
| 6743 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6744 | DCHECK_EQ(value_type, DataType::Type::kReference); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6745 | __ Mov(temp1, value); |
| 6746 | GetAssembler()->PoisonHeapReference(temp1); |
| 6747 | source = temp1; |
| 6748 | } |
| 6749 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6750 | { |
| 6751 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6752 | // As two macro instructions can be emitted the max size is doubled. |
| 6753 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| 6754 | if (index.IsConstant()) { |
| 6755 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| 6756 | GetAssembler()->StoreToOffset(kStoreWord, source, array, offset); |
| 6757 | } else { |
| 6758 | DCHECK(index.IsRegister()) << index; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6759 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6760 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6761 | vixl32::Register temp = temps.Acquire(); |
| 6762 | __ Add(temp, array, data_offset); |
| 6763 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6764 | LocationFrom(source), |
| 6765 | temp, |
| 6766 | RegisterFrom(index)); |
| 6767 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6768 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6769 | if (can_value_be_null || !needs_type_check) { |
| 6770 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6771 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6772 | } |
| 6773 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6774 | if (slow_path != nullptr) { |
| 6775 | __ Bind(slow_path->GetExitLabel()); |
| 6776 | } |
| 6777 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6778 | break; |
| 6779 | } |
| 6780 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6781 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6782 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6783 | // As two macro instructions can be emitted the max size is doubled. |
| 6784 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6785 | Location value = locations->InAt(2); |
| 6786 | if (index.IsConstant()) { |
| 6787 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6788 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6789 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), array, offset); |
| 6790 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6791 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6792 | vixl32::Register temp = temps.Acquire(); |
| 6793 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6794 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), temp, data_offset); |
| 6795 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6796 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6797 | break; |
| 6798 | } |
| 6799 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6800 | case DataType::Type::kFloat32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6801 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6802 | // As two macro instructions can be emitted the max size is doubled. |
| 6803 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6804 | Location value = locations->InAt(2); |
| 6805 | DCHECK(value.IsFpuRegister()); |
| 6806 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6807 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6808 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), array, offset); |
| 6809 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6810 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6811 | vixl32::Register temp = temps.Acquire(); |
| 6812 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6813 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), temp, data_offset); |
| 6814 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6815 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6816 | break; |
| 6817 | } |
| 6818 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6819 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6820 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6821 | // As two macro instructions can be emitted the max size is doubled. |
| 6822 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6823 | Location value = locations->InAt(2); |
| 6824 | DCHECK(value.IsFpuRegisterPair()); |
| 6825 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6826 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6827 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), array, offset); |
| 6828 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6829 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6830 | vixl32::Register temp = temps.Acquire(); |
| 6831 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6832 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), temp, data_offset); |
| 6833 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6834 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6835 | break; |
| 6836 | } |
| 6837 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6838 | case DataType::Type::kUint32: |
| 6839 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6840 | case DataType::Type::kVoid: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6841 | LOG(FATAL) << "Unreachable type " << value_type; |
| 6842 | UNREACHABLE(); |
| 6843 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6844 | } |
| 6845 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6846 | void LocationsBuilderARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6847 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6848 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6849 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6850 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6851 | } |
| 6852 | |
| 6853 | void InstructionCodeGeneratorARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6854 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| 6855 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6856 | vixl32::Register out = OutputRegister(instruction); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6857 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6858 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6859 | vixl32::kMaxInstructionSizeInBytes, |
| 6860 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6861 | __ ldr(out, MemOperand(obj, offset)); |
| 6862 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6863 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6864 | // Mask out compression flag from String's array length. |
| 6865 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6866 | __ Lsr(out, out, 1u); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6867 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6868 | } |
| 6869 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6870 | void LocationsBuilderARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6871 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6872 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6873 | |
| 6874 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6875 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6876 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6877 | } |
| 6878 | |
| 6879 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6880 | vixl32::Register out = OutputRegister(instruction); |
| 6881 | vixl32::Register first = InputRegisterAt(instruction, 0); |
| 6882 | Location second = instruction->GetLocations()->InAt(1); |
| 6883 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6884 | if (second.IsRegister()) { |
| 6885 | __ Add(out, first, RegisterFrom(second)); |
| 6886 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6887 | __ Add(out, first, Int32ConstantFrom(second)); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6888 | } |
| 6889 | } |
| 6890 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 6891 | void LocationsBuilderARMVIXL::VisitIntermediateAddressIndex( |
| 6892 | HIntermediateAddressIndex* instruction) { |
| 6893 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6894 | } |
| 6895 | |
| 6896 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddressIndex( |
| 6897 | HIntermediateAddressIndex* instruction) { |
| 6898 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6899 | } |
| 6900 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6901 | void LocationsBuilderARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6902 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6903 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6904 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6905 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 6906 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6907 | |
| 6908 | HInstruction* index = instruction->InputAt(0); |
| 6909 | HInstruction* length = instruction->InputAt(1); |
| 6910 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6911 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6912 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6913 | // locations. |
| 6914 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6915 | locations->SetInAt(0, both_const |
| 6916 | ? Location::ConstantLocation(index->AsConstant()) |
| 6917 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6918 | locations->SetInAt(1, both_const |
| 6919 | ? Location::ConstantLocation(length->AsConstant()) |
| 6920 | : ArmEncodableConstantOrRegister(length, CMP)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6921 | } |
| 6922 | |
| 6923 | void InstructionCodeGeneratorARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6924 | LocationSummary* locations = instruction->GetLocations(); |
| 6925 | Location index_loc = locations->InAt(0); |
| 6926 | Location length_loc = locations->InAt(1); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6927 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6928 | if (length_loc.IsConstant()) { |
| 6929 | int32_t length = Int32ConstantFrom(length_loc); |
| 6930 | if (index_loc.IsConstant()) { |
| 6931 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6932 | int32_t index = Int32ConstantFrom(index_loc); |
| 6933 | if (index < 0 || index >= length) { |
| 6934 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6935 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6936 | codegen_->AddSlowPath(slow_path); |
| 6937 | __ B(slow_path->GetEntryLabel()); |
| 6938 | } else { |
| 6939 | // Some optimization after BCE may have generated this, and we should not |
| 6940 | // generate a bounds check if it is a valid range. |
| 6941 | } |
| 6942 | return; |
| 6943 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6944 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6945 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6946 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6947 | __ Cmp(RegisterFrom(index_loc), length); |
| 6948 | codegen_->AddSlowPath(slow_path); |
| 6949 | __ B(hs, slow_path->GetEntryLabel()); |
| 6950 | } else { |
| 6951 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6952 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6953 | __ Cmp(RegisterFrom(length_loc), InputOperandAt(instruction, 0)); |
| 6954 | codegen_->AddSlowPath(slow_path); |
| 6955 | __ B(ls, slow_path->GetEntryLabel()); |
| 6956 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6957 | } |
| 6958 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6959 | void CodeGeneratorARMVIXL::MarkGCCard(vixl32::Register temp, |
| 6960 | vixl32::Register card, |
| 6961 | vixl32::Register object, |
| 6962 | vixl32::Register value, |
| 6963 | bool can_be_null) { |
| 6964 | vixl32::Label is_null; |
| 6965 | if (can_be_null) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6966 | __ CompareAndBranchIfZero(value, &is_null); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6967 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 6968 | // Load the address of the card table into `card`. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6969 | GetAssembler()->LoadFromOffset( |
| 6970 | kLoadWord, card, tr, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 6971 | // Calculate the offset (in the card table) of the card corresponding to |
| 6972 | // `object`. |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 6973 | __ Lsr(temp, object, Operand::From(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 6974 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 6975 | // `object`'s card. |
| 6976 | // |
| 6977 | // Register `card` contains the address of the card table. Note that the card |
| 6978 | // table's base is biased during its creation so that it always starts at an |
| 6979 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 6980 | // art::gc::accounting::CardTable::Create). Therefore the STRB instruction |
| 6981 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 6982 | // (located at `card + object >> kCardShift`). |
| 6983 | // |
| 6984 | // This dual use of the value in register `card` (1. to calculate the location |
| 6985 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 6986 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6987 | __ Strb(card, MemOperand(card, temp)); |
| 6988 | if (can_be_null) { |
| 6989 | __ Bind(&is_null); |
| 6990 | } |
| 6991 | } |
| 6992 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6993 | void LocationsBuilderARMVIXL::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6994 | LOG(FATAL) << "Unreachable"; |
| 6995 | } |
| 6996 | |
| 6997 | void InstructionCodeGeneratorARMVIXL::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6998 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6999 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 7000 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 7001 | // The back edge will generate the suspend check. |
| 7002 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 7003 | } |
| 7004 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7005 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 7006 | } |
| 7007 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7008 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7009 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7010 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7011 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7012 | } |
| 7013 | |
| 7014 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 7015 | HBasicBlock* block = instruction->GetBlock(); |
| 7016 | if (block->GetLoopInformation() != nullptr) { |
| 7017 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 7018 | // The back edge will generate the suspend check. |
| 7019 | return; |
| 7020 | } |
| 7021 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 7022 | // The goto will generate the suspend check. |
| 7023 | return; |
| 7024 | } |
| 7025 | GenerateSuspendCheck(instruction, nullptr); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7026 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 14); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7027 | } |
| 7028 | |
| 7029 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 7030 | HBasicBlock* successor) { |
| 7031 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 7032 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 7033 | if (slow_path == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7034 | slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7035 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7036 | instruction->SetSlowPath(slow_path); |
| 7037 | codegen_->AddSlowPath(slow_path); |
| 7038 | if (successor != nullptr) { |
| 7039 | DCHECK(successor->IsLoopHeader()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7040 | } |
| 7041 | } else { |
| 7042 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 7043 | } |
| 7044 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7045 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7046 | vixl32::Register temp = temps.Acquire(); |
| 7047 | GetAssembler()->LoadFromOffset( |
| 7048 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 7049 | if (successor == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7050 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7051 | __ Bind(slow_path->GetReturnLabel()); |
| 7052 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7053 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7054 | __ B(slow_path->GetEntryLabel()); |
| 7055 | } |
| 7056 | } |
| 7057 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7058 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 7059 | return codegen_->GetAssembler(); |
| 7060 | } |
| 7061 | |
| 7062 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7063 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7064 | MoveOperands* move = moves_[index]; |
| 7065 | Location source = move->GetSource(); |
| 7066 | Location destination = move->GetDestination(); |
| 7067 | |
| 7068 | if (source.IsRegister()) { |
| 7069 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7070 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7071 | } else if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7072 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7073 | } else { |
| 7074 | DCHECK(destination.IsStackSlot()); |
| 7075 | GetAssembler()->StoreToOffset(kStoreWord, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7076 | RegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7077 | sp, |
| 7078 | destination.GetStackIndex()); |
| 7079 | } |
| 7080 | } else if (source.IsStackSlot()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7081 | if (destination.IsRegister()) { |
| 7082 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 7083 | RegisterFrom(destination), |
| 7084 | sp, |
| 7085 | source.GetStackIndex()); |
| 7086 | } else if (destination.IsFpuRegister()) { |
| 7087 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 7088 | } else { |
| 7089 | DCHECK(destination.IsStackSlot()); |
| 7090 | vixl32::Register temp = temps.Acquire(); |
| 7091 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 7092 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7093 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7094 | } else if (source.IsFpuRegister()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7095 | if (destination.IsRegister()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7096 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7097 | } else if (destination.IsFpuRegister()) { |
| 7098 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 7099 | } else { |
| 7100 | DCHECK(destination.IsStackSlot()); |
| 7101 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 7102 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7103 | } else if (source.IsDoubleStackSlot()) { |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7104 | if (destination.IsDoubleStackSlot()) { |
| 7105 | vixl32::DRegister temp = temps.AcquireD(); |
| 7106 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 7107 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 7108 | } else if (destination.IsRegisterPair()) { |
| 7109 | DCHECK(ExpectedPairLayout(destination)); |
| 7110 | GetAssembler()->LoadFromOffset( |
| 7111 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 7112 | } else { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7113 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 7114 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7115 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7116 | } else if (source.IsRegisterPair()) { |
| 7117 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7118 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 7119 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7120 | } else if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7121 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7122 | } else { |
| 7123 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7124 | DCHECK(ExpectedPairLayout(source)); |
| 7125 | GetAssembler()->StoreToOffset(kStoreWordPair, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7126 | LowRegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7127 | sp, |
| 7128 | destination.GetStackIndex()); |
| 7129 | } |
| 7130 | } else if (source.IsFpuRegisterPair()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7131 | if (destination.IsRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7132 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7133 | } else if (destination.IsFpuRegisterPair()) { |
| 7134 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 7135 | } else { |
| 7136 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7137 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 7138 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7139 | } else { |
| 7140 | DCHECK(source.IsConstant()) << source; |
| 7141 | HConstant* constant = source.GetConstant(); |
| 7142 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 7143 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 7144 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7145 | __ Mov(RegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7146 | } else { |
| 7147 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7148 | vixl32::Register temp = temps.Acquire(); |
| 7149 | __ Mov(temp, value); |
| 7150 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7151 | } |
| 7152 | } else if (constant->IsLongConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 7153 | int64_t value = Int64ConstantFrom(source); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7154 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7155 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 7156 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7157 | } else { |
| 7158 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7159 | vixl32::Register temp = temps.Acquire(); |
| 7160 | __ Mov(temp, Low32Bits(value)); |
| 7161 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7162 | __ Mov(temp, High32Bits(value)); |
| 7163 | GetAssembler()->StoreToOffset(kStoreWord, |
| 7164 | temp, |
| 7165 | sp, |
| 7166 | destination.GetHighStackIndex(kArmWordSize)); |
| 7167 | } |
| 7168 | } else if (constant->IsDoubleConstant()) { |
| 7169 | double value = constant->AsDoubleConstant()->GetValue(); |
| 7170 | if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7171 | __ Vmov(DRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7172 | } else { |
| 7173 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7174 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7175 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7176 | __ Mov(temp, Low32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7177 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7178 | __ Mov(temp, High32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7179 | GetAssembler()->StoreToOffset(kStoreWord, |
| 7180 | temp, |
| 7181 | sp, |
| 7182 | destination.GetHighStackIndex(kArmWordSize)); |
| 7183 | } |
| 7184 | } else { |
| 7185 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 7186 | float value = constant->AsFloatConstant()->GetValue(); |
| 7187 | if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7188 | __ Vmov(SRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7189 | } else { |
| 7190 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7191 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7192 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7193 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7194 | } |
| 7195 | } |
| 7196 | } |
| 7197 | } |
| 7198 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7199 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 7200 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 7201 | vixl32::Register temp = temps.Acquire(); |
| 7202 | __ Mov(temp, reg); |
| 7203 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 7204 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7205 | } |
| 7206 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7207 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 7208 | // TODO(VIXL32): Double check the performance of this implementation. |
| 7209 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7210 | vixl32::Register temp1 = temps.Acquire(); |
| 7211 | ScratchRegisterScope ensure_scratch( |
| 7212 | this, temp1.GetCode(), r0.GetCode(), codegen_->GetNumberOfCoreRegisters()); |
| 7213 | vixl32::Register temp2(ensure_scratch.GetRegister()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7214 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7215 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 7216 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, sp, mem1 + stack_offset); |
| 7217 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, sp, mem2 + stack_offset); |
| 7218 | GetAssembler()->StoreToOffset(kStoreWord, temp1, sp, mem2 + stack_offset); |
| 7219 | GetAssembler()->StoreToOffset(kStoreWord, temp2, sp, mem1 + stack_offset); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7220 | } |
| 7221 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7222 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 7223 | MoveOperands* move = moves_[index]; |
| 7224 | Location source = move->GetSource(); |
| 7225 | Location destination = move->GetDestination(); |
| 7226 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 7227 | |
| 7228 | if (source.IsRegister() && destination.IsRegister()) { |
| 7229 | vixl32::Register temp = temps.Acquire(); |
| 7230 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 7231 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 7232 | __ Mov(temp, RegisterFrom(destination)); |
| 7233 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 7234 | __ Mov(RegisterFrom(source), temp); |
| 7235 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 7236 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 7237 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 7238 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 7239 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7240 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7241 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7242 | vixl32::Register temp = temps.Acquire(); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7243 | __ Vmov(temp, SRegisterFrom(source)); |
| 7244 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 7245 | __ Vmov(SRegisterFrom(destination), temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7246 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 7247 | vixl32::DRegister temp = temps.AcquireD(); |
| 7248 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 7249 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 7250 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 7251 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 7252 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 7253 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 7254 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 7255 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 7256 | vixl32::DRegister temp = temps.AcquireD(); |
| 7257 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 7258 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 7259 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 7260 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7261 | vixl32::DRegister first = DRegisterFrom(source); |
| 7262 | vixl32::DRegister second = DRegisterFrom(destination); |
| 7263 | vixl32::DRegister temp = temps.AcquireD(); |
| 7264 | __ Vmov(temp, first); |
| 7265 | __ Vmov(first, second); |
| 7266 | __ Vmov(second, temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7267 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7268 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 7269 | ? DRegisterFrom(source) |
| 7270 | : DRegisterFrom(destination); |
| 7271 | int mem = source.IsFpuRegisterPair() |
| 7272 | ? destination.GetStackIndex() |
| 7273 | : source.GetStackIndex(); |
| 7274 | vixl32::DRegister temp = temps.AcquireD(); |
| 7275 | __ Vmov(temp, reg); |
| 7276 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 7277 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7278 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7279 | vixl32::SRegister reg = source.IsFpuRegister() |
| 7280 | ? SRegisterFrom(source) |
| 7281 | : SRegisterFrom(destination); |
| 7282 | int mem = source.IsFpuRegister() |
| 7283 | ? destination.GetStackIndex() |
| 7284 | : source.GetStackIndex(); |
| 7285 | vixl32::Register temp = temps.Acquire(); |
| 7286 | __ Vmov(temp, reg); |
| 7287 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 7288 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7289 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 7290 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 7291 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 7292 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 7293 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 7294 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 7295 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 7296 | } else { |
| 7297 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 7298 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7299 | } |
| 7300 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7301 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg) { |
| 7302 | __ Push(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7303 | } |
| 7304 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7305 | void ParallelMoveResolverARMVIXL::RestoreScratch(int reg) { |
| 7306 | __ Pop(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7307 | } |
| 7308 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7309 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7310 | HLoadClass::LoadKind desired_class_load_kind) { |
| 7311 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7312 | case HLoadClass::LoadKind::kInvalid: |
| 7313 | LOG(FATAL) << "UNREACHABLE"; |
| 7314 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7315 | case HLoadClass::LoadKind::kReferrersClass: |
| 7316 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7317 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7318 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7319 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7320 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7321 | case HLoadClass::LoadKind::kBssEntryPackage: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7322 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7323 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7324 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7325 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7326 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7327 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7328 | case HLoadClass::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7329 | break; |
| 7330 | } |
| 7331 | return desired_class_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7332 | } |
| 7333 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7334 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7335 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7336 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7337 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7338 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7339 | cls, |
| 7340 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7341 | LocationFrom(r0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7342 | DCHECK(calling_convention.GetRegisterAt(0).Is(r0)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7343 | return; |
| 7344 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7345 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7346 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7347 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7348 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7349 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7350 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7351 | ? LocationSummary::kCallOnSlowPath |
| 7352 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7353 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7354 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7355 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7356 | } |
| 7357 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7358 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7359 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7360 | } |
| 7361 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7362 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7363 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7364 | // 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] | 7365 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7366 | } else { |
| 7367 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7368 | } |
| 7369 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7370 | } |
| 7371 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7372 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7373 | // move. |
| 7374 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7375 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7376 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7377 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7378 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 15); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7379 | return; |
| 7380 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7381 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7382 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7383 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7384 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7385 | LocationSummary* locations = cls->GetLocations(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7386 | Location out_loc = locations->Out(); |
| 7387 | vixl32::Register out = OutputRegister(cls); |
| 7388 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7389 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7390 | ? kWithoutReadBarrier |
| 7391 | : kCompilerReadBarrierOption; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7392 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7393 | switch (load_kind) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7394 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7395 | DCHECK(!cls->CanCallRuntime()); |
| 7396 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7397 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7398 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7399 | codegen_->GenerateGcRootFieldLoad(cls, |
| 7400 | out_loc, |
| 7401 | current_method, |
| 7402 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 7403 | read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7404 | break; |
| 7405 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7406 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7407 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7408 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7409 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7410 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7411 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7412 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7413 | break; |
| 7414 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7415 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7416 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7417 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 7418 | codegen_->NewBootImageRelRoPatch(CodeGenerator::GetBootImageOffset(cls)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7419 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7420 | __ Ldr(out, MemOperand(out, /* offset= */ 0)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7421 | break; |
| 7422 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 7423 | case HLoadClass::LoadKind::kBssEntry: |
| 7424 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7425 | case HLoadClass::LoadKind::kBssEntryPackage: { |
| 7426 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = codegen_->NewTypeBssEntryPatch(cls); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7427 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7428 | // All aligned loads are implicitly atomic consume operations on ARM. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7429 | codegen_->GenerateGcRootFieldLoad(cls, out_loc, out, /* offset= */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7430 | generate_null_check = true; |
| 7431 | break; |
| 7432 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7433 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 7434 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7435 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 7436 | DCHECK_NE(address, 0u); |
| 7437 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7438 | break; |
| 7439 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7440 | case HLoadClass::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7441 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 7442 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7443 | cls->GetClass())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7444 | // /* GcRoot<mirror::Class> */ out = *out |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7445 | codegen_->GenerateGcRootFieldLoad(cls, out_loc, out, /* offset= */ 0, read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7446 | break; |
| 7447 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7448 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7449 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7450 | LOG(FATAL) << "UNREACHABLE"; |
| 7451 | UNREACHABLE(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7452 | } |
| 7453 | |
| 7454 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7455 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7456 | LoadClassSlowPathARMVIXL* slow_path = |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7457 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL(cls, cls); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7458 | codegen_->AddSlowPath(slow_path); |
| 7459 | if (generate_null_check) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7460 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7461 | } |
| 7462 | if (cls->MustGenerateClinitCheck()) { |
| 7463 | GenerateClassInitializationCheck(slow_path, out); |
| 7464 | } else { |
| 7465 | __ Bind(slow_path->GetExitLabel()); |
| 7466 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7467 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 16); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7468 | } |
| 7469 | } |
| 7470 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7471 | void LocationsBuilderARMVIXL::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7472 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7473 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 7474 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 7475 | } |
| 7476 | |
| 7477 | void InstructionCodeGeneratorARMVIXL::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7478 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 7479 | } |
| 7480 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7481 | void LocationsBuilderARMVIXL::VisitLoadMethodType(HLoadMethodType* load) { |
| 7482 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7483 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 7484 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 7485 | } |
| 7486 | |
| 7487 | void InstructionCodeGeneratorARMVIXL::VisitLoadMethodType(HLoadMethodType* load) { |
| 7488 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 7489 | } |
| 7490 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7491 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7492 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7493 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7494 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7495 | if (check->HasUses()) { |
| 7496 | locations->SetOut(Location::SameAsFirstInput()); |
| 7497 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7498 | // Rely on the type initialization to save everything we need. |
| 7499 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7500 | } |
| 7501 | |
| 7502 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7503 | // We assume the class is not null. |
| 7504 | LoadClassSlowPathARMVIXL* slow_path = |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7505 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), check); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7506 | codegen_->AddSlowPath(slow_path); |
| 7507 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 7508 | } |
| 7509 | |
| 7510 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 7511 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 7512 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7513 | vixl32::Register temp = temps.Acquire(); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7514 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7515 | constexpr uint32_t shifted_visibly_initialized_value = |
| 7516 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << status_lsb_position; |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7517 | |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7518 | const size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 7519 | GetAssembler()->LoadFromOffset(kLoadWord, temp, class_reg, status_offset); |
| 7520 | __ Cmp(temp, shifted_visibly_initialized_value); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 7521 | __ B(lo, slow_path->GetEntryLabel()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7522 | __ Bind(slow_path->GetExitLabel()); |
| 7523 | } |
| 7524 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7525 | void InstructionCodeGeneratorARMVIXL::GenerateBitstringTypeCheckCompare( |
| 7526 | HTypeCheckInstruction* check, |
| 7527 | vixl32::Register temp, |
| 7528 | vixl32::FlagsUpdate flags_update) { |
| 7529 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 7530 | uint32_t mask = check->GetBitstringMask(); |
| 7531 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 7532 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 7533 | |
| 7534 | // Note that HInstanceOf shall check for zero value in `temp` but HCheckCast needs |
| 7535 | // the Z flag for BNE. This is indicated by the `flags_update` parameter. |
| 7536 | if (mask_bits == 16u) { |
| 7537 | // Load only the bitstring part of the status word. |
| 7538 | __ Ldrh(temp, MemOperand(temp, mirror::Class::StatusOffset().Int32Value())); |
| 7539 | // Check if the bitstring bits are equal to `path_to_root`. |
| 7540 | if (flags_update == SetFlags) { |
| 7541 | __ Cmp(temp, path_to_root); |
| 7542 | } else { |
| 7543 | __ Sub(temp, temp, path_to_root); |
| 7544 | } |
| 7545 | } else { |
| 7546 | // /* uint32_t */ temp = temp->status_ |
| 7547 | __ Ldr(temp, MemOperand(temp, mirror::Class::StatusOffset().Int32Value())); |
| 7548 | if (GetAssembler()->ShifterOperandCanHold(SUB, path_to_root)) { |
| 7549 | // Compare the bitstring bits using SUB. |
| 7550 | __ Sub(temp, temp, path_to_root); |
| 7551 | // Shift out bits that do not contribute to the comparison. |
| 7552 | __ Lsl(flags_update, temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7553 | } else if (IsUint<16>(path_to_root)) { |
| 7554 | if (temp.IsLow()) { |
| 7555 | // Note: Optimized for size but contains one more dependent instruction than necessary. |
| 7556 | // MOVW+SUB(register) would be 8 bytes unless we find a low-reg temporary but the |
| 7557 | // macro assembler would use the high reg IP for the constant by default. |
| 7558 | // Compare the bitstring bits using SUB. |
| 7559 | __ Sub(temp, temp, path_to_root & 0x00ffu); // 16-bit SUB (immediate) T2 |
| 7560 | __ Sub(temp, temp, path_to_root & 0xff00u); // 32-bit SUB (immediate) T3 |
| 7561 | // Shift out bits that do not contribute to the comparison. |
| 7562 | __ Lsl(flags_update, temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7563 | } else { |
| 7564 | // Extract the bitstring bits. |
| 7565 | __ Ubfx(temp, temp, 0, mask_bits); |
| 7566 | // Check if the bitstring bits are equal to `path_to_root`. |
| 7567 | if (flags_update == SetFlags) { |
| 7568 | __ Cmp(temp, path_to_root); |
| 7569 | } else { |
| 7570 | __ Sub(temp, temp, path_to_root); |
| 7571 | } |
| 7572 | } |
| 7573 | } else { |
| 7574 | // Shift out bits that do not contribute to the comparison. |
| 7575 | __ Lsl(temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7576 | // Check if the shifted bitstring bits are equal to `path_to_root << (32u - mask_bits)`. |
| 7577 | if (flags_update == SetFlags) { |
| 7578 | __ Cmp(temp, path_to_root << (32u - mask_bits)); |
| 7579 | } else { |
| 7580 | __ Sub(temp, temp, path_to_root << (32u - mask_bits)); |
| 7581 | } |
| 7582 | } |
| 7583 | } |
| 7584 | } |
| 7585 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7586 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7587 | HLoadString::LoadKind desired_string_load_kind) { |
| 7588 | switch (desired_string_load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7589 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7590 | case HLoadString::LoadKind::kBootImageRelRo: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7591 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7592 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7593 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7594 | case HLoadString::LoadKind::kJitBootImageAddress: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7595 | case HLoadString::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7596 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7597 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7598 | case HLoadString::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7599 | break; |
| 7600 | } |
| 7601 | return desired_string_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7602 | } |
| 7603 | |
| 7604 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7605 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7606 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7607 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7608 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7609 | locations->SetOut(LocationFrom(r0)); |
| 7610 | } else { |
| 7611 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7612 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7613 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7614 | // 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] | 7615 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7616 | } else { |
| 7617 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7618 | } |
| 7619 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7620 | } |
| 7621 | } |
| 7622 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7623 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7624 | // move. |
| 7625 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7626 | LocationSummary* locations = load->GetLocations(); |
| 7627 | Location out_loc = locations->Out(); |
| 7628 | vixl32::Register out = OutputRegister(load); |
| 7629 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 7630 | |
| 7631 | switch (load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7632 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7633 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7634 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7635 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7636 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7637 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7638 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7639 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7640 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7641 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7642 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 7643 | codegen_->NewBootImageRelRoPatch(CodeGenerator::GetBootImageOffset(load)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7644 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7645 | __ Ldr(out, MemOperand(out, /* offset= */ 0)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7646 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7647 | } |
| 7648 | case HLoadString::LoadKind::kBssEntry: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7649 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7650 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7651 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7652 | // All aligned loads are implicitly atomic consume operations on ARM. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7653 | codegen_->GenerateGcRootFieldLoad( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7654 | load, out_loc, out, /* offset= */ 0, kCompilerReadBarrierOption); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7655 | LoadStringSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7656 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARMVIXL(load); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7657 | codegen_->AddSlowPath(slow_path); |
| 7658 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7659 | __ Bind(slow_path->GetExitLabel()); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7660 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 17); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7661 | return; |
| 7662 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7663 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 7664 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 7665 | DCHECK_NE(address, 0u); |
| 7666 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7667 | return; |
| 7668 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7669 | case HLoadString::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7670 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7671 | load->GetStringIndex(), |
| 7672 | load->GetString())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7673 | // /* GcRoot<mirror::String> */ out = *out |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7674 | codegen_->GenerateGcRootFieldLoad( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7675 | load, out_loc, out, /* offset= */ 0, kCompilerReadBarrierOption); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7676 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7677 | } |
| 7678 | default: |
| 7679 | break; |
| 7680 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7681 | |
| 7682 | // 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] | 7683 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7684 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7685 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7686 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7687 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7688 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 18); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7689 | } |
| 7690 | |
| 7691 | static int32_t GetExceptionTlsOffset() { |
| 7692 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 7693 | } |
| 7694 | |
| 7695 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 7696 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7697 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7698 | locations->SetOut(Location::RequiresRegister()); |
| 7699 | } |
| 7700 | |
| 7701 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 7702 | vixl32::Register out = OutputRegister(load); |
| 7703 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 7704 | } |
| 7705 | |
| 7706 | |
| 7707 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7708 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7709 | } |
| 7710 | |
| 7711 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7712 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7713 | vixl32::Register temp = temps.Acquire(); |
| 7714 | __ Mov(temp, 0); |
| 7715 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 7716 | } |
| 7717 | |
| 7718 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7719 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7720 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7721 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7722 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7723 | } |
| 7724 | |
| 7725 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 7726 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 7727 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7728 | } |
| 7729 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7730 | // Temp is used for read barrier. |
| 7731 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7732 | if (kEmitCompilerReadBarrier && |
| 7733 | (kUseBakerReadBarrier || |
| 7734 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7735 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7736 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7737 | return 1; |
| 7738 | } |
| 7739 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7740 | } |
| 7741 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7742 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 7743 | // interface pointer, one for loading the current interface. |
| 7744 | // The other checks have one temp for loading the object's class. |
| 7745 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7746 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7747 | return 3; |
| 7748 | } |
| 7749 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 7750 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7751 | |
| 7752 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7753 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7754 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7755 | bool baker_read_barrier_slow_path = false; |
| 7756 | switch (type_check_kind) { |
| 7757 | case TypeCheckKind::kExactCheck: |
| 7758 | case TypeCheckKind::kAbstractClassCheck: |
| 7759 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7760 | case TypeCheckKind::kArrayObjectCheck: { |
| 7761 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7762 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7763 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7764 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7765 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7766 | case TypeCheckKind::kArrayCheck: |
| 7767 | case TypeCheckKind::kUnresolvedCheck: |
| 7768 | case TypeCheckKind::kInterfaceCheck: |
| 7769 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7770 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7771 | case TypeCheckKind::kBitstringCheck: |
| 7772 | break; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7773 | } |
| 7774 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7775 | LocationSummary* locations = |
| 7776 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7777 | if (baker_read_barrier_slow_path) { |
| 7778 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7779 | } |
| 7780 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7781 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7782 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7783 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7784 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7785 | } else { |
| 7786 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7787 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7788 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7789 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7790 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7791 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7792 | } |
| 7793 | |
| 7794 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7795 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7796 | LocationSummary* locations = instruction->GetLocations(); |
| 7797 | Location obj_loc = locations->InAt(0); |
| 7798 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7799 | vixl32::Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 7800 | ? vixl32::Register() |
| 7801 | : InputRegisterAt(instruction, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7802 | Location out_loc = locations->Out(); |
| 7803 | vixl32::Register out = OutputRegister(instruction); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7804 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7805 | DCHECK_LE(num_temps, 1u); |
| 7806 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7807 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7808 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7809 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7810 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7811 | vixl32::Label done; |
| 7812 | vixl32::Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7813 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 7814 | |
| 7815 | // Return 0 if `obj` is null. |
| 7816 | // avoid null check if we know obj is not null. |
| 7817 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7818 | DCHECK(!out.Is(obj)); |
| 7819 | __ Mov(out, 0); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7820 | __ CompareAndBranchIfZero(obj, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7821 | } |
| 7822 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7823 | switch (type_check_kind) { |
| 7824 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7825 | ReadBarrierOption read_barrier_option = |
| 7826 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7827 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7828 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7829 | out_loc, |
| 7830 | obj_loc, |
| 7831 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7832 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7833 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7834 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7835 | __ Cmp(out, cls); |
| 7836 | // We speculatively set the result to false without changing the condition |
| 7837 | // flags, which allows us to avoid some branching later. |
| 7838 | __ Mov(LeaveFlags, out, 0); |
| 7839 | |
| 7840 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7841 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7842 | // encoding can be used. |
| 7843 | if (out.IsLow()) { |
| 7844 | // We use the scope because of the IT block that follows. |
| 7845 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7846 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7847 | CodeBufferCheckScope::kExactSize); |
| 7848 | |
| 7849 | __ it(eq); |
| 7850 | __ mov(eq, out, 1); |
| 7851 | } else { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7852 | __ B(ne, final_label, /* is_far_target= */ false); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7853 | __ Mov(out, 1); |
| 7854 | } |
| 7855 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7856 | break; |
| 7857 | } |
| 7858 | |
| 7859 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7860 | ReadBarrierOption read_barrier_option = |
| 7861 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7862 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7863 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7864 | out_loc, |
| 7865 | obj_loc, |
| 7866 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7867 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7868 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7869 | // If the class is abstract, we eagerly fetch the super class of the |
| 7870 | // object to avoid doing a comparison we know will fail. |
| 7871 | vixl32::Label loop; |
| 7872 | __ Bind(&loop); |
| 7873 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7874 | GenerateReferenceLoadOneRegister(instruction, |
| 7875 | out_loc, |
| 7876 | super_offset, |
| 7877 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7878 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7879 | // 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] | 7880 | __ CompareAndBranchIfZero(out, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7881 | __ Cmp(out, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7882 | __ B(ne, &loop, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7883 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7884 | break; |
| 7885 | } |
| 7886 | |
| 7887 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7888 | ReadBarrierOption read_barrier_option = |
| 7889 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7890 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7891 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7892 | out_loc, |
| 7893 | obj_loc, |
| 7894 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7895 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7896 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7897 | // Walk over the class hierarchy to find a match. |
| 7898 | vixl32::Label loop, success; |
| 7899 | __ Bind(&loop); |
| 7900 | __ Cmp(out, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7901 | __ B(eq, &success, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7902 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7903 | GenerateReferenceLoadOneRegister(instruction, |
| 7904 | out_loc, |
| 7905 | super_offset, |
| 7906 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7907 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7908 | // This is essentially a null check, but it sets the condition flags to the |
| 7909 | // proper value for the code that follows the loop, i.e. not `eq`. |
| 7910 | __ Cmp(out, 1); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7911 | __ B(hs, &loop, /* is_far_target= */ false); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7912 | |
| 7913 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7914 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7915 | // encoding can be used. |
| 7916 | if (out.IsLow()) { |
| 7917 | // If `out` is null, we use it for the result, and the condition flags |
| 7918 | // have already been set to `ne`, so the IT block that comes afterwards |
| 7919 | // (and which handles the successful case) turns into a NOP (instead of |
| 7920 | // overwriting `out`). |
| 7921 | __ Bind(&success); |
| 7922 | |
| 7923 | // We use the scope because of the IT block that follows. |
| 7924 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7925 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7926 | CodeBufferCheckScope::kExactSize); |
| 7927 | |
| 7928 | // There is only one branch to the `success` label (which is bound to this |
| 7929 | // IT block), and it has the same condition, `eq`, so in that case the MOV |
| 7930 | // is executed. |
| 7931 | __ it(eq); |
| 7932 | __ mov(eq, out, 1); |
| 7933 | } else { |
| 7934 | // 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] | 7935 | __ B(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7936 | __ Bind(&success); |
| 7937 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7938 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7939 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7940 | break; |
| 7941 | } |
| 7942 | |
| 7943 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7944 | ReadBarrierOption read_barrier_option = |
| 7945 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7946 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7947 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7948 | out_loc, |
| 7949 | obj_loc, |
| 7950 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7951 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7952 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7953 | // Do an exact check. |
| 7954 | vixl32::Label exact_check; |
| 7955 | __ Cmp(out, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7956 | __ B(eq, &exact_check, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7957 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7958 | // /* HeapReference<Class> */ out = out->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7959 | GenerateReferenceLoadOneRegister(instruction, |
| 7960 | out_loc, |
| 7961 | component_offset, |
| 7962 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7963 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7964 | // 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] | 7965 | __ CompareAndBranchIfZero(out, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7966 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7967 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7968 | __ Cmp(out, 0); |
| 7969 | // We speculatively set the result to false without changing the condition |
| 7970 | // flags, which allows us to avoid some branching later. |
| 7971 | __ Mov(LeaveFlags, out, 0); |
| 7972 | |
| 7973 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7974 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7975 | // encoding can be used. |
| 7976 | if (out.IsLow()) { |
| 7977 | __ Bind(&exact_check); |
| 7978 | |
| 7979 | // We use the scope because of the IT block that follows. |
| 7980 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7981 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7982 | CodeBufferCheckScope::kExactSize); |
| 7983 | |
| 7984 | __ it(eq); |
| 7985 | __ mov(eq, out, 1); |
| 7986 | } else { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7987 | __ B(ne, final_label, /* is_far_target= */ false); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7988 | __ Bind(&exact_check); |
| 7989 | __ Mov(out, 1); |
| 7990 | } |
| 7991 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7992 | break; |
| 7993 | } |
| 7994 | |
| 7995 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7996 | // No read barrier since the slow path will retry upon failure. |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7997 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7998 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7999 | out_loc, |
| 8000 | obj_loc, |
| 8001 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8002 | maybe_temp_loc, |
| 8003 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8004 | __ Cmp(out, cls); |
| 8005 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8006 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8007 | instruction, /* is_fatal= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8008 | codegen_->AddSlowPath(slow_path); |
| 8009 | __ B(ne, slow_path->GetEntryLabel()); |
| 8010 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8011 | break; |
| 8012 | } |
| 8013 | |
| 8014 | case TypeCheckKind::kUnresolvedCheck: |
| 8015 | case TypeCheckKind::kInterfaceCheck: { |
| 8016 | // Note that we indeed only call on slow path, but we always go |
| 8017 | // into the slow path for the unresolved and interface check |
| 8018 | // cases. |
| 8019 | // |
| 8020 | // We cannot directly call the InstanceofNonTrivial runtime |
| 8021 | // entry point without resorting to a type checking slow path |
| 8022 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 8023 | // require to assign fixed registers for the inputs of this |
| 8024 | // HInstanceOf instruction (following the runtime calling |
| 8025 | // convention), which might be cluttered by the potential first |
| 8026 | // read barrier emission at the beginning of this method. |
| 8027 | // |
| 8028 | // TODO: Introduce a new runtime entry point taking the object |
| 8029 | // to test (instead of its class) as argument, and let it deal |
| 8030 | // with the read barrier issues. This will let us refactor this |
| 8031 | // case of the `switch` code as it was previously (with a direct |
| 8032 | // call to the runtime not using a type checking slow path). |
| 8033 | // This should also be beneficial for the other cases above. |
| 8034 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8035 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8036 | instruction, /* is_fatal= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8037 | codegen_->AddSlowPath(slow_path); |
| 8038 | __ B(slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8039 | break; |
| 8040 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8041 | |
| 8042 | case TypeCheckKind::kBitstringCheck: { |
| 8043 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8044 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8045 | out_loc, |
| 8046 | obj_loc, |
| 8047 | class_offset, |
| 8048 | maybe_temp_loc, |
| 8049 | kWithoutReadBarrier); |
| 8050 | |
| 8051 | GenerateBitstringTypeCheckCompare(instruction, out, DontCare); |
| 8052 | // If `out` is a low reg and we would have another low reg temp, we could |
| 8053 | // optimize this as RSBS+ADC, see GenerateConditionWithZero(). |
| 8054 | // |
| 8055 | // Also, in some cases when `out` is a low reg and we're loading a constant to IP |
| 8056 | // it would make sense to use CMP+MOV+IT+MOV instead of SUB+CLZ+LSR as the code size |
| 8057 | // would be the same and we would have fewer direct data dependencies. |
| 8058 | codegen_->GenerateConditionWithZero(kCondEQ, out, out); // CLZ+LSR |
| 8059 | break; |
| 8060 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8061 | } |
| 8062 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8063 | if (done.IsReferenced()) { |
| 8064 | __ Bind(&done); |
| 8065 | } |
| 8066 | |
| 8067 | if (slow_path != nullptr) { |
| 8068 | __ Bind(slow_path->GetExitLabel()); |
| 8069 | } |
| 8070 | } |
| 8071 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8072 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8073 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8074 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8075 | LocationSummary* locations = |
| 8076 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8077 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8078 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 8079 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 8080 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 8081 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 8082 | } else { |
| 8083 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8084 | } |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8085 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8086 | } |
| 8087 | |
| 8088 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 8089 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 8090 | LocationSummary* locations = instruction->GetLocations(); |
| 8091 | Location obj_loc = locations->InAt(0); |
| 8092 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8093 | vixl32::Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 8094 | ? vixl32::Register() |
| 8095 | : InputRegisterAt(instruction, 1); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8096 | Location temp_loc = locations->GetTemp(0); |
| 8097 | vixl32::Register temp = RegisterFrom(temp_loc); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8098 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 8099 | DCHECK_LE(num_temps, 3u); |
| 8100 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 8101 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 8102 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 8103 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 8104 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 8105 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 8106 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 8107 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 8108 | const uint32_t object_array_data_offset = |
| 8109 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8110 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8111 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8112 | SlowPathCodeARMVIXL* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8113 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 8114 | instruction, is_type_check_slow_path_fatal); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8115 | codegen_->AddSlowPath(type_check_slow_path); |
| 8116 | |
| 8117 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8118 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8119 | // Avoid null check if we know obj is not null. |
| 8120 | if (instruction->MustDoNullCheck()) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8121 | __ CompareAndBranchIfZero(obj, final_label, /* is_far_target= */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8122 | } |
| 8123 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8124 | switch (type_check_kind) { |
| 8125 | case TypeCheckKind::kExactCheck: |
| 8126 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8127 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8128 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8129 | temp_loc, |
| 8130 | obj_loc, |
| 8131 | class_offset, |
| 8132 | maybe_temp2_loc, |
| 8133 | kWithoutReadBarrier); |
| 8134 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8135 | __ Cmp(temp, cls); |
| 8136 | // Jump to slow path for throwing the exception or doing a |
| 8137 | // more involved array check. |
| 8138 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 8139 | break; |
| 8140 | } |
| 8141 | |
| 8142 | case TypeCheckKind::kAbstractClassCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8143 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8144 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8145 | temp_loc, |
| 8146 | obj_loc, |
| 8147 | class_offset, |
| 8148 | maybe_temp2_loc, |
| 8149 | kWithoutReadBarrier); |
| 8150 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8151 | // If the class is abstract, we eagerly fetch the super class of the |
| 8152 | // object to avoid doing a comparison we know will fail. |
| 8153 | vixl32::Label loop; |
| 8154 | __ Bind(&loop); |
| 8155 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8156 | GenerateReferenceLoadOneRegister(instruction, |
| 8157 | temp_loc, |
| 8158 | super_offset, |
| 8159 | maybe_temp2_loc, |
| 8160 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8161 | |
| 8162 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 8163 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8164 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8165 | |
| 8166 | // Otherwise, compare the classes. |
| 8167 | __ Cmp(temp, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8168 | __ B(ne, &loop, /* is_far_target= */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8169 | break; |
| 8170 | } |
| 8171 | |
| 8172 | case TypeCheckKind::kClassHierarchyCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8173 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8174 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8175 | temp_loc, |
| 8176 | obj_loc, |
| 8177 | class_offset, |
| 8178 | maybe_temp2_loc, |
| 8179 | kWithoutReadBarrier); |
| 8180 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8181 | // Walk over the class hierarchy to find a match. |
| 8182 | vixl32::Label loop; |
| 8183 | __ Bind(&loop); |
| 8184 | __ Cmp(temp, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8185 | __ B(eq, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8186 | |
| 8187 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8188 | GenerateReferenceLoadOneRegister(instruction, |
| 8189 | temp_loc, |
| 8190 | super_offset, |
| 8191 | maybe_temp2_loc, |
| 8192 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8193 | |
| 8194 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 8195 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8196 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8197 | // Otherwise, jump to the beginning of the loop. |
| 8198 | __ B(&loop); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8199 | break; |
| 8200 | } |
| 8201 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8202 | case TypeCheckKind::kArrayObjectCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8203 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8204 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8205 | temp_loc, |
| 8206 | obj_loc, |
| 8207 | class_offset, |
| 8208 | maybe_temp2_loc, |
| 8209 | kWithoutReadBarrier); |
| 8210 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8211 | // Do an exact check. |
| 8212 | __ Cmp(temp, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8213 | __ B(eq, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8214 | |
| 8215 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 8216 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8217 | GenerateReferenceLoadOneRegister(instruction, |
| 8218 | temp_loc, |
| 8219 | component_offset, |
| 8220 | maybe_temp2_loc, |
| 8221 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8222 | // 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] | 8223 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8224 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 8225 | // to further check that this component type is not a primitive type. |
| 8226 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8227 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8228 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8229 | break; |
| 8230 | } |
| 8231 | |
| 8232 | case TypeCheckKind::kUnresolvedCheck: |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8233 | // 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] | 8234 | // We cannot directly call the CheckCast runtime entry point |
| 8235 | // without resorting to a type checking slow path here (i.e. by |
| 8236 | // calling InvokeRuntime directly), as it would require to |
| 8237 | // assign fixed registers for the inputs of this HInstanceOf |
| 8238 | // instruction (following the runtime calling convention), which |
| 8239 | // might be cluttered by the potential first read barrier |
| 8240 | // emission at the beginning of this method. |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8241 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8242 | __ B(type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8243 | break; |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8244 | |
| 8245 | case TypeCheckKind::kInterfaceCheck: { |
| 8246 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 8247 | // positives by doing this. |
| 8248 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8249 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8250 | temp_loc, |
| 8251 | obj_loc, |
| 8252 | class_offset, |
| 8253 | maybe_temp2_loc, |
| 8254 | kWithoutReadBarrier); |
| 8255 | |
| 8256 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 8257 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8258 | temp_loc, |
| 8259 | temp_loc, |
| 8260 | iftable_offset, |
| 8261 | maybe_temp2_loc, |
| 8262 | kWithoutReadBarrier); |
| 8263 | // Iftable is never null. |
| 8264 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 8265 | // Loop through the iftable and check if any class matches. |
| 8266 | vixl32::Label start_loop; |
| 8267 | __ Bind(&start_loop); |
| 8268 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 8269 | type_check_slow_path->GetEntryLabel()); |
| 8270 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 8271 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 8272 | // Go to next interface. |
| 8273 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 8274 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 8275 | // Compare the classes and continue the loop if they do not match. |
| 8276 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8277 | __ B(ne, &start_loop, /* is_far_target= */ false); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8278 | break; |
| 8279 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8280 | |
| 8281 | case TypeCheckKind::kBitstringCheck: { |
| 8282 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8283 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8284 | temp_loc, |
| 8285 | obj_loc, |
| 8286 | class_offset, |
| 8287 | maybe_temp2_loc, |
| 8288 | kWithoutReadBarrier); |
| 8289 | |
| 8290 | GenerateBitstringTypeCheckCompare(instruction, temp, SetFlags); |
| 8291 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 8292 | break; |
| 8293 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8294 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8295 | if (done.IsReferenced()) { |
| 8296 | __ Bind(&done); |
| 8297 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8298 | |
| 8299 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 8300 | } |
| 8301 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8302 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8303 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8304 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8305 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 8306 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 8307 | } |
| 8308 | |
| 8309 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8310 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 8311 | instruction, |
| 8312 | instruction->GetDexPc()); |
| 8313 | if (instruction->IsEnter()) { |
| 8314 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8315 | } else { |
| 8316 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8317 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 8318 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 19); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8319 | } |
| 8320 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8321 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 8322 | HandleBitwiseOperation(instruction, AND); |
| 8323 | } |
| 8324 | |
| 8325 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 8326 | HandleBitwiseOperation(instruction, ORR); |
| 8327 | } |
| 8328 | |
| 8329 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 8330 | HandleBitwiseOperation(instruction, EOR); |
| 8331 | } |
| 8332 | |
| 8333 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 8334 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8335 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8336 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8337 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8338 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 8339 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8340 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 8341 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8342 | } |
| 8343 | |
| 8344 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 8345 | HandleBitwiseOperation(instruction); |
| 8346 | } |
| 8347 | |
| 8348 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 8349 | HandleBitwiseOperation(instruction); |
| 8350 | } |
| 8351 | |
| 8352 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 8353 | HandleBitwiseOperation(instruction); |
| 8354 | } |
| 8355 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8356 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8357 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8358 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8359 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8360 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8361 | |
| 8362 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8363 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8364 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8365 | } |
| 8366 | |
| 8367 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8368 | LocationSummary* locations = instruction->GetLocations(); |
| 8369 | Location first = locations->InAt(0); |
| 8370 | Location second = locations->InAt(1); |
| 8371 | Location out = locations->Out(); |
| 8372 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8373 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8374 | vixl32::Register first_reg = RegisterFrom(first); |
| 8375 | vixl32::Register second_reg = RegisterFrom(second); |
| 8376 | vixl32::Register out_reg = RegisterFrom(out); |
| 8377 | |
| 8378 | switch (instruction->GetOpKind()) { |
| 8379 | case HInstruction::kAnd: |
| 8380 | __ Bic(out_reg, first_reg, second_reg); |
| 8381 | break; |
| 8382 | case HInstruction::kOr: |
| 8383 | __ Orn(out_reg, first_reg, second_reg); |
| 8384 | break; |
| 8385 | // There is no EON on arm. |
| 8386 | case HInstruction::kXor: |
| 8387 | default: |
| 8388 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8389 | UNREACHABLE(); |
| 8390 | } |
| 8391 | return; |
| 8392 | |
| 8393 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8394 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8395 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8396 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8397 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8398 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8399 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8400 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8401 | |
| 8402 | switch (instruction->GetOpKind()) { |
| 8403 | case HInstruction::kAnd: |
| 8404 | __ Bic(out_low, first_low, second_low); |
| 8405 | __ Bic(out_high, first_high, second_high); |
| 8406 | break; |
| 8407 | case HInstruction::kOr: |
| 8408 | __ Orn(out_low, first_low, second_low); |
| 8409 | __ Orn(out_high, first_high, second_high); |
| 8410 | break; |
| 8411 | // There is no EON on arm. |
| 8412 | case HInstruction::kXor: |
| 8413 | default: |
| 8414 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8415 | UNREACHABLE(); |
| 8416 | } |
| 8417 | } |
| 8418 | } |
| 8419 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8420 | void LocationsBuilderARMVIXL::VisitDataProcWithShifterOp( |
| 8421 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8422 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 8423 | instruction->GetType() == DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8424 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8425 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8426 | const bool overlap = instruction->GetType() == DataType::Type::kInt64 && |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8427 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 8428 | |
| 8429 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8430 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8431 | locations->SetOut(Location::RequiresRegister(), |
| 8432 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 8433 | } |
| 8434 | |
| 8435 | void InstructionCodeGeneratorARMVIXL::VisitDataProcWithShifterOp( |
| 8436 | HDataProcWithShifterOp* instruction) { |
| 8437 | const LocationSummary* const locations = instruction->GetLocations(); |
| 8438 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 8439 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 8440 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8441 | if (instruction->GetType() == DataType::Type::kInt32) { |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8442 | const vixl32::Register first = InputRegisterAt(instruction, 0); |
| 8443 | const vixl32::Register output = OutputRegister(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8444 | const vixl32::Register second = instruction->InputAt(1)->GetType() == DataType::Type::kInt64 |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8445 | ? LowRegisterFrom(locations->InAt(1)) |
| 8446 | : InputRegisterAt(instruction, 1); |
| 8447 | |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8448 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8449 | DCHECK_EQ(kind, HInstruction::kAdd); |
| 8450 | |
| 8451 | switch (op_kind) { |
| 8452 | case HDataProcWithShifterOp::kUXTB: |
| 8453 | __ Uxtab(output, first, second); |
| 8454 | break; |
| 8455 | case HDataProcWithShifterOp::kUXTH: |
| 8456 | __ Uxtah(output, first, second); |
| 8457 | break; |
| 8458 | case HDataProcWithShifterOp::kSXTB: |
| 8459 | __ Sxtab(output, first, second); |
| 8460 | break; |
| 8461 | case HDataProcWithShifterOp::kSXTH: |
| 8462 | __ Sxtah(output, first, second); |
| 8463 | break; |
| 8464 | default: |
| 8465 | LOG(FATAL) << "Unexpected operation kind: " << op_kind; |
| 8466 | UNREACHABLE(); |
| 8467 | } |
| 8468 | } else { |
| 8469 | GenerateDataProcInstruction(kind, |
| 8470 | output, |
| 8471 | first, |
| 8472 | Operand(second, |
| 8473 | ShiftFromOpKind(op_kind), |
| 8474 | instruction->GetShiftAmount()), |
| 8475 | codegen_); |
| 8476 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8477 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8478 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8479 | |
| 8480 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8481 | const vixl32::Register second = InputRegisterAt(instruction, 1); |
| 8482 | |
| 8483 | DCHECK(!LowRegisterFrom(locations->Out()).Is(second)); |
| 8484 | GenerateDataProc(kind, |
| 8485 | locations->Out(), |
| 8486 | locations->InAt(0), |
| 8487 | second, |
| 8488 | Operand(second, ShiftType::ASR, 31), |
| 8489 | codegen_); |
| 8490 | } else { |
| 8491 | GenerateLongDataProc(instruction, codegen_); |
| 8492 | } |
| 8493 | } |
| 8494 | } |
| 8495 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8496 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8497 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 8498 | vixl32::Register first, |
| 8499 | uint32_t value) { |
| 8500 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 8501 | if (value == 0xffffffffu) { |
| 8502 | if (!out.Is(first)) { |
| 8503 | __ Mov(out, first); |
| 8504 | } |
| 8505 | return; |
| 8506 | } |
| 8507 | if (value == 0u) { |
| 8508 | __ Mov(out, 0); |
| 8509 | return; |
| 8510 | } |
| 8511 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8512 | __ And(out, first, value); |
| 8513 | } else if (GetAssembler()->ShifterOperandCanHold(BIC, ~value)) { |
| 8514 | __ Bic(out, first, ~value); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8515 | } else { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8516 | DCHECK(IsPowerOfTwo(value + 1)); |
| 8517 | __ Ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8518 | } |
| 8519 | } |
| 8520 | |
| 8521 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8522 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 8523 | vixl32::Register first, |
| 8524 | uint32_t value) { |
| 8525 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 8526 | if (value == 0u) { |
| 8527 | if (!out.Is(first)) { |
| 8528 | __ Mov(out, first); |
| 8529 | } |
| 8530 | return; |
| 8531 | } |
| 8532 | if (value == 0xffffffffu) { |
| 8533 | __ Mvn(out, 0); |
| 8534 | return; |
| 8535 | } |
| 8536 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 8537 | __ Orr(out, first, value); |
| 8538 | } else { |
| 8539 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 8540 | __ Orn(out, first, ~value); |
| 8541 | } |
| 8542 | } |
| 8543 | |
| 8544 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8545 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 8546 | vixl32::Register first, |
| 8547 | uint32_t value) { |
| 8548 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 8549 | if (value == 0u) { |
| 8550 | if (!out.Is(first)) { |
| 8551 | __ Mov(out, first); |
| 8552 | } |
| 8553 | return; |
| 8554 | } |
| 8555 | __ Eor(out, first, value); |
| 8556 | } |
| 8557 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8558 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 8559 | Location first, |
| 8560 | uint64_t value) { |
| 8561 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8562 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8563 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8564 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8565 | uint32_t value_low = Low32Bits(value); |
| 8566 | uint32_t value_high = High32Bits(value); |
| 8567 | if (value_low == 0u) { |
| 8568 | if (!out_low.Is(first_low)) { |
| 8569 | __ Mov(out_low, first_low); |
| 8570 | } |
| 8571 | __ Add(out_high, first_high, value_high); |
| 8572 | return; |
| 8573 | } |
| 8574 | __ Adds(out_low, first_low, value_low); |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8575 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8576 | __ Adc(out_high, first_high, value_high); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8577 | } else { |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8578 | DCHECK(GetAssembler()->ShifterOperandCanHold(SBC, ~value_high)); |
| 8579 | __ Sbc(out_high, first_high, ~value_high); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8580 | } |
| 8581 | } |
| 8582 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8583 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8584 | LocationSummary* locations = instruction->GetLocations(); |
| 8585 | Location first = locations->InAt(0); |
| 8586 | Location second = locations->InAt(1); |
| 8587 | Location out = locations->Out(); |
| 8588 | |
| 8589 | if (second.IsConstant()) { |
| 8590 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 8591 | uint32_t value_low = Low32Bits(value); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8592 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8593 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8594 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8595 | if (instruction->IsAnd()) { |
| 8596 | GenerateAndConst(out_reg, first_reg, value_low); |
| 8597 | } else if (instruction->IsOr()) { |
| 8598 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 8599 | } else { |
| 8600 | DCHECK(instruction->IsXor()); |
| 8601 | GenerateEorConst(out_reg, first_reg, value_low); |
| 8602 | } |
| 8603 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8604 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8605 | uint32_t value_high = High32Bits(value); |
| 8606 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8607 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8608 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8609 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8610 | if (instruction->IsAnd()) { |
| 8611 | GenerateAndConst(out_low, first_low, value_low); |
| 8612 | GenerateAndConst(out_high, first_high, value_high); |
| 8613 | } else if (instruction->IsOr()) { |
| 8614 | GenerateOrrConst(out_low, first_low, value_low); |
| 8615 | GenerateOrrConst(out_high, first_high, value_high); |
| 8616 | } else { |
| 8617 | DCHECK(instruction->IsXor()); |
| 8618 | GenerateEorConst(out_low, first_low, value_low); |
| 8619 | GenerateEorConst(out_high, first_high, value_high); |
| 8620 | } |
| 8621 | } |
| 8622 | return; |
| 8623 | } |
| 8624 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8625 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8626 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8627 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 8628 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8629 | if (instruction->IsAnd()) { |
| 8630 | __ And(out_reg, first_reg, second_reg); |
| 8631 | } else if (instruction->IsOr()) { |
| 8632 | __ Orr(out_reg, first_reg, second_reg); |
| 8633 | } else { |
| 8634 | DCHECK(instruction->IsXor()); |
| 8635 | __ Eor(out_reg, first_reg, second_reg); |
| 8636 | } |
| 8637 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8638 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8639 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8640 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8641 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8642 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8643 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8644 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8645 | if (instruction->IsAnd()) { |
| 8646 | __ And(out_low, first_low, second_low); |
| 8647 | __ And(out_high, first_high, second_high); |
| 8648 | } else if (instruction->IsOr()) { |
| 8649 | __ Orr(out_low, first_low, second_low); |
| 8650 | __ Orr(out_high, first_high, second_high); |
| 8651 | } else { |
| 8652 | DCHECK(instruction->IsXor()); |
| 8653 | __ Eor(out_low, first_low, second_low); |
| 8654 | __ Eor(out_high, first_high, second_high); |
| 8655 | } |
| 8656 | } |
| 8657 | } |
| 8658 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8659 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8660 | HInstruction* instruction, |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8661 | Location out, |
| 8662 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8663 | Location maybe_temp, |
| 8664 | ReadBarrierOption read_barrier_option) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8665 | vixl32::Register out_reg = RegisterFrom(out); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8666 | if (read_barrier_option == kWithReadBarrier) { |
| 8667 | CHECK(kEmitCompilerReadBarrier); |
| 8668 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8669 | if (kUseBakerReadBarrier) { |
| 8670 | // Load with fast path based Baker's read barrier. |
| 8671 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8672 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8673 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check= */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8674 | } else { |
| 8675 | // Load with slow path based read barrier. |
| 8676 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 8677 | // in the following move operation, as we will need it for the |
| 8678 | // read barrier below. |
| 8679 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 8680 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8681 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8682 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 8683 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8684 | } else { |
| 8685 | // Plain load with no read barrier. |
| 8686 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8687 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8688 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8689 | } |
| 8690 | } |
| 8691 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8692 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8693 | HInstruction* instruction, |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8694 | Location out, |
| 8695 | Location obj, |
| 8696 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8697 | Location maybe_temp, |
| 8698 | ReadBarrierOption read_barrier_option) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8699 | vixl32::Register out_reg = RegisterFrom(out); |
| 8700 | vixl32::Register obj_reg = RegisterFrom(obj); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8701 | if (read_barrier_option == kWithReadBarrier) { |
| 8702 | CHECK(kEmitCompilerReadBarrier); |
| 8703 | if (kUseBakerReadBarrier) { |
| 8704 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8705 | // Load with fast path based Baker's read barrier. |
| 8706 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8707 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8708 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check= */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8709 | } else { |
| 8710 | // Load with slow path based read barrier. |
| 8711 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8712 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8713 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8714 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8715 | } else { |
| 8716 | // Plain load with no read barrier. |
| 8717 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8718 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8719 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8720 | } |
| 8721 | } |
| 8722 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8723 | void CodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8724 | HInstruction* instruction, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8725 | Location root, |
| 8726 | vixl32::Register obj, |
| 8727 | uint32_t offset, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8728 | ReadBarrierOption read_barrier_option) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8729 | vixl32::Register root_reg = RegisterFrom(root); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8730 | if (read_barrier_option == kWithReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8731 | DCHECK(kEmitCompilerReadBarrier); |
| 8732 | if (kUseBakerReadBarrier) { |
| 8733 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8734 | // Baker's read barrier are used. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8735 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8736 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8737 | // the Marking Register) to decide whether we need to enter |
| 8738 | // the slow path to mark the GC root. |
| 8739 | // |
| 8740 | // We use shared thunks for the slow path; shared within the method |
| 8741 | // for JIT, across methods for AOT. That thunk checks the reference |
| 8742 | // and jumps to the entrypoint if needed. |
| 8743 | // |
| 8744 | // lr = &return_address; |
| 8745 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8746 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8747 | // goto gc_root_thunk<root_reg>(lr) |
| 8748 | // } |
| 8749 | // return_address: |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8750 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8751 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8752 | temps.Exclude(ip); |
| 8753 | bool narrow = CanEmitNarrowLdr(root_reg, obj, offset); |
| 8754 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode(), narrow); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8755 | |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8756 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u) + /* LDR */ (narrow ? 1u : 0u); |
| 8757 | size_t wide_instructions = /* ADR+CMP+LDR+BNE */ 4u - narrow_instructions; |
| 8758 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8759 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8760 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8761 | vixl32::Label return_address; |
| 8762 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8763 | __ cmp(mr, Operand(0)); |
| 8764 | // Currently the offset is always within range. If that changes, |
| 8765 | // we shall have to split the load the same way as for fields. |
| 8766 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
| 8767 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8768 | __ ldr(EncodingSize(narrow ? Narrow : Wide), root_reg, MemOperand(obj, offset)); |
| 8769 | EmitBakerReadBarrierBne(custom_data); |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8770 | __ bind(&return_address); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8771 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8772 | narrow ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8773 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8774 | } else { |
| 8775 | // GC root loaded through a slow path for read barriers other |
| 8776 | // than Baker's. |
| 8777 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8778 | __ Add(root_reg, obj, offset); |
| 8779 | // /* mirror::Object* */ root = root->Read() |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8780 | GenerateReadBarrierForRootSlow(instruction, root, root); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8781 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8782 | } else { |
| 8783 | // Plain GC root load with no read barrier. |
| 8784 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8785 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8786 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8787 | // do not have to unpoison `root_reg` here. |
| 8788 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 8789 | MaybeGenerateMarkingRegisterCheck(/* code= */ 20); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8790 | } |
| 8791 | |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8792 | void CodeGeneratorARMVIXL::GenerateUnsafeCasOldValueAddWithBakerReadBarrier( |
| 8793 | vixl::aarch32::Register old_value, |
| 8794 | vixl::aarch32::Register adjusted_old_value, |
| 8795 | vixl::aarch32::Register expected) { |
| 8796 | DCHECK(kEmitCompilerReadBarrier); |
| 8797 | DCHECK(kUseBakerReadBarrier); |
| 8798 | |
| 8799 | // Similar to the Baker RB path in GenerateGcRootFieldLoad(), with an ADD instead of LDR. |
| 8800 | uint32_t custom_data = EncodeBakerReadBarrierUnsafeCasData(old_value.GetCode()); |
| 8801 | |
| 8802 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u); |
| 8803 | size_t wide_instructions = /* ADR+CMP+ADD+BNE */ 4u - narrow_instructions; |
| 8804 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8805 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8806 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
| 8807 | vixl32::Label return_address; |
| 8808 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8809 | __ cmp(mr, Operand(0)); |
| 8810 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8811 | __ add(EncodingSize(Wide), old_value, adjusted_old_value, Operand(expected)); // Preserves flags. |
| 8812 | EmitBakerReadBarrierBne(custom_data); |
| 8813 | __ bind(&return_address); |
| 8814 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8815 | BAKER_MARK_INTROSPECTION_UNSAFE_CAS_ADD_OFFSET); |
| 8816 | } |
| 8817 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8818 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8819 | Location ref, |
| 8820 | vixl32::Register obj, |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8821 | const vixl32::MemOperand& src, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8822 | bool needs_null_check) { |
| 8823 | DCHECK(kEmitCompilerReadBarrier); |
| 8824 | DCHECK(kUseBakerReadBarrier); |
| 8825 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8826 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8827 | // Marking Register) to decide whether we need to enter the slow |
| 8828 | // path to mark the reference. Then, in the slow path, check the |
| 8829 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8830 | // decide whether to mark `ref` or not. |
| 8831 | // |
| 8832 | // We use shared thunks for the slow path; shared within the method |
| 8833 | // for JIT, across methods for AOT. That thunk checks the holder |
| 8834 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 8835 | // it creates a fake dependency and returns to the LDR instruction. |
| 8836 | // |
| 8837 | // lr = &gray_return_address; |
| 8838 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8839 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8840 | // } |
| 8841 | // not_gray_return_address: |
| 8842 | // // Original reference load. If the offset is too large to fit |
| 8843 | // // into LDR, we use an adjusted base register here. |
| 8844 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 8845 | // gray_return_address: |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8846 | |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8847 | DCHECK(src.GetAddrMode() == vixl32::Offset); |
| 8848 | DCHECK_ALIGNED(src.GetOffsetImmediate(), sizeof(mirror::HeapReference<mirror::Object>)); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8849 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8850 | bool narrow = CanEmitNarrowLdr(ref_reg, src.GetBaseRegister(), src.GetOffsetImmediate()); |
| 8851 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8852 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8853 | temps.Exclude(ip); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8854 | uint32_t custom_data = |
| 8855 | EncodeBakerReadBarrierFieldData(src.GetBaseRegister().GetCode(), obj.GetCode(), narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8856 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8857 | { |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8858 | size_t narrow_instructions = |
| 8859 | /* CMP */ (mr.IsLow() ? 1u : 0u) + |
| 8860 | /* LDR+unpoison? */ (narrow ? (kPoisonHeapReferences ? 2u : 1u) : 0u); |
| 8861 | size_t wide_instructions = |
| 8862 | /* ADR+CMP+LDR+BNE+unpoison? */ (kPoisonHeapReferences ? 5u : 4u) - narrow_instructions; |
| 8863 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8864 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8865 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8866 | vixl32::Label return_address; |
| 8867 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8868 | __ cmp(mr, Operand(0)); |
| 8869 | EmitBakerReadBarrierBne(custom_data); |
| 8870 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8871 | __ ldr(EncodingSize(narrow ? Narrow : Wide), ref_reg, src); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8872 | if (needs_null_check) { |
| 8873 | MaybeRecordImplicitNullCheck(instruction); |
| 8874 | } |
| 8875 | // Note: We need a specific width for the unpoisoning NEG. |
| 8876 | if (kPoisonHeapReferences) { |
| 8877 | if (narrow) { |
| 8878 | // The only 16-bit encoding is T1 which sets flags outside IT block (i.e. RSBS, not RSB). |
| 8879 | __ rsbs(EncodingSize(Narrow), ref_reg, ref_reg, Operand(0)); |
| 8880 | } else { |
| 8881 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8882 | } |
| 8883 | } |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8884 | __ bind(&return_address); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8885 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8886 | narrow ? BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| 8887 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET); |
| 8888 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 8889 | MaybeGenerateMarkingRegisterCheck(/* code= */ 21, /* temp_loc= */ LocationFrom(ip)); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8890 | } |
| 8891 | |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8892 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8893 | Location ref, |
| 8894 | vixl32::Register obj, |
| 8895 | uint32_t offset, |
Vladimir Marko | 01b6552 | 2020-10-28 15:43:54 +0000 | [diff] [blame] | 8896 | Location maybe_temp, |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8897 | bool needs_null_check) { |
| 8898 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 8899 | vixl32::Register base = obj; |
| 8900 | if (offset >= kReferenceLoadMinFarOffset) { |
Vladimir Marko | 01b6552 | 2020-10-28 15:43:54 +0000 | [diff] [blame] | 8901 | base = RegisterFrom(maybe_temp); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8902 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8903 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 8904 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 8905 | } |
| 8906 | GenerateFieldLoadWithBakerReadBarrier( |
| 8907 | instruction, ref, obj, MemOperand(base, offset), needs_null_check); |
| 8908 | } |
| 8909 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8910 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(Location ref, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8911 | vixl32::Register obj, |
| 8912 | uint32_t data_offset, |
| 8913 | Location index, |
| 8914 | Location temp, |
| 8915 | bool needs_null_check) { |
| 8916 | DCHECK(kEmitCompilerReadBarrier); |
| 8917 | DCHECK(kUseBakerReadBarrier); |
| 8918 | |
| 8919 | static_assert( |
| 8920 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8921 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8922 | ScaleFactor scale_factor = TIMES_4; |
| 8923 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8924 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8925 | // Marking Register) to decide whether we need to enter the slow |
| 8926 | // path to mark the reference. Then, in the slow path, check the |
| 8927 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8928 | // decide whether to mark `ref` or not. |
| 8929 | // |
| 8930 | // We use shared thunks for the slow path; shared within the method |
| 8931 | // for JIT, across methods for AOT. That thunk checks the holder |
| 8932 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 8933 | // it creates a fake dependency and returns to the LDR instruction. |
| 8934 | // |
| 8935 | // lr = &gray_return_address; |
| 8936 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8937 | // goto array_thunk<base_reg>(lr) |
| 8938 | // } |
| 8939 | // not_gray_return_address: |
| 8940 | // // Original reference load. If the offset is too large to fit |
| 8941 | // // into LDR, we use an adjusted base register here. |
| 8942 | // HeapReference<mirror::Object> reference = data[index]; |
| 8943 | // gray_return_address: |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8944 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8945 | DCHECK(index.IsValid()); |
| 8946 | vixl32::Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 8947 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 8948 | vixl32::Register data_reg = RegisterFrom(temp, DataType::Type::kInt32); // Raw pointer. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8949 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8950 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8951 | temps.Exclude(ip); |
| 8952 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(data_reg.GetCode()); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8953 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8954 | __ Add(data_reg, obj, Operand(data_offset)); |
| 8955 | { |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8956 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u); |
| 8957 | size_t wide_instructions = |
| 8958 | /* ADR+CMP+BNE+LDR+unpoison? */ (kPoisonHeapReferences ? 5u : 4u) - narrow_instructions; |
| 8959 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8960 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8961 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8962 | vixl32::Label return_address; |
| 8963 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8964 | __ cmp(mr, Operand(0)); |
| 8965 | EmitBakerReadBarrierBne(custom_data); |
| 8966 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8967 | __ ldr(ref_reg, MemOperand(data_reg, index_reg, vixl32::LSL, scale_factor)); |
| 8968 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 8969 | // Note: We need a Wide NEG for the unpoisoning. |
| 8970 | if (kPoisonHeapReferences) { |
| 8971 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8972 | } |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8973 | __ bind(&return_address); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8974 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8975 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8976 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 8977 | MaybeGenerateMarkingRegisterCheck(/* code= */ 22, /* temp_loc= */ LocationFrom(ip)); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8978 | } |
| 8979 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8980 | void CodeGeneratorARMVIXL::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 8981 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 8982 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 8983 | // The following condition is a run-time one; it is executed after the |
| 8984 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 8985 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 8986 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8987 | vixl32::Register temp = temp_loc.IsValid() ? RegisterFrom(temp_loc) : temps.Acquire(); |
| 8988 | GetAssembler()->GenerateMarkingRegisterCheck(temp, |
| 8989 | kMarkingRegisterCheckBreakCodeBaseCode + code); |
| 8990 | } |
| 8991 | } |
| 8992 | } |
| 8993 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8994 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8995 | Location out, |
| 8996 | Location ref, |
| 8997 | Location obj, |
| 8998 | uint32_t offset, |
| 8999 | Location index) { |
| 9000 | DCHECK(kEmitCompilerReadBarrier); |
| 9001 | |
| 9002 | // Insert a slow path based read barrier *after* the reference load. |
| 9003 | // |
| 9004 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 9005 | // reference will be carried out by the runtime within the slow |
| 9006 | // path. |
| 9007 | // |
| 9008 | // Note that `ref` currently does not get unpoisoned (when heap |
| 9009 | // poisoning is enabled), which is alright as the `ref` argument is |
| 9010 | // not used by the artReadBarrierSlow entry point. |
| 9011 | // |
| 9012 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9013 | SlowPathCodeARMVIXL* slow_path = new (GetScopedAllocator()) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9014 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 9015 | AddSlowPath(slow_path); |
| 9016 | |
| 9017 | __ B(slow_path->GetEntryLabel()); |
| 9018 | __ Bind(slow_path->GetExitLabel()); |
| 9019 | } |
| 9020 | |
| 9021 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9022 | Location out, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9023 | Location ref, |
| 9024 | Location obj, |
| 9025 | uint32_t offset, |
| 9026 | Location index) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9027 | if (kEmitCompilerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9028 | // Baker's read barriers shall be handled by the fast path |
Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 9029 | // (CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier). |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9030 | DCHECK(!kUseBakerReadBarrier); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9031 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 9032 | // by the runtime within the slow path. |
| 9033 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9034 | } else if (kPoisonHeapReferences) { |
| 9035 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 9036 | } |
| 9037 | } |
| 9038 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9039 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 9040 | Location out, |
| 9041 | Location root) { |
| 9042 | DCHECK(kEmitCompilerReadBarrier); |
| 9043 | |
| 9044 | // Insert a slow path based read barrier *after* the GC root load. |
| 9045 | // |
| 9046 | // Note that GC roots are not affected by heap poisoning, so we do |
| 9047 | // not need to do anything special for this here. |
| 9048 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9049 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9050 | AddSlowPath(slow_path); |
| 9051 | |
| 9052 | __ B(slow_path->GetEntryLabel()); |
| 9053 | __ Bind(slow_path->GetExitLabel()); |
| 9054 | } |
| 9055 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9056 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 9057 | // otherwise return a fall-back info that should be used instead. |
| 9058 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9059 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9060 | ArtMethod* method) { |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 9061 | if (method->IsIntrinsic() && |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9062 | desired_dispatch_info.code_ptr_location == CodePtrLocation::kCallCriticalNative) { |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 9063 | // As a work-around for soft-float native ABI interfering with type checks, we are |
| 9064 | // inserting fake calls to Float.floatToRawIntBits() or Double.doubleToRawLongBits() |
| 9065 | // when a float or double argument is passed in core registers but we cannot do that |
| 9066 | // for actual intrinsic implementations that expect them in FP registers. Therefore |
| 9067 | // we do not use `kCallCriticalNative` for intrinsics with FP arguments; if they are |
| 9068 | // properly intrinsified, the dispatch type does not matter anyway. |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9069 | ScopedObjectAccess soa(Thread::Current()); |
| 9070 | uint32_t shorty_len; |
| 9071 | const char* shorty = method->GetShorty(&shorty_len); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9072 | for (uint32_t i = 1; i != shorty_len; ++i) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9073 | if (shorty[i] == 'D' || shorty[i] == 'F') { |
| 9074 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9075 | dispatch_info.code_ptr_location = CodePtrLocation::kCallArtMethod; |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9076 | return dispatch_info; |
| 9077 | } |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9078 | } |
| 9079 | } |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 9080 | return desired_dispatch_info; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9081 | } |
| 9082 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 9083 | |
| 9084 | void CodeGeneratorARMVIXL::LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke) { |
| 9085 | switch (load_kind) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9086 | case MethodLoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 9087 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 9088 | PcRelativePatchInfo* labels = NewBootImageMethodPatch(invoke->GetResolvedMethodReference()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9089 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9090 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 9091 | break; |
| 9092 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9093 | case MethodLoadKind::kBootImageRelRo: { |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 9094 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9095 | PcRelativePatchInfo* labels = NewBootImageRelRoPatch(boot_image_offset); |
| 9096 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9097 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 9098 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
| 9099 | break; |
| 9100 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9101 | case MethodLoadKind::kBssEntry: { |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 9102 | PcRelativePatchInfo* labels = NewMethodBssEntryPatch(invoke->GetMethodReference()); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9103 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 9104 | EmitMovwMovtPlaceholder(labels, temp_reg); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 9105 | // All aligned loads are implicitly atomic consume operations on ARM. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9106 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9107 | break; |
| 9108 | } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 9109 | case MethodLoadKind::kJitDirectAddress: { |
| 9110 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetResolvedMethod())); |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 9111 | break; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 9112 | } |
| 9113 | case MethodLoadKind::kRuntimeCall: { |
| 9114 | // Test situation, don't do anything. |
| 9115 | break; |
| 9116 | } |
| 9117 | default: { |
| 9118 | LOG(FATAL) << "Load kind should have already been handled " << load_kind; |
| 9119 | UNREACHABLE(); |
| 9120 | } |
| 9121 | } |
| 9122 | } |
| 9123 | |
| 9124 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall( |
| 9125 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| 9126 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 9127 | switch (invoke->GetMethodLoadKind()) { |
| 9128 | case MethodLoadKind::kStringInit: { |
| 9129 | uint32_t offset = |
| 9130 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 9131 | // temp = thread->string_init_entrypoint |
| 9132 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 9133 | break; |
| 9134 | } |
| 9135 | case MethodLoadKind::kRecursive: { |
| 9136 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
| 9137 | break; |
| 9138 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9139 | case MethodLoadKind::kRuntimeCall: { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9140 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 9141 | return; // No code pointer retrieval; the runtime performs the call directly. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9142 | } |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 9143 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
| 9144 | // Note: Unlike arm64, x86 and x86-64, we do not avoid the materialization of method |
| 9145 | // pointer for kCallCriticalNative because it would not save us an instruction from |
| 9146 | // the current sequence MOVW+MOVT+ADD(pc)+LDR+BL. The ADD(pc) separates the patched |
| 9147 | // offset instructions MOVW+MOVT from the entrypoint load, so they cannot be fused. |
| 9148 | FALLTHROUGH_INTENDED; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 9149 | default: { |
| 9150 | LoadMethod(invoke->GetMethodLoadKind(), temp, invoke); |
| 9151 | break; |
| 9152 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9153 | } |
| 9154 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9155 | auto call_code_pointer_member = [&](MemberOffset offset) { |
| 9156 | // LR = callee_method->member; |
| 9157 | GetAssembler()->LoadFromOffset(kLoadWord, lr, RegisterFrom(callee_method), offset.Int32Value()); |
| 9158 | { |
| 9159 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9160 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 9161 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9162 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9163 | CodeBufferCheckScope::kExactSize); |
| 9164 | // LR() |
| 9165 | __ blx(lr); |
| 9166 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9167 | } |
| 9168 | }; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9169 | switch (invoke->GetCodePtrLocation()) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9170 | case CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9171 | { |
| 9172 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9173 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9174 | vixl32::k32BitT32InstructionSizeInBytes, |
| 9175 | CodeBufferCheckScope::kMaximumSize); |
| 9176 | __ bl(GetFrameEntryLabel()); |
| 9177 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9178 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9179 | break; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9180 | case CodePtrLocation::kCallCriticalNative: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9181 | size_t out_frame_size = |
| 9182 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorARMVIXL, |
| 9183 | kAapcsStackAlignment, |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 9184 | GetCriticalNativeDirectCallFrameSize>(invoke); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9185 | call_code_pointer_member(ArtMethod::EntryPointFromJniOffset(kArmPointerSize)); |
| 9186 | // Move the result when needed due to native and managed ABI mismatch. |
| 9187 | switch (invoke->GetType()) { |
| 9188 | case DataType::Type::kFloat32: |
| 9189 | __ Vmov(s0, r0); |
| 9190 | break; |
| 9191 | case DataType::Type::kFloat64: |
| 9192 | __ Vmov(d0, r0, r1); |
| 9193 | break; |
| 9194 | case DataType::Type::kBool: |
| 9195 | case DataType::Type::kInt8: |
| 9196 | case DataType::Type::kUint16: |
| 9197 | case DataType::Type::kInt16: |
| 9198 | case DataType::Type::kInt32: |
| 9199 | case DataType::Type::kInt64: |
| 9200 | case DataType::Type::kVoid: |
| 9201 | break; |
| 9202 | default: |
| 9203 | DCHECK(false) << invoke->GetType(); |
| 9204 | break; |
| 9205 | } |
| 9206 | if (out_frame_size != 0u) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 9207 | DecreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9208 | } |
| 9209 | break; |
| 9210 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9211 | case CodePtrLocation::kCallArtMethod: |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9212 | call_code_pointer_member(ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9213 | break; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9214 | } |
| 9215 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9216 | DCHECK(!IsLeafMethod()); |
| 9217 | } |
| 9218 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9219 | void CodeGeneratorARMVIXL::GenerateVirtualCall( |
| 9220 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9221 | vixl32::Register temp = RegisterFrom(temp_location); |
| 9222 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9223 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 9224 | |
| 9225 | // Use the calling convention instead of the location of the receiver, as |
| 9226 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 9227 | // slow path, the arguments have been moved to the right place, so here we are |
| 9228 | // guaranteed that the receiver is the first register of the calling convention. |
| 9229 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 9230 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 9231 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9232 | { |
| 9233 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9234 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9235 | vixl32::kMaxInstructionSizeInBytes, |
| 9236 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9237 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 9238 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 9239 | MaybeRecordImplicitNullCheck(invoke); |
| 9240 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9241 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 9242 | // emit a read barrier for the previous class reference load. |
| 9243 | // However this is not required in practice, as this is an |
| 9244 | // intermediate/temporary reference and because the current |
| 9245 | // concurrent copying collector keeps the from-space memory |
| 9246 | // intact/accessible until the end of the marking phase (the |
| 9247 | // concurrent copying collector may not in the future). |
| 9248 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 9249 | |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 9250 | // If we're compiling baseline, update the inline cache. |
| 9251 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 9252 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9253 | // temp = temp->GetMethodAt(method_offset); |
| 9254 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 9255 | kArmPointerSize).Int32Value(); |
| 9256 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 9257 | // LR = temp->GetEntryPoint(); |
| 9258 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9259 | { |
| 9260 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9261 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 9262 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9263 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9264 | CodeBufferCheckScope::kExactSize); |
| 9265 | // LR(); |
| 9266 | __ blx(lr); |
| 9267 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9268 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9269 | } |
| 9270 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9271 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageIntrinsicPatch( |
| 9272 | uint32_t intrinsic_data) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9273 | return NewPcRelativePatch(/* dex_file= */ nullptr, intrinsic_data, &boot_image_other_patches_); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9274 | } |
| 9275 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9276 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageRelRoPatch( |
| 9277 | uint32_t boot_image_offset) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9278 | return NewPcRelativePatch(/* dex_file= */ nullptr, |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9279 | boot_image_offset, |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9280 | &boot_image_other_patches_); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9281 | } |
| 9282 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9283 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageMethodPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9284 | MethodReference target_method) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9285 | return NewPcRelativePatch( |
| 9286 | target_method.dex_file, target_method.index, &boot_image_method_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9287 | } |
| 9288 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9289 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewMethodBssEntryPatch( |
| 9290 | MethodReference target_method) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9291 | return NewPcRelativePatch( |
| 9292 | target_method.dex_file, target_method.index, &method_bss_entry_patches_); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9293 | } |
| 9294 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9295 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageTypePatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9296 | const DexFile& dex_file, dex::TypeIndex type_index) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9297 | return NewPcRelativePatch(&dex_file, type_index.index_, &boot_image_type_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9298 | } |
| 9299 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9300 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewTypeBssEntryPatch( |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 9301 | HLoadClass* load_class) { |
| 9302 | const DexFile& dex_file = load_class->GetDexFile(); |
| 9303 | dex::TypeIndex type_index = load_class->GetTypeIndex(); |
| 9304 | ArenaDeque<PcRelativePatchInfo>* patches = nullptr; |
| 9305 | switch (load_class->GetLoadKind()) { |
| 9306 | case HLoadClass::LoadKind::kBssEntry: |
| 9307 | patches = &type_bss_entry_patches_; |
| 9308 | break; |
| 9309 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 9310 | patches = &public_type_bss_entry_patches_; |
| 9311 | break; |
| 9312 | case HLoadClass::LoadKind::kBssEntryPackage: |
| 9313 | patches = &package_type_bss_entry_patches_; |
| 9314 | break; |
| 9315 | default: |
| 9316 | LOG(FATAL) << "Unexpected load kind: " << load_class->GetLoadKind(); |
| 9317 | UNREACHABLE(); |
| 9318 | } |
Vladimir Marko | baade40 | 2020-09-30 14:45:39 +0000 | [diff] [blame] | 9319 | return NewPcRelativePatch(&dex_file, type_index.index_, patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9320 | } |
| 9321 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9322 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageStringPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9323 | const DexFile& dex_file, dex::StringIndex string_index) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9324 | return NewPcRelativePatch(&dex_file, string_index.index_, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9325 | } |
| 9326 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9327 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewStringBssEntryPatch( |
| 9328 | const DexFile& dex_file, dex::StringIndex string_index) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9329 | return NewPcRelativePatch(&dex_file, string_index.index_, &string_bss_entry_patches_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9330 | } |
| 9331 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9332 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9333 | const DexFile* dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9334 | patches->emplace_back(dex_file, offset_or_index); |
| 9335 | return &patches->back(); |
| 9336 | } |
| 9337 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9338 | void CodeGeneratorARMVIXL::EmitEntrypointThunkCall(ThreadOffset32 entrypoint_offset) { |
| 9339 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 9340 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9341 | call_entrypoint_patches_.emplace_back(/*dex_file*/ nullptr, entrypoint_offset.Uint32Value()); |
| 9342 | vixl::aarch32::Label* bl_label = &call_entrypoint_patches_.back().label; |
| 9343 | __ bind(bl_label); |
| 9344 | vixl32::Label placeholder_label; |
| 9345 | __ bl(&placeholder_label); // Placeholder, patched at link-time. |
| 9346 | __ bind(&placeholder_label); |
| 9347 | } |
| 9348 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9349 | void CodeGeneratorARMVIXL::EmitBakerReadBarrierBne(uint32_t custom_data) { |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9350 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 9351 | if (GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9352 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 9353 | vixl::aarch32::Label* slow_path_entry = &it->second.label; |
| 9354 | __ b(ne, EncodingSize(Wide), slow_path_entry); |
| 9355 | } else { |
| 9356 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 9357 | vixl::aarch32::Label* patch_label = &baker_read_barrier_patches_.back().label; |
| 9358 | __ bind(patch_label); |
| 9359 | vixl32::Label placeholder_label; |
| 9360 | __ b(ne, EncodingSize(Wide), &placeholder_label); // Placeholder, patched at link-time. |
| 9361 | __ bind(&placeholder_label); |
| 9362 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9363 | } |
| 9364 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9365 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 9366 | return DeduplicateUint32Literal(address, &uint32_literals_); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9367 | } |
| 9368 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 9369 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitStringLiteral( |
| 9370 | const DexFile& dex_file, |
| 9371 | dex::StringIndex string_index, |
| 9372 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9373 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9374 | return jit_string_patches_.GetOrCreate( |
| 9375 | StringReference(&dex_file, string_index), |
| 9376 | [this]() { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9377 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9378 | }); |
| 9379 | } |
| 9380 | |
| 9381 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 9382 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 9383 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9384 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9385 | return jit_class_patches_.GetOrCreate( |
| 9386 | TypeReference(&dex_file, type_index), |
| 9387 | [this]() { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9388 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9389 | }); |
| 9390 | } |
| 9391 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9392 | void CodeGeneratorARMVIXL::LoadBootImageAddress(vixl32::Register reg, |
| 9393 | uint32_t boot_image_reference) { |
| 9394 | if (GetCompilerOptions().IsBootImage()) { |
| 9395 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 9396 | NewBootImageIntrinsicPatch(boot_image_reference); |
| 9397 | EmitMovwMovtPlaceholder(labels, reg); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 9398 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9399 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 9400 | NewBootImageRelRoPatch(boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9401 | EmitMovwMovtPlaceholder(labels, reg); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9402 | __ Ldr(reg, MemOperand(reg, /* offset= */ 0)); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9403 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 9404 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9405 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 9406 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| 9407 | uintptr_t address = |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9408 | reinterpret_cast<uintptr_t>(heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9409 | __ Ldr(reg, DeduplicateBootImageAddressLiteral(dchecked_integral_cast<uint32_t>(address))); |
| 9410 | } |
| 9411 | } |
| 9412 | |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 9413 | void CodeGeneratorARMVIXL::LoadIntrinsicDeclaringClass(vixl32::Register reg, HInvoke* invoke) { |
| 9414 | DCHECK_NE(invoke->GetIntrinsic(), Intrinsics::kNone); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9415 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9416 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 9417 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9418 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 9419 | PcRelativePatchInfo* labels = NewBootImageTypePatch(*target_method.dex_file, type_idx); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 9420 | EmitMovwMovtPlaceholder(labels, reg); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9421 | } else { |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 9422 | uint32_t boot_image_offset = GetBootImageOffsetOfIntrinsicDeclaringClass(invoke); |
| 9423 | LoadBootImageAddress(reg, boot_image_offset); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9424 | } |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9425 | } |
| 9426 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9427 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9428 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 9429 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9430 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9431 | for (const PcRelativePatchInfo& info : infos) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9432 | const DexFile* dex_file = info.target_dex_file; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9433 | size_t offset_or_index = info.offset_or_index; |
| 9434 | DCHECK(info.add_pc_label.IsBound()); |
| 9435 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 9436 | // Add MOVW patch. |
| 9437 | DCHECK(info.movw_label.IsBound()); |
| 9438 | 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] | 9439 | 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] | 9440 | // Add MOVT patch. |
| 9441 | DCHECK(info.movt_label.IsBound()); |
| 9442 | 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] | 9443 | 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] | 9444 | } |
| 9445 | } |
| 9446 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9447 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 9448 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 9449 | const DexFile* target_dex_file, |
| 9450 | uint32_t pc_insn_offset, |
| 9451 | uint32_t boot_image_offset) { |
| 9452 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 9453 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9454 | } |
| 9455 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9456 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9457 | DCHECK(linker_patches->empty()); |
| 9458 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9459 | /* MOVW+MOVT for each entry */ 2u * boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9460 | /* MOVW+MOVT for each entry */ 2u * method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9461 | /* MOVW+MOVT for each entry */ 2u * boot_image_type_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9462 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 9463 | /* MOVW+MOVT for each entry */ 2u * public_type_bss_entry_patches_.size() + |
| 9464 | /* MOVW+MOVT for each entry */ 2u * package_type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9465 | /* MOVW+MOVT for each entry */ 2u * boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9466 | /* MOVW+MOVT for each entry */ 2u * string_bss_entry_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9467 | /* MOVW+MOVT for each entry */ 2u * boot_image_other_patches_.size() + |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9468 | call_entrypoint_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9469 | baker_read_barrier_patches_.size(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9470 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 9471 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9472 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9473 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9474 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9475 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9476 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9477 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9478 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9479 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 9480 | DCHECK(boot_image_type_patches_.empty()); |
| 9481 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9482 | } |
| 9483 | if (GetCompilerOptions().IsBootImage()) { |
| 9484 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 9485 | boot_image_other_patches_, linker_patches); |
| 9486 | } else { |
| 9487 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 9488 | boot_image_other_patches_, linker_patches); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9489 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9490 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 9491 | method_bss_entry_patches_, linker_patches); |
| 9492 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 9493 | type_bss_entry_patches_, linker_patches); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 9494 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PublicTypeBssEntryPatch>( |
| 9495 | public_type_bss_entry_patches_, linker_patches); |
| 9496 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PackageTypeBssEntryPatch>( |
| 9497 | package_type_bss_entry_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9498 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 9499 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9500 | for (const PatchInfo<vixl32::Label>& info : call_entrypoint_patches_) { |
| 9501 | DCHECK(info.target_dex_file == nullptr); |
| 9502 | linker_patches->push_back(linker::LinkerPatch::CallEntrypointPatch( |
| 9503 | info.label.GetLocation(), info.offset_or_index)); |
| 9504 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9505 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9506 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 9507 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9508 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9509 | DCHECK_EQ(size, linker_patches->size()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9510 | } |
| 9511 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9512 | bool CodeGeneratorARMVIXL::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9513 | return patch.GetType() == linker::LinkerPatch::Type::kCallEntrypoint || |
| 9514 | patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9515 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 9516 | } |
| 9517 | |
| 9518 | void CodeGeneratorARMVIXL::EmitThunkCode(const linker::LinkerPatch& patch, |
| 9519 | /*out*/ ArenaVector<uint8_t>* code, |
| 9520 | /*out*/ std::string* debug_name) { |
| 9521 | arm::ArmVIXLAssembler assembler(GetGraph()->GetAllocator()); |
| 9522 | switch (patch.GetType()) { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9523 | case linker::LinkerPatch::Type::kCallRelative: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9524 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 9525 | // to the generic JNI and interpreter trampolines. |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9526 | MemberOffset offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 9527 | assembler.LoadFromOffset(arm::kLoadWord, vixl32::pc, vixl32::r0, offset.Int32Value()); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9528 | assembler.GetVIXLAssembler()->Bkpt(0); |
| 9529 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 9530 | *debug_name = "MethodCallThunk"; |
| 9531 | } |
| 9532 | break; |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9533 | } |
| 9534 | case linker::LinkerPatch::Type::kCallEntrypoint: { |
| 9535 | assembler.LoadFromOffset(arm::kLoadWord, vixl32::pc, tr, patch.EntrypointOffset()); |
| 9536 | assembler.GetVIXLAssembler()->Bkpt(0); |
| 9537 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 9538 | *debug_name = "EntrypointCallThunk_" + std::to_string(patch.EntrypointOffset()); |
| 9539 | } |
| 9540 | break; |
| 9541 | } |
| 9542 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9543 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 9544 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 9545 | break; |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9546 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9547 | default: |
| 9548 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 9549 | UNREACHABLE(); |
| 9550 | } |
| 9551 | |
| 9552 | // Ensure we emit the literal pool if any. |
| 9553 | assembler.FinalizeCode(); |
| 9554 | code->resize(assembler.CodeSize()); |
| 9555 | MemoryRegion code_region(code->data(), code->size()); |
| 9556 | assembler.FinalizeInstructions(code_region); |
| 9557 | } |
| 9558 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9559 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateUint32Literal( |
| 9560 | uint32_t value, |
| 9561 | Uint32ToLiteralMap* map) { |
| 9562 | return map->GetOrCreate( |
| 9563 | value, |
| 9564 | [this, value]() { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9565 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ value); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9566 | }); |
| 9567 | } |
| 9568 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9569 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9570 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9571 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9572 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 9573 | Location::RequiresRegister()); |
| 9574 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 9575 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 9576 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9577 | } |
| 9578 | |
| 9579 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9580 | vixl32::Register res = OutputRegister(instr); |
| 9581 | vixl32::Register accumulator = |
| 9582 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 9583 | vixl32::Register mul_left = |
| 9584 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 9585 | vixl32::Register mul_right = |
| 9586 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 9587 | |
| 9588 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 9589 | __ Mla(res, mul_left, mul_right, accumulator); |
| 9590 | } else { |
| 9591 | __ Mls(res, mul_left, mul_right, accumulator); |
| 9592 | } |
| 9593 | } |
| 9594 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9595 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9596 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9597 | LOG(FATAL) << "Unreachable"; |
| 9598 | } |
| 9599 | |
| 9600 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9601 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9602 | LOG(FATAL) << "Unreachable"; |
| 9603 | } |
| 9604 | |
| 9605 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 9606 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9607 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9608 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9609 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9610 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 9611 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9612 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 9613 | if (switch_instr->GetStartValue() != 0) { |
| 9614 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 9615 | } |
| 9616 | } |
| 9617 | } |
| 9618 | |
| 9619 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 9620 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9621 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9622 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9623 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9624 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 9625 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9626 | |
| 9627 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 9628 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9629 | // Create a series of compare/jumps. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9630 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9631 | vixl32::Register temp_reg = temps.Acquire(); |
| 9632 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 9633 | // the immediate, because IP is used as the destination register. For the other |
| 9634 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 9635 | // and they can be encoded in the instruction without making use of IP register. |
| 9636 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 9637 | |
| 9638 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 9639 | // Jump to successors[0] if value == lower_bound. |
| 9640 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 9641 | int32_t last_index = 0; |
| 9642 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9643 | __ Adds(temp_reg, temp_reg, -2); |
| 9644 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9645 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9646 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9647 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9648 | } |
| 9649 | if (num_entries - last_index == 2) { |
| 9650 | // The last missing case_value. |
| 9651 | __ Cmp(temp_reg, 1); |
| 9652 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9653 | } |
| 9654 | |
| 9655 | // And the default for any other value. |
| 9656 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 9657 | __ B(codegen_->GetLabelOf(default_block)); |
| 9658 | } |
| 9659 | } else { |
| 9660 | // Create a table lookup. |
| 9661 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 9662 | |
| 9663 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 9664 | |
| 9665 | // Remove the bias. |
| 9666 | vixl32::Register key_reg; |
| 9667 | if (lower_bound != 0) { |
| 9668 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 9669 | __ Sub(key_reg, value_reg, lower_bound); |
| 9670 | } else { |
| 9671 | key_reg = value_reg; |
| 9672 | } |
| 9673 | |
| 9674 | // Check whether the value is in the table, jump to default block if not. |
| 9675 | __ Cmp(key_reg, num_entries - 1); |
| 9676 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 9677 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9678 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9679 | vixl32::Register jump_offset = temps.Acquire(); |
| 9680 | |
| 9681 | // Load jump offset from the table. |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9682 | { |
| 9683 | const size_t jump_size = switch_instr->GetNumEntries() * sizeof(int32_t); |
| 9684 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9685 | (vixl32::kMaxInstructionSizeInBytes * 4) + jump_size, |
| 9686 | CodeBufferCheckScope::kMaximumSize); |
| 9687 | __ adr(table_base, jump_table->GetTableStartLabel()); |
| 9688 | __ ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9689 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9690 | // Jump to target block by branching to table_base(pc related) + offset. |
| 9691 | vixl32::Register target_address = table_base; |
| 9692 | __ add(target_address, table_base, jump_offset); |
| 9693 | __ bx(target_address); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 9694 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9695 | jump_table->EmitTable(codegen_); |
| 9696 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9697 | } |
| 9698 | } |
| 9699 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9700 | // Copy the result of a call into the given target. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9701 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, DataType::Type type) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9702 | if (!trg.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9703 | DCHECK_EQ(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9704 | return; |
| 9705 | } |
| 9706 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9707 | DCHECK_NE(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9708 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9709 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9710 | if (return_loc.Equals(trg)) { |
| 9711 | return; |
| 9712 | } |
| 9713 | |
| 9714 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 9715 | // with the last branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9716 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9717 | TODO_VIXL32(FATAL); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9718 | } else if (type == DataType::Type::kFloat64) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9719 | TODO_VIXL32(FATAL); |
| 9720 | } else { |
| 9721 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9722 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9723 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 9724 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9725 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9726 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9727 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9728 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9729 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9730 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9731 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9732 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9733 | } |
| 9734 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9735 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9736 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 9737 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9738 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 9739 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9740 | OutputRegister(instruction), |
| 9741 | InputRegisterAt(instruction, 0), |
| 9742 | method_offset); |
| 9743 | } else { |
| 9744 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 9745 | instruction->GetIndex(), kArmPointerSize)); |
| 9746 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9747 | OutputRegister(instruction), |
| 9748 | InputRegisterAt(instruction, 0), |
| 9749 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 9750 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9751 | OutputRegister(instruction), |
| 9752 | OutputRegister(instruction), |
| 9753 | method_offset); |
| 9754 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9755 | } |
| 9756 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9757 | static void PatchJitRootUse(uint8_t* code, |
| 9758 | const uint8_t* roots_data, |
| 9759 | VIXLUInt32Literal* literal, |
| 9760 | uint64_t index_in_table) { |
| 9761 | DCHECK(literal->IsBound()); |
| 9762 | uint32_t literal_offset = literal->GetLocation(); |
| 9763 | uintptr_t address = |
| 9764 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9765 | uint8_t* data = code + literal_offset; |
| 9766 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9767 | } |
| 9768 | |
| 9769 | void CodeGeneratorARMVIXL::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9770 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9771 | const StringReference& string_reference = entry.first; |
| 9772 | VIXLUInt32Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9773 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9774 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9775 | } |
| 9776 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9777 | const TypeReference& type_reference = entry.first; |
| 9778 | VIXLUInt32Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9779 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9780 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9781 | } |
| 9782 | } |
| 9783 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9784 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 9785 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 9786 | vixl32::Register out) { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9787 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9788 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 9789 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9790 | // TODO(VIXL): Think about using mov instead of movw. |
| 9791 | __ bind(&labels->movw_label); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9792 | __ movw(out, /* operand= */ 0u); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9793 | __ bind(&labels->movt_label); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9794 | __ movt(out, /* operand= */ 0u); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9795 | __ bind(&labels->add_pc_label); |
| 9796 | __ add(out, out, pc); |
| 9797 | } |
| 9798 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9799 | #undef __ |
| 9800 | #undef QUICK_ENTRY_POINT |
| 9801 | #undef TODO_VIXL32 |
| 9802 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9803 | #define __ assembler.GetVIXLAssembler()-> |
| 9804 | |
| 9805 | static void EmitGrayCheckAndFastPath(ArmVIXLAssembler& assembler, |
| 9806 | vixl32::Register base_reg, |
| 9807 | vixl32::MemOperand& lock_word, |
| 9808 | vixl32::Label* slow_path, |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9809 | int32_t raw_ldr_offset, |
| 9810 | vixl32::Label* throw_npe = nullptr) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9811 | // Load the lock word containing the rb_state. |
| 9812 | __ Ldr(ip, lock_word); |
| 9813 | // 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] | 9814 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9815 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 9816 | __ Tst(ip, Operand(LockWord::kReadBarrierStateMaskShifted)); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9817 | __ B(ne, slow_path, /* is_far_target= */ false); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9818 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 9819 | if (throw_npe != nullptr) { |
| 9820 | __ Bind(throw_npe); |
| 9821 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9822 | __ Add(lr, lr, raw_ldr_offset); |
| 9823 | // Introduce a dependency on the lock_word including rb_state, |
| 9824 | // to prevent load-load reordering, and without using |
| 9825 | // a memory barrier (which would be more expensive). |
| 9826 | __ Add(base_reg, base_reg, Operand(ip, LSR, 32)); |
| 9827 | __ Bx(lr); // And return back to the function. |
| 9828 | // Note: The fake dependency is unnecessary for the slow path. |
| 9829 | } |
| 9830 | |
| 9831 | // Load the read barrier introspection entrypoint in register `entrypoint` |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9832 | static vixl32::Register LoadReadBarrierMarkIntrospectionEntrypoint(ArmVIXLAssembler& assembler) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9833 | // The register where the read barrier introspection entrypoint is loaded |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9834 | // is the marking register. We clobber it here and the entrypoint restores it to 1. |
| 9835 | vixl32::Register entrypoint = mr; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9836 | // entrypoint = Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 9837 | DCHECK_EQ(ip.GetCode(), 12u); |
| 9838 | const int32_t entry_point_offset = |
| 9839 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ip.GetCode()); |
| 9840 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9841 | return entrypoint; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9842 | } |
| 9843 | |
| 9844 | void CodeGeneratorARMVIXL::CompileBakerReadBarrierThunk(ArmVIXLAssembler& assembler, |
| 9845 | uint32_t encoded_data, |
| 9846 | /*out*/ std::string* debug_name) { |
| 9847 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 9848 | switch (kind) { |
| 9849 | case BakerReadBarrierKind::kField: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9850 | vixl32::Register base_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 9851 | CheckValidReg(base_reg.GetCode()); |
| 9852 | vixl32::Register holder_reg(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9853 | CheckValidReg(holder_reg.GetCode()); |
| 9854 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 9855 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 9856 | temps.Exclude(ip); |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 9857 | // In the case of a field load, if `base_reg` differs from |
| 9858 | // `holder_reg`, the offset was too large and we must have emitted (during the construction |
| 9859 | // of the HIR graph, see `art::HInstructionBuilder::BuildInstanceFieldAccess`) and preserved |
| 9860 | // (see `art::PrepareForRegisterAllocation::VisitNullCheck`) an explicit null check before |
| 9861 | // the load. Otherwise, for implicit null checks, we need to null-check the holder as we do |
| 9862 | // not necessarily do that check before going to the thunk. |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9863 | vixl32::Label throw_npe_label; |
| 9864 | vixl32::Label* throw_npe = nullptr; |
| 9865 | if (GetCompilerOptions().GetImplicitNullChecks() && holder_reg.Is(base_reg)) { |
| 9866 | throw_npe = &throw_npe_label; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9867 | __ CompareAndBranchIfZero(holder_reg, throw_npe, /* is_far_target= */ false); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9868 | } |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9869 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 9870 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 9871 | // to load the reference and call the entrypoint that performs further checks on the |
| 9872 | // reference and marks it if needed. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9873 | vixl32::Label slow_path; |
| 9874 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
| 9875 | const int32_t raw_ldr_offset = (width == BakerReadBarrierWidth::kWide) |
| 9876 | ? BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET |
| 9877 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET; |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9878 | EmitGrayCheckAndFastPath( |
| 9879 | assembler, base_reg, lock_word, &slow_path, raw_ldr_offset, throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9880 | __ Bind(&slow_path); |
| 9881 | const int32_t ldr_offset = /* Thumb state adjustment (LR contains Thumb state). */ -1 + |
| 9882 | raw_ldr_offset; |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9883 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9884 | if (width == BakerReadBarrierWidth::kWide) { |
| 9885 | MemOperand ldr_half_address(lr, ldr_offset + 2); |
| 9886 | __ Ldrh(ip, ldr_half_address); // Load the LDR immediate half-word with "Rt | imm12". |
| 9887 | __ Ubfx(ip, ip, 0, 12); // Extract the offset imm12. |
| 9888 | __ Ldr(ip, MemOperand(base_reg, ip)); // Load the reference. |
| 9889 | } else { |
| 9890 | MemOperand ldr_address(lr, ldr_offset); |
| 9891 | __ Ldrh(ip, ldr_address); // Load the LDR immediate, encoding T1. |
| 9892 | __ Add(ep_reg, // Adjust the entrypoint address to the entrypoint |
| 9893 | ep_reg, // for narrow LDR. |
| 9894 | Operand(BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_ENTRYPOINT_OFFSET)); |
| 9895 | __ Ubfx(ip, ip, 6, 5); // Extract the imm5, i.e. offset / 4. |
| 9896 | __ Ldr(ip, MemOperand(base_reg, ip, LSL, 2)); // Load the reference. |
| 9897 | } |
| 9898 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 9899 | __ Bx(ep_reg); // Jump to the entrypoint. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9900 | break; |
| 9901 | } |
| 9902 | case BakerReadBarrierKind::kArray: { |
| 9903 | vixl32::Register base_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 9904 | CheckValidReg(base_reg.GetCode()); |
| 9905 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9906 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9907 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 9908 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 9909 | temps.Exclude(ip); |
| 9910 | vixl32::Label slow_path; |
| 9911 | int32_t data_offset = |
| 9912 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 9913 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 9914 | DCHECK_LT(lock_word.GetOffsetImmediate(), 0); |
| 9915 | const int32_t raw_ldr_offset = BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET; |
| 9916 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, raw_ldr_offset); |
| 9917 | __ Bind(&slow_path); |
| 9918 | const int32_t ldr_offset = /* Thumb state adjustment (LR contains Thumb state). */ -1 + |
| 9919 | raw_ldr_offset; |
| 9920 | MemOperand ldr_address(lr, ldr_offset + 2); |
| 9921 | __ Ldrb(ip, ldr_address); // Load the LDR (register) byte with "00 | imm2 | Rm", |
| 9922 | // i.e. Rm+32 because the scale in imm2 is 2. |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9923 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9924 | __ Bfi(ep_reg, ip, 3, 6); // Insert ip to the entrypoint address to create |
| 9925 | // a switch case target based on the index register. |
| 9926 | __ Mov(ip, base_reg); // Move the base register to ip0. |
| 9927 | __ Bx(ep_reg); // Jump to the entrypoint's array switch case. |
| 9928 | break; |
| 9929 | } |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9930 | case BakerReadBarrierKind::kGcRoot: |
| 9931 | case BakerReadBarrierKind::kUnsafeCas: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9932 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 9933 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 9934 | // otherwise return the reference (or the extracted forwarding address). |
| 9935 | // There is no gray bit check for GC roots. |
| 9936 | vixl32::Register root_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 9937 | CheckValidReg(root_reg.GetCode()); |
| 9938 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9939 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9940 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 9941 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 9942 | temps.Exclude(ip); |
| 9943 | vixl32::Label return_label, not_marked, forwarding_address; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9944 | __ CompareAndBranchIfZero(root_reg, &return_label, /* is_far_target= */ false); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9945 | MemOperand lock_word(root_reg, mirror::Object::MonitorOffset().Int32Value()); |
| 9946 | __ Ldr(ip, lock_word); |
| 9947 | __ Tst(ip, LockWord::kMarkBitStateMaskShifted); |
| 9948 | __ B(eq, ¬_marked); |
| 9949 | __ Bind(&return_label); |
| 9950 | __ Bx(lr); |
| 9951 | __ Bind(¬_marked); |
| 9952 | static_assert(LockWord::kStateShift == 30 && LockWord::kStateForwardingAddress == 3, |
| 9953 | "To use 'CMP ip, #modified-immediate; BHS', we need the lock word state in " |
| 9954 | " the highest bits and the 'forwarding address' state to have all bits set"); |
| 9955 | __ Cmp(ip, Operand(0xc0000000)); |
| 9956 | __ B(hs, &forwarding_address); |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9957 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9958 | // Adjust the art_quick_read_barrier_mark_introspection address in kBakerCcEntrypointRegister |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9959 | // to one of art_quick_read_barrier_mark_introspection_{gc_roots_{wide,narrow},unsafe_cas}. |
| 9960 | DCHECK(kind != BakerReadBarrierKind::kUnsafeCas || width == BakerReadBarrierWidth::kWide); |
| 9961 | int32_t entrypoint_offset = |
| 9962 | (kind == BakerReadBarrierKind::kGcRoot) |
| 9963 | ? (width == BakerReadBarrierWidth::kWide) |
| 9964 | ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_ENTRYPOINT_OFFSET |
| 9965 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_ENTRYPOINT_OFFSET |
| 9966 | : BAKER_MARK_INTROSPECTION_UNSAFE_CAS_ENTRYPOINT_OFFSET; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9967 | __ Add(ep_reg, ep_reg, Operand(entrypoint_offset)); |
| 9968 | __ Mov(ip, root_reg); |
| 9969 | __ Bx(ep_reg); |
| 9970 | __ Bind(&forwarding_address); |
| 9971 | __ Lsl(root_reg, ip, LockWord::kForwardingAddressShift); |
| 9972 | __ Bx(lr); |
| 9973 | break; |
| 9974 | } |
| 9975 | default: |
| 9976 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 9977 | UNREACHABLE(); |
| 9978 | } |
| 9979 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9980 | // For JIT, the slow path is considered part of the compiled method, |
Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 9981 | // so JIT should pass null as `debug_name`. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 9982 | DCHECK(!GetCompilerOptions().IsJitCompiler() || debug_name == nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9983 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9984 | std::ostringstream oss; |
| 9985 | oss << "BakerReadBarrierThunk"; |
| 9986 | switch (kind) { |
| 9987 | case BakerReadBarrierKind::kField: |
| 9988 | oss << "Field"; |
| 9989 | if (BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide) { |
| 9990 | oss << "Wide"; |
| 9991 | } |
| 9992 | oss << "_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 9993 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 9994 | break; |
| 9995 | case BakerReadBarrierKind::kArray: |
| 9996 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 9997 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9998 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9999 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 10000 | break; |
| 10001 | case BakerReadBarrierKind::kGcRoot: |
| 10002 | oss << "GcRoot"; |
| 10003 | if (BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide) { |
| 10004 | oss << "Wide"; |
| 10005 | } |
| 10006 | oss << "_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 10007 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 10008 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10009 | break; |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 10010 | case BakerReadBarrierKind::kUnsafeCas: |
| 10011 | oss << "UnsafeCas_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 10012 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 10013 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 10014 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 10015 | break; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 10016 | } |
| 10017 | *debug_name = oss.str(); |
| 10018 | } |
| 10019 | } |
| 10020 | |
| 10021 | #undef __ |
| 10022 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 10023 | } // namespace arm |
| 10024 | } // namespace art |