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() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 766 | (instruction_->IsInvokeVirtual() && 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. |
| 3435 | invoke->GetLocations()->AddTemp(LocationFrom(r12)); |
| 3436 | } |
| 3437 | |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3438 | void CodeGeneratorARMVIXL::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 3439 | vixl32::Register klass) { |
| 3440 | DCHECK_EQ(r0.GetCode(), klass.GetCode()); |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 3441 | // We know the destination of an intrinsic, so no need to record inline |
| 3442 | // caches. |
| 3443 | if (!instruction->GetLocations()->Intrinsified() && |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 3444 | GetGraph()->IsCompilingBaseline() && |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 3445 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3446 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 3447 | ScopedProfilingInfoUse spiu( |
| 3448 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 3449 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 3450 | if (info != nullptr) { |
| 3451 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 3452 | uint32_t address = reinterpret_cast32<uint32_t>(cache); |
| 3453 | vixl32::Label done; |
| 3454 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3455 | temps.Exclude(ip); |
| 3456 | __ Mov(r4, address); |
| 3457 | __ Ldr(ip, MemOperand(r4, InlineCache::ClassesOffset().Int32Value())); |
| 3458 | // Fast path for a monomorphic cache. |
| 3459 | __ Cmp(klass, ip); |
| 3460 | __ B(eq, &done, /* is_far_target= */ false); |
| 3461 | InvokeRuntime(kQuickUpdateInlineCache, instruction, instruction->GetDexPc()); |
| 3462 | __ Bind(&done); |
| 3463 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3464 | } |
| 3465 | } |
| 3466 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3467 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3468 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 3469 | LocationSummary* locations = invoke->GetLocations(); |
| 3470 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 3471 | vixl32::Register hidden_reg = RegisterFrom(locations->GetTemp(1)); |
| 3472 | Location receiver = locations->InAt(0); |
| 3473 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3474 | |
| 3475 | DCHECK(!receiver.IsStackSlot()); |
| 3476 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3477 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 3478 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3479 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 3480 | vixl32::kMaxInstructionSizeInBytes, |
| 3481 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3482 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 3483 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 3484 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3485 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3486 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3487 | // emit a read barrier for the previous class reference load. |
| 3488 | // However this is not required in practice, as this is an |
| 3489 | // intermediate/temporary reference and because the current |
| 3490 | // concurrent copying collector keeps the from-space memory |
| 3491 | // intact/accessible until the end of the marking phase (the |
| 3492 | // concurrent copying collector may not in the future). |
| 3493 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3494 | |
| 3495 | // If we're compiling baseline, update the inline cache. |
| 3496 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 3497 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3498 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3499 | temp, |
| 3500 | temp, |
| 3501 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3502 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3503 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 3504 | invoke->GetImtIndex(), kArmPointerSize)); |
| 3505 | // temp = temp->GetImtEntryAt(method_offset); |
| 3506 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3507 | uint32_t entry_point = |
| 3508 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 3509 | // LR = temp->GetEntryPoint(); |
| 3510 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 3511 | |
| 3512 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 3513 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 3514 | DCHECK(hidden_reg.Is(r12)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3515 | |
| 3516 | { |
| 3517 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 3518 | // so it checks if the application is using them (by passing them to the macro assembler |
| 3519 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 3520 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 3521 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 3522 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 3523 | // (to materialize the constant), since the destination register becomes available for such use |
| 3524 | // internally for the duration of the macro instruction. |
| 3525 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3526 | temps.Exclude(hidden_reg); |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 3527 | __ Mov(hidden_reg, invoke->GetMethodReference().index); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3528 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3529 | { |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3530 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 3531 | // 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] | 3532 | ExactAssemblyScope aas(GetVIXLAssembler(), |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3533 | vixl32::k16BitT32InstructionSizeInBytes, |
| 3534 | CodeBufferCheckScope::kExactSize); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3535 | // LR(); |
| 3536 | __ blx(lr); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3537 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3538 | DCHECK(!codegen_->IsLeafMethod()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3539 | } |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3540 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3541 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 8); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3542 | } |
| 3543 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3544 | void LocationsBuilderARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3545 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3546 | if (intrinsic.TryDispatch(invoke)) { |
| 3547 | return; |
| 3548 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3549 | HandleInvoke(invoke); |
| 3550 | } |
| 3551 | |
| 3552 | void InstructionCodeGeneratorARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3553 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3554 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 9); |
| 3555 | return; |
| 3556 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3557 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3558 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 10); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3559 | } |
| 3560 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 3561 | void LocationsBuilderARMVIXL::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 3562 | HandleInvoke(invoke); |
| 3563 | } |
| 3564 | |
| 3565 | void InstructionCodeGeneratorARMVIXL::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 3566 | codegen_->GenerateInvokeCustomCall(invoke); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 3567 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 11); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 3568 | } |
| 3569 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3570 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 3571 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3572 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3573 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3574 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3575 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3576 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3577 | break; |
| 3578 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3579 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3580 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3581 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3582 | break; |
| 3583 | } |
| 3584 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3585 | case DataType::Type::kFloat32: |
| 3586 | case DataType::Type::kFloat64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3587 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3588 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3589 | break; |
| 3590 | |
| 3591 | default: |
| 3592 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3593 | } |
| 3594 | } |
| 3595 | |
| 3596 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 3597 | LocationSummary* locations = neg->GetLocations(); |
| 3598 | Location out = locations->Out(); |
| 3599 | Location in = locations->InAt(0); |
| 3600 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3601 | case DataType::Type::kInt32: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3602 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 3603 | break; |
| 3604 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3605 | case DataType::Type::kInt64: |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3606 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3607 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 3608 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3609 | // instruction here, as it does not exist in the Thumb-2 |
| 3610 | // instruction set. We use the following approach |
| 3611 | // using SBC and SUB instead. |
| 3612 | // |
| 3613 | // out.hi = -C |
| 3614 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 3615 | // out.hi = out.hi - in.hi |
| 3616 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 3617 | break; |
| 3618 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3619 | case DataType::Type::kFloat32: |
| 3620 | case DataType::Type::kFloat64: |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3621 | __ Vneg(OutputVRegister(neg), InputVRegister(neg)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3622 | break; |
| 3623 | |
| 3624 | default: |
| 3625 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3626 | } |
| 3627 | } |
| 3628 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3629 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3630 | DataType::Type result_type = conversion->GetResultType(); |
| 3631 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3632 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3633 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3634 | |
| 3635 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3636 | // rely on a call to the runtime. |
| 3637 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3638 | (((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 3639 | && result_type == DataType::Type::kInt64) |
| 3640 | || (input_type == DataType::Type::kInt64 && result_type == DataType::Type::kFloat32)) |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3641 | ? LocationSummary::kCallOnMainOnly |
| 3642 | : LocationSummary::kNoCall; |
| 3643 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3644 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3645 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3646 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3647 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3648 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3649 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3650 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3651 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 3652 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3653 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3654 | break; |
| 3655 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3656 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3657 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3658 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3659 | locations->SetInAt(0, Location::Any()); |
| 3660 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3661 | break; |
| 3662 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3663 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3664 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3665 | locations->SetOut(Location::RequiresRegister()); |
| 3666 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3667 | break; |
| 3668 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3669 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3670 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3671 | locations->SetOut(Location::RequiresRegister()); |
| 3672 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3673 | break; |
| 3674 | |
| 3675 | default: |
| 3676 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3677 | << " to " << result_type; |
| 3678 | } |
| 3679 | break; |
| 3680 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3681 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3682 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3683 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3684 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3685 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3686 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3687 | case DataType::Type::kInt16: |
| 3688 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3689 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3690 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3691 | break; |
| 3692 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3693 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3694 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3695 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3696 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3697 | break; |
| 3698 | } |
| 3699 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3700 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3701 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3702 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 3703 | calling_convention.GetFpuRegisterAt(1))); |
| 3704 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3705 | break; |
| 3706 | } |
| 3707 | |
| 3708 | default: |
| 3709 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3710 | << " to " << result_type; |
| 3711 | } |
| 3712 | break; |
| 3713 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3714 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3715 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3716 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3717 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3718 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3719 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3720 | case DataType::Type::kInt16: |
| 3721 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3722 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3723 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3724 | break; |
| 3725 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3726 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3727 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3728 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 3729 | calling_convention.GetRegisterAt(1))); |
| 3730 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3731 | break; |
| 3732 | } |
| 3733 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3734 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3735 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3736 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3737 | break; |
| 3738 | |
| 3739 | default: |
| 3740 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3741 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3742 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3743 | break; |
| 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 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3747 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3748 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3749 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3750 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3751 | case DataType::Type::kInt16: |
| 3752 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3753 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3754 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3755 | break; |
| 3756 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3757 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3758 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3759 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3760 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3761 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3762 | break; |
| 3763 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3764 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3765 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3766 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3767 | break; |
| 3768 | |
| 3769 | default: |
| 3770 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3771 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3772 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3773 | break; |
| 3774 | |
| 3775 | default: |
| 3776 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3777 | << " to " << result_type; |
| 3778 | } |
| 3779 | } |
| 3780 | |
| 3781 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3782 | LocationSummary* locations = conversion->GetLocations(); |
| 3783 | Location out = locations->Out(); |
| 3784 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3785 | DataType::Type result_type = conversion->GetResultType(); |
| 3786 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3787 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3788 | << input_type << " -> " << result_type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3789 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3790 | case DataType::Type::kUint8: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3791 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3792 | case DataType::Type::kInt8: |
| 3793 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3794 | case DataType::Type::kInt16: |
| 3795 | case DataType::Type::kInt32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3796 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3797 | break; |
| 3798 | case DataType::Type::kInt64: |
| 3799 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3800 | break; |
| 3801 | |
| 3802 | default: |
| 3803 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3804 | << " to " << result_type; |
| 3805 | } |
| 3806 | break; |
| 3807 | |
| 3808 | case DataType::Type::kInt8: |
| 3809 | switch (input_type) { |
| 3810 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3811 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3812 | case DataType::Type::kInt16: |
| 3813 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3814 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3815 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3816 | case DataType::Type::kInt64: |
| 3817 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3818 | break; |
| 3819 | |
| 3820 | default: |
| 3821 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3822 | << " to " << result_type; |
| 3823 | } |
| 3824 | break; |
| 3825 | |
| 3826 | case DataType::Type::kUint16: |
| 3827 | switch (input_type) { |
| 3828 | case DataType::Type::kInt8: |
| 3829 | case DataType::Type::kInt16: |
| 3830 | case DataType::Type::kInt32: |
| 3831 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3832 | break; |
| 3833 | case DataType::Type::kInt64: |
| 3834 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3835 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3836 | |
| 3837 | default: |
| 3838 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3839 | << " to " << result_type; |
| 3840 | } |
| 3841 | break; |
| 3842 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3843 | case DataType::Type::kInt16: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3844 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3845 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3846 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3847 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3848 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3849 | case DataType::Type::kInt64: |
| 3850 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3851 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3852 | |
| 3853 | default: |
| 3854 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3855 | << " to " << result_type; |
| 3856 | } |
| 3857 | break; |
| 3858 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3859 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3860 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3861 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3862 | DCHECK(out.IsRegister()); |
| 3863 | if (in.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3864 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3865 | } else if (in.IsDoubleStackSlot()) { |
| 3866 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3867 | OutputRegister(conversion), |
| 3868 | sp, |
| 3869 | in.GetStackIndex()); |
| 3870 | } else { |
| 3871 | DCHECK(in.IsConstant()); |
| 3872 | DCHECK(in.GetConstant()->IsLongConstant()); |
Vladimir Marko | ba1a48e | 2017-04-13 11:50:14 +0100 | [diff] [blame] | 3873 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3874 | __ Mov(OutputRegister(conversion), static_cast<int32_t>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3875 | } |
| 3876 | break; |
| 3877 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3878 | case DataType::Type::kFloat32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3879 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3880 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3881 | __ Vmov(OutputRegister(conversion), temp); |
| 3882 | break; |
| 3883 | } |
| 3884 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3885 | case DataType::Type::kFloat64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3886 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3887 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3888 | __ Vmov(OutputRegister(conversion), temp_s); |
| 3889 | break; |
| 3890 | } |
| 3891 | |
| 3892 | default: |
| 3893 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3894 | << " to " << result_type; |
| 3895 | } |
| 3896 | break; |
| 3897 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3898 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3899 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3900 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3901 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3902 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3903 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3904 | case DataType::Type::kInt16: |
| 3905 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3906 | DCHECK(out.IsRegisterPair()); |
| 3907 | DCHECK(in.IsRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3908 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3909 | // Sign extension. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3910 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3911 | break; |
| 3912 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3913 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3914 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 3915 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 3916 | break; |
| 3917 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3918 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3919 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 3920 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 3921 | break; |
| 3922 | |
| 3923 | default: |
| 3924 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3925 | << " to " << result_type; |
| 3926 | } |
| 3927 | break; |
| 3928 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3929 | case DataType::Type::kFloat32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3930 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3931 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3932 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3933 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3934 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3935 | case DataType::Type::kInt16: |
| 3936 | case DataType::Type::kInt32: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3937 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3938 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3939 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3940 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3941 | case DataType::Type::kInt64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3942 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 3943 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 3944 | break; |
| 3945 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3946 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3947 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3948 | break; |
| 3949 | |
| 3950 | default: |
| 3951 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3952 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3953 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3954 | break; |
| 3955 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3956 | case DataType::Type::kFloat64: |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3957 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3958 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3959 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3960 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3961 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3962 | case DataType::Type::kInt16: |
| 3963 | case DataType::Type::kInt32: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3964 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3965 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3966 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3967 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3968 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3969 | vixl32::Register low = LowRegisterFrom(in); |
| 3970 | vixl32::Register high = HighRegisterFrom(in); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3971 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3972 | vixl32::DRegister out_d = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3973 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3974 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3975 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3976 | |
| 3977 | // temp_d = int-to-double(high) |
| 3978 | __ Vmov(temp_s, high); |
Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3979 | __ Vcvt(F64, S32, temp_d, temp_s); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3980 | // constant_d = k2Pow32EncodingForDouble |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3981 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3982 | // out_d = unsigned-to-double(low) |
| 3983 | __ Vmov(out_s, low); |
| 3984 | __ Vcvt(F64, U32, out_d, out_s); |
| 3985 | // out_d += temp_d * constant_d |
| 3986 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 3987 | break; |
| 3988 | } |
| 3989 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3990 | case DataType::Type::kFloat32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3991 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3992 | break; |
| 3993 | |
| 3994 | default: |
| 3995 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3996 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3997 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3998 | break; |
| 3999 | |
| 4000 | default: |
| 4001 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4002 | << " to " << result_type; |
| 4003 | } |
| 4004 | } |
| 4005 | |
| 4006 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 4007 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4008 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4009 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4010 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4011 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4012 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 4013 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4014 | break; |
| 4015 | } |
| 4016 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4017 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4018 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4019 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4020 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4021 | break; |
| 4022 | } |
| 4023 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4024 | case DataType::Type::kFloat32: |
| 4025 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4026 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4027 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4028 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4029 | break; |
| 4030 | } |
| 4031 | |
| 4032 | default: |
| 4033 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4034 | } |
| 4035 | } |
| 4036 | |
| 4037 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 4038 | LocationSummary* locations = add->GetLocations(); |
| 4039 | Location out = locations->Out(); |
| 4040 | Location first = locations->InAt(0); |
| 4041 | Location second = locations->InAt(1); |
| 4042 | |
| 4043 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4044 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4045 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 4046 | } |
| 4047 | break; |
| 4048 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4049 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4050 | if (second.IsConstant()) { |
| 4051 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4052 | GenerateAddLongConst(out, first, value); |
| 4053 | } else { |
| 4054 | DCHECK(second.IsRegisterPair()); |
| 4055 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4056 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4057 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4058 | break; |
| 4059 | } |
| 4060 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4061 | case DataType::Type::kFloat32: |
| 4062 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4063 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4064 | break; |
| 4065 | |
| 4066 | default: |
| 4067 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 4068 | } |
| 4069 | } |
| 4070 | |
| 4071 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 4072 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4073 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4074 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4075 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4076 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4077 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 4078 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4079 | break; |
| 4080 | } |
| 4081 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4082 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4083 | locations->SetInAt(0, Location::RequiresRegister()); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4084 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4085 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4086 | break; |
| 4087 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4088 | case DataType::Type::kFloat32: |
| 4089 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4090 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4091 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4092 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4093 | break; |
| 4094 | } |
| 4095 | default: |
| 4096 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4097 | } |
| 4098 | } |
| 4099 | |
| 4100 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 4101 | LocationSummary* locations = sub->GetLocations(); |
| 4102 | Location out = locations->Out(); |
| 4103 | Location first = locations->InAt(0); |
| 4104 | Location second = locations->InAt(1); |
| 4105 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4106 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4107 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4108 | break; |
| 4109 | } |
| 4110 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4111 | case DataType::Type::kInt64: { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4112 | if (second.IsConstant()) { |
| 4113 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4114 | GenerateAddLongConst(out, first, -value); |
| 4115 | } else { |
| 4116 | DCHECK(second.IsRegisterPair()); |
| 4117 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 4118 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 4119 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4120 | break; |
| 4121 | } |
| 4122 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4123 | case DataType::Type::kFloat32: |
| 4124 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4125 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4126 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4127 | |
| 4128 | default: |
| 4129 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 4130 | } |
| 4131 | } |
| 4132 | |
| 4133 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 4134 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4135 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4136 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4137 | case DataType::Type::kInt32: |
| 4138 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4139 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4140 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4141 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4142 | break; |
| 4143 | } |
| 4144 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4145 | case DataType::Type::kFloat32: |
| 4146 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4147 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4148 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4149 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4150 | break; |
| 4151 | } |
| 4152 | |
| 4153 | default: |
| 4154 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4155 | } |
| 4156 | } |
| 4157 | |
| 4158 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 4159 | LocationSummary* locations = mul->GetLocations(); |
| 4160 | Location out = locations->Out(); |
| 4161 | Location first = locations->InAt(0); |
| 4162 | Location second = locations->InAt(1); |
| 4163 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4164 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4165 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4166 | break; |
| 4167 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4168 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4169 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 4170 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 4171 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 4172 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 4173 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 4174 | vixl32::Register in2_lo = LowRegisterFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4175 | |
| 4176 | // Extra checks to protect caused by the existence of R1_R2. |
| 4177 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4178 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4179 | DCHECK(!out_hi.Is(in1_lo)); |
| 4180 | DCHECK(!out_hi.Is(in2_lo)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4181 | |
| 4182 | // input: in1 - 64 bits, in2 - 64 bits |
| 4183 | // output: out |
| 4184 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4185 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4186 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4187 | |
| 4188 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4189 | vixl32::Register temp = temps.Acquire(); |
| 4190 | // temp <- in1.lo * in2.hi |
| 4191 | __ Mul(temp, in1_lo, in2_hi); |
| 4192 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4193 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 4194 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4195 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 4196 | // 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] | 4197 | __ Add(out_hi, out_hi, temp); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4198 | break; |
| 4199 | } |
| 4200 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4201 | case DataType::Type::kFloat32: |
| 4202 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4203 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4204 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4205 | |
| 4206 | default: |
| 4207 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4208 | } |
| 4209 | } |
| 4210 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4211 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4212 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4213 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4214 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4215 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4216 | DCHECK(second.IsConstant()); |
| 4217 | |
| 4218 | vixl32::Register out = OutputRegister(instruction); |
| 4219 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4220 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4221 | DCHECK(imm == 1 || imm == -1); |
| 4222 | |
| 4223 | if (instruction->IsRem()) { |
| 4224 | __ Mov(out, 0); |
| 4225 | } else { |
| 4226 | if (imm == 1) { |
| 4227 | __ Mov(out, dividend); |
| 4228 | } else { |
| 4229 | __ Rsb(out, dividend, 0); |
| 4230 | } |
| 4231 | } |
| 4232 | } |
| 4233 | |
| 4234 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4235 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4236 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4237 | |
| 4238 | LocationSummary* locations = instruction->GetLocations(); |
| 4239 | Location second = locations->InAt(1); |
| 4240 | DCHECK(second.IsConstant()); |
| 4241 | |
| 4242 | vixl32::Register out = OutputRegister(instruction); |
| 4243 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4244 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4245 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 4246 | int ctz_imm = CTZ(abs_imm); |
| 4247 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4248 | auto generate_div_code = [this, imm, ctz_imm](vixl32::Register out, vixl32::Register in) { |
| 4249 | __ Asr(out, in, ctz_imm); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4250 | if (imm < 0) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4251 | __ Rsb(out, out, 0); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4252 | } |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4253 | }; |
| 4254 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4255 | if (HasNonNegativeOrMinIntInputAt(instruction, 0)) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4256 | // No need to adjust the result for non-negative dividends or the INT32_MIN dividend. |
| 4257 | // NOTE: The generated code for HDiv/HRem correctly works for the INT32_MIN dividend: |
| 4258 | // imm == 2 |
| 4259 | // HDiv |
| 4260 | // add out, dividend(0x80000000), dividend(0x80000000), lsr #31 => out = 0x80000001 |
| 4261 | // asr out, out(0x80000001), #1 => out = 0xc0000000 |
| 4262 | // This is the same as 'asr out, dividend(0x80000000), #1' |
| 4263 | // |
| 4264 | // imm > 2 |
| 4265 | // HDiv |
| 4266 | // asr out, dividend(0x80000000), #31 => out = -1 |
| 4267 | // add out, dividend(0x80000000), out(-1), lsr #(32 - ctz_imm) => out = 0b10..01..1, |
| 4268 | // where the number of the rightmost 1s is ctz_imm. |
| 4269 | // asr out, out(0b10..01..1), #ctz_imm => out = 0b1..10..0, where the number of the |
| 4270 | // leftmost 1s is ctz_imm + 1. |
| 4271 | // This is the same as 'asr out, dividend(0x80000000), #ctz_imm'. |
| 4272 | // |
| 4273 | // imm == INT32_MIN |
| 4274 | // HDiv |
| 4275 | // asr out, dividend(0x80000000), #31 => out = -1 |
| 4276 | // add out, dividend(0x80000000), out(-1), lsr #1 => out = 0xc0000000 |
| 4277 | // asr out, out(0xc0000000), #31 => out = -1 |
| 4278 | // rsb out, out(-1), #0 => out = 1 |
| 4279 | // This is the same as |
| 4280 | // asr out, dividend(0x80000000), #31 |
| 4281 | // rsb out, out, #0 |
| 4282 | // |
| 4283 | // |
| 4284 | // INT_MIN % imm must be 0 for any imm of power 2. 'and' and 'ubfx' work only with bits |
| 4285 | // 0..30 of a dividend. For INT32_MIN those bits are zeros. So 'and' and 'ubfx' always |
| 4286 | // produce zero. |
| 4287 | if (instruction->IsDiv()) { |
| 4288 | generate_div_code(out, dividend); |
| 4289 | } else { |
| 4290 | if (GetVIXLAssembler()->IsModifiedImmediate(abs_imm - 1)) { |
| 4291 | __ And(out, dividend, abs_imm - 1); |
| 4292 | } else { |
| 4293 | __ Ubfx(out, dividend, 0, ctz_imm); |
| 4294 | } |
| 4295 | return; |
| 4296 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4297 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4298 | vixl32::Register add_right_input = dividend; |
| 4299 | if (ctz_imm > 1) { |
| 4300 | __ Asr(out, dividend, 31); |
| 4301 | add_right_input = out; |
| 4302 | } |
| 4303 | __ Add(out, dividend, Operand(add_right_input, vixl32::LSR, 32 - ctz_imm)); |
| 4304 | |
| 4305 | if (instruction->IsDiv()) { |
| 4306 | generate_div_code(out, out); |
| 4307 | } else { |
| 4308 | __ Bfc(out, 0, ctz_imm); |
| 4309 | __ Sub(out, dividend, out); |
| 4310 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4311 | } |
| 4312 | } |
| 4313 | |
| 4314 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4315 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4316 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4317 | |
| 4318 | LocationSummary* locations = instruction->GetLocations(); |
| 4319 | Location second = locations->InAt(1); |
| 4320 | DCHECK(second.IsConstant()); |
| 4321 | |
| 4322 | vixl32::Register out = OutputRegister(instruction); |
| 4323 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4324 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 4325 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4326 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4327 | |
| 4328 | int64_t magic; |
| 4329 | int shift; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4330 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4331 | |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 4332 | auto generate_unsigned_div_code =[this, magic, shift](vixl32::Register out, |
| 4333 | vixl32::Register dividend, |
| 4334 | vixl32::Register temp1, |
| 4335 | vixl32::Register temp2) { |
| 4336 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4337 | __ Mov(temp1, static_cast<int32_t>(magic)); |
| 4338 | if (magic > 0 && shift == 0) { |
| 4339 | __ Smull(temp2, out, dividend, temp1); |
| 4340 | } else { |
| 4341 | __ Smull(temp2, temp1, dividend, temp1); |
| 4342 | if (magic < 0) { |
| 4343 | // The negative magic M = static_cast<int>(m) means that the multiplier m is greater |
| 4344 | // than INT32_MAX. In such a case shift is never 0. |
| 4345 | // Proof: |
| 4346 | // m = (2^p + d - 2^p % d) / d, where p = 32 + shift, d > 2 |
| 4347 | // |
| 4348 | // If shift == 0, m = (2^32 + d - 2^32 % d) / d = |
| 4349 | // = (2^32 + d - (2^32 - (2^32 / d) * d)) / d = |
| 4350 | // = (d + (2^32 / d) * d) / d = 1 + (2^32 / d), here '/' is the integer division. |
| 4351 | // |
| 4352 | // 1 + (2^32 / d) is decreasing when d is increasing. |
| 4353 | // The maximum is 1 431 655 766, when d == 3. This value is less than INT32_MAX. |
| 4354 | // the minimum is 3, when d = 2^31 -1. |
| 4355 | // So for all values of d in [3, INT32_MAX] m with p == 32 is in [3, INT32_MAX) and |
| 4356 | // is never less than 0. |
| 4357 | __ Add(temp1, temp1, dividend); |
| 4358 | } |
| 4359 | DCHECK_NE(shift, 0); |
| 4360 | __ Lsr(out, temp1, shift); |
| 4361 | } |
| 4362 | }; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4363 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4364 | if (imm > 0 && HasNonNegativeInputAt(instruction, 0)) { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 4365 | // No need to adjust the result for a non-negative dividend and a positive divisor. |
| 4366 | if (instruction->IsDiv()) { |
| 4367 | generate_unsigned_div_code(out, dividend, temp1, temp2); |
| 4368 | } else { |
| 4369 | generate_unsigned_div_code(temp1, dividend, temp1, temp2); |
| 4370 | __ Mov(temp2, imm); |
| 4371 | __ Mls(out, temp1, temp2, dividend); |
| 4372 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4373 | } else { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 4374 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4375 | __ Mov(temp1, static_cast<int32_t>(magic)); |
| 4376 | __ Smull(temp2, temp1, dividend, temp1); |
| 4377 | |
| 4378 | if (imm > 0 && magic < 0) { |
| 4379 | __ Add(temp1, temp1, dividend); |
| 4380 | } else if (imm < 0 && magic > 0) { |
| 4381 | __ Sub(temp1, temp1, dividend); |
| 4382 | } |
| 4383 | |
| 4384 | if (shift != 0) { |
| 4385 | __ Asr(temp1, temp1, shift); |
| 4386 | } |
| 4387 | |
| 4388 | if (instruction->IsDiv()) { |
| 4389 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4390 | } else { |
| 4391 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4392 | // TODO: Strength reduction for mls. |
| 4393 | __ Mov(temp2, imm); |
| 4394 | __ Mls(out, temp1, temp2, dividend); |
| 4395 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4396 | } |
| 4397 | } |
| 4398 | |
| 4399 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 4400 | HBinaryOperation* instruction) { |
| 4401 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4402 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4403 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4404 | Location second = instruction->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4405 | DCHECK(second.IsConstant()); |
| 4406 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4407 | int32_t imm = Int32ConstantFrom(second); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4408 | if (imm == 0) { |
| 4409 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4410 | } else if (imm == 1 || imm == -1) { |
| 4411 | DivRemOneOrMinusOne(instruction); |
| 4412 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4413 | DivRemByPowerOfTwo(instruction); |
| 4414 | } else { |
| 4415 | DCHECK(imm <= -2 || imm >= 2); |
| 4416 | GenerateDivRemWithAnyConstant(instruction); |
| 4417 | } |
| 4418 | } |
| 4419 | |
| 4420 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 4421 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4422 | if (div->GetResultType() == DataType::Type::kInt64) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4423 | // pLdiv runtime call. |
| 4424 | call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4425 | } else if (div->GetResultType() == DataType::Type::kInt32 && div->InputAt(1)->IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4426 | // sdiv will be replaced by other instruction sequence. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4427 | } else if (div->GetResultType() == DataType::Type::kInt32 && |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4428 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4429 | // pIdivmod runtime call. |
| 4430 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4431 | } |
| 4432 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4433 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4434 | |
| 4435 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4436 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4437 | if (div->InputAt(1)->IsConstant()) { |
| 4438 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4439 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4440 | int32_t value = Int32ConstantFrom(div->InputAt(1)); |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4441 | Location::OutputOverlap out_overlaps = Location::kNoOutputOverlap; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4442 | if (value == 1 || value == 0 || value == -1) { |
| 4443 | // No temp register required. |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 4444 | } else if (IsPowerOfTwo(AbsOrMin(value)) && |
| 4445 | value != 2 && |
| 4446 | value != -2 && |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4447 | !HasNonNegativeOrMinIntInputAt(div, 0)) { |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4448 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 4449 | out_overlaps = Location::kOutputOverlap; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4450 | } else { |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4451 | locations->AddRegisterTemps(2); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4452 | } |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4453 | locations->SetOut(Location::RequiresRegister(), out_overlaps); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4454 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4455 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4456 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4457 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4458 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4459 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4460 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4461 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4462 | // 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] | 4463 | // we only need the former. |
| 4464 | locations->SetOut(LocationFrom(r0)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4465 | } |
| 4466 | break; |
| 4467 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4468 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4469 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4470 | locations->SetInAt(0, LocationFrom( |
| 4471 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4472 | locations->SetInAt(1, LocationFrom( |
| 4473 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4474 | locations->SetOut(LocationFrom(r0, r1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4475 | break; |
| 4476 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4477 | case DataType::Type::kFloat32: |
| 4478 | case DataType::Type::kFloat64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4479 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4480 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4481 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4482 | break; |
| 4483 | } |
| 4484 | |
| 4485 | default: |
| 4486 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4487 | } |
| 4488 | } |
| 4489 | |
| 4490 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4491 | Location lhs = div->GetLocations()->InAt(0); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4492 | Location rhs = div->GetLocations()->InAt(1); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4493 | |
| 4494 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4495 | case DataType::Type::kInt32: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4496 | if (rhs.IsConstant()) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4497 | GenerateDivRemConstantIntegral(div); |
| 4498 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4499 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 4500 | } else { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4501 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4502 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 4503 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 4504 | DCHECK(r0.Is(OutputRegister(div))); |
| 4505 | |
| 4506 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 4507 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4508 | } |
| 4509 | break; |
| 4510 | } |
| 4511 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4512 | case DataType::Type::kInt64: { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4513 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4514 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 4515 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 4516 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 4517 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 4518 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 4519 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 4520 | |
| 4521 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 4522 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4523 | break; |
| 4524 | } |
| 4525 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4526 | case DataType::Type::kFloat32: |
| 4527 | case DataType::Type::kFloat64: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4528 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4529 | break; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4530 | |
| 4531 | default: |
| 4532 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4533 | } |
| 4534 | } |
| 4535 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4536 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4537 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4538 | |
| 4539 | // Most remainders are implemented in the runtime. |
| 4540 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4541 | if (rem->GetResultType() == DataType::Type::kInt32 && rem->InputAt(1)->IsConstant()) { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4542 | // sdiv will be replaced by other instruction sequence. |
| 4543 | call_kind = LocationSummary::kNoCall; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4544 | } else if ((rem->GetResultType() == DataType::Type::kInt32) |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4545 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4546 | // Have hardware divide instruction for int, do it with three instructions. |
| 4547 | call_kind = LocationSummary::kNoCall; |
| 4548 | } |
| 4549 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4550 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4551 | |
| 4552 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4553 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4554 | if (rem->InputAt(1)->IsConstant()) { |
| 4555 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4556 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4557 | int32_t value = Int32ConstantFrom(rem->InputAt(1)); |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4558 | Location::OutputOverlap out_overlaps = Location::kNoOutputOverlap; |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4559 | if (value == 1 || value == 0 || value == -1) { |
| 4560 | // No temp register required. |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 4561 | } else if (IsPowerOfTwo(AbsOrMin(value)) && !HasNonNegativeOrMinIntInputAt(rem, 0)) { |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4562 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 4563 | out_overlaps = Location::kOutputOverlap; |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4564 | } else { |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4565 | locations->AddRegisterTemps(2); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4566 | } |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 4567 | locations->SetOut(Location::RequiresRegister(), out_overlaps); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4568 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4569 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4570 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4571 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4572 | locations->AddTemp(Location::RequiresRegister()); |
| 4573 | } else { |
| 4574 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4575 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4576 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4577 | // 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] | 4578 | // we only need the latter. |
| 4579 | locations->SetOut(LocationFrom(r1)); |
| 4580 | } |
| 4581 | break; |
| 4582 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4583 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4584 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4585 | locations->SetInAt(0, LocationFrom( |
| 4586 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4587 | locations->SetInAt(1, LocationFrom( |
| 4588 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4589 | // The runtime helper puts the output in R2,R3. |
| 4590 | locations->SetOut(LocationFrom(r2, r3)); |
| 4591 | break; |
| 4592 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4593 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4594 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4595 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4596 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4597 | locations->SetOut(LocationFrom(s0)); |
| 4598 | break; |
| 4599 | } |
| 4600 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4601 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4602 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4603 | locations->SetInAt(0, LocationFrom( |
| 4604 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4605 | locations->SetInAt(1, LocationFrom( |
| 4606 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4607 | locations->SetOut(LocationFrom(s0, s1)); |
| 4608 | break; |
| 4609 | } |
| 4610 | |
| 4611 | default: |
| 4612 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4613 | } |
| 4614 | } |
| 4615 | |
| 4616 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 4617 | LocationSummary* locations = rem->GetLocations(); |
| 4618 | Location second = locations->InAt(1); |
| 4619 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4620 | DataType::Type type = rem->GetResultType(); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4621 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4622 | case DataType::Type::kInt32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4623 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 4624 | vixl32::Register out_reg = OutputRegister(rem); |
| 4625 | if (second.IsConstant()) { |
| 4626 | GenerateDivRemConstantIntegral(rem); |
| 4627 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4628 | vixl32::Register reg2 = RegisterFrom(second); |
| 4629 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4630 | |
| 4631 | // temp = reg1 / reg2 (integer division) |
| 4632 | // dest = reg1 - temp * reg2 |
| 4633 | __ Sdiv(temp, reg1, reg2); |
| 4634 | __ Mls(out_reg, temp, reg2, reg1); |
| 4635 | } else { |
| 4636 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4637 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 4638 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 4639 | DCHECK(out_reg.Is(r1)); |
| 4640 | |
| 4641 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 4642 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 4643 | } |
| 4644 | break; |
| 4645 | } |
| 4646 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4647 | case DataType::Type::kInt64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4648 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 4649 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 4650 | break; |
| 4651 | } |
| 4652 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4653 | case DataType::Type::kFloat32: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4654 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 4655 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4656 | break; |
| 4657 | } |
| 4658 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4659 | case DataType::Type::kFloat64: { |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4660 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 4661 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4662 | break; |
| 4663 | } |
| 4664 | |
| 4665 | default: |
| 4666 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4667 | } |
| 4668 | } |
| 4669 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4670 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4671 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4672 | switch (minmax->GetResultType()) { |
| 4673 | case DataType::Type::kInt32: |
| 4674 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4675 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4676 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4677 | break; |
| 4678 | case DataType::Type::kInt64: |
| 4679 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4680 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4681 | locations->SetOut(Location::SameAsFirstInput()); |
| 4682 | break; |
| 4683 | case DataType::Type::kFloat32: |
| 4684 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4685 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4686 | locations->SetOut(Location::SameAsFirstInput()); |
| 4687 | locations->AddTemp(Location::RequiresRegister()); |
| 4688 | break; |
| 4689 | case DataType::Type::kFloat64: |
| 4690 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4691 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4692 | locations->SetOut(Location::SameAsFirstInput()); |
| 4693 | break; |
| 4694 | default: |
| 4695 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4696 | } |
| 4697 | } |
| 4698 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4699 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxInt(LocationSummary* locations, bool is_min) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4700 | Location op1_loc = locations->InAt(0); |
| 4701 | Location op2_loc = locations->InAt(1); |
| 4702 | Location out_loc = locations->Out(); |
| 4703 | |
| 4704 | vixl32::Register op1 = RegisterFrom(op1_loc); |
| 4705 | vixl32::Register op2 = RegisterFrom(op2_loc); |
| 4706 | vixl32::Register out = RegisterFrom(out_loc); |
| 4707 | |
| 4708 | __ Cmp(op1, op2); |
| 4709 | |
| 4710 | { |
| 4711 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 4712 | 3 * kMaxInstructionSizeInBytes, |
| 4713 | CodeBufferCheckScope::kMaximumSize); |
| 4714 | |
| 4715 | __ ite(is_min ? lt : gt); |
| 4716 | __ mov(is_min ? lt : gt, out, op1); |
| 4717 | __ mov(is_min ? ge : le, out, op2); |
| 4718 | } |
| 4719 | } |
| 4720 | |
| 4721 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxLong(LocationSummary* locations, bool is_min) { |
| 4722 | Location op1_loc = locations->InAt(0); |
| 4723 | Location op2_loc = locations->InAt(1); |
| 4724 | Location out_loc = locations->Out(); |
| 4725 | |
| 4726 | // Optimization: don't generate any code if inputs are the same. |
| 4727 | if (op1_loc.Equals(op2_loc)) { |
| 4728 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder. |
| 4729 | return; |
| 4730 | } |
| 4731 | |
| 4732 | vixl32::Register op1_lo = LowRegisterFrom(op1_loc); |
| 4733 | vixl32::Register op1_hi = HighRegisterFrom(op1_loc); |
| 4734 | vixl32::Register op2_lo = LowRegisterFrom(op2_loc); |
| 4735 | vixl32::Register op2_hi = HighRegisterFrom(op2_loc); |
| 4736 | vixl32::Register out_lo = LowRegisterFrom(out_loc); |
| 4737 | vixl32::Register out_hi = HighRegisterFrom(out_loc); |
| 4738 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4739 | const vixl32::Register temp = temps.Acquire(); |
| 4740 | |
| 4741 | DCHECK(op1_lo.Is(out_lo)); |
| 4742 | DCHECK(op1_hi.Is(out_hi)); |
| 4743 | |
| 4744 | // Compare op1 >= op2, or op1 < op2. |
| 4745 | __ Cmp(out_lo, op2_lo); |
| 4746 | __ Sbcs(temp, out_hi, op2_hi); |
| 4747 | |
| 4748 | // Now GE/LT condition code is correct for the long comparison. |
| 4749 | { |
| 4750 | vixl32::ConditionType cond = is_min ? ge : lt; |
| 4751 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4752 | 3 * kMaxInstructionSizeInBytes, |
| 4753 | CodeBufferCheckScope::kMaximumSize); |
| 4754 | __ itt(cond); |
| 4755 | __ mov(cond, out_lo, op2_lo); |
| 4756 | __ mov(cond, out_hi, op2_hi); |
| 4757 | } |
| 4758 | } |
| 4759 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4760 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxFloat(HInstruction* minmax, bool is_min) { |
| 4761 | LocationSummary* locations = minmax->GetLocations(); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4762 | Location op1_loc = locations->InAt(0); |
| 4763 | Location op2_loc = locations->InAt(1); |
| 4764 | Location out_loc = locations->Out(); |
| 4765 | |
| 4766 | // Optimization: don't generate any code if inputs are the same. |
| 4767 | if (op1_loc.Equals(op2_loc)) { |
| 4768 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder. |
| 4769 | return; |
| 4770 | } |
| 4771 | |
| 4772 | vixl32::SRegister op1 = SRegisterFrom(op1_loc); |
| 4773 | vixl32::SRegister op2 = SRegisterFrom(op2_loc); |
| 4774 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 4775 | |
| 4776 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4777 | const vixl32::Register temp1 = temps.Acquire(); |
| 4778 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(0)); |
| 4779 | vixl32::Label nan, done; |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4780 | vixl32::Label* final_label = codegen_->GetFinalLabel(minmax, &done); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4781 | |
| 4782 | DCHECK(op1.Is(out)); |
| 4783 | |
| 4784 | __ Vcmp(op1, op2); |
| 4785 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4786 | __ 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] | 4787 | |
| 4788 | // op1 <> op2 |
| 4789 | vixl32::ConditionType cond = is_min ? gt : lt; |
| 4790 | { |
| 4791 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4792 | 2 * kMaxInstructionSizeInBytes, |
| 4793 | CodeBufferCheckScope::kMaximumSize); |
| 4794 | __ it(cond); |
| 4795 | __ vmov(cond, F32, out, op2); |
| 4796 | } |
| 4797 | // for <>(not equal), we've done min/max calculation. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4798 | __ B(ne, final_label, /* is_far_target= */ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4799 | |
| 4800 | // handle op1 == op2, max(+0.0,-0.0), min(+0.0,-0.0). |
| 4801 | __ Vmov(temp1, op1); |
| 4802 | __ Vmov(temp2, op2); |
| 4803 | if (is_min) { |
| 4804 | __ Orr(temp1, temp1, temp2); |
| 4805 | } else { |
| 4806 | __ And(temp1, temp1, temp2); |
| 4807 | } |
| 4808 | __ Vmov(out, temp1); |
| 4809 | __ B(final_label); |
| 4810 | |
| 4811 | // handle NaN input. |
| 4812 | __ Bind(&nan); |
| 4813 | __ Movt(temp1, High16Bits(kNanFloat)); // 0x7FC0xxxx is a NaN. |
| 4814 | __ Vmov(out, temp1); |
| 4815 | |
| 4816 | if (done.IsReferenced()) { |
| 4817 | __ Bind(&done); |
| 4818 | } |
| 4819 | } |
| 4820 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4821 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxDouble(HInstruction* minmax, bool is_min) { |
| 4822 | LocationSummary* locations = minmax->GetLocations(); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4823 | Location op1_loc = locations->InAt(0); |
| 4824 | Location op2_loc = locations->InAt(1); |
| 4825 | Location out_loc = locations->Out(); |
| 4826 | |
| 4827 | // Optimization: don't generate any code if inputs are the same. |
| 4828 | if (op1_loc.Equals(op2_loc)) { |
| 4829 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in. |
| 4830 | return; |
| 4831 | } |
| 4832 | |
| 4833 | vixl32::DRegister op1 = DRegisterFrom(op1_loc); |
| 4834 | vixl32::DRegister op2 = DRegisterFrom(op2_loc); |
| 4835 | vixl32::DRegister out = DRegisterFrom(out_loc); |
| 4836 | vixl32::Label handle_nan_eq, done; |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4837 | vixl32::Label* final_label = codegen_->GetFinalLabel(minmax, &done); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4838 | |
| 4839 | DCHECK(op1.Is(out)); |
| 4840 | |
| 4841 | __ Vcmp(op1, op2); |
| 4842 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4843 | __ 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] | 4844 | |
| 4845 | // op1 <> op2 |
| 4846 | vixl32::ConditionType cond = is_min ? gt : lt; |
| 4847 | { |
| 4848 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4849 | 2 * kMaxInstructionSizeInBytes, |
| 4850 | CodeBufferCheckScope::kMaximumSize); |
| 4851 | __ it(cond); |
| 4852 | __ vmov(cond, F64, out, op2); |
| 4853 | } |
| 4854 | // for <>(not equal), we've done min/max calculation. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4855 | __ B(ne, final_label, /* is_far_target= */ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4856 | |
| 4857 | // handle op1 == op2, max(+0.0,-0.0). |
| 4858 | if (!is_min) { |
| 4859 | __ Vand(F64, out, op1, op2); |
| 4860 | __ B(final_label); |
| 4861 | } |
| 4862 | |
| 4863 | // handle op1 == op2, min(+0.0,-0.0), NaN input. |
| 4864 | __ Bind(&handle_nan_eq); |
| 4865 | __ Vorr(F64, out, op1, op2); // assemble op1/-0.0/NaN. |
| 4866 | |
| 4867 | if (done.IsReferenced()) { |
| 4868 | __ Bind(&done); |
| 4869 | } |
| 4870 | } |
| 4871 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4872 | void InstructionCodeGeneratorARMVIXL::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4873 | DataType::Type type = minmax->GetResultType(); |
| 4874 | switch (type) { |
| 4875 | case DataType::Type::kInt32: |
| 4876 | GenerateMinMaxInt(minmax->GetLocations(), is_min); |
| 4877 | break; |
| 4878 | case DataType::Type::kInt64: |
| 4879 | GenerateMinMaxLong(minmax->GetLocations(), is_min); |
| 4880 | break; |
| 4881 | case DataType::Type::kFloat32: |
| 4882 | GenerateMinMaxFloat(minmax, is_min); |
| 4883 | break; |
| 4884 | case DataType::Type::kFloat64: |
| 4885 | GenerateMinMaxDouble(minmax, is_min); |
| 4886 | break; |
| 4887 | default: |
| 4888 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4889 | } |
| 4890 | } |
| 4891 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4892 | void LocationsBuilderARMVIXL::VisitMin(HMin* min) { |
| 4893 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4894 | } |
| 4895 | |
| 4896 | void InstructionCodeGeneratorARMVIXL::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4897 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | void LocationsBuilderARMVIXL::VisitMax(HMax* max) { |
| 4901 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4902 | } |
| 4903 | |
| 4904 | void InstructionCodeGeneratorARMVIXL::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4905 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4906 | } |
| 4907 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4908 | void LocationsBuilderARMVIXL::VisitAbs(HAbs* abs) { |
| 4909 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4910 | switch (abs->GetResultType()) { |
| 4911 | case DataType::Type::kInt32: |
| 4912 | case DataType::Type::kInt64: |
| 4913 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4914 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4915 | locations->AddTemp(Location::RequiresRegister()); |
| 4916 | break; |
| 4917 | case DataType::Type::kFloat32: |
| 4918 | case DataType::Type::kFloat64: |
| 4919 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4920 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4921 | break; |
| 4922 | default: |
| 4923 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 4924 | } |
| 4925 | } |
| 4926 | |
| 4927 | void InstructionCodeGeneratorARMVIXL::VisitAbs(HAbs* abs) { |
| 4928 | LocationSummary* locations = abs->GetLocations(); |
| 4929 | switch (abs->GetResultType()) { |
| 4930 | case DataType::Type::kInt32: { |
| 4931 | vixl32::Register in_reg = RegisterFrom(locations->InAt(0)); |
| 4932 | vixl32::Register out_reg = RegisterFrom(locations->Out()); |
| 4933 | vixl32::Register mask = RegisterFrom(locations->GetTemp(0)); |
| 4934 | __ Asr(mask, in_reg, 31); |
| 4935 | __ Add(out_reg, in_reg, mask); |
| 4936 | __ Eor(out_reg, out_reg, mask); |
| 4937 | break; |
| 4938 | } |
| 4939 | case DataType::Type::kInt64: { |
| 4940 | Location in = locations->InAt(0); |
| 4941 | vixl32::Register in_reg_lo = LowRegisterFrom(in); |
| 4942 | vixl32::Register in_reg_hi = HighRegisterFrom(in); |
| 4943 | Location output = locations->Out(); |
| 4944 | vixl32::Register out_reg_lo = LowRegisterFrom(output); |
| 4945 | vixl32::Register out_reg_hi = HighRegisterFrom(output); |
| 4946 | DCHECK(!out_reg_lo.Is(in_reg_hi)) << "Diagonal overlap unexpected."; |
| 4947 | vixl32::Register mask = RegisterFrom(locations->GetTemp(0)); |
| 4948 | __ Asr(mask, in_reg_hi, 31); |
| 4949 | __ Adds(out_reg_lo, in_reg_lo, mask); |
| 4950 | __ Adc(out_reg_hi, in_reg_hi, mask); |
| 4951 | __ Eor(out_reg_lo, out_reg_lo, mask); |
| 4952 | __ Eor(out_reg_hi, out_reg_hi, mask); |
| 4953 | break; |
| 4954 | } |
| 4955 | case DataType::Type::kFloat32: |
| 4956 | case DataType::Type::kFloat64: |
| 4957 | __ Vabs(OutputVRegister(abs), InputVRegisterAt(abs, 0)); |
| 4958 | break; |
| 4959 | default: |
| 4960 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 4961 | } |
| 4962 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4963 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4964 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 4965 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4966 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4967 | } |
| 4968 | |
| 4969 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 4970 | DivZeroCheckSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4971 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARMVIXL(instruction); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4972 | codegen_->AddSlowPath(slow_path); |
| 4973 | |
| 4974 | LocationSummary* locations = instruction->GetLocations(); |
| 4975 | Location value = locations->InAt(0); |
| 4976 | |
| 4977 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4978 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4979 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4980 | case DataType::Type::kInt8: |
| 4981 | case DataType::Type::kUint16: |
| 4982 | case DataType::Type::kInt16: |
| 4983 | case DataType::Type::kInt32: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4984 | if (value.IsRegister()) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 4985 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4986 | } else { |
| 4987 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4988 | if (Int32ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4989 | __ B(slow_path->GetEntryLabel()); |
| 4990 | } |
| 4991 | } |
| 4992 | break; |
| 4993 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4994 | case DataType::Type::kInt64: { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4995 | if (value.IsRegisterPair()) { |
| 4996 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4997 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4998 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4999 | __ B(eq, slow_path->GetEntryLabel()); |
| 5000 | } else { |
| 5001 | DCHECK(value.IsConstant()) << value; |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5002 | if (Int64ConstantFrom(value) == 0) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 5003 | __ B(slow_path->GetEntryLabel()); |
| 5004 | } |
| 5005 | } |
| 5006 | break; |
| 5007 | } |
| 5008 | default: |
| 5009 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 5010 | } |
| 5011 | } |
| 5012 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5013 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 5014 | LocationSummary* locations = ror->GetLocations(); |
| 5015 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 5016 | Location rhs = locations->InAt(1); |
| 5017 | vixl32::Register out = OutputRegister(ror); |
| 5018 | |
| 5019 | if (rhs.IsConstant()) { |
| 5020 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 5021 | // so map all rotations to a +ve. equivalent in that range. |
| 5022 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 5023 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 5024 | if (rot) { |
| 5025 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 5026 | // (e.g. left by 2 bits == right by 30.) |
| 5027 | __ Ror(out, in, rot); |
| 5028 | } else if (!out.Is(in)) { |
| 5029 | __ Mov(out, in); |
| 5030 | } |
| 5031 | } else { |
| 5032 | __ Ror(out, in, RegisterFrom(rhs)); |
| 5033 | } |
| 5034 | } |
| 5035 | |
| 5036 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 5037 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 5038 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 5039 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 5040 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 5041 | LocationSummary* locations = ror->GetLocations(); |
| 5042 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 5043 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 5044 | Location rhs = locations->InAt(1); |
| 5045 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 5046 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 5047 | |
| 5048 | if (rhs.IsConstant()) { |
| 5049 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 5050 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 5051 | rot &= kMaxLongShiftDistance; |
| 5052 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 5053 | // logic below to a simple pair of binary orr. |
| 5054 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 5055 | if (rot >= kArmBitsPerWord) { |
| 5056 | rot -= kArmBitsPerWord; |
| 5057 | std::swap(in_reg_hi, in_reg_lo); |
| 5058 | } |
| 5059 | // Rotate, or mov to out for zero or word size rotations. |
| 5060 | if (rot != 0u) { |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5061 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5062 | __ 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] | 5063 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5064 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 5065 | } else { |
| 5066 | __ Mov(out_reg_lo, in_reg_lo); |
| 5067 | __ Mov(out_reg_hi, in_reg_hi); |
| 5068 | } |
| 5069 | } else { |
| 5070 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 5071 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 5072 | vixl32::Label end; |
| 5073 | vixl32::Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5074 | vixl32::Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5075 | |
| 5076 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 5077 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 5078 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5079 | __ B(cc, &shift_by_32_plus_shift_right, /* is_far_target= */ false); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5080 | |
| 5081 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 5082 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 5083 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 5084 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 5085 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 5086 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 5087 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 5088 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5089 | __ B(final_label); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5090 | |
| 5091 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 5092 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 5093 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 5094 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 5095 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 5096 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 5097 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 5098 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 5099 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 5100 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5101 | if (end.IsReferenced()) { |
| 5102 | __ Bind(&end); |
| 5103 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5104 | } |
| 5105 | } |
| 5106 | |
| 5107 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 5108 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5109 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5110 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5111 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5112 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5113 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 5114 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5115 | break; |
| 5116 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5117 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5118 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5119 | if (ror->InputAt(1)->IsConstant()) { |
| 5120 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 5121 | } else { |
| 5122 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5123 | locations->AddTemp(Location::RequiresRegister()); |
| 5124 | locations->AddTemp(Location::RequiresRegister()); |
| 5125 | } |
| 5126 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5127 | break; |
| 5128 | } |
| 5129 | default: |
| 5130 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 5131 | } |
| 5132 | } |
| 5133 | |
| 5134 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5135 | DataType::Type type = ror->GetResultType(); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5136 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5137 | case DataType::Type::kInt32: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5138 | HandleIntegerRotate(ror); |
| 5139 | break; |
| 5140 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5141 | case DataType::Type::kInt64: { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5142 | HandleLongRotate(ror); |
| 5143 | break; |
| 5144 | } |
| 5145 | default: |
| 5146 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5147 | UNREACHABLE(); |
| 5148 | } |
| 5149 | } |
| 5150 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5151 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 5152 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5153 | |
| 5154 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5155 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5156 | |
| 5157 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5158 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5159 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5160 | if (op->InputAt(1)->IsConstant()) { |
| 5161 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5162 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5163 | } else { |
| 5164 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5165 | // Make the output overlap, as it will be used to hold the masked |
| 5166 | // second input. |
| 5167 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5168 | } |
| 5169 | break; |
| 5170 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5171 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5172 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5173 | if (op->InputAt(1)->IsConstant()) { |
| 5174 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5175 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 5176 | // don't clash with high registers which the register allocator currently guarantees. |
| 5177 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5178 | } else { |
| 5179 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5180 | locations->AddTemp(Location::RequiresRegister()); |
| 5181 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5182 | } |
| 5183 | break; |
| 5184 | } |
| 5185 | default: |
| 5186 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 5187 | } |
| 5188 | } |
| 5189 | |
| 5190 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 5191 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5192 | |
| 5193 | LocationSummary* locations = op->GetLocations(); |
| 5194 | Location out = locations->Out(); |
| 5195 | Location first = locations->InAt(0); |
| 5196 | Location second = locations->InAt(1); |
| 5197 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5198 | DataType::Type type = op->GetResultType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5199 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5200 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5201 | vixl32::Register out_reg = OutputRegister(op); |
| 5202 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 5203 | if (second.IsRegister()) { |
| 5204 | vixl32::Register second_reg = RegisterFrom(second); |
| 5205 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 5206 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 5207 | if (op->IsShl()) { |
| 5208 | __ Lsl(out_reg, first_reg, out_reg); |
| 5209 | } else if (op->IsShr()) { |
| 5210 | __ Asr(out_reg, first_reg, out_reg); |
| 5211 | } else { |
| 5212 | __ Lsr(out_reg, first_reg, out_reg); |
| 5213 | } |
| 5214 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5215 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5216 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 5217 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 5218 | __ Mov(out_reg, first_reg); |
| 5219 | } else if (op->IsShl()) { |
| 5220 | __ Lsl(out_reg, first_reg, shift_value); |
| 5221 | } else if (op->IsShr()) { |
| 5222 | __ Asr(out_reg, first_reg, shift_value); |
| 5223 | } else { |
| 5224 | __ Lsr(out_reg, first_reg, shift_value); |
| 5225 | } |
| 5226 | } |
| 5227 | break; |
| 5228 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5229 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5230 | vixl32::Register o_h = HighRegisterFrom(out); |
| 5231 | vixl32::Register o_l = LowRegisterFrom(out); |
| 5232 | |
| 5233 | vixl32::Register high = HighRegisterFrom(first); |
| 5234 | vixl32::Register low = LowRegisterFrom(first); |
| 5235 | |
| 5236 | if (second.IsRegister()) { |
| 5237 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5238 | |
| 5239 | vixl32::Register second_reg = RegisterFrom(second); |
| 5240 | |
| 5241 | if (op->IsShl()) { |
| 5242 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 5243 | // Shift the high part |
| 5244 | __ Lsl(o_h, high, o_l); |
| 5245 | // Shift the low part and `or` what overflew on the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5246 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5247 | __ Lsr(temp, low, temp); |
| 5248 | __ Orr(o_h, o_h, temp); |
| 5249 | // If the shift is > 32 bits, override the high part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5250 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5251 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5252 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5253 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5254 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5255 | __ it(pl); |
| 5256 | __ lsl(pl, o_h, low, temp); |
| 5257 | } |
| 5258 | // Shift the low part |
| 5259 | __ Lsl(o_l, low, o_l); |
| 5260 | } else if (op->IsShr()) { |
| 5261 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5262 | // Shift the low part |
| 5263 | __ Lsr(o_l, low, o_h); |
| 5264 | // Shift the high part and `or` what underflew on the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5265 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5266 | __ Lsl(temp, high, temp); |
| 5267 | __ Orr(o_l, o_l, temp); |
| 5268 | // If the shift is > 32 bits, override the low part |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5269 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5270 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5271 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5272 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5273 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5274 | __ it(pl); |
| 5275 | __ asr(pl, o_l, high, temp); |
| 5276 | } |
| 5277 | // Shift the high part |
| 5278 | __ Asr(o_h, high, o_h); |
| 5279 | } else { |
| 5280 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5281 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 5282 | __ Lsr(o_l, low, o_h); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5283 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5284 | __ Lsl(temp, high, temp); |
| 5285 | __ Orr(o_l, o_l, temp); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5286 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5287 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5288 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5289 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5290 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5291 | __ it(pl); |
| 5292 | __ lsr(pl, o_l, high, temp); |
| 5293 | } |
| 5294 | __ Lsr(o_h, high, o_h); |
| 5295 | } |
| 5296 | } else { |
| 5297 | // Register allocator doesn't create partial overlap. |
| 5298 | DCHECK(!o_l.Is(high)); |
| 5299 | DCHECK(!o_h.Is(low)); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5300 | int32_t cst = Int32ConstantFrom(second); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5301 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 5302 | if (shift_value > 32) { |
| 5303 | if (op->IsShl()) { |
| 5304 | __ Lsl(o_h, low, shift_value - 32); |
| 5305 | __ Mov(o_l, 0); |
| 5306 | } else if (op->IsShr()) { |
| 5307 | __ Asr(o_l, high, shift_value - 32); |
| 5308 | __ Asr(o_h, high, 31); |
| 5309 | } else { |
| 5310 | __ Lsr(o_l, high, shift_value - 32); |
| 5311 | __ Mov(o_h, 0); |
| 5312 | } |
| 5313 | } else if (shift_value == 32) { |
| 5314 | if (op->IsShl()) { |
| 5315 | __ Mov(o_h, low); |
| 5316 | __ Mov(o_l, 0); |
| 5317 | } else if (op->IsShr()) { |
| 5318 | __ Mov(o_l, high); |
| 5319 | __ Asr(o_h, high, 31); |
| 5320 | } else { |
| 5321 | __ Mov(o_l, high); |
| 5322 | __ Mov(o_h, 0); |
| 5323 | } |
| 5324 | } else if (shift_value == 1) { |
| 5325 | if (op->IsShl()) { |
| 5326 | __ Lsls(o_l, low, 1); |
| 5327 | __ Adc(o_h, high, high); |
| 5328 | } else if (op->IsShr()) { |
| 5329 | __ Asrs(o_h, high, 1); |
| 5330 | __ Rrx(o_l, low); |
| 5331 | } else { |
| 5332 | __ Lsrs(o_h, high, 1); |
| 5333 | __ Rrx(o_l, low); |
| 5334 | } |
Nicolas Geoffray | 9b195cc | 2019-04-02 08:29:00 +0100 | [diff] [blame] | 5335 | } else if (shift_value == 0) { |
| 5336 | __ Mov(o_l, low); |
| 5337 | __ Mov(o_h, high); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5338 | } else { |
Nicolas Geoffray | 9b195cc | 2019-04-02 08:29:00 +0100 | [diff] [blame] | 5339 | DCHECK(0 < shift_value && shift_value < 32) << shift_value; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5340 | if (op->IsShl()) { |
| 5341 | __ Lsl(o_h, high, shift_value); |
| 5342 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 5343 | __ Lsl(o_l, low, shift_value); |
| 5344 | } else if (op->IsShr()) { |
| 5345 | __ Lsr(o_l, low, shift_value); |
| 5346 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5347 | __ Asr(o_h, high, shift_value); |
| 5348 | } else { |
| 5349 | __ Lsr(o_l, low, shift_value); |
| 5350 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5351 | __ Lsr(o_h, high, shift_value); |
| 5352 | } |
| 5353 | } |
| 5354 | } |
| 5355 | break; |
| 5356 | } |
| 5357 | default: |
| 5358 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5359 | UNREACHABLE(); |
| 5360 | } |
| 5361 | } |
| 5362 | |
| 5363 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 5364 | HandleShift(shl); |
| 5365 | } |
| 5366 | |
| 5367 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 5368 | HandleShift(shl); |
| 5369 | } |
| 5370 | |
| 5371 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 5372 | HandleShift(shr); |
| 5373 | } |
| 5374 | |
| 5375 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 5376 | HandleShift(shr); |
| 5377 | } |
| 5378 | |
| 5379 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 5380 | HandleShift(ushr); |
| 5381 | } |
| 5382 | |
| 5383 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 5384 | HandleShift(ushr); |
| 5385 | } |
| 5386 | |
| 5387 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5388 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5389 | instruction, LocationSummary::kCallOnMainOnly); |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5390 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5391 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5392 | locations->SetOut(LocationFrom(r0)); |
| 5393 | } |
| 5394 | |
| 5395 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5396 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5397 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 5398 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 12); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5399 | } |
| 5400 | |
| 5401 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5402 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5403 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5404 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5405 | locations->SetOut(LocationFrom(r0)); |
Nicolas Geoffray | 8c7c4f1 | 2017-01-26 10:13:11 +0000 | [diff] [blame] | 5406 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5407 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5411 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5412 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5413 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5414 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5415 | DCHECK(!codegen_->IsLeafMethod()); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 5416 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 13); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5417 | } |
| 5418 | |
| 5419 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 5420 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5421 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5422 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5423 | if (location.IsStackSlot()) { |
| 5424 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5425 | } else if (location.IsDoubleStackSlot()) { |
| 5426 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5427 | } |
| 5428 | locations->SetOut(location); |
| 5429 | } |
| 5430 | |
| 5431 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 5432 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 5433 | // Nothing to do, the parameter is already at its location. |
| 5434 | } |
| 5435 | |
| 5436 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5437 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5438 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5439 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 5440 | } |
| 5441 | |
| 5442 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 5443 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5444 | // Nothing to do, the method is already at its location. |
| 5445 | } |
| 5446 | |
| 5447 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 5448 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5449 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5450 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5451 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5452 | } |
| 5453 | |
| 5454 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 5455 | LocationSummary* locations = not_->GetLocations(); |
| 5456 | Location out = locations->Out(); |
| 5457 | Location in = locations->InAt(0); |
| 5458 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5459 | case DataType::Type::kInt32: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5460 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 5461 | break; |
| 5462 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5463 | case DataType::Type::kInt64: |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5464 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 5465 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 5466 | break; |
| 5467 | |
| 5468 | default: |
| 5469 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5470 | } |
| 5471 | } |
| 5472 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5473 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5474 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5475 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5476 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5477 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5478 | } |
| 5479 | |
| 5480 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5481 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 5482 | } |
| 5483 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5484 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 5485 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5486 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5487 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5488 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5489 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5490 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5491 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5492 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5493 | case DataType::Type::kInt32: |
| 5494 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5495 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5496 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5497 | // Output overlaps because it is written before doing the low comparison. |
| 5498 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5499 | break; |
| 5500 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5501 | case DataType::Type::kFloat32: |
| 5502 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5503 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5504 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 5505 | locations->SetOut(Location::RequiresRegister()); |
| 5506 | break; |
| 5507 | } |
| 5508 | default: |
| 5509 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5510 | } |
| 5511 | } |
| 5512 | |
| 5513 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 5514 | LocationSummary* locations = compare->GetLocations(); |
| 5515 | vixl32::Register out = OutputRegister(compare); |
| 5516 | Location left = locations->InAt(0); |
| 5517 | Location right = locations->InAt(1); |
| 5518 | |
| 5519 | vixl32::Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5520 | vixl32::Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5521 | DataType::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 5522 | vixl32::Condition less_cond = vixl32::Condition::None(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5523 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5524 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5525 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5526 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5527 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5528 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5529 | case DataType::Type::kInt32: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5530 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 5531 | __ Mov(out, 0); |
| 5532 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 5533 | less_cond = lt; |
| 5534 | break; |
| 5535 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5536 | case DataType::Type::kInt64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5537 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5538 | __ B(lt, &less, /* is_far_target= */ false); |
| 5539 | __ B(gt, &greater, /* is_far_target= */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5540 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 5541 | __ Mov(out, 0); |
| 5542 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 5543 | less_cond = lo; |
| 5544 | break; |
| 5545 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5546 | case DataType::Type::kFloat32: |
| 5547 | case DataType::Type::kFloat64: { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5548 | __ Mov(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5549 | GenerateVcmp(compare, codegen_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5550 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 5551 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 5552 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 5553 | break; |
| 5554 | } |
| 5555 | default: |
| 5556 | LOG(FATAL) << "Unexpected compare type " << type; |
| 5557 | UNREACHABLE(); |
| 5558 | } |
| 5559 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5560 | __ B(eq, final_label, /* is_far_target= */ false); |
| 5561 | __ B(less_cond, &less, /* is_far_target= */ false); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5562 | |
| 5563 | __ Bind(&greater); |
| 5564 | __ Mov(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5565 | __ B(final_label); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5566 | |
| 5567 | __ Bind(&less); |
| 5568 | __ Mov(out, -1); |
| 5569 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5570 | if (done.IsReferenced()) { |
| 5571 | __ Bind(&done); |
| 5572 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5573 | } |
| 5574 | |
| 5575 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 5576 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5577 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5578 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 5579 | locations->SetInAt(i, Location::Any()); |
| 5580 | } |
| 5581 | locations->SetOut(Location::Any()); |
| 5582 | } |
| 5583 | |
| 5584 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5585 | LOG(FATAL) << "Unreachable"; |
| 5586 | } |
| 5587 | |
| 5588 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5589 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5590 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 5591 | switch (kind) { |
| 5592 | case MemBarrierKind::kAnyStore: |
| 5593 | case MemBarrierKind::kLoadAny: |
| 5594 | case MemBarrierKind::kAnyAny: { |
| 5595 | flavor = DmbOptions::ISH; |
| 5596 | break; |
| 5597 | } |
| 5598 | case MemBarrierKind::kStoreStore: { |
| 5599 | flavor = DmbOptions::ISHST; |
| 5600 | break; |
| 5601 | } |
| 5602 | default: |
| 5603 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5604 | } |
| 5605 | __ Dmb(flavor); |
| 5606 | } |
| 5607 | |
| 5608 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 5609 | uint32_t offset, |
| 5610 | vixl32::Register out_lo, |
| 5611 | vixl32::Register out_hi) { |
| 5612 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5613 | if (offset != 0) { |
| 5614 | vixl32::Register temp = temps.Acquire(); |
| 5615 | __ Add(temp, addr, offset); |
| 5616 | addr = temp; |
| 5617 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5618 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5619 | } |
| 5620 | |
| 5621 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 5622 | uint32_t offset, |
| 5623 | vixl32::Register value_lo, |
| 5624 | vixl32::Register value_hi, |
| 5625 | vixl32::Register temp1, |
| 5626 | vixl32::Register temp2, |
| 5627 | HInstruction* instruction) { |
| 5628 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5629 | vixl32::Label fail; |
| 5630 | if (offset != 0) { |
| 5631 | vixl32::Register temp = temps.Acquire(); |
| 5632 | __ Add(temp, addr, offset); |
| 5633 | addr = temp; |
| 5634 | } |
| 5635 | __ Bind(&fail); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5636 | { |
| 5637 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5638 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5639 | vixl32::kMaxInstructionSizeInBytes, |
| 5640 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5641 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5642 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5643 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 5644 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5645 | } |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5646 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5647 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5648 | } |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5649 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5650 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 5651 | HInstruction* instruction, const FieldInfo& field_info) { |
| 5652 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5653 | |
| 5654 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5655 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5656 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5657 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5658 | DataType::Type field_type = field_info.GetFieldType(); |
| 5659 | if (DataType::IsFloatingPointType(field_type)) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5660 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5661 | } else { |
| 5662 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5663 | } |
| 5664 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5665 | 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] | 5666 | bool generate_volatile = field_info.IsVolatile() |
| 5667 | && is_wide |
| 5668 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5669 | bool needs_write_barrier = |
| 5670 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5671 | // Temporary registers for the write barrier. |
| 5672 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 5673 | if (needs_write_barrier) { |
| 5674 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 5675 | locations->AddTemp(Location::RequiresRegister()); |
| 5676 | } else if (generate_volatile) { |
| 5677 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5678 | // - registers need to be consecutive |
| 5679 | // - the first register should be even but not R14. |
| 5680 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5681 | // revisit this if we ever enable ARM encoding. |
| 5682 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5683 | |
| 5684 | locations->AddTemp(Location::RequiresRegister()); |
| 5685 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5686 | if (field_type == DataType::Type::kFloat64) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5687 | // For doubles we need two more registers to copy the value. |
| 5688 | locations->AddTemp(LocationFrom(r2)); |
| 5689 | locations->AddTemp(LocationFrom(r3)); |
| 5690 | } |
| 5691 | } |
| 5692 | } |
| 5693 | |
| 5694 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 5695 | const FieldInfo& field_info, |
| 5696 | bool value_can_be_null) { |
| 5697 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5698 | |
| 5699 | LocationSummary* locations = instruction->GetLocations(); |
| 5700 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5701 | Location value = locations->InAt(1); |
| 5702 | |
| 5703 | bool is_volatile = field_info.IsVolatile(); |
| 5704 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5705 | DataType::Type field_type = field_info.GetFieldType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5706 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5707 | bool needs_write_barrier = |
| 5708 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5709 | |
| 5710 | if (is_volatile) { |
| 5711 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5712 | } |
| 5713 | |
| 5714 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5715 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5716 | case DataType::Type::kUint8: |
| 5717 | case DataType::Type::kInt8: |
| 5718 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5719 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5720 | case DataType::Type::kInt32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5721 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5722 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5723 | StoreOperandType operand_type = GetStoreOperandType(field_type); |
| 5724 | GetAssembler()->StoreToOffset(operand_type, RegisterFrom(value), base, offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5725 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5726 | break; |
| 5727 | } |
| 5728 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5729 | case DataType::Type::kReference: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5730 | vixl32::Register value_reg = RegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5731 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5732 | // Note that in the case where `value` is a null reference, |
| 5733 | // we do not enter this block, as a null reference does not |
| 5734 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5735 | DCHECK_EQ(field_type, DataType::Type::kReference); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5736 | value_reg = RegisterFrom(locations->GetTemp(0)); |
| 5737 | __ Mov(value_reg, RegisterFrom(value)); |
| 5738 | GetAssembler()->PoisonHeapReference(value_reg); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5739 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5740 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5741 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5742 | GetAssembler()->StoreToOffset(kStoreWord, value_reg, base, offset); |
| 5743 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5744 | break; |
| 5745 | } |
| 5746 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5747 | case DataType::Type::kInt64: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5748 | if (is_volatile && !atomic_ldrd_strd) { |
| 5749 | GenerateWideAtomicStore(base, |
| 5750 | offset, |
| 5751 | LowRegisterFrom(value), |
| 5752 | HighRegisterFrom(value), |
| 5753 | RegisterFrom(locations->GetTemp(0)), |
| 5754 | RegisterFrom(locations->GetTemp(1)), |
| 5755 | instruction); |
| 5756 | } else { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5757 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5758 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5759 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 5760 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5761 | } |
| 5762 | break; |
| 5763 | } |
| 5764 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5765 | case DataType::Type::kFloat32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5766 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5767 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5768 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5769 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5770 | break; |
| 5771 | } |
| 5772 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5773 | case DataType::Type::kFloat64: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5774 | vixl32::DRegister value_reg = DRegisterFrom(value); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5775 | if (is_volatile && !atomic_ldrd_strd) { |
| 5776 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 5777 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 5778 | |
| 5779 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 5780 | |
| 5781 | GenerateWideAtomicStore(base, |
| 5782 | offset, |
| 5783 | value_reg_lo, |
| 5784 | value_reg_hi, |
| 5785 | RegisterFrom(locations->GetTemp(2)), |
| 5786 | RegisterFrom(locations->GetTemp(3)), |
| 5787 | instruction); |
| 5788 | } else { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5789 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5790 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5791 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 5792 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5793 | } |
| 5794 | break; |
| 5795 | } |
| 5796 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5797 | case DataType::Type::kUint32: |
| 5798 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5799 | case DataType::Type::kVoid: |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5800 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5801 | UNREACHABLE(); |
| 5802 | } |
| 5803 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5804 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5805 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5806 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 5807 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 5808 | } |
| 5809 | |
| 5810 | if (is_volatile) { |
| 5811 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5812 | } |
| 5813 | } |
| 5814 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5815 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5816 | const FieldInfo& field_info) { |
| 5817 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5818 | |
| 5819 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5820 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == DataType::Type::kReference); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5821 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5822 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5823 | object_field_get_with_read_barrier |
| 5824 | ? LocationSummary::kCallOnSlowPath |
| 5825 | : LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5826 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5827 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5828 | } |
| 5829 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5830 | |
| 5831 | bool volatile_for_double = field_info.IsVolatile() |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5832 | && (field_info.GetFieldType() == DataType::Type::kFloat64) |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5833 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5834 | // The output overlaps in case of volatile long: we don't want the |
| 5835 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5836 | // object's location. Likewise, in the case of an object field get |
| 5837 | // with read barriers enabled, we do not want the load to overwrite |
| 5838 | // 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] | 5839 | bool overlap = |
| 5840 | (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) || |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5841 | object_field_get_with_read_barrier; |
| 5842 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5843 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5844 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5845 | } else { |
| 5846 | locations->SetOut(Location::RequiresRegister(), |
| 5847 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5848 | } |
| 5849 | if (volatile_for_double) { |
| 5850 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5851 | // - registers need to be consecutive |
| 5852 | // - the first register should be even but not R14. |
| 5853 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5854 | // revisit this if we ever enable ARM encoding. |
| 5855 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5856 | locations->AddTemp(Location::RequiresRegister()); |
| 5857 | locations->AddTemp(Location::RequiresRegister()); |
| 5858 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 5859 | // We need a temporary register for the read barrier load in |
| 5860 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier() |
| 5861 | // only if the offset is too big. |
| 5862 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5863 | locations->AddTemp(Location::RequiresRegister()); |
| 5864 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5865 | } |
| 5866 | } |
| 5867 | |
| 5868 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5869 | DCHECK(DataType::IsFloatingPointType(input->GetType())) << input->GetType(); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5870 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5871 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5872 | return Location::ConstantLocation(input->AsConstant()); |
| 5873 | } else { |
| 5874 | return Location::RequiresFpuRegister(); |
| 5875 | } |
| 5876 | } |
| 5877 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5878 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5879 | Opcode opcode) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5880 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5881 | if (constant->IsConstant() && |
| 5882 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5883 | return Location::ConstantLocation(constant->AsConstant()); |
| 5884 | } |
| 5885 | return Location::RequiresRegister(); |
| 5886 | } |
| 5887 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5888 | static bool CanEncode32BitConstantAsImmediate( |
| 5889 | CodeGeneratorARMVIXL* codegen, |
| 5890 | uint32_t value, |
| 5891 | Opcode opcode, |
| 5892 | vixl32::FlagsUpdate flags_update = vixl32::FlagsUpdate::DontCare) { |
| 5893 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
| 5894 | if (assembler->ShifterOperandCanHold(opcode, value, flags_update)) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5895 | return true; |
| 5896 | } |
| 5897 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5898 | uint32_t neg_value = 0; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5899 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5900 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5901 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5902 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5903 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5904 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5905 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5906 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5907 | default: |
| 5908 | return false; |
| 5909 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5910 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5911 | if (assembler->ShifterOperandCanHold(neg_opcode, neg_value, flags_update)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5912 | return true; |
| 5913 | } |
| 5914 | |
| 5915 | return opcode == AND && IsPowerOfTwo(value + 1); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5916 | } |
| 5917 | |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5918 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, Opcode opcode) { |
| 5919 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5920 | if (DataType::Is64BitType(input_cst->GetType())) { |
| 5921 | Opcode high_opcode = opcode; |
| 5922 | vixl32::FlagsUpdate low_flags_update = vixl32::FlagsUpdate::DontCare; |
| 5923 | switch (opcode) { |
| 5924 | case SUB: |
| 5925 | // Flip the operation to an ADD. |
| 5926 | value = -value; |
| 5927 | opcode = ADD; |
| 5928 | FALLTHROUGH_INTENDED; |
| 5929 | case ADD: |
| 5930 | if (Low32Bits(value) == 0u) { |
| 5931 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), opcode); |
| 5932 | } |
| 5933 | high_opcode = ADC; |
| 5934 | low_flags_update = vixl32::FlagsUpdate::SetFlags; |
| 5935 | break; |
| 5936 | default: |
| 5937 | break; |
| 5938 | } |
| 5939 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), high_opcode) && |
| 5940 | CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode, low_flags_update); |
| 5941 | } else { |
| 5942 | return CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode); |
| 5943 | } |
| 5944 | } |
| 5945 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5946 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5947 | const FieldInfo& field_info) { |
| 5948 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5949 | |
| 5950 | LocationSummary* locations = instruction->GetLocations(); |
| 5951 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5952 | Location out = locations->Out(); |
| 5953 | bool is_volatile = field_info.IsVolatile(); |
| 5954 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5955 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5956 | DataType::Type load_type = instruction->GetType(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5957 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5958 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5959 | switch (load_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5960 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5961 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5962 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5963 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5964 | case DataType::Type::kInt16: |
| 5965 | case DataType::Type::kInt32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5966 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5967 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5968 | LoadOperandType operand_type = GetLoadOperandType(load_type); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5969 | GetAssembler()->LoadFromOffset(operand_type, RegisterFrom(out), base, offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5970 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5971 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5972 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5973 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5974 | case DataType::Type::kReference: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5975 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5976 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 5977 | Location maybe_temp = (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location(); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5978 | // Note that a potential implicit null check is handled in this |
| 5979 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier call. |
| 5980 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5981 | instruction, out, base, offset, maybe_temp, /* needs_null_check= */ true); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5982 | if (is_volatile) { |
| 5983 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5984 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5985 | } else { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5986 | { |
| 5987 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5988 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5989 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
| 5990 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5991 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5992 | if (is_volatile) { |
| 5993 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5994 | } |
| 5995 | // If read barriers are enabled, emit read barriers other than |
| 5996 | // Baker's using a slow path (and also unpoison the loaded |
| 5997 | // reference, if heap poisoning is enabled). |
| 5998 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, locations->InAt(0), offset); |
| 5999 | } |
| 6000 | break; |
| 6001 | } |
| 6002 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6003 | case DataType::Type::kInt64: { |
| 6004 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6005 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6006 | if (is_volatile && !atomic_ldrd_strd) { |
| 6007 | GenerateWideAtomicLoad(base, offset, LowRegisterFrom(out), HighRegisterFrom(out)); |
| 6008 | } else { |
| 6009 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out), base, offset); |
| 6010 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6011 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6012 | break; |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6013 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6014 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6015 | case DataType::Type::kFloat32: { |
| 6016 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6017 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6018 | GetAssembler()->LoadSFromOffset(SRegisterFrom(out), base, offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6019 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6020 | break; |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6021 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6022 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6023 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6024 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6025 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6026 | vixl32::DRegister out_dreg = DRegisterFrom(out); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6027 | if (is_volatile && !atomic_ldrd_strd) { |
| 6028 | vixl32::Register lo = RegisterFrom(locations->GetTemp(0)); |
| 6029 | vixl32::Register hi = RegisterFrom(locations->GetTemp(1)); |
| 6030 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6031 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6032 | __ Vmov(out_dreg, lo, hi); |
| 6033 | } else { |
| 6034 | GetAssembler()->LoadDFromOffset(out_dreg, base, offset); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6035 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6036 | } |
| 6037 | break; |
| 6038 | } |
| 6039 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6040 | case DataType::Type::kUint32: |
| 6041 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6042 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6043 | LOG(FATAL) << "Unreachable type " << load_type; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6044 | UNREACHABLE(); |
| 6045 | } |
| 6046 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6047 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6048 | if (load_type == DataType::Type::kReference) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6049 | // Memory barriers, in the case of references, are also handled |
| 6050 | // in the previous switch statement. |
| 6051 | } else { |
| 6052 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6053 | } |
| 6054 | } |
| 6055 | } |
| 6056 | |
| 6057 | void LocationsBuilderARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6058 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6059 | } |
| 6060 | |
| 6061 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 6062 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 6063 | } |
| 6064 | |
| 6065 | void LocationsBuilderARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6066 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6067 | } |
| 6068 | |
| 6069 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 6070 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6071 | } |
| 6072 | |
| 6073 | void LocationsBuilderARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6074 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6075 | } |
| 6076 | |
| 6077 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 6078 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 6079 | } |
| 6080 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6081 | void LocationsBuilderARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6082 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 6083 | } |
| 6084 | |
| 6085 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 6086 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 6087 | } |
| 6088 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 6089 | void LocationsBuilderARMVIXL::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6090 | codegen_->CreateStringBuilderAppendLocations(instruction, LocationFrom(r0)); |
| 6091 | } |
| 6092 | |
| 6093 | void InstructionCodeGeneratorARMVIXL::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6094 | __ Mov(r0, instruction->GetFormat()->GetValue()); |
| 6095 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 6096 | } |
| 6097 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 6098 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 6099 | HUnresolvedInstanceFieldGet* instruction) { |
| 6100 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6101 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6102 | instruction, instruction->GetFieldType(), calling_convention); |
| 6103 | } |
| 6104 | |
| 6105 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 6106 | HUnresolvedInstanceFieldGet* instruction) { |
| 6107 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6108 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6109 | instruction->GetFieldType(), |
| 6110 | instruction->GetFieldIndex(), |
| 6111 | instruction->GetDexPc(), |
| 6112 | calling_convention); |
| 6113 | } |
| 6114 | |
| 6115 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 6116 | HUnresolvedInstanceFieldSet* instruction) { |
| 6117 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6118 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6119 | instruction, instruction->GetFieldType(), calling_convention); |
| 6120 | } |
| 6121 | |
| 6122 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 6123 | HUnresolvedInstanceFieldSet* instruction) { |
| 6124 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6125 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6126 | instruction->GetFieldType(), |
| 6127 | instruction->GetFieldIndex(), |
| 6128 | instruction->GetDexPc(), |
| 6129 | calling_convention); |
| 6130 | } |
| 6131 | |
| 6132 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldGet( |
| 6133 | HUnresolvedStaticFieldGet* instruction) { |
| 6134 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6135 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6136 | instruction, instruction->GetFieldType(), calling_convention); |
| 6137 | } |
| 6138 | |
| 6139 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldGet( |
| 6140 | HUnresolvedStaticFieldGet* instruction) { |
| 6141 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6142 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6143 | instruction->GetFieldType(), |
| 6144 | instruction->GetFieldIndex(), |
| 6145 | instruction->GetDexPc(), |
| 6146 | calling_convention); |
| 6147 | } |
| 6148 | |
| 6149 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldSet( |
| 6150 | HUnresolvedStaticFieldSet* instruction) { |
| 6151 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6152 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6153 | instruction, instruction->GetFieldType(), calling_convention); |
| 6154 | } |
| 6155 | |
| 6156 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldSet( |
| 6157 | HUnresolvedStaticFieldSet* instruction) { |
| 6158 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 6159 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6160 | instruction->GetFieldType(), |
| 6161 | instruction->GetFieldIndex(), |
| 6162 | instruction->GetDexPc(), |
| 6163 | calling_convention); |
| 6164 | } |
| 6165 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6166 | void LocationsBuilderARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6167 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6168 | locations->SetInAt(0, Location::RequiresRegister()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6169 | } |
| 6170 | |
| 6171 | void CodeGeneratorARMVIXL::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6172 | if (CanMoveNullCheckToUser(instruction)) { |
| 6173 | return; |
| 6174 | } |
| 6175 | |
| 6176 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6177 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6178 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6179 | vixl32::kMaxInstructionSizeInBytes, |
| 6180 | CodeBufferCheckScope::kMaximumSize); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6181 | __ ldr(temps.Acquire(), MemOperand(InputRegisterAt(instruction, 0))); |
| 6182 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 6183 | } |
| 6184 | |
| 6185 | void CodeGeneratorARMVIXL::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 6186 | NullCheckSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6187 | new (GetScopedAllocator()) NullCheckSlowPathARMVIXL(instruction); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6188 | AddSlowPath(slow_path); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6189 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6190 | } |
| 6191 | |
| 6192 | void InstructionCodeGeneratorARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| 6193 | codegen_->GenerateNullCheck(instruction); |
| 6194 | } |
| 6195 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6196 | void CodeGeneratorARMVIXL::LoadFromShiftedRegOffset(DataType::Type type, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6197 | Location out_loc, |
| 6198 | vixl32::Register base, |
| 6199 | vixl32::Register reg_index, |
| 6200 | vixl32::Condition cond) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6201 | uint32_t shift_count = DataType::SizeShift(type); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6202 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 6203 | |
| 6204 | switch (type) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6205 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6206 | case DataType::Type::kUint8: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6207 | __ Ldrb(cond, RegisterFrom(out_loc), mem_address); |
| 6208 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6209 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6210 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 6211 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6212 | case DataType::Type::kUint16: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6213 | __ Ldrh(cond, RegisterFrom(out_loc), mem_address); |
| 6214 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6215 | case DataType::Type::kInt16: |
| 6216 | __ Ldrsh(cond, RegisterFrom(out_loc), mem_address); |
| 6217 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6218 | case DataType::Type::kReference: |
| 6219 | case DataType::Type::kInt32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6220 | __ Ldr(cond, RegisterFrom(out_loc), mem_address); |
| 6221 | break; |
| 6222 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6223 | case DataType::Type::kInt64: |
| 6224 | case DataType::Type::kFloat32: |
| 6225 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6226 | default: |
| 6227 | LOG(FATAL) << "Unreachable type " << type; |
| 6228 | UNREACHABLE(); |
| 6229 | } |
| 6230 | } |
| 6231 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6232 | void CodeGeneratorARMVIXL::StoreToShiftedRegOffset(DataType::Type type, |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6233 | Location loc, |
| 6234 | vixl32::Register base, |
| 6235 | vixl32::Register reg_index, |
| 6236 | vixl32::Condition cond) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6237 | uint32_t shift_count = DataType::SizeShift(type); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6238 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 6239 | |
| 6240 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6241 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6242 | case DataType::Type::kUint8: |
| 6243 | case DataType::Type::kInt8: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6244 | __ Strb(cond, RegisterFrom(loc), mem_address); |
| 6245 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6246 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6247 | case DataType::Type::kInt16: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6248 | __ Strh(cond, RegisterFrom(loc), mem_address); |
| 6249 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6250 | case DataType::Type::kReference: |
| 6251 | case DataType::Type::kInt32: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6252 | __ Str(cond, RegisterFrom(loc), mem_address); |
| 6253 | break; |
| 6254 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6255 | case DataType::Type::kInt64: |
| 6256 | case DataType::Type::kFloat32: |
| 6257 | case DataType::Type::kFloat64: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6258 | default: |
| 6259 | LOG(FATAL) << "Unreachable type " << type; |
| 6260 | UNREACHABLE(); |
| 6261 | } |
| 6262 | } |
| 6263 | |
| 6264 | void LocationsBuilderARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| 6265 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6266 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6267 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6268 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 6269 | object_array_get_with_read_barrier |
| 6270 | ? LocationSummary::kCallOnSlowPath |
| 6271 | : LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6272 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6273 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6274 | } |
| 6275 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6276 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6277 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6278 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6279 | } else { |
| 6280 | // The output overlaps in the case of an object array get with |
| 6281 | // read barriers enabled: we do not want the move to overwrite the |
| 6282 | // array's location, as we need it to emit the read barrier. |
| 6283 | locations->SetOut( |
| 6284 | Location::RequiresRegister(), |
| 6285 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 6286 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6287 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6288 | if (instruction->GetIndex()->IsConstant()) { |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6289 | // Array loads with constant index are treated as field loads. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6290 | // We need a temporary register for the read barrier load in |
| 6291 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier() |
| 6292 | // only if the offset is too big. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6293 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 6294 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6295 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6296 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6297 | locations->AddTemp(Location::RequiresRegister()); |
| 6298 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6299 | } else { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6300 | // We need a non-scratch temporary for the array data pointer in |
| 6301 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(). |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6302 | locations->AddTemp(Location::RequiresRegister()); |
| 6303 | } |
| 6304 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6305 | // Also need a temporary for String compression feature. |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6306 | locations->AddTemp(Location::RequiresRegister()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6307 | } |
| 6308 | } |
| 6309 | |
| 6310 | void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6311 | LocationSummary* locations = instruction->GetLocations(); |
| 6312 | Location obj_loc = locations->InAt(0); |
| 6313 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6314 | Location index = locations->InAt(1); |
| 6315 | Location out_loc = locations->Out(); |
| 6316 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6317 | DataType::Type type = instruction->GetType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6318 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 6319 | instruction->IsStringCharAt(); |
| 6320 | HInstruction* array_instr = instruction->GetArray(); |
| 6321 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6322 | |
| 6323 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6324 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6325 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6326 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6327 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6328 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6329 | case DataType::Type::kInt32: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6330 | vixl32::Register length; |
| 6331 | if (maybe_compressed_char_at) { |
| 6332 | length = RegisterFrom(locations->GetTemp(0)); |
| 6333 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6334 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6335 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6336 | GetAssembler()->LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 6337 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6338 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6339 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6340 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6341 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6342 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6343 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6344 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6345 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6346 | "Expecting 0=compressed, 1=uncompressed"); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6347 | __ B(cs, &uncompressed_load, /* is_far_target= */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6348 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, |
| 6349 | RegisterFrom(out_loc), |
| 6350 | obj, |
| 6351 | data_offset + const_index); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6352 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6353 | __ Bind(&uncompressed_load); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6354 | GetAssembler()->LoadFromOffset(GetLoadOperandType(DataType::Type::kUint16), |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6355 | RegisterFrom(out_loc), |
| 6356 | obj, |
| 6357 | data_offset + (const_index << 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6358 | if (done.IsReferenced()) { |
| 6359 | __ Bind(&done); |
| 6360 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6361 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6362 | uint32_t full_offset = data_offset + (const_index << DataType::SizeShift(type)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6363 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6364 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6365 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6366 | LoadOperandType load_type = GetLoadOperandType(type); |
| 6367 | GetAssembler()->LoadFromOffset(load_type, RegisterFrom(out_loc), obj, full_offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6368 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6369 | } |
| 6370 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6371 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6372 | vixl32::Register temp = temps.Acquire(); |
| 6373 | |
| 6374 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6375 | // We do not need to compute the intermediate address from the array: the |
| 6376 | // input instruction has done it already. See the comment in |
| 6377 | // `TryExtractArrayAccessAddress()`. |
| 6378 | if (kIsDebugBuild) { |
| 6379 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6380 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6381 | } |
| 6382 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6383 | } else { |
| 6384 | __ Add(temp, obj, data_offset); |
| 6385 | } |
| 6386 | if (maybe_compressed_char_at) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6387 | vixl32::Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6388 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6389 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6390 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6391 | "Expecting 0=compressed, 1=uncompressed"); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6392 | __ B(cs, &uncompressed_load, /* is_far_target= */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6393 | __ Ldrb(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 0)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6394 | __ B(final_label); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6395 | __ Bind(&uncompressed_load); |
| 6396 | __ Ldrh(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6397 | if (done.IsReferenced()) { |
| 6398 | __ Bind(&done); |
| 6399 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6400 | } else { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6401 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6402 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6403 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6404 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6405 | } |
| 6406 | } |
| 6407 | break; |
| 6408 | } |
| 6409 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6410 | case DataType::Type::kReference: { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6411 | // The read barrier instrumentation of object ArrayGet |
| 6412 | // instructions does not support the HIntermediateAddress |
| 6413 | // instruction. |
| 6414 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 6415 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6416 | static_assert( |
| 6417 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6418 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6419 | // /* HeapReference<Object> */ out = |
| 6420 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6421 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6422 | // Note that a potential implicit null check is handled in this |
| 6423 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6424 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 6425 | if (index.IsConstant()) { |
| 6426 | // 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] | 6427 | Location maybe_temp = |
| 6428 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6429 | data_offset += Int32ConstantFrom(index) << DataType::SizeShift(type); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6430 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6431 | out_loc, |
| 6432 | obj, |
| 6433 | data_offset, |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 6434 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6435 | /* needs_null_check= */ false); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6436 | } else { |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 6437 | Location temp = locations->GetTemp(0); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6438 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6439 | out_loc, obj, data_offset, index, temp, /* needs_null_check= */ false); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6440 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6441 | } else { |
| 6442 | vixl32::Register out = OutputRegister(instruction); |
| 6443 | if (index.IsConstant()) { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6444 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| 6445 | { |
| 6446 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6447 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6448 | GetAssembler()->LoadFromOffset(kLoadWord, out, obj, offset); |
| 6449 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6450 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6451 | // If read barriers are enabled, emit read barriers other than |
| 6452 | // Baker's using a slow path (and also unpoison the loaded |
| 6453 | // reference, if heap poisoning is enabled). |
| 6454 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6455 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6456 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6457 | vixl32::Register temp = temps.Acquire(); |
| 6458 | |
| 6459 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6460 | // We do not need to compute the intermediate address from the array: the |
| 6461 | // input instruction has done it already. See the comment in |
| 6462 | // `TryExtractArrayAccessAddress()`. |
| 6463 | if (kIsDebugBuild) { |
| 6464 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6465 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6466 | } |
| 6467 | temp = obj; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6468 | } else { |
| 6469 | __ Add(temp, obj, data_offset); |
| 6470 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6471 | { |
| 6472 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6473 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6474 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| 6475 | temps.Close(); |
| 6476 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6477 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6478 | // If read barriers are enabled, emit read barriers other than |
| 6479 | // Baker's using a slow path (and also unpoison the loaded |
| 6480 | // reference, if heap poisoning is enabled). |
| 6481 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6482 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6483 | } |
| 6484 | } |
| 6485 | break; |
| 6486 | } |
| 6487 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6488 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6489 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6490 | // As two macro instructions can be emitted the max size is doubled. |
| 6491 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6492 | if (index.IsConstant()) { |
| 6493 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6494 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6495 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), obj, offset); |
| 6496 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6497 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6498 | vixl32::Register temp = temps.Acquire(); |
| 6499 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6500 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), temp, data_offset); |
| 6501 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6502 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6503 | break; |
| 6504 | } |
| 6505 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6506 | case DataType::Type::kFloat32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6507 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6508 | // As two macro instructions can be emitted the max size is doubled. |
| 6509 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6510 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 6511 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6512 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6513 | GetAssembler()->LoadSFromOffset(out, obj, offset); |
| 6514 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6515 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6516 | vixl32::Register temp = temps.Acquire(); |
| 6517 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6518 | GetAssembler()->LoadSFromOffset(out, temp, data_offset); |
| 6519 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6520 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6521 | break; |
| 6522 | } |
| 6523 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6524 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6525 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6526 | // As two macro instructions can be emitted the max size is doubled. |
| 6527 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6528 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6529 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6530 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), obj, offset); |
| 6531 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6532 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6533 | vixl32::Register temp = temps.Acquire(); |
| 6534 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6535 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), temp, data_offset); |
| 6536 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6537 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6538 | break; |
| 6539 | } |
| 6540 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6541 | case DataType::Type::kUint32: |
| 6542 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6543 | case DataType::Type::kVoid: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6544 | LOG(FATAL) << "Unreachable type " << type; |
| 6545 | UNREACHABLE(); |
| 6546 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6547 | } |
| 6548 | |
| 6549 | void LocationsBuilderARMVIXL::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6550 | DataType::Type value_type = instruction->GetComponentType(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6551 | |
| 6552 | bool needs_write_barrier = |
| 6553 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6554 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6555 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6556 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6557 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6558 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6559 | |
| 6560 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6561 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6562 | if (DataType::IsFloatingPointType(value_type)) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6563 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 6564 | } else { |
| 6565 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6566 | } |
| 6567 | if (needs_write_barrier) { |
| 6568 | // Temporary registers for the write barrier. |
| 6569 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6570 | locations->AddTemp(Location::RequiresRegister()); |
| 6571 | } |
| 6572 | } |
| 6573 | |
| 6574 | void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6575 | LocationSummary* locations = instruction->GetLocations(); |
| 6576 | vixl32::Register array = InputRegisterAt(instruction, 0); |
| 6577 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6578 | DataType::Type value_type = instruction->GetComponentType(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6579 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6580 | bool needs_write_barrier = |
| 6581 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6582 | uint32_t data_offset = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6583 | mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6584 | Location value_loc = locations->InAt(2); |
| 6585 | HInstruction* array_instr = instruction->GetArray(); |
| 6586 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6587 | |
| 6588 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6589 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6590 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6591 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6592 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6593 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6594 | case DataType::Type::kInt32: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6595 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6596 | int32_t const_index = Int32ConstantFrom(index); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6597 | uint32_t full_offset = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6598 | data_offset + (const_index << DataType::SizeShift(value_type)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6599 | StoreOperandType store_type = GetStoreOperandType(value_type); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6600 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6601 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6602 | GetAssembler()->StoreToOffset(store_type, RegisterFrom(value_loc), array, full_offset); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6603 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6604 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6605 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6606 | vixl32::Register temp = temps.Acquire(); |
| 6607 | |
| 6608 | if (has_intermediate_address) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6609 | // We do not need to compute the intermediate address from the array: the |
| 6610 | // input instruction has done it already. See the comment in |
| 6611 | // `TryExtractArrayAccessAddress()`. |
| 6612 | if (kIsDebugBuild) { |
| 6613 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6614 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6615 | } |
| 6616 | temp = array; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6617 | } else { |
| 6618 | __ Add(temp, array, data_offset); |
| 6619 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6620 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6621 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6622 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6623 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6624 | } |
| 6625 | break; |
| 6626 | } |
| 6627 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6628 | case DataType::Type::kReference: { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6629 | vixl32::Register value = RegisterFrom(value_loc); |
| 6630 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6631 | // See the comment in instruction_simplifier_shared.cc. |
| 6632 | DCHECK(!has_intermediate_address); |
| 6633 | |
| 6634 | if (instruction->InputAt(2)->IsNullConstant()) { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6635 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6636 | // As two macro instructions can be emitted the max size is doubled. |
| 6637 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6638 | // Just setting null. |
| 6639 | if (index.IsConstant()) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6640 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6641 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6642 | } else { |
| 6643 | DCHECK(index.IsRegister()) << index; |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6644 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6645 | vixl32::Register temp = temps.Acquire(); |
| 6646 | __ Add(temp, array, data_offset); |
| 6647 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6648 | } |
| 6649 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6650 | DCHECK(!needs_write_barrier); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6651 | DCHECK(!needs_type_check); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6652 | break; |
| 6653 | } |
| 6654 | |
| 6655 | DCHECK(needs_write_barrier); |
| 6656 | Location temp1_loc = locations->GetTemp(0); |
| 6657 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 6658 | Location temp2_loc = locations->GetTemp(1); |
| 6659 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6660 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6661 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 6662 | vixl32::Label do_store; |
| 6663 | if (can_value_be_null) { |
| 6664 | __ CompareAndBranchIfZero(value, &do_store, /* is_far_target= */ false); |
| 6665 | } |
| 6666 | |
| 6667 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 6668 | if (needs_type_check) { |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6669 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARMVIXL(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6670 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6671 | |
| 6672 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6673 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6674 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6675 | |
| 6676 | // Note that when read barriers are enabled, the type checks |
| 6677 | // are performed without read barriers. This is fine, even in |
| 6678 | // the case where a class object is in the from-space after |
| 6679 | // the flip, as a comparison involving such a type would not |
| 6680 | // produce a false positive; it may of course produce a false |
| 6681 | // negative, in which case we would take the ArraySet slow |
| 6682 | // path. |
| 6683 | |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6684 | { |
| 6685 | // Ensure we record the pc position immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6686 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6687 | vixl32::kMaxInstructionSizeInBytes, |
| 6688 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6689 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6690 | __ ldr(temp1, MemOperand(array, class_offset)); |
| 6691 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6692 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6693 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6694 | |
| 6695 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6696 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6697 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6698 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6699 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6700 | // nor `temp2`, as we are comparing two poisoned references. |
| 6701 | __ Cmp(temp1, temp2); |
| 6702 | |
| 6703 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6704 | vixl32::Label do_put; |
| 6705 | __ B(eq, &do_put, /* is_far_target= */ false); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6706 | // If heap poisoning is enabled, the `temp1` reference has |
| 6707 | // not been unpoisoned yet; unpoison it now. |
| 6708 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6709 | |
| 6710 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6711 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6712 | // If heap poisoning is enabled, no need to unpoison |
| 6713 | // `temp1`, as we are comparing against null below. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6714 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6715 | __ Bind(&do_put); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6716 | } else { |
| 6717 | __ B(ne, slow_path->GetEntryLabel()); |
| 6718 | } |
| 6719 | } |
| 6720 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6721 | codegen_->MarkGCCard(temp1, temp2, array, value, /* can_be_null= */ false); |
| 6722 | |
| 6723 | if (can_value_be_null) { |
| 6724 | DCHECK(do_store.IsReferenced()); |
| 6725 | __ Bind(&do_store); |
| 6726 | } |
| 6727 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6728 | vixl32::Register source = value; |
| 6729 | if (kPoisonHeapReferences) { |
| 6730 | // Note that in the case where `value` is a null reference, |
| 6731 | // we do not enter this block, as a null reference does not |
| 6732 | // need poisoning. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6733 | DCHECK_EQ(value_type, DataType::Type::kReference); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6734 | __ Mov(temp1, value); |
| 6735 | GetAssembler()->PoisonHeapReference(temp1); |
| 6736 | source = temp1; |
| 6737 | } |
| 6738 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6739 | { |
| 6740 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6741 | // As two macro instructions can be emitted the max size is doubled. |
| 6742 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| 6743 | if (index.IsConstant()) { |
| 6744 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| 6745 | GetAssembler()->StoreToOffset(kStoreWord, source, array, offset); |
| 6746 | } else { |
| 6747 | DCHECK(index.IsRegister()) << index; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6748 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6749 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6750 | vixl32::Register temp = temps.Acquire(); |
| 6751 | __ Add(temp, array, data_offset); |
| 6752 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6753 | LocationFrom(source), |
| 6754 | temp, |
| 6755 | RegisterFrom(index)); |
| 6756 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6757 | |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6758 | if (can_value_be_null || !needs_type_check) { |
| 6759 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6760 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6761 | } |
| 6762 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6763 | if (slow_path != nullptr) { |
| 6764 | __ Bind(slow_path->GetExitLabel()); |
| 6765 | } |
| 6766 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6767 | break; |
| 6768 | } |
| 6769 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6770 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6771 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6772 | // As two macro instructions can be emitted the max size is doubled. |
| 6773 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6774 | Location value = locations->InAt(2); |
| 6775 | if (index.IsConstant()) { |
| 6776 | size_t offset = |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6777 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6778 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), array, offset); |
| 6779 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6780 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6781 | vixl32::Register temp = temps.Acquire(); |
| 6782 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6783 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), temp, data_offset); |
| 6784 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6785 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6786 | break; |
| 6787 | } |
| 6788 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6789 | case DataType::Type::kFloat32: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6790 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6791 | // As two macro instructions can be emitted the max size is doubled. |
| 6792 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6793 | Location value = locations->InAt(2); |
| 6794 | DCHECK(value.IsFpuRegister()); |
| 6795 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6796 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6797 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), array, offset); |
| 6798 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6799 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6800 | vixl32::Register temp = temps.Acquire(); |
| 6801 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6802 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), temp, data_offset); |
| 6803 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6804 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6805 | break; |
| 6806 | } |
| 6807 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6808 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6809 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6810 | // As two macro instructions can be emitted the max size is doubled. |
| 6811 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6812 | Location value = locations->InAt(2); |
| 6813 | DCHECK(value.IsFpuRegisterPair()); |
| 6814 | if (index.IsConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6815 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6816 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), array, offset); |
| 6817 | } else { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6818 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6819 | vixl32::Register temp = temps.Acquire(); |
| 6820 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6821 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), temp, data_offset); |
| 6822 | } |
Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6823 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6824 | break; |
| 6825 | } |
| 6826 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6827 | case DataType::Type::kUint32: |
| 6828 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6829 | case DataType::Type::kVoid: |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6830 | LOG(FATAL) << "Unreachable type " << value_type; |
| 6831 | UNREACHABLE(); |
| 6832 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6833 | } |
| 6834 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6835 | void LocationsBuilderARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6836 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6837 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6838 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6839 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6840 | } |
| 6841 | |
| 6842 | void InstructionCodeGeneratorARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6843 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| 6844 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6845 | vixl32::Register out = OutputRegister(instruction); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6846 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6847 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6848 | vixl32::kMaxInstructionSizeInBytes, |
| 6849 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6850 | __ ldr(out, MemOperand(obj, offset)); |
| 6851 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6852 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6853 | // Mask out compression flag from String's array length. |
| 6854 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6855 | __ Lsr(out, out, 1u); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6856 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6857 | } |
| 6858 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6859 | void LocationsBuilderARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6860 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6861 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6862 | |
| 6863 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6864 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6865 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6866 | } |
| 6867 | |
| 6868 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6869 | vixl32::Register out = OutputRegister(instruction); |
| 6870 | vixl32::Register first = InputRegisterAt(instruction, 0); |
| 6871 | Location second = instruction->GetLocations()->InAt(1); |
| 6872 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6873 | if (second.IsRegister()) { |
| 6874 | __ Add(out, first, RegisterFrom(second)); |
| 6875 | } else { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6876 | __ Add(out, first, Int32ConstantFrom(second)); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6877 | } |
| 6878 | } |
| 6879 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 6880 | void LocationsBuilderARMVIXL::VisitIntermediateAddressIndex( |
| 6881 | HIntermediateAddressIndex* instruction) { |
| 6882 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6883 | } |
| 6884 | |
| 6885 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddressIndex( |
| 6886 | HIntermediateAddressIndex* instruction) { |
| 6887 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6888 | } |
| 6889 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6890 | void LocationsBuilderARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6891 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6892 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6893 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6894 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 6895 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6896 | |
| 6897 | HInstruction* index = instruction->InputAt(0); |
| 6898 | HInstruction* length = instruction->InputAt(1); |
| 6899 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6900 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6901 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6902 | // locations. |
| 6903 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6904 | locations->SetInAt(0, both_const |
| 6905 | ? Location::ConstantLocation(index->AsConstant()) |
| 6906 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6907 | locations->SetInAt(1, both_const |
| 6908 | ? Location::ConstantLocation(length->AsConstant()) |
| 6909 | : ArmEncodableConstantOrRegister(length, CMP)); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6910 | } |
| 6911 | |
| 6912 | void InstructionCodeGeneratorARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6913 | LocationSummary* locations = instruction->GetLocations(); |
| 6914 | Location index_loc = locations->InAt(0); |
| 6915 | Location length_loc = locations->InAt(1); |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6916 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6917 | if (length_loc.IsConstant()) { |
| 6918 | int32_t length = Int32ConstantFrom(length_loc); |
| 6919 | if (index_loc.IsConstant()) { |
| 6920 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6921 | int32_t index = Int32ConstantFrom(index_loc); |
| 6922 | if (index < 0 || index >= length) { |
| 6923 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6924 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6925 | codegen_->AddSlowPath(slow_path); |
| 6926 | __ B(slow_path->GetEntryLabel()); |
| 6927 | } else { |
| 6928 | // Some optimization after BCE may have generated this, and we should not |
| 6929 | // generate a bounds check if it is a valid range. |
| 6930 | } |
| 6931 | return; |
| 6932 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6933 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 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 | __ Cmp(RegisterFrom(index_loc), length); |
| 6937 | codegen_->AddSlowPath(slow_path); |
| 6938 | __ B(hs, slow_path->GetEntryLabel()); |
| 6939 | } else { |
| 6940 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6941 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6942 | __ Cmp(RegisterFrom(length_loc), InputOperandAt(instruction, 0)); |
| 6943 | codegen_->AddSlowPath(slow_path); |
| 6944 | __ B(ls, slow_path->GetEntryLabel()); |
| 6945 | } |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6946 | } |
| 6947 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6948 | void CodeGeneratorARMVIXL::MarkGCCard(vixl32::Register temp, |
| 6949 | vixl32::Register card, |
| 6950 | vixl32::Register object, |
| 6951 | vixl32::Register value, |
| 6952 | bool can_be_null) { |
| 6953 | vixl32::Label is_null; |
| 6954 | if (can_be_null) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6955 | __ CompareAndBranchIfZero(value, &is_null); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6956 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 6957 | // Load the address of the card table into `card`. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6958 | GetAssembler()->LoadFromOffset( |
| 6959 | kLoadWord, card, tr, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 6960 | // Calculate the offset (in the card table) of the card corresponding to |
| 6961 | // `object`. |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 6962 | __ Lsr(temp, object, Operand::From(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 6963 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 6964 | // `object`'s card. |
| 6965 | // |
| 6966 | // Register `card` contains the address of the card table. Note that the card |
| 6967 | // table's base is biased during its creation so that it always starts at an |
| 6968 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 6969 | // art::gc::accounting::CardTable::Create). Therefore the STRB instruction |
| 6970 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 6971 | // (located at `card + object >> kCardShift`). |
| 6972 | // |
| 6973 | // This dual use of the value in register `card` (1. to calculate the location |
| 6974 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 6975 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6976 | __ Strb(card, MemOperand(card, temp)); |
| 6977 | if (can_be_null) { |
| 6978 | __ Bind(&is_null); |
| 6979 | } |
| 6980 | } |
| 6981 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6982 | void LocationsBuilderARMVIXL::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6983 | LOG(FATAL) << "Unreachable"; |
| 6984 | } |
| 6985 | |
| 6986 | void InstructionCodeGeneratorARMVIXL::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6987 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6988 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6989 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6990 | // The back edge will generate the suspend check. |
| 6991 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6992 | } |
| 6993 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6994 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6995 | } |
| 6996 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6997 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6998 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6999 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7000 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7001 | } |
| 7002 | |
| 7003 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 7004 | HBasicBlock* block = instruction->GetBlock(); |
| 7005 | if (block->GetLoopInformation() != nullptr) { |
| 7006 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 7007 | // The back edge will generate the suspend check. |
| 7008 | return; |
| 7009 | } |
| 7010 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 7011 | // The goto will generate the suspend check. |
| 7012 | return; |
| 7013 | } |
| 7014 | GenerateSuspendCheck(instruction, nullptr); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7015 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 14); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7016 | } |
| 7017 | |
| 7018 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 7019 | HBasicBlock* successor) { |
| 7020 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 7021 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 7022 | if (slow_path == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7023 | slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7024 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7025 | instruction->SetSlowPath(slow_path); |
| 7026 | codegen_->AddSlowPath(slow_path); |
| 7027 | if (successor != nullptr) { |
| 7028 | DCHECK(successor->IsLoopHeader()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7029 | } |
| 7030 | } else { |
| 7031 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 7032 | } |
| 7033 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7034 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7035 | vixl32::Register temp = temps.Acquire(); |
| 7036 | GetAssembler()->LoadFromOffset( |
| 7037 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 7038 | if (successor == nullptr) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7039 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7040 | __ Bind(slow_path->GetReturnLabel()); |
| 7041 | } else { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7042 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7043 | __ B(slow_path->GetEntryLabel()); |
| 7044 | } |
| 7045 | } |
| 7046 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7047 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 7048 | return codegen_->GetAssembler(); |
| 7049 | } |
| 7050 | |
| 7051 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7052 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7053 | MoveOperands* move = moves_[index]; |
| 7054 | Location source = move->GetSource(); |
| 7055 | Location destination = move->GetDestination(); |
| 7056 | |
| 7057 | if (source.IsRegister()) { |
| 7058 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7059 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7060 | } else if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7061 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7062 | } else { |
| 7063 | DCHECK(destination.IsStackSlot()); |
| 7064 | GetAssembler()->StoreToOffset(kStoreWord, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7065 | RegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7066 | sp, |
| 7067 | destination.GetStackIndex()); |
| 7068 | } |
| 7069 | } else if (source.IsStackSlot()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7070 | if (destination.IsRegister()) { |
| 7071 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 7072 | RegisterFrom(destination), |
| 7073 | sp, |
| 7074 | source.GetStackIndex()); |
| 7075 | } else if (destination.IsFpuRegister()) { |
| 7076 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 7077 | } else { |
| 7078 | DCHECK(destination.IsStackSlot()); |
| 7079 | vixl32::Register temp = temps.Acquire(); |
| 7080 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 7081 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7082 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7083 | } else if (source.IsFpuRegister()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7084 | if (destination.IsRegister()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7085 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7086 | } else if (destination.IsFpuRegister()) { |
| 7087 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 7088 | } else { |
| 7089 | DCHECK(destination.IsStackSlot()); |
| 7090 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 7091 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7092 | } else if (source.IsDoubleStackSlot()) { |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7093 | if (destination.IsDoubleStackSlot()) { |
| 7094 | vixl32::DRegister temp = temps.AcquireD(); |
| 7095 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 7096 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 7097 | } else if (destination.IsRegisterPair()) { |
| 7098 | DCHECK(ExpectedPairLayout(destination)); |
| 7099 | GetAssembler()->LoadFromOffset( |
| 7100 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 7101 | } else { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7102 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 7103 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7104 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7105 | } else if (source.IsRegisterPair()) { |
| 7106 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7107 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 7108 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7109 | } else if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7110 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7111 | } else { |
| 7112 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7113 | DCHECK(ExpectedPairLayout(source)); |
| 7114 | GetAssembler()->StoreToOffset(kStoreWordPair, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7115 | LowRegisterFrom(source), |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7116 | sp, |
| 7117 | destination.GetStackIndex()); |
| 7118 | } |
| 7119 | } else if (source.IsFpuRegisterPair()) { |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7120 | if (destination.IsRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7121 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 7122 | } else if (destination.IsFpuRegisterPair()) { |
| 7123 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 7124 | } else { |
| 7125 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7126 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 7127 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7128 | } else { |
| 7129 | DCHECK(source.IsConstant()) << source; |
| 7130 | HConstant* constant = source.GetConstant(); |
| 7131 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 7132 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 7133 | if (destination.IsRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7134 | __ Mov(RegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7135 | } else { |
| 7136 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7137 | vixl32::Register temp = temps.Acquire(); |
| 7138 | __ Mov(temp, value); |
| 7139 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7140 | } |
| 7141 | } else if (constant->IsLongConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 7142 | int64_t value = Int64ConstantFrom(source); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7143 | if (destination.IsRegisterPair()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7144 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 7145 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7146 | } else { |
| 7147 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7148 | vixl32::Register temp = temps.Acquire(); |
| 7149 | __ Mov(temp, Low32Bits(value)); |
| 7150 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7151 | __ Mov(temp, High32Bits(value)); |
| 7152 | GetAssembler()->StoreToOffset(kStoreWord, |
| 7153 | temp, |
| 7154 | sp, |
| 7155 | destination.GetHighStackIndex(kArmWordSize)); |
| 7156 | } |
| 7157 | } else if (constant->IsDoubleConstant()) { |
| 7158 | double value = constant->AsDoubleConstant()->GetValue(); |
| 7159 | if (destination.IsFpuRegisterPair()) { |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 7160 | __ Vmov(DRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7161 | } else { |
| 7162 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7163 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7164 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7165 | __ Mov(temp, Low32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7166 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7167 | __ Mov(temp, High32Bits(int_value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7168 | GetAssembler()->StoreToOffset(kStoreWord, |
| 7169 | temp, |
| 7170 | sp, |
| 7171 | destination.GetHighStackIndex(kArmWordSize)); |
| 7172 | } |
| 7173 | } else { |
| 7174 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 7175 | float value = constant->AsFloatConstant()->GetValue(); |
| 7176 | if (destination.IsFpuRegister()) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7177 | __ Vmov(SRegisterFrom(destination), value); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7178 | } else { |
| 7179 | DCHECK(destination.IsStackSlot()); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7180 | vixl32::Register temp = temps.Acquire(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7181 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7182 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 7183 | } |
| 7184 | } |
| 7185 | } |
| 7186 | } |
| 7187 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7188 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 7189 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 7190 | vixl32::Register temp = temps.Acquire(); |
| 7191 | __ Mov(temp, reg); |
| 7192 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 7193 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7194 | } |
| 7195 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7196 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 7197 | // TODO(VIXL32): Double check the performance of this implementation. |
| 7198 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7199 | vixl32::Register temp1 = temps.Acquire(); |
| 7200 | ScratchRegisterScope ensure_scratch( |
| 7201 | this, temp1.GetCode(), r0.GetCode(), codegen_->GetNumberOfCoreRegisters()); |
| 7202 | vixl32::Register temp2(ensure_scratch.GetRegister()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7203 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7204 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 7205 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, sp, mem1 + stack_offset); |
| 7206 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, sp, mem2 + stack_offset); |
| 7207 | GetAssembler()->StoreToOffset(kStoreWord, temp1, sp, mem2 + stack_offset); |
| 7208 | GetAssembler()->StoreToOffset(kStoreWord, temp2, sp, mem1 + stack_offset); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7209 | } |
| 7210 | |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7211 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 7212 | MoveOperands* move = moves_[index]; |
| 7213 | Location source = move->GetSource(); |
| 7214 | Location destination = move->GetDestination(); |
| 7215 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 7216 | |
| 7217 | if (source.IsRegister() && destination.IsRegister()) { |
| 7218 | vixl32::Register temp = temps.Acquire(); |
| 7219 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 7220 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 7221 | __ Mov(temp, RegisterFrom(destination)); |
| 7222 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 7223 | __ Mov(RegisterFrom(source), temp); |
| 7224 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 7225 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 7226 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 7227 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 7228 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7229 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7230 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7231 | vixl32::Register temp = temps.Acquire(); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7232 | __ Vmov(temp, SRegisterFrom(source)); |
| 7233 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 7234 | __ Vmov(SRegisterFrom(destination), temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7235 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 7236 | vixl32::DRegister temp = temps.AcquireD(); |
| 7237 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 7238 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 7239 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 7240 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 7241 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 7242 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 7243 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 7244 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 7245 | vixl32::DRegister temp = temps.AcquireD(); |
| 7246 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 7247 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 7248 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 7249 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7250 | vixl32::DRegister first = DRegisterFrom(source); |
| 7251 | vixl32::DRegister second = DRegisterFrom(destination); |
| 7252 | vixl32::DRegister temp = temps.AcquireD(); |
| 7253 | __ Vmov(temp, first); |
| 7254 | __ Vmov(first, second); |
| 7255 | __ Vmov(second, temp); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7256 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7257 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 7258 | ? DRegisterFrom(source) |
| 7259 | : DRegisterFrom(destination); |
| 7260 | int mem = source.IsFpuRegisterPair() |
| 7261 | ? destination.GetStackIndex() |
| 7262 | : source.GetStackIndex(); |
| 7263 | vixl32::DRegister temp = temps.AcquireD(); |
| 7264 | __ Vmov(temp, reg); |
| 7265 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 7266 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7267 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7268 | vixl32::SRegister reg = source.IsFpuRegister() |
| 7269 | ? SRegisterFrom(source) |
| 7270 | : SRegisterFrom(destination); |
| 7271 | int mem = source.IsFpuRegister() |
| 7272 | ? destination.GetStackIndex() |
| 7273 | : source.GetStackIndex(); |
| 7274 | vixl32::Register temp = temps.Acquire(); |
| 7275 | __ Vmov(temp, reg); |
| 7276 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 7277 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7278 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 7279 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 7280 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 7281 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 7282 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 7283 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 7284 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 7285 | } else { |
| 7286 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 7287 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7288 | } |
| 7289 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7290 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg) { |
| 7291 | __ Push(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7292 | } |
| 7293 | |
Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7294 | void ParallelMoveResolverARMVIXL::RestoreScratch(int reg) { |
| 7295 | __ Pop(vixl32::Register(reg)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7296 | } |
| 7297 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7298 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7299 | HLoadClass::LoadKind desired_class_load_kind) { |
| 7300 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7301 | case HLoadClass::LoadKind::kInvalid: |
| 7302 | LOG(FATAL) << "UNREACHABLE"; |
| 7303 | UNREACHABLE(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7304 | case HLoadClass::LoadKind::kReferrersClass: |
| 7305 | break; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7306 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7307 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7308 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame^] | 7309 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7310 | case HLoadClass::LoadKind::kBssEntryPackage: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7311 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7312 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7313 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7314 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7315 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7316 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7317 | case HLoadClass::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7318 | break; |
| 7319 | } |
| 7320 | return desired_class_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7321 | } |
| 7322 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7323 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7324 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7325 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7326 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7327 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7328 | cls, |
| 7329 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7330 | LocationFrom(r0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7331 | DCHECK(calling_convention.GetRegisterAt(0).Is(r0)); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7332 | return; |
| 7333 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame^] | 7334 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7335 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7336 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7337 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7338 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7339 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7340 | ? LocationSummary::kCallOnSlowPath |
| 7341 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7342 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7343 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7344 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7345 | } |
| 7346 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7347 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7348 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7349 | } |
| 7350 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7351 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7352 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7353 | // 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] | 7354 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7355 | } else { |
| 7356 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7357 | } |
| 7358 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7359 | } |
| 7360 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7361 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7362 | // move. |
| 7363 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7364 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7365 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7366 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7367 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 15); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7368 | return; |
| 7369 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame^] | 7370 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 7371 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 7372 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7373 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7374 | LocationSummary* locations = cls->GetLocations(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7375 | Location out_loc = locations->Out(); |
| 7376 | vixl32::Register out = OutputRegister(cls); |
| 7377 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7378 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7379 | ? kWithoutReadBarrier |
| 7380 | : kCompilerReadBarrierOption; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7381 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7382 | switch (load_kind) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7383 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7384 | DCHECK(!cls->CanCallRuntime()); |
| 7385 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7386 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7387 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7388 | codegen_->GenerateGcRootFieldLoad(cls, |
| 7389 | out_loc, |
| 7390 | current_method, |
| 7391 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 7392 | read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7393 | break; |
| 7394 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7395 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7396 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7397 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7398 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7399 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7400 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7401 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7402 | break; |
| 7403 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7404 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7405 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7406 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7407 | codegen_->NewBootImageRelRoPatch(codegen_->GetBootImageOffset(cls)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7408 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7409 | __ Ldr(out, MemOperand(out, /* offset= */ 0)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7410 | break; |
| 7411 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame^] | 7412 | case HLoadClass::LoadKind::kBssEntry: |
| 7413 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 7414 | case HLoadClass::LoadKind::kBssEntryPackage: { |
| 7415 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = codegen_->NewTypeBssEntryPatch(cls); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7416 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7417 | // All aligned loads are implicitly atomic consume operations on ARM. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7418 | codegen_->GenerateGcRootFieldLoad(cls, out_loc, out, /* offset= */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7419 | generate_null_check = true; |
| 7420 | break; |
| 7421 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7422 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 7423 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7424 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 7425 | DCHECK_NE(address, 0u); |
| 7426 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7427 | break; |
| 7428 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7429 | case HLoadClass::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7430 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 7431 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7432 | cls->GetClass())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7433 | // /* GcRoot<mirror::Class> */ out = *out |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7434 | codegen_->GenerateGcRootFieldLoad(cls, out_loc, out, /* offset= */ 0, read_barrier_option); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7435 | break; |
| 7436 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7437 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7438 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7439 | LOG(FATAL) << "UNREACHABLE"; |
| 7440 | UNREACHABLE(); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7441 | } |
| 7442 | |
| 7443 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7444 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7445 | LoadClassSlowPathARMVIXL* slow_path = |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7446 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL(cls, cls); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7447 | codegen_->AddSlowPath(slow_path); |
| 7448 | if (generate_null_check) { |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7449 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7450 | } |
| 7451 | if (cls->MustGenerateClinitCheck()) { |
| 7452 | GenerateClassInitializationCheck(slow_path, out); |
| 7453 | } else { |
| 7454 | __ Bind(slow_path->GetExitLabel()); |
| 7455 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7456 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 16); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7457 | } |
| 7458 | } |
| 7459 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7460 | void LocationsBuilderARMVIXL::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7461 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7462 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 7463 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 7464 | } |
| 7465 | |
| 7466 | void InstructionCodeGeneratorARMVIXL::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7467 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 7468 | } |
| 7469 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7470 | void LocationsBuilderARMVIXL::VisitLoadMethodType(HLoadMethodType* load) { |
| 7471 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7472 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 7473 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 7474 | } |
| 7475 | |
| 7476 | void InstructionCodeGeneratorARMVIXL::VisitLoadMethodType(HLoadMethodType* load) { |
| 7477 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 7478 | } |
| 7479 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7480 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7481 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7482 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7483 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7484 | if (check->HasUses()) { |
| 7485 | locations->SetOut(Location::SameAsFirstInput()); |
| 7486 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7487 | // Rely on the type initialization to save everything we need. |
| 7488 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7489 | } |
| 7490 | |
| 7491 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7492 | // We assume the class is not null. |
| 7493 | LoadClassSlowPathARMVIXL* slow_path = |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7494 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), check); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7495 | codegen_->AddSlowPath(slow_path); |
| 7496 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 7497 | } |
| 7498 | |
| 7499 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 7500 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 7501 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7502 | vixl32::Register temp = temps.Acquire(); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7503 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7504 | constexpr uint32_t shifted_visibly_initialized_value = |
| 7505 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << status_lsb_position; |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7506 | |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7507 | const size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 7508 | GetAssembler()->LoadFromOffset(kLoadWord, temp, class_reg, status_offset); |
| 7509 | __ Cmp(temp, shifted_visibly_initialized_value); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 7510 | __ B(lo, slow_path->GetEntryLabel()); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7511 | __ Bind(slow_path->GetExitLabel()); |
| 7512 | } |
| 7513 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7514 | void InstructionCodeGeneratorARMVIXL::GenerateBitstringTypeCheckCompare( |
| 7515 | HTypeCheckInstruction* check, |
| 7516 | vixl32::Register temp, |
| 7517 | vixl32::FlagsUpdate flags_update) { |
| 7518 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 7519 | uint32_t mask = check->GetBitstringMask(); |
| 7520 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 7521 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 7522 | |
| 7523 | // Note that HInstanceOf shall check for zero value in `temp` but HCheckCast needs |
| 7524 | // the Z flag for BNE. This is indicated by the `flags_update` parameter. |
| 7525 | if (mask_bits == 16u) { |
| 7526 | // Load only the bitstring part of the status word. |
| 7527 | __ Ldrh(temp, MemOperand(temp, mirror::Class::StatusOffset().Int32Value())); |
| 7528 | // Check if the bitstring bits are equal to `path_to_root`. |
| 7529 | if (flags_update == SetFlags) { |
| 7530 | __ Cmp(temp, path_to_root); |
| 7531 | } else { |
| 7532 | __ Sub(temp, temp, path_to_root); |
| 7533 | } |
| 7534 | } else { |
| 7535 | // /* uint32_t */ temp = temp->status_ |
| 7536 | __ Ldr(temp, MemOperand(temp, mirror::Class::StatusOffset().Int32Value())); |
| 7537 | if (GetAssembler()->ShifterOperandCanHold(SUB, path_to_root)) { |
| 7538 | // Compare the bitstring bits using SUB. |
| 7539 | __ Sub(temp, temp, path_to_root); |
| 7540 | // Shift out bits that do not contribute to the comparison. |
| 7541 | __ Lsl(flags_update, temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7542 | } else if (IsUint<16>(path_to_root)) { |
| 7543 | if (temp.IsLow()) { |
| 7544 | // Note: Optimized for size but contains one more dependent instruction than necessary. |
| 7545 | // MOVW+SUB(register) would be 8 bytes unless we find a low-reg temporary but the |
| 7546 | // macro assembler would use the high reg IP for the constant by default. |
| 7547 | // Compare the bitstring bits using SUB. |
| 7548 | __ Sub(temp, temp, path_to_root & 0x00ffu); // 16-bit SUB (immediate) T2 |
| 7549 | __ Sub(temp, temp, path_to_root & 0xff00u); // 32-bit SUB (immediate) T3 |
| 7550 | // Shift out bits that do not contribute to the comparison. |
| 7551 | __ Lsl(flags_update, temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7552 | } else { |
| 7553 | // Extract the bitstring bits. |
| 7554 | __ Ubfx(temp, temp, 0, mask_bits); |
| 7555 | // Check if the bitstring bits are equal to `path_to_root`. |
| 7556 | if (flags_update == SetFlags) { |
| 7557 | __ Cmp(temp, path_to_root); |
| 7558 | } else { |
| 7559 | __ Sub(temp, temp, path_to_root); |
| 7560 | } |
| 7561 | } |
| 7562 | } else { |
| 7563 | // Shift out bits that do not contribute to the comparison. |
| 7564 | __ Lsl(temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7565 | // Check if the shifted bitstring bits are equal to `path_to_root << (32u - mask_bits)`. |
| 7566 | if (flags_update == SetFlags) { |
| 7567 | __ Cmp(temp, path_to_root << (32u - mask_bits)); |
| 7568 | } else { |
| 7569 | __ Sub(temp, temp, path_to_root << (32u - mask_bits)); |
| 7570 | } |
| 7571 | } |
| 7572 | } |
| 7573 | } |
| 7574 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7575 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7576 | HLoadString::LoadKind desired_string_load_kind) { |
| 7577 | switch (desired_string_load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7578 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7579 | case HLoadString::LoadKind::kBootImageRelRo: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7580 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7581 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7582 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7583 | case HLoadString::LoadKind::kJitBootImageAddress: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7584 | case HLoadString::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7585 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7586 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7587 | case HLoadString::LoadKind::kRuntimeCall: |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7588 | break; |
| 7589 | } |
| 7590 | return desired_string_load_kind; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7591 | } |
| 7592 | |
| 7593 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7594 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7595 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7596 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7597 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7598 | locations->SetOut(LocationFrom(r0)); |
| 7599 | } else { |
| 7600 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7601 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7602 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7603 | // 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] | 7604 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7605 | } else { |
| 7606 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7607 | } |
| 7608 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7609 | } |
| 7610 | } |
| 7611 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7612 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7613 | // move. |
| 7614 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7615 | LocationSummary* locations = load->GetLocations(); |
| 7616 | Location out_loc = locations->Out(); |
| 7617 | vixl32::Register out = OutputRegister(load); |
| 7618 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 7619 | |
| 7620 | switch (load_kind) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7621 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7622 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7623 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7624 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7625 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7626 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7627 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7628 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7629 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7630 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7631 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7632 | codegen_->NewBootImageRelRoPatch(codegen_->GetBootImageOffset(load)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7633 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7634 | __ Ldr(out, MemOperand(out, /* offset= */ 0)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7635 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7636 | } |
| 7637 | case HLoadString::LoadKind::kBssEntry: { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7638 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7639 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7640 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7641 | // All aligned loads are implicitly atomic consume operations on ARM. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7642 | codegen_->GenerateGcRootFieldLoad( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7643 | load, out_loc, out, /* offset= */ 0, kCompilerReadBarrierOption); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7644 | LoadStringSlowPathARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7645 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARMVIXL(load); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7646 | codegen_->AddSlowPath(slow_path); |
| 7647 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7648 | __ Bind(slow_path->GetExitLabel()); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7649 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 17); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7650 | return; |
| 7651 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7652 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 7653 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 7654 | DCHECK_NE(address, 0u); |
| 7655 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7656 | return; |
| 7657 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7658 | case HLoadString::LoadKind::kJitTableAddress: { |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7659 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7660 | load->GetStringIndex(), |
| 7661 | load->GetString())); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7662 | // /* GcRoot<mirror::String> */ out = *out |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7663 | codegen_->GenerateGcRootFieldLoad( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7664 | load, out_loc, out, /* offset= */ 0, kCompilerReadBarrierOption); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7665 | return; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7666 | } |
| 7667 | default: |
| 7668 | break; |
| 7669 | } |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7670 | |
| 7671 | // 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] | 7672 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7673 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7674 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7675 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7676 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 7677 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 18); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7678 | } |
| 7679 | |
| 7680 | static int32_t GetExceptionTlsOffset() { |
| 7681 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 7682 | } |
| 7683 | |
| 7684 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 7685 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7686 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7687 | locations->SetOut(Location::RequiresRegister()); |
| 7688 | } |
| 7689 | |
| 7690 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 7691 | vixl32::Register out = OutputRegister(load); |
| 7692 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 7693 | } |
| 7694 | |
| 7695 | |
| 7696 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7697 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7698 | } |
| 7699 | |
| 7700 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7701 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7702 | vixl32::Register temp = temps.Acquire(); |
| 7703 | __ Mov(temp, 0); |
| 7704 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 7705 | } |
| 7706 | |
| 7707 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7708 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7709 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7710 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7711 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7712 | } |
| 7713 | |
| 7714 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 7715 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 7716 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7717 | } |
| 7718 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7719 | // Temp is used for read barrier. |
| 7720 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7721 | if (kEmitCompilerReadBarrier && |
| 7722 | (kUseBakerReadBarrier || |
| 7723 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7724 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7725 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7726 | return 1; |
| 7727 | } |
| 7728 | return 0; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7729 | } |
| 7730 | |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7731 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 7732 | // interface pointer, one for loading the current interface. |
| 7733 | // The other checks have one temp for loading the object's class. |
| 7734 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7735 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7736 | return 3; |
| 7737 | } |
| 7738 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 7739 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7740 | |
| 7741 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7742 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7743 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7744 | bool baker_read_barrier_slow_path = false; |
| 7745 | switch (type_check_kind) { |
| 7746 | case TypeCheckKind::kExactCheck: |
| 7747 | case TypeCheckKind::kAbstractClassCheck: |
| 7748 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7749 | case TypeCheckKind::kArrayObjectCheck: { |
| 7750 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7751 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7752 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7753 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7754 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7755 | case TypeCheckKind::kArrayCheck: |
| 7756 | case TypeCheckKind::kUnresolvedCheck: |
| 7757 | case TypeCheckKind::kInterfaceCheck: |
| 7758 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7759 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7760 | case TypeCheckKind::kBitstringCheck: |
| 7761 | break; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7762 | } |
| 7763 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7764 | LocationSummary* locations = |
| 7765 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7766 | if (baker_read_barrier_slow_path) { |
| 7767 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7768 | } |
| 7769 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7770 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7771 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7772 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7773 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7774 | } else { |
| 7775 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7776 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7777 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7778 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7779 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7780 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7781 | } |
| 7782 | |
| 7783 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7784 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7785 | LocationSummary* locations = instruction->GetLocations(); |
| 7786 | Location obj_loc = locations->InAt(0); |
| 7787 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7788 | vixl32::Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 7789 | ? vixl32::Register() |
| 7790 | : InputRegisterAt(instruction, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7791 | Location out_loc = locations->Out(); |
| 7792 | vixl32::Register out = OutputRegister(instruction); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7793 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7794 | DCHECK_LE(num_temps, 1u); |
| 7795 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7796 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7797 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7798 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7799 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7800 | vixl32::Label done; |
| 7801 | vixl32::Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7802 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 7803 | |
| 7804 | // Return 0 if `obj` is null. |
| 7805 | // avoid null check if we know obj is not null. |
| 7806 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7807 | DCHECK(!out.Is(obj)); |
| 7808 | __ Mov(out, 0); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7809 | __ CompareAndBranchIfZero(obj, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7810 | } |
| 7811 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7812 | switch (type_check_kind) { |
| 7813 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7814 | ReadBarrierOption read_barrier_option = |
| 7815 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7816 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7817 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7818 | out_loc, |
| 7819 | obj_loc, |
| 7820 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7821 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7822 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7823 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7824 | __ Cmp(out, cls); |
| 7825 | // We speculatively set the result to false without changing the condition |
| 7826 | // flags, which allows us to avoid some branching later. |
| 7827 | __ Mov(LeaveFlags, out, 0); |
| 7828 | |
| 7829 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7830 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7831 | // encoding can be used. |
| 7832 | if (out.IsLow()) { |
| 7833 | // We use the scope because of the IT block that follows. |
| 7834 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7835 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7836 | CodeBufferCheckScope::kExactSize); |
| 7837 | |
| 7838 | __ it(eq); |
| 7839 | __ mov(eq, out, 1); |
| 7840 | } else { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7841 | __ B(ne, final_label, /* is_far_target= */ false); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7842 | __ Mov(out, 1); |
| 7843 | } |
| 7844 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7845 | break; |
| 7846 | } |
| 7847 | |
| 7848 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7849 | ReadBarrierOption read_barrier_option = |
| 7850 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7851 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7852 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7853 | out_loc, |
| 7854 | obj_loc, |
| 7855 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7856 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7857 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7858 | // If the class is abstract, we eagerly fetch the super class of the |
| 7859 | // object to avoid doing a comparison we know will fail. |
| 7860 | vixl32::Label loop; |
| 7861 | __ Bind(&loop); |
| 7862 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7863 | GenerateReferenceLoadOneRegister(instruction, |
| 7864 | out_loc, |
| 7865 | super_offset, |
| 7866 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7867 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7868 | // 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] | 7869 | __ CompareAndBranchIfZero(out, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7870 | __ Cmp(out, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7871 | __ B(ne, &loop, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7872 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7873 | break; |
| 7874 | } |
| 7875 | |
| 7876 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7877 | ReadBarrierOption read_barrier_option = |
| 7878 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7879 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7880 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7881 | out_loc, |
| 7882 | obj_loc, |
| 7883 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7884 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7885 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7886 | // Walk over the class hierarchy to find a match. |
| 7887 | vixl32::Label loop, success; |
| 7888 | __ Bind(&loop); |
| 7889 | __ Cmp(out, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7890 | __ B(eq, &success, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7891 | // /* HeapReference<Class> */ out = out->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7892 | GenerateReferenceLoadOneRegister(instruction, |
| 7893 | out_loc, |
| 7894 | super_offset, |
| 7895 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7896 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7897 | // This is essentially a null check, but it sets the condition flags to the |
| 7898 | // proper value for the code that follows the loop, i.e. not `eq`. |
| 7899 | __ Cmp(out, 1); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7900 | __ B(hs, &loop, /* is_far_target= */ false); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7901 | |
| 7902 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7903 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7904 | // encoding can be used. |
| 7905 | if (out.IsLow()) { |
| 7906 | // If `out` is null, we use it for the result, and the condition flags |
| 7907 | // have already been set to `ne`, so the IT block that comes afterwards |
| 7908 | // (and which handles the successful case) turns into a NOP (instead of |
| 7909 | // overwriting `out`). |
| 7910 | __ Bind(&success); |
| 7911 | |
| 7912 | // We use the scope because of the IT block that follows. |
| 7913 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7914 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7915 | CodeBufferCheckScope::kExactSize); |
| 7916 | |
| 7917 | // There is only one branch to the `success` label (which is bound to this |
| 7918 | // IT block), and it has the same condition, `eq`, so in that case the MOV |
| 7919 | // is executed. |
| 7920 | __ it(eq); |
| 7921 | __ mov(eq, out, 1); |
| 7922 | } else { |
| 7923 | // 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] | 7924 | __ B(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7925 | __ Bind(&success); |
| 7926 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7927 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7928 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7929 | break; |
| 7930 | } |
| 7931 | |
| 7932 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7933 | ReadBarrierOption read_barrier_option = |
| 7934 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7935 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7936 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7937 | out_loc, |
| 7938 | obj_loc, |
| 7939 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7940 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7941 | read_barrier_option); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7942 | // Do an exact check. |
| 7943 | vixl32::Label exact_check; |
| 7944 | __ Cmp(out, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7945 | __ B(eq, &exact_check, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7946 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7947 | // /* HeapReference<Class> */ out = out->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7948 | GenerateReferenceLoadOneRegister(instruction, |
| 7949 | out_loc, |
| 7950 | component_offset, |
| 7951 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7952 | read_barrier_option); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7953 | // 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] | 7954 | __ CompareAndBranchIfZero(out, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7955 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7956 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7957 | __ Cmp(out, 0); |
| 7958 | // We speculatively set the result to false without changing the condition |
| 7959 | // flags, which allows us to avoid some branching later. |
| 7960 | __ Mov(LeaveFlags, out, 0); |
| 7961 | |
| 7962 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7963 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7964 | // encoding can be used. |
| 7965 | if (out.IsLow()) { |
| 7966 | __ Bind(&exact_check); |
| 7967 | |
| 7968 | // We use the scope because of the IT block that follows. |
| 7969 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7970 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7971 | CodeBufferCheckScope::kExactSize); |
| 7972 | |
| 7973 | __ it(eq); |
| 7974 | __ mov(eq, out, 1); |
| 7975 | } else { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7976 | __ B(ne, final_label, /* is_far_target= */ false); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7977 | __ Bind(&exact_check); |
| 7978 | __ Mov(out, 1); |
| 7979 | } |
| 7980 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7981 | break; |
| 7982 | } |
| 7983 | |
| 7984 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7985 | // No read barrier since the slow path will retry upon failure. |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7986 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7987 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7988 | out_loc, |
| 7989 | obj_loc, |
| 7990 | class_offset, |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7991 | maybe_temp_loc, |
| 7992 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7993 | __ Cmp(out, cls); |
| 7994 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7995 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7996 | instruction, /* is_fatal= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7997 | codegen_->AddSlowPath(slow_path); |
| 7998 | __ B(ne, slow_path->GetEntryLabel()); |
| 7999 | __ Mov(out, 1); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8000 | break; |
| 8001 | } |
| 8002 | |
| 8003 | case TypeCheckKind::kUnresolvedCheck: |
| 8004 | case TypeCheckKind::kInterfaceCheck: { |
| 8005 | // Note that we indeed only call on slow path, but we always go |
| 8006 | // into the slow path for the unresolved and interface check |
| 8007 | // cases. |
| 8008 | // |
| 8009 | // We cannot directly call the InstanceofNonTrivial runtime |
| 8010 | // entry point without resorting to a type checking slow path |
| 8011 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 8012 | // require to assign fixed registers for the inputs of this |
| 8013 | // HInstanceOf instruction (following the runtime calling |
| 8014 | // convention), which might be cluttered by the potential first |
| 8015 | // read barrier emission at the beginning of this method. |
| 8016 | // |
| 8017 | // TODO: Introduce a new runtime entry point taking the object |
| 8018 | // to test (instead of its class) as argument, and let it deal |
| 8019 | // with the read barrier issues. This will let us refactor this |
| 8020 | // case of the `switch` code as it was previously (with a direct |
| 8021 | // call to the runtime not using a type checking slow path). |
| 8022 | // This should also be beneficial for the other cases above. |
| 8023 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8024 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8025 | instruction, /* is_fatal= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8026 | codegen_->AddSlowPath(slow_path); |
| 8027 | __ B(slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8028 | break; |
| 8029 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8030 | |
| 8031 | case TypeCheckKind::kBitstringCheck: { |
| 8032 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8033 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8034 | out_loc, |
| 8035 | obj_loc, |
| 8036 | class_offset, |
| 8037 | maybe_temp_loc, |
| 8038 | kWithoutReadBarrier); |
| 8039 | |
| 8040 | GenerateBitstringTypeCheckCompare(instruction, out, DontCare); |
| 8041 | // If `out` is a low reg and we would have another low reg temp, we could |
| 8042 | // optimize this as RSBS+ADC, see GenerateConditionWithZero(). |
| 8043 | // |
| 8044 | // Also, in some cases when `out` is a low reg and we're loading a constant to IP |
| 8045 | // it would make sense to use CMP+MOV+IT+MOV instead of SUB+CLZ+LSR as the code size |
| 8046 | // would be the same and we would have fewer direct data dependencies. |
| 8047 | codegen_->GenerateConditionWithZero(kCondEQ, out, out); // CLZ+LSR |
| 8048 | break; |
| 8049 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8050 | } |
| 8051 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8052 | if (done.IsReferenced()) { |
| 8053 | __ Bind(&done); |
| 8054 | } |
| 8055 | |
| 8056 | if (slow_path != nullptr) { |
| 8057 | __ Bind(slow_path->GetExitLabel()); |
| 8058 | } |
| 8059 | } |
| 8060 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8061 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8062 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8063 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8064 | LocationSummary* locations = |
| 8065 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8066 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8067 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 8068 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 8069 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 8070 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 8071 | } else { |
| 8072 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8073 | } |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8074 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8075 | } |
| 8076 | |
| 8077 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 8078 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 8079 | LocationSummary* locations = instruction->GetLocations(); |
| 8080 | Location obj_loc = locations->InAt(0); |
| 8081 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8082 | vixl32::Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 8083 | ? vixl32::Register() |
| 8084 | : InputRegisterAt(instruction, 1); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8085 | Location temp_loc = locations->GetTemp(0); |
| 8086 | vixl32::Register temp = RegisterFrom(temp_loc); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8087 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 8088 | DCHECK_LE(num_temps, 3u); |
| 8089 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 8090 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 8091 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 8092 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 8093 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 8094 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 8095 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 8096 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 8097 | const uint32_t object_array_data_offset = |
| 8098 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8099 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 8100 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8101 | SlowPathCodeARMVIXL* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8102 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 8103 | instruction, is_type_check_slow_path_fatal); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8104 | codegen_->AddSlowPath(type_check_slow_path); |
| 8105 | |
| 8106 | vixl32::Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8107 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8108 | // Avoid null check if we know obj is not null. |
| 8109 | if (instruction->MustDoNullCheck()) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8110 | __ CompareAndBranchIfZero(obj, final_label, /* is_far_target= */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8111 | } |
| 8112 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8113 | switch (type_check_kind) { |
| 8114 | case TypeCheckKind::kExactCheck: |
| 8115 | case TypeCheckKind::kArrayCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8116 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8117 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8118 | temp_loc, |
| 8119 | obj_loc, |
| 8120 | class_offset, |
| 8121 | maybe_temp2_loc, |
| 8122 | kWithoutReadBarrier); |
| 8123 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8124 | __ Cmp(temp, cls); |
| 8125 | // Jump to slow path for throwing the exception or doing a |
| 8126 | // more involved array check. |
| 8127 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 8128 | break; |
| 8129 | } |
| 8130 | |
| 8131 | case TypeCheckKind::kAbstractClassCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8132 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8133 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8134 | temp_loc, |
| 8135 | obj_loc, |
| 8136 | class_offset, |
| 8137 | maybe_temp2_loc, |
| 8138 | kWithoutReadBarrier); |
| 8139 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8140 | // If the class is abstract, we eagerly fetch the super class of the |
| 8141 | // object to avoid doing a comparison we know will fail. |
| 8142 | vixl32::Label loop; |
| 8143 | __ Bind(&loop); |
| 8144 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8145 | GenerateReferenceLoadOneRegister(instruction, |
| 8146 | temp_loc, |
| 8147 | super_offset, |
| 8148 | maybe_temp2_loc, |
| 8149 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8150 | |
| 8151 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 8152 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8153 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8154 | |
| 8155 | // Otherwise, compare the classes. |
| 8156 | __ Cmp(temp, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8157 | __ B(ne, &loop, /* is_far_target= */ false); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8158 | break; |
| 8159 | } |
| 8160 | |
| 8161 | case TypeCheckKind::kClassHierarchyCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8162 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8163 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8164 | temp_loc, |
| 8165 | obj_loc, |
| 8166 | class_offset, |
| 8167 | maybe_temp2_loc, |
| 8168 | kWithoutReadBarrier); |
| 8169 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8170 | // Walk over the class hierarchy to find a match. |
| 8171 | vixl32::Label loop; |
| 8172 | __ Bind(&loop); |
| 8173 | __ Cmp(temp, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8174 | __ B(eq, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8175 | |
| 8176 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8177 | GenerateReferenceLoadOneRegister(instruction, |
| 8178 | temp_loc, |
| 8179 | super_offset, |
| 8180 | maybe_temp2_loc, |
| 8181 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8182 | |
| 8183 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 8184 | // exception. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8185 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8186 | // Otherwise, jump to the beginning of the loop. |
| 8187 | __ B(&loop); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8188 | break; |
| 8189 | } |
| 8190 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8191 | case TypeCheckKind::kArrayObjectCheck: { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8192 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8193 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8194 | temp_loc, |
| 8195 | obj_loc, |
| 8196 | class_offset, |
| 8197 | maybe_temp2_loc, |
| 8198 | kWithoutReadBarrier); |
| 8199 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8200 | // Do an exact check. |
| 8201 | __ Cmp(temp, cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8202 | __ B(eq, final_label, /* is_far_target= */ false); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8203 | |
| 8204 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 8205 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8206 | GenerateReferenceLoadOneRegister(instruction, |
| 8207 | temp_loc, |
| 8208 | component_offset, |
| 8209 | maybe_temp2_loc, |
| 8210 | kWithoutReadBarrier); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8211 | // 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] | 8212 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8213 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 8214 | // to further check that this component type is not a primitive type. |
| 8215 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8216 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 8217 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8218 | break; |
| 8219 | } |
| 8220 | |
| 8221 | case TypeCheckKind::kUnresolvedCheck: |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8222 | // 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] | 8223 | // We cannot directly call the CheckCast runtime entry point |
| 8224 | // without resorting to a type checking slow path here (i.e. by |
| 8225 | // calling InvokeRuntime directly), as it would require to |
| 8226 | // assign fixed registers for the inputs of this HInstanceOf |
| 8227 | // instruction (following the runtime calling convention), which |
| 8228 | // might be cluttered by the potential first read barrier |
| 8229 | // emission at the beginning of this method. |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8230 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8231 | __ B(type_check_slow_path->GetEntryLabel()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8232 | break; |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8233 | |
| 8234 | case TypeCheckKind::kInterfaceCheck: { |
| 8235 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 8236 | // positives by doing this. |
| 8237 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8238 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8239 | temp_loc, |
| 8240 | obj_loc, |
| 8241 | class_offset, |
| 8242 | maybe_temp2_loc, |
| 8243 | kWithoutReadBarrier); |
| 8244 | |
| 8245 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 8246 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8247 | temp_loc, |
| 8248 | temp_loc, |
| 8249 | iftable_offset, |
| 8250 | maybe_temp2_loc, |
| 8251 | kWithoutReadBarrier); |
| 8252 | // Iftable is never null. |
| 8253 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 8254 | // Loop through the iftable and check if any class matches. |
| 8255 | vixl32::Label start_loop; |
| 8256 | __ Bind(&start_loop); |
| 8257 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 8258 | type_check_slow_path->GetEntryLabel()); |
| 8259 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 8260 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 8261 | // Go to next interface. |
| 8262 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 8263 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 8264 | // Compare the classes and continue the loop if they do not match. |
| 8265 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8266 | __ B(ne, &start_loop, /* is_far_target= */ false); |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8267 | break; |
| 8268 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8269 | |
| 8270 | case TypeCheckKind::kBitstringCheck: { |
| 8271 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8272 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8273 | temp_loc, |
| 8274 | obj_loc, |
| 8275 | class_offset, |
| 8276 | maybe_temp2_loc, |
| 8277 | kWithoutReadBarrier); |
| 8278 | |
| 8279 | GenerateBitstringTypeCheckCompare(instruction, temp, SetFlags); |
| 8280 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 8281 | break; |
| 8282 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8283 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8284 | if (done.IsReferenced()) { |
| 8285 | __ Bind(&done); |
| 8286 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8287 | |
| 8288 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 8289 | } |
| 8290 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8291 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8292 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8293 | instruction, LocationSummary::kCallOnMainOnly); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8294 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 8295 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 8296 | } |
| 8297 | |
| 8298 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8299 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 8300 | instruction, |
| 8301 | instruction->GetDexPc()); |
| 8302 | if (instruction->IsEnter()) { |
| 8303 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8304 | } else { |
| 8305 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8306 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 8307 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 19); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8308 | } |
| 8309 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8310 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 8311 | HandleBitwiseOperation(instruction, AND); |
| 8312 | } |
| 8313 | |
| 8314 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 8315 | HandleBitwiseOperation(instruction, ORR); |
| 8316 | } |
| 8317 | |
| 8318 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 8319 | HandleBitwiseOperation(instruction, EOR); |
| 8320 | } |
| 8321 | |
| 8322 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 8323 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8324 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8325 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8326 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8327 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 8328 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8329 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 8330 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8331 | } |
| 8332 | |
| 8333 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 8334 | HandleBitwiseOperation(instruction); |
| 8335 | } |
| 8336 | |
| 8337 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 8338 | HandleBitwiseOperation(instruction); |
| 8339 | } |
| 8340 | |
| 8341 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 8342 | HandleBitwiseOperation(instruction); |
| 8343 | } |
| 8344 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8345 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8346 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8347 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8348 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8349 | || instruction->GetResultType() == DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8350 | |
| 8351 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8352 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8353 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8354 | } |
| 8355 | |
| 8356 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8357 | LocationSummary* locations = instruction->GetLocations(); |
| 8358 | Location first = locations->InAt(0); |
| 8359 | Location second = locations->InAt(1); |
| 8360 | Location out = locations->Out(); |
| 8361 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8362 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8363 | vixl32::Register first_reg = RegisterFrom(first); |
| 8364 | vixl32::Register second_reg = RegisterFrom(second); |
| 8365 | vixl32::Register out_reg = RegisterFrom(out); |
| 8366 | |
| 8367 | switch (instruction->GetOpKind()) { |
| 8368 | case HInstruction::kAnd: |
| 8369 | __ Bic(out_reg, first_reg, second_reg); |
| 8370 | break; |
| 8371 | case HInstruction::kOr: |
| 8372 | __ Orn(out_reg, first_reg, second_reg); |
| 8373 | break; |
| 8374 | // There is no EON on arm. |
| 8375 | case HInstruction::kXor: |
| 8376 | default: |
| 8377 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8378 | UNREACHABLE(); |
| 8379 | } |
| 8380 | return; |
| 8381 | |
| 8382 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8383 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8384 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8385 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8386 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8387 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8388 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8389 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8390 | |
| 8391 | switch (instruction->GetOpKind()) { |
| 8392 | case HInstruction::kAnd: |
| 8393 | __ Bic(out_low, first_low, second_low); |
| 8394 | __ Bic(out_high, first_high, second_high); |
| 8395 | break; |
| 8396 | case HInstruction::kOr: |
| 8397 | __ Orn(out_low, first_low, second_low); |
| 8398 | __ Orn(out_high, first_high, second_high); |
| 8399 | break; |
| 8400 | // There is no EON on arm. |
| 8401 | case HInstruction::kXor: |
| 8402 | default: |
| 8403 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8404 | UNREACHABLE(); |
| 8405 | } |
| 8406 | } |
| 8407 | } |
| 8408 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8409 | void LocationsBuilderARMVIXL::VisitDataProcWithShifterOp( |
| 8410 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8411 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 8412 | instruction->GetType() == DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8413 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8414 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8415 | const bool overlap = instruction->GetType() == DataType::Type::kInt64 && |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8416 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 8417 | |
| 8418 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8419 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8420 | locations->SetOut(Location::RequiresRegister(), |
| 8421 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 8422 | } |
| 8423 | |
| 8424 | void InstructionCodeGeneratorARMVIXL::VisitDataProcWithShifterOp( |
| 8425 | HDataProcWithShifterOp* instruction) { |
| 8426 | const LocationSummary* const locations = instruction->GetLocations(); |
| 8427 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 8428 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 8429 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8430 | if (instruction->GetType() == DataType::Type::kInt32) { |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8431 | const vixl32::Register first = InputRegisterAt(instruction, 0); |
| 8432 | const vixl32::Register output = OutputRegister(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8433 | const vixl32::Register second = instruction->InputAt(1)->GetType() == DataType::Type::kInt64 |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8434 | ? LowRegisterFrom(locations->InAt(1)) |
| 8435 | : InputRegisterAt(instruction, 1); |
| 8436 | |
Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8437 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8438 | DCHECK_EQ(kind, HInstruction::kAdd); |
| 8439 | |
| 8440 | switch (op_kind) { |
| 8441 | case HDataProcWithShifterOp::kUXTB: |
| 8442 | __ Uxtab(output, first, second); |
| 8443 | break; |
| 8444 | case HDataProcWithShifterOp::kUXTH: |
| 8445 | __ Uxtah(output, first, second); |
| 8446 | break; |
| 8447 | case HDataProcWithShifterOp::kSXTB: |
| 8448 | __ Sxtab(output, first, second); |
| 8449 | break; |
| 8450 | case HDataProcWithShifterOp::kSXTH: |
| 8451 | __ Sxtah(output, first, second); |
| 8452 | break; |
| 8453 | default: |
| 8454 | LOG(FATAL) << "Unexpected operation kind: " << op_kind; |
| 8455 | UNREACHABLE(); |
| 8456 | } |
| 8457 | } else { |
| 8458 | GenerateDataProcInstruction(kind, |
| 8459 | output, |
| 8460 | first, |
| 8461 | Operand(second, |
| 8462 | ShiftFromOpKind(op_kind), |
| 8463 | instruction->GetShiftAmount()), |
| 8464 | codegen_); |
| 8465 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8466 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8467 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8468 | |
| 8469 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8470 | const vixl32::Register second = InputRegisterAt(instruction, 1); |
| 8471 | |
| 8472 | DCHECK(!LowRegisterFrom(locations->Out()).Is(second)); |
| 8473 | GenerateDataProc(kind, |
| 8474 | locations->Out(), |
| 8475 | locations->InAt(0), |
| 8476 | second, |
| 8477 | Operand(second, ShiftType::ASR, 31), |
| 8478 | codegen_); |
| 8479 | } else { |
| 8480 | GenerateLongDataProc(instruction, codegen_); |
| 8481 | } |
| 8482 | } |
| 8483 | } |
| 8484 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8485 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8486 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 8487 | vixl32::Register first, |
| 8488 | uint32_t value) { |
| 8489 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 8490 | if (value == 0xffffffffu) { |
| 8491 | if (!out.Is(first)) { |
| 8492 | __ Mov(out, first); |
| 8493 | } |
| 8494 | return; |
| 8495 | } |
| 8496 | if (value == 0u) { |
| 8497 | __ Mov(out, 0); |
| 8498 | return; |
| 8499 | } |
| 8500 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8501 | __ And(out, first, value); |
| 8502 | } else if (GetAssembler()->ShifterOperandCanHold(BIC, ~value)) { |
| 8503 | __ Bic(out, first, ~value); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8504 | } else { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8505 | DCHECK(IsPowerOfTwo(value + 1)); |
| 8506 | __ Ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8507 | } |
| 8508 | } |
| 8509 | |
| 8510 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8511 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 8512 | vixl32::Register first, |
| 8513 | uint32_t value) { |
| 8514 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 8515 | if (value == 0u) { |
| 8516 | if (!out.Is(first)) { |
| 8517 | __ Mov(out, first); |
| 8518 | } |
| 8519 | return; |
| 8520 | } |
| 8521 | if (value == 0xffffffffu) { |
| 8522 | __ Mvn(out, 0); |
| 8523 | return; |
| 8524 | } |
| 8525 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 8526 | __ Orr(out, first, value); |
| 8527 | } else { |
| 8528 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 8529 | __ Orn(out, first, ~value); |
| 8530 | } |
| 8531 | } |
| 8532 | |
| 8533 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8534 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 8535 | vixl32::Register first, |
| 8536 | uint32_t value) { |
| 8537 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 8538 | if (value == 0u) { |
| 8539 | if (!out.Is(first)) { |
| 8540 | __ Mov(out, first); |
| 8541 | } |
| 8542 | return; |
| 8543 | } |
| 8544 | __ Eor(out, first, value); |
| 8545 | } |
| 8546 | |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8547 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 8548 | Location first, |
| 8549 | uint64_t value) { |
| 8550 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8551 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8552 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8553 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8554 | uint32_t value_low = Low32Bits(value); |
| 8555 | uint32_t value_high = High32Bits(value); |
| 8556 | if (value_low == 0u) { |
| 8557 | if (!out_low.Is(first_low)) { |
| 8558 | __ Mov(out_low, first_low); |
| 8559 | } |
| 8560 | __ Add(out_high, first_high, value_high); |
| 8561 | return; |
| 8562 | } |
| 8563 | __ Adds(out_low, first_low, value_low); |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8564 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high)) { |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8565 | __ Adc(out_high, first_high, value_high); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8566 | } else { |
Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8567 | DCHECK(GetAssembler()->ShifterOperandCanHold(SBC, ~value_high)); |
| 8568 | __ Sbc(out_high, first_high, ~value_high); |
Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8569 | } |
| 8570 | } |
| 8571 | |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8572 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8573 | LocationSummary* locations = instruction->GetLocations(); |
| 8574 | Location first = locations->InAt(0); |
| 8575 | Location second = locations->InAt(1); |
| 8576 | Location out = locations->Out(); |
| 8577 | |
| 8578 | if (second.IsConstant()) { |
| 8579 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 8580 | uint32_t value_low = Low32Bits(value); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8581 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8582 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8583 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8584 | if (instruction->IsAnd()) { |
| 8585 | GenerateAndConst(out_reg, first_reg, value_low); |
| 8586 | } else if (instruction->IsOr()) { |
| 8587 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 8588 | } else { |
| 8589 | DCHECK(instruction->IsXor()); |
| 8590 | GenerateEorConst(out_reg, first_reg, value_low); |
| 8591 | } |
| 8592 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8593 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8594 | uint32_t value_high = High32Bits(value); |
| 8595 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8596 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8597 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8598 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8599 | if (instruction->IsAnd()) { |
| 8600 | GenerateAndConst(out_low, first_low, value_low); |
| 8601 | GenerateAndConst(out_high, first_high, value_high); |
| 8602 | } else if (instruction->IsOr()) { |
| 8603 | GenerateOrrConst(out_low, first_low, value_low); |
| 8604 | GenerateOrrConst(out_high, first_high, value_high); |
| 8605 | } else { |
| 8606 | DCHECK(instruction->IsXor()); |
| 8607 | GenerateEorConst(out_low, first_low, value_low); |
| 8608 | GenerateEorConst(out_high, first_high, value_high); |
| 8609 | } |
| 8610 | } |
| 8611 | return; |
| 8612 | } |
| 8613 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8614 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8615 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8616 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 8617 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8618 | if (instruction->IsAnd()) { |
| 8619 | __ And(out_reg, first_reg, second_reg); |
| 8620 | } else if (instruction->IsOr()) { |
| 8621 | __ Orr(out_reg, first_reg, second_reg); |
| 8622 | } else { |
| 8623 | DCHECK(instruction->IsXor()); |
| 8624 | __ Eor(out_reg, first_reg, second_reg); |
| 8625 | } |
| 8626 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8627 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8628 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8629 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8630 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8631 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8632 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8633 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8634 | if (instruction->IsAnd()) { |
| 8635 | __ And(out_low, first_low, second_low); |
| 8636 | __ And(out_high, first_high, second_high); |
| 8637 | } else if (instruction->IsOr()) { |
| 8638 | __ Orr(out_low, first_low, second_low); |
| 8639 | __ Orr(out_high, first_high, second_high); |
| 8640 | } else { |
| 8641 | DCHECK(instruction->IsXor()); |
| 8642 | __ Eor(out_low, first_low, second_low); |
| 8643 | __ Eor(out_high, first_high, second_high); |
| 8644 | } |
| 8645 | } |
| 8646 | } |
| 8647 | |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8648 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8649 | HInstruction* instruction, |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8650 | Location out, |
| 8651 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8652 | Location maybe_temp, |
| 8653 | ReadBarrierOption read_barrier_option) { |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8654 | vixl32::Register out_reg = RegisterFrom(out); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8655 | if (read_barrier_option == kWithReadBarrier) { |
| 8656 | CHECK(kEmitCompilerReadBarrier); |
| 8657 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8658 | if (kUseBakerReadBarrier) { |
| 8659 | // Load with fast path based Baker's read barrier. |
| 8660 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8661 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8662 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check= */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8663 | } else { |
| 8664 | // Load with slow path based read barrier. |
| 8665 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 8666 | // in the following move operation, as we will need it for the |
| 8667 | // read barrier below. |
| 8668 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 8669 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8670 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8671 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 8672 | } |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8673 | } else { |
| 8674 | // Plain load with no read barrier. |
| 8675 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8676 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8677 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8678 | } |
| 8679 | } |
| 8680 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8681 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8682 | HInstruction* instruction, |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8683 | Location out, |
| 8684 | Location obj, |
| 8685 | uint32_t offset, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8686 | Location maybe_temp, |
| 8687 | ReadBarrierOption read_barrier_option) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8688 | vixl32::Register out_reg = RegisterFrom(out); |
| 8689 | vixl32::Register obj_reg = RegisterFrom(obj); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8690 | if (read_barrier_option == kWithReadBarrier) { |
| 8691 | CHECK(kEmitCompilerReadBarrier); |
| 8692 | if (kUseBakerReadBarrier) { |
| 8693 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8694 | // Load with fast path based Baker's read barrier. |
| 8695 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8696 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8697 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check= */ false); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8698 | } else { |
| 8699 | // Load with slow path based read barrier. |
| 8700 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8701 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8702 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8703 | } |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8704 | } else { |
| 8705 | // Plain load with no read barrier. |
| 8706 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8707 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8708 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8709 | } |
| 8710 | } |
| 8711 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8712 | void CodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8713 | HInstruction* instruction, |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8714 | Location root, |
| 8715 | vixl32::Register obj, |
| 8716 | uint32_t offset, |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8717 | ReadBarrierOption read_barrier_option) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8718 | vixl32::Register root_reg = RegisterFrom(root); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8719 | if (read_barrier_option == kWithReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8720 | DCHECK(kEmitCompilerReadBarrier); |
| 8721 | if (kUseBakerReadBarrier) { |
| 8722 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8723 | // Baker's read barrier are used. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8724 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8725 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8726 | // the Marking Register) to decide whether we need to enter |
| 8727 | // the slow path to mark the GC root. |
| 8728 | // |
| 8729 | // We use shared thunks for the slow path; shared within the method |
| 8730 | // for JIT, across methods for AOT. That thunk checks the reference |
| 8731 | // and jumps to the entrypoint if needed. |
| 8732 | // |
| 8733 | // lr = &return_address; |
| 8734 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8735 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8736 | // goto gc_root_thunk<root_reg>(lr) |
| 8737 | // } |
| 8738 | // return_address: |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8739 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8740 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8741 | temps.Exclude(ip); |
| 8742 | bool narrow = CanEmitNarrowLdr(root_reg, obj, offset); |
| 8743 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode(), narrow); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8744 | |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8745 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u) + /* LDR */ (narrow ? 1u : 0u); |
| 8746 | size_t wide_instructions = /* ADR+CMP+LDR+BNE */ 4u - narrow_instructions; |
| 8747 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8748 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8749 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8750 | vixl32::Label return_address; |
| 8751 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8752 | __ cmp(mr, Operand(0)); |
| 8753 | // Currently the offset is always within range. If that changes, |
| 8754 | // we shall have to split the load the same way as for fields. |
| 8755 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
| 8756 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8757 | __ ldr(EncodingSize(narrow ? Narrow : Wide), root_reg, MemOperand(obj, offset)); |
| 8758 | EmitBakerReadBarrierBne(custom_data); |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8759 | __ bind(&return_address); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8760 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8761 | narrow ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8762 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8763 | } else { |
| 8764 | // GC root loaded through a slow path for read barriers other |
| 8765 | // than Baker's. |
| 8766 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8767 | __ Add(root_reg, obj, offset); |
| 8768 | // /* mirror::Object* */ root = root->Read() |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8769 | GenerateReadBarrierForRootSlow(instruction, root, root); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8770 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8771 | } else { |
| 8772 | // Plain GC root load with no read barrier. |
| 8773 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8774 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8775 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8776 | // do not have to unpoison `root_reg` here. |
| 8777 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 8778 | MaybeGenerateMarkingRegisterCheck(/* code= */ 20); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8779 | } |
| 8780 | |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8781 | void CodeGeneratorARMVIXL::GenerateUnsafeCasOldValueAddWithBakerReadBarrier( |
| 8782 | vixl::aarch32::Register old_value, |
| 8783 | vixl::aarch32::Register adjusted_old_value, |
| 8784 | vixl::aarch32::Register expected) { |
| 8785 | DCHECK(kEmitCompilerReadBarrier); |
| 8786 | DCHECK(kUseBakerReadBarrier); |
| 8787 | |
| 8788 | // Similar to the Baker RB path in GenerateGcRootFieldLoad(), with an ADD instead of LDR. |
| 8789 | uint32_t custom_data = EncodeBakerReadBarrierUnsafeCasData(old_value.GetCode()); |
| 8790 | |
| 8791 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u); |
| 8792 | size_t wide_instructions = /* ADR+CMP+ADD+BNE */ 4u - narrow_instructions; |
| 8793 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8794 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8795 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
| 8796 | vixl32::Label return_address; |
| 8797 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8798 | __ cmp(mr, Operand(0)); |
| 8799 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8800 | __ add(EncodingSize(Wide), old_value, adjusted_old_value, Operand(expected)); // Preserves flags. |
| 8801 | EmitBakerReadBarrierBne(custom_data); |
| 8802 | __ bind(&return_address); |
| 8803 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8804 | BAKER_MARK_INTROSPECTION_UNSAFE_CAS_ADD_OFFSET); |
| 8805 | } |
| 8806 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8807 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8808 | Location ref, |
| 8809 | vixl32::Register obj, |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8810 | const vixl32::MemOperand& src, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8811 | bool needs_null_check) { |
| 8812 | DCHECK(kEmitCompilerReadBarrier); |
| 8813 | DCHECK(kUseBakerReadBarrier); |
| 8814 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8815 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8816 | // Marking Register) to decide whether we need to enter the slow |
| 8817 | // path to mark the reference. Then, in the slow path, check the |
| 8818 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8819 | // decide whether to mark `ref` or not. |
| 8820 | // |
| 8821 | // We use shared thunks for the slow path; shared within the method |
| 8822 | // for JIT, across methods for AOT. That thunk checks the holder |
| 8823 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 8824 | // it creates a fake dependency and returns to the LDR instruction. |
| 8825 | // |
| 8826 | // lr = &gray_return_address; |
| 8827 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8828 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8829 | // } |
| 8830 | // not_gray_return_address: |
| 8831 | // // Original reference load. If the offset is too large to fit |
| 8832 | // // into LDR, we use an adjusted base register here. |
| 8833 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 8834 | // gray_return_address: |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8835 | |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8836 | DCHECK(src.GetAddrMode() == vixl32::Offset); |
| 8837 | DCHECK_ALIGNED(src.GetOffsetImmediate(), sizeof(mirror::HeapReference<mirror::Object>)); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8838 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8839 | bool narrow = CanEmitNarrowLdr(ref_reg, src.GetBaseRegister(), src.GetOffsetImmediate()); |
| 8840 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8841 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8842 | temps.Exclude(ip); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8843 | uint32_t custom_data = |
| 8844 | EncodeBakerReadBarrierFieldData(src.GetBaseRegister().GetCode(), obj.GetCode(), narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8845 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8846 | { |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8847 | size_t narrow_instructions = |
| 8848 | /* CMP */ (mr.IsLow() ? 1u : 0u) + |
| 8849 | /* LDR+unpoison? */ (narrow ? (kPoisonHeapReferences ? 2u : 1u) : 0u); |
| 8850 | size_t wide_instructions = |
| 8851 | /* ADR+CMP+LDR+BNE+unpoison? */ (kPoisonHeapReferences ? 5u : 4u) - narrow_instructions; |
| 8852 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8853 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8854 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8855 | vixl32::Label return_address; |
| 8856 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8857 | __ cmp(mr, Operand(0)); |
| 8858 | EmitBakerReadBarrierBne(custom_data); |
| 8859 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8860 | __ ldr(EncodingSize(narrow ? Narrow : Wide), ref_reg, src); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8861 | if (needs_null_check) { |
| 8862 | MaybeRecordImplicitNullCheck(instruction); |
| 8863 | } |
| 8864 | // Note: We need a specific width for the unpoisoning NEG. |
| 8865 | if (kPoisonHeapReferences) { |
| 8866 | if (narrow) { |
| 8867 | // The only 16-bit encoding is T1 which sets flags outside IT block (i.e. RSBS, not RSB). |
| 8868 | __ rsbs(EncodingSize(Narrow), ref_reg, ref_reg, Operand(0)); |
| 8869 | } else { |
| 8870 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8871 | } |
| 8872 | } |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8873 | __ bind(&return_address); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8874 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8875 | narrow ? BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| 8876 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET); |
| 8877 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 8878 | MaybeGenerateMarkingRegisterCheck(/* code= */ 21, /* temp_loc= */ LocationFrom(ip)); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8879 | } |
| 8880 | |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8881 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8882 | Location ref, |
| 8883 | vixl32::Register obj, |
| 8884 | uint32_t offset, |
| 8885 | Location temp, |
| 8886 | bool needs_null_check) { |
| 8887 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 8888 | vixl32::Register base = obj; |
| 8889 | if (offset >= kReferenceLoadMinFarOffset) { |
| 8890 | base = RegisterFrom(temp); |
| 8891 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8892 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 8893 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 8894 | } |
| 8895 | GenerateFieldLoadWithBakerReadBarrier( |
| 8896 | instruction, ref, obj, MemOperand(base, offset), needs_null_check); |
| 8897 | } |
| 8898 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8899 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(Location ref, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8900 | vixl32::Register obj, |
| 8901 | uint32_t data_offset, |
| 8902 | Location index, |
| 8903 | Location temp, |
| 8904 | bool needs_null_check) { |
| 8905 | DCHECK(kEmitCompilerReadBarrier); |
| 8906 | DCHECK(kUseBakerReadBarrier); |
| 8907 | |
| 8908 | static_assert( |
| 8909 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8910 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8911 | ScaleFactor scale_factor = TIMES_4; |
| 8912 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8913 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8914 | // Marking Register) to decide whether we need to enter the slow |
| 8915 | // path to mark the reference. Then, in the slow path, check the |
| 8916 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8917 | // decide whether to mark `ref` or not. |
| 8918 | // |
| 8919 | // We use shared thunks for the slow path; shared within the method |
| 8920 | // for JIT, across methods for AOT. That thunk checks the holder |
| 8921 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 8922 | // it creates a fake dependency and returns to the LDR instruction. |
| 8923 | // |
| 8924 | // lr = &gray_return_address; |
| 8925 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8926 | // goto array_thunk<base_reg>(lr) |
| 8927 | // } |
| 8928 | // not_gray_return_address: |
| 8929 | // // Original reference load. If the offset is too large to fit |
| 8930 | // // into LDR, we use an adjusted base register here. |
| 8931 | // HeapReference<mirror::Object> reference = data[index]; |
| 8932 | // gray_return_address: |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8933 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8934 | DCHECK(index.IsValid()); |
| 8935 | vixl32::Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 8936 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 8937 | vixl32::Register data_reg = RegisterFrom(temp, DataType::Type::kInt32); // Raw pointer. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8938 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8939 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8940 | temps.Exclude(ip); |
| 8941 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(data_reg.GetCode()); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8942 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8943 | __ Add(data_reg, obj, Operand(data_offset)); |
| 8944 | { |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8945 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u); |
| 8946 | size_t wide_instructions = |
| 8947 | /* ADR+CMP+BNE+LDR+unpoison? */ (kPoisonHeapReferences ? 5u : 4u) - narrow_instructions; |
| 8948 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8949 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8950 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8951 | vixl32::Label return_address; |
| 8952 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8953 | __ cmp(mr, Operand(0)); |
| 8954 | EmitBakerReadBarrierBne(custom_data); |
| 8955 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8956 | __ ldr(ref_reg, MemOperand(data_reg, index_reg, vixl32::LSL, scale_factor)); |
| 8957 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 8958 | // Note: We need a Wide NEG for the unpoisoning. |
| 8959 | if (kPoisonHeapReferences) { |
| 8960 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8961 | } |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8962 | __ bind(&return_address); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8963 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8964 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8965 | } |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 8966 | MaybeGenerateMarkingRegisterCheck(/* code= */ 22, /* temp_loc= */ LocationFrom(ip)); |
Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8967 | } |
| 8968 | |
Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8969 | void CodeGeneratorARMVIXL::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 8970 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 8971 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 8972 | // The following condition is a run-time one; it is executed after the |
| 8973 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 8974 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 8975 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8976 | vixl32::Register temp = temp_loc.IsValid() ? RegisterFrom(temp_loc) : temps.Acquire(); |
| 8977 | GetAssembler()->GenerateMarkingRegisterCheck(temp, |
| 8978 | kMarkingRegisterCheckBreakCodeBaseCode + code); |
| 8979 | } |
| 8980 | } |
| 8981 | } |
| 8982 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8983 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8984 | Location out, |
| 8985 | Location ref, |
| 8986 | Location obj, |
| 8987 | uint32_t offset, |
| 8988 | Location index) { |
| 8989 | DCHECK(kEmitCompilerReadBarrier); |
| 8990 | |
| 8991 | // Insert a slow path based read barrier *after* the reference load. |
| 8992 | // |
| 8993 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8994 | // reference will be carried out by the runtime within the slow |
| 8995 | // path. |
| 8996 | // |
| 8997 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8998 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8999 | // not used by the artReadBarrierSlow entry point. |
| 9000 | // |
| 9001 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9002 | SlowPathCodeARMVIXL* slow_path = new (GetScopedAllocator()) |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9003 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 9004 | AddSlowPath(slow_path); |
| 9005 | |
| 9006 | __ B(slow_path->GetEntryLabel()); |
| 9007 | __ Bind(slow_path->GetExitLabel()); |
| 9008 | } |
| 9009 | |
| 9010 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9011 | Location out, |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9012 | Location ref, |
| 9013 | Location obj, |
| 9014 | uint32_t offset, |
| 9015 | Location index) { |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9016 | if (kEmitCompilerReadBarrier) { |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9017 | // Baker's read barriers shall be handled by the fast path |
Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 9018 | // (CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier). |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9019 | DCHECK(!kUseBakerReadBarrier); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9020 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 9021 | // by the runtime within the slow path. |
| 9022 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9023 | } else if (kPoisonHeapReferences) { |
| 9024 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 9025 | } |
| 9026 | } |
| 9027 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9028 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 9029 | Location out, |
| 9030 | Location root) { |
| 9031 | DCHECK(kEmitCompilerReadBarrier); |
| 9032 | |
| 9033 | // Insert a slow path based read barrier *after* the GC root load. |
| 9034 | // |
| 9035 | // Note that GC roots are not affected by heap poisoning, so we do |
| 9036 | // not need to do anything special for this here. |
| 9037 | SlowPathCodeARMVIXL* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9038 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9039 | AddSlowPath(slow_path); |
| 9040 | |
| 9041 | __ B(slow_path->GetEntryLabel()); |
| 9042 | __ Bind(slow_path->GetExitLabel()); |
| 9043 | } |
| 9044 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9045 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 9046 | // otherwise return a fall-back info that should be used instead. |
| 9047 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9048 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9049 | ArtMethod* method) { |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 9050 | if (method->IsIntrinsic() && |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9051 | desired_dispatch_info.code_ptr_location == CodePtrLocation::kCallCriticalNative) { |
Vladimir Marko | d3e9c62 | 2020-08-05 12:20:28 +0100 | [diff] [blame] | 9052 | // As a work-around for soft-float native ABI interfering with type checks, we are |
| 9053 | // inserting fake calls to Float.floatToRawIntBits() or Double.doubleToRawLongBits() |
| 9054 | // when a float or double argument is passed in core registers but we cannot do that |
| 9055 | // for actual intrinsic implementations that expect them in FP registers. Therefore |
| 9056 | // we do not use `kCallCriticalNative` for intrinsics with FP arguments; if they are |
| 9057 | // properly intrinsified, the dispatch type does not matter anyway. |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9058 | ScopedObjectAccess soa(Thread::Current()); |
| 9059 | uint32_t shorty_len; |
| 9060 | const char* shorty = method->GetShorty(&shorty_len); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9061 | for (uint32_t i = 1; i != shorty_len; ++i) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9062 | if (shorty[i] == 'D' || shorty[i] == 'F') { |
| 9063 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9064 | dispatch_info.code_ptr_location = CodePtrLocation::kCallArtMethod; |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9065 | return dispatch_info; |
| 9066 | } |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9067 | } |
| 9068 | } |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 9069 | return desired_dispatch_info; |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9070 | } |
| 9071 | |
Vladimir Marko | d254f5c | 2017-06-02 15:18:36 +0000 | [diff] [blame] | 9072 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall( |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9073 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9074 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9075 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9076 | case MethodLoadKind::kStringInit: { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9077 | uint32_t offset = |
| 9078 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 9079 | // temp = thread->string_init_entrypoint |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9080 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 9081 | break; |
| 9082 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9083 | case MethodLoadKind::kRecursive: |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9084 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9085 | break; |
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 | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9109 | case MethodLoadKind::kJitDirectAddress: |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 9110 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetMethodAddress())); |
| 9111 | break; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9112 | case MethodLoadKind::kRuntimeCall: { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9113 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 9114 | return; // No code pointer retrieval; the runtime performs the call directly. |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9115 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9116 | } |
| 9117 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9118 | auto call_code_pointer_member = [&](MemberOffset offset) { |
| 9119 | // LR = callee_method->member; |
| 9120 | GetAssembler()->LoadFromOffset(kLoadWord, lr, RegisterFrom(callee_method), offset.Int32Value()); |
| 9121 | { |
| 9122 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9123 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 9124 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9125 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9126 | CodeBufferCheckScope::kExactSize); |
| 9127 | // LR() |
| 9128 | __ blx(lr); |
| 9129 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9130 | } |
| 9131 | }; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9132 | switch (invoke->GetCodePtrLocation()) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9133 | case CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9134 | { |
| 9135 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9136 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9137 | vixl32::k32BitT32InstructionSizeInBytes, |
| 9138 | CodeBufferCheckScope::kMaximumSize); |
| 9139 | __ bl(GetFrameEntryLabel()); |
| 9140 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9141 | } |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9142 | break; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9143 | case CodePtrLocation::kCallCriticalNative: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9144 | size_t out_frame_size = |
| 9145 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorARMVIXL, |
| 9146 | kAapcsStackAlignment, |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 9147 | GetCriticalNativeDirectCallFrameSize>(invoke); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9148 | call_code_pointer_member(ArtMethod::EntryPointFromJniOffset(kArmPointerSize)); |
| 9149 | // Move the result when needed due to native and managed ABI mismatch. |
| 9150 | switch (invoke->GetType()) { |
| 9151 | case DataType::Type::kFloat32: |
| 9152 | __ Vmov(s0, r0); |
| 9153 | break; |
| 9154 | case DataType::Type::kFloat64: |
| 9155 | __ Vmov(d0, r0, r1); |
| 9156 | break; |
| 9157 | case DataType::Type::kBool: |
| 9158 | case DataType::Type::kInt8: |
| 9159 | case DataType::Type::kUint16: |
| 9160 | case DataType::Type::kInt16: |
| 9161 | case DataType::Type::kInt32: |
| 9162 | case DataType::Type::kInt64: |
| 9163 | case DataType::Type::kVoid: |
| 9164 | break; |
| 9165 | default: |
| 9166 | DCHECK(false) << invoke->GetType(); |
| 9167 | break; |
| 9168 | } |
| 9169 | if (out_frame_size != 0u) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 9170 | DecreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9171 | } |
| 9172 | break; |
| 9173 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 9174 | case CodePtrLocation::kCallArtMethod: |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 9175 | call_code_pointer_member(ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize)); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9176 | break; |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9177 | } |
| 9178 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9179 | DCHECK(!IsLeafMethod()); |
| 9180 | } |
| 9181 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9182 | void CodeGeneratorARMVIXL::GenerateVirtualCall( |
| 9183 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9184 | vixl32::Register temp = RegisterFrom(temp_location); |
| 9185 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9186 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 9187 | |
| 9188 | // Use the calling convention instead of the location of the receiver, as |
| 9189 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 9190 | // slow path, the arguments have been moved to the right place, so here we are |
| 9191 | // guaranteed that the receiver is the first register of the calling convention. |
| 9192 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 9193 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 9194 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9195 | { |
| 9196 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9197 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9198 | vixl32::kMaxInstructionSizeInBytes, |
| 9199 | CodeBufferCheckScope::kMaximumSize); |
Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 9200 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 9201 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 9202 | MaybeRecordImplicitNullCheck(invoke); |
| 9203 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9204 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 9205 | // emit a read barrier for the previous class reference load. |
| 9206 | // However this is not required in practice, as this is an |
| 9207 | // intermediate/temporary reference and because the current |
| 9208 | // concurrent copying collector keeps the from-space memory |
| 9209 | // intact/accessible until the end of the marking phase (the |
| 9210 | // concurrent copying collector may not in the future). |
| 9211 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 9212 | |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 9213 | // If we're compiling baseline, update the inline cache. |
| 9214 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 9215 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9216 | // temp = temp->GetMethodAt(method_offset); |
| 9217 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 9218 | kArmPointerSize).Int32Value(); |
| 9219 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 9220 | // LR = temp->GetEntryPoint(); |
| 9221 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9222 | { |
| 9223 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 9224 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 9225 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9226 | vixl32::k16BitT32InstructionSizeInBytes, |
| 9227 | CodeBufferCheckScope::kExactSize); |
| 9228 | // LR(); |
| 9229 | __ blx(lr); |
| 9230 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 9231 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9232 | } |
| 9233 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9234 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageIntrinsicPatch( |
| 9235 | uint32_t intrinsic_data) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9236 | return NewPcRelativePatch(/* dex_file= */ nullptr, intrinsic_data, &boot_image_other_patches_); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9237 | } |
| 9238 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9239 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageRelRoPatch( |
| 9240 | uint32_t boot_image_offset) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9241 | return NewPcRelativePatch(/* dex_file= */ nullptr, |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9242 | boot_image_offset, |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9243 | &boot_image_other_patches_); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9244 | } |
| 9245 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9246 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageMethodPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9247 | MethodReference target_method) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9248 | return NewPcRelativePatch( |
| 9249 | target_method.dex_file, target_method.index, &boot_image_method_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9250 | } |
| 9251 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9252 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewMethodBssEntryPatch( |
| 9253 | MethodReference target_method) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9254 | return NewPcRelativePatch( |
| 9255 | target_method.dex_file, target_method.index, &method_bss_entry_patches_); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9256 | } |
| 9257 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9258 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageTypePatch( |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9259 | const DexFile& dex_file, dex::TypeIndex type_index) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9260 | return NewPcRelativePatch(&dex_file, type_index.index_, &boot_image_type_patches_); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9261 | } |
| 9262 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9263 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewTypeBssEntryPatch( |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame^] | 9264 | HLoadClass* load_class) { |
| 9265 | const DexFile& dex_file = load_class->GetDexFile(); |
| 9266 | dex::TypeIndex type_index = load_class->GetTypeIndex(); |
| 9267 | ArenaDeque<PcRelativePatchInfo>* patches = nullptr; |
| 9268 | switch (load_class->GetLoadKind()) { |
| 9269 | case HLoadClass::LoadKind::kBssEntry: |
| 9270 | patches = &type_bss_entry_patches_; |
| 9271 | break; |
| 9272 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 9273 | patches = &public_type_bss_entry_patches_; |
| 9274 | break; |
| 9275 | case HLoadClass::LoadKind::kBssEntryPackage: |
| 9276 | patches = &package_type_bss_entry_patches_; |
| 9277 | break; |
| 9278 | default: |
| 9279 | LOG(FATAL) << "Unexpected load kind: " << load_class->GetLoadKind(); |
| 9280 | UNREACHABLE(); |
| 9281 | } |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9282 | return NewPcRelativePatch(&dex_file, type_index.index_, &type_bss_entry_patches_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9283 | } |
| 9284 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9285 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageStringPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9286 | const DexFile& dex_file, dex::StringIndex string_index) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9287 | return NewPcRelativePatch(&dex_file, string_index.index_, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9288 | } |
| 9289 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9290 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewStringBssEntryPatch( |
| 9291 | const DexFile& dex_file, dex::StringIndex string_index) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9292 | return NewPcRelativePatch(&dex_file, string_index.index_, &string_bss_entry_patches_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9293 | } |
| 9294 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9295 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9296 | const DexFile* dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9297 | patches->emplace_back(dex_file, offset_or_index); |
| 9298 | return &patches->back(); |
| 9299 | } |
| 9300 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9301 | void CodeGeneratorARMVIXL::EmitEntrypointThunkCall(ThreadOffset32 entrypoint_offset) { |
| 9302 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 9303 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9304 | call_entrypoint_patches_.emplace_back(/*dex_file*/ nullptr, entrypoint_offset.Uint32Value()); |
| 9305 | vixl::aarch32::Label* bl_label = &call_entrypoint_patches_.back().label; |
| 9306 | __ bind(bl_label); |
| 9307 | vixl32::Label placeholder_label; |
| 9308 | __ bl(&placeholder_label); // Placeholder, patched at link-time. |
| 9309 | __ bind(&placeholder_label); |
| 9310 | } |
| 9311 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9312 | void CodeGeneratorARMVIXL::EmitBakerReadBarrierBne(uint32_t custom_data) { |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9313 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 9314 | if (GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9315 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 9316 | vixl::aarch32::Label* slow_path_entry = &it->second.label; |
| 9317 | __ b(ne, EncodingSize(Wide), slow_path_entry); |
| 9318 | } else { |
| 9319 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 9320 | vixl::aarch32::Label* patch_label = &baker_read_barrier_patches_.back().label; |
| 9321 | __ bind(patch_label); |
| 9322 | vixl32::Label placeholder_label; |
| 9323 | __ b(ne, EncodingSize(Wide), &placeholder_label); // Placeholder, patched at link-time. |
| 9324 | __ bind(&placeholder_label); |
| 9325 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9326 | } |
| 9327 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9328 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 9329 | return DeduplicateUint32Literal(address, &uint32_literals_); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9330 | } |
| 9331 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 9332 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitStringLiteral( |
| 9333 | const DexFile& dex_file, |
| 9334 | dex::StringIndex string_index, |
| 9335 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9336 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9337 | return jit_string_patches_.GetOrCreate( |
| 9338 | StringReference(&dex_file, string_index), |
| 9339 | [this]() { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9340 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9341 | }); |
| 9342 | } |
| 9343 | |
| 9344 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 9345 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 9346 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9347 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9348 | return jit_class_patches_.GetOrCreate( |
| 9349 | TypeReference(&dex_file, type_index), |
| 9350 | [this]() { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9351 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9352 | }); |
| 9353 | } |
| 9354 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9355 | void CodeGeneratorARMVIXL::LoadBootImageAddress(vixl32::Register reg, |
| 9356 | uint32_t boot_image_reference) { |
| 9357 | if (GetCompilerOptions().IsBootImage()) { |
| 9358 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 9359 | NewBootImageIntrinsicPatch(boot_image_reference); |
| 9360 | EmitMovwMovtPlaceholder(labels, reg); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 9361 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9362 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 9363 | NewBootImageRelRoPatch(boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9364 | EmitMovwMovtPlaceholder(labels, reg); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9365 | __ Ldr(reg, MemOperand(reg, /* offset= */ 0)); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9366 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 9367 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9368 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 9369 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| 9370 | uintptr_t address = |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9371 | reinterpret_cast<uintptr_t>(heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9372 | __ Ldr(reg, DeduplicateBootImageAddressLiteral(dchecked_integral_cast<uint32_t>(address))); |
| 9373 | } |
| 9374 | } |
| 9375 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9376 | void CodeGeneratorARMVIXL::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 9377 | uint32_t boot_image_offset) { |
| 9378 | DCHECK(invoke->IsStatic()); |
| 9379 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 9380 | vixl32::Register argument = calling_convention.GetRegisterAt(0); |
| 9381 | if (GetCompilerOptions().IsBootImage()) { |
| 9382 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 9383 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 9384 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9385 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 9386 | PcRelativePatchInfo* labels = NewBootImageTypePatch(*target_method.dex_file, type_idx); |
| 9387 | EmitMovwMovtPlaceholder(labels, argument); |
| 9388 | } else { |
| 9389 | LoadBootImageAddress(argument, boot_image_offset); |
| 9390 | } |
| 9391 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 9392 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 9393 | } |
| 9394 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9395 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9396 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 9397 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9398 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9399 | for (const PcRelativePatchInfo& info : infos) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9400 | const DexFile* dex_file = info.target_dex_file; |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9401 | size_t offset_or_index = info.offset_or_index; |
| 9402 | DCHECK(info.add_pc_label.IsBound()); |
| 9403 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 9404 | // Add MOVW patch. |
| 9405 | DCHECK(info.movw_label.IsBound()); |
| 9406 | 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] | 9407 | 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] | 9408 | // Add MOVT patch. |
| 9409 | DCHECK(info.movt_label.IsBound()); |
| 9410 | 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] | 9411 | 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] | 9412 | } |
| 9413 | } |
| 9414 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9415 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 9416 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 9417 | const DexFile* target_dex_file, |
| 9418 | uint32_t pc_insn_offset, |
| 9419 | uint32_t boot_image_offset) { |
| 9420 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 9421 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9422 | } |
| 9423 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9424 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9425 | DCHECK(linker_patches->empty()); |
| 9426 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9427 | /* MOVW+MOVT for each entry */ 2u * boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9428 | /* MOVW+MOVT for each entry */ 2u * method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9429 | /* MOVW+MOVT for each entry */ 2u * boot_image_type_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9430 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame^] | 9431 | /* MOVW+MOVT for each entry */ 2u * public_type_bss_entry_patches_.size() + |
| 9432 | /* MOVW+MOVT for each entry */ 2u * package_type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9433 | /* MOVW+MOVT for each entry */ 2u * boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9434 | /* MOVW+MOVT for each entry */ 2u * string_bss_entry_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9435 | /* MOVW+MOVT for each entry */ 2u * boot_image_other_patches_.size() + |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9436 | call_entrypoint_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9437 | baker_read_barrier_patches_.size(); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9438 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 9439 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9440 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9441 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9442 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9443 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9444 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9445 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9446 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9447 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 9448 | DCHECK(boot_image_type_patches_.empty()); |
| 9449 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9450 | } |
| 9451 | if (GetCompilerOptions().IsBootImage()) { |
| 9452 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 9453 | boot_image_other_patches_, linker_patches); |
| 9454 | } else { |
| 9455 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 9456 | boot_image_other_patches_, linker_patches); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9457 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9458 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 9459 | method_bss_entry_patches_, linker_patches); |
| 9460 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 9461 | type_bss_entry_patches_, linker_patches); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame^] | 9462 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PublicTypeBssEntryPatch>( |
| 9463 | public_type_bss_entry_patches_, linker_patches); |
| 9464 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PackageTypeBssEntryPatch>( |
| 9465 | package_type_bss_entry_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9466 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 9467 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9468 | for (const PatchInfo<vixl32::Label>& info : call_entrypoint_patches_) { |
| 9469 | DCHECK(info.target_dex_file == nullptr); |
| 9470 | linker_patches->push_back(linker::LinkerPatch::CallEntrypointPatch( |
| 9471 | info.label.GetLocation(), info.offset_or_index)); |
| 9472 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9473 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9474 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 9475 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9476 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9477 | DCHECK_EQ(size, linker_patches->size()); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9478 | } |
| 9479 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9480 | bool CodeGeneratorARMVIXL::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9481 | return patch.GetType() == linker::LinkerPatch::Type::kCallEntrypoint || |
| 9482 | patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9483 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 9484 | } |
| 9485 | |
| 9486 | void CodeGeneratorARMVIXL::EmitThunkCode(const linker::LinkerPatch& patch, |
| 9487 | /*out*/ ArenaVector<uint8_t>* code, |
| 9488 | /*out*/ std::string* debug_name) { |
| 9489 | arm::ArmVIXLAssembler assembler(GetGraph()->GetAllocator()); |
| 9490 | switch (patch.GetType()) { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9491 | case linker::LinkerPatch::Type::kCallRelative: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9492 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 9493 | // to the generic JNI and interpreter trampolines. |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9494 | MemberOffset offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 9495 | assembler.LoadFromOffset(arm::kLoadWord, vixl32::pc, vixl32::r0, offset.Int32Value()); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9496 | assembler.GetVIXLAssembler()->Bkpt(0); |
| 9497 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 9498 | *debug_name = "MethodCallThunk"; |
| 9499 | } |
| 9500 | break; |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9501 | } |
| 9502 | case linker::LinkerPatch::Type::kCallEntrypoint: { |
| 9503 | assembler.LoadFromOffset(arm::kLoadWord, vixl32::pc, tr, patch.EntrypointOffset()); |
| 9504 | assembler.GetVIXLAssembler()->Bkpt(0); |
| 9505 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 9506 | *debug_name = "EntrypointCallThunk_" + std::to_string(patch.EntrypointOffset()); |
| 9507 | } |
| 9508 | break; |
| 9509 | } |
| 9510 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9511 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 9512 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 9513 | break; |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9514 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9515 | default: |
| 9516 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 9517 | UNREACHABLE(); |
| 9518 | } |
| 9519 | |
| 9520 | // Ensure we emit the literal pool if any. |
| 9521 | assembler.FinalizeCode(); |
| 9522 | code->resize(assembler.CodeSize()); |
| 9523 | MemoryRegion code_region(code->data(), code->size()); |
| 9524 | assembler.FinalizeInstructions(code_region); |
| 9525 | } |
| 9526 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9527 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateUint32Literal( |
| 9528 | uint32_t value, |
| 9529 | Uint32ToLiteralMap* map) { |
| 9530 | return map->GetOrCreate( |
| 9531 | value, |
| 9532 | [this, value]() { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9533 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ value); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9534 | }); |
| 9535 | } |
| 9536 | |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9537 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9538 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9539 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9540 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 9541 | Location::RequiresRegister()); |
| 9542 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 9543 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 9544 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9545 | } |
| 9546 | |
| 9547 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9548 | vixl32::Register res = OutputRegister(instr); |
| 9549 | vixl32::Register accumulator = |
| 9550 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 9551 | vixl32::Register mul_left = |
| 9552 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 9553 | vixl32::Register mul_right = |
| 9554 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 9555 | |
| 9556 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 9557 | __ Mla(res, mul_left, mul_right, accumulator); |
| 9558 | } else { |
| 9559 | __ Mls(res, mul_left, mul_right, accumulator); |
| 9560 | } |
| 9561 | } |
| 9562 | |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9563 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9564 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9565 | LOG(FATAL) << "Unreachable"; |
| 9566 | } |
| 9567 | |
| 9568 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9569 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9570 | LOG(FATAL) << "Unreachable"; |
| 9571 | } |
| 9572 | |
| 9573 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 9574 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9575 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9576 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9577 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9578 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 9579 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9580 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 9581 | if (switch_instr->GetStartValue() != 0) { |
| 9582 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 9583 | } |
| 9584 | } |
| 9585 | } |
| 9586 | |
| 9587 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 9588 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9589 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9590 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9591 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9592 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 9593 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9594 | |
| 9595 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 9596 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9597 | // Create a series of compare/jumps. |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9598 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9599 | vixl32::Register temp_reg = temps.Acquire(); |
| 9600 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 9601 | // the immediate, because IP is used as the destination register. For the other |
| 9602 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 9603 | // and they can be encoded in the instruction without making use of IP register. |
| 9604 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 9605 | |
| 9606 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 9607 | // Jump to successors[0] if value == lower_bound. |
| 9608 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 9609 | int32_t last_index = 0; |
| 9610 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9611 | __ Adds(temp_reg, temp_reg, -2); |
| 9612 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9613 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9614 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9615 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9616 | } |
| 9617 | if (num_entries - last_index == 2) { |
| 9618 | // The last missing case_value. |
| 9619 | __ Cmp(temp_reg, 1); |
| 9620 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9621 | } |
| 9622 | |
| 9623 | // And the default for any other value. |
| 9624 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 9625 | __ B(codegen_->GetLabelOf(default_block)); |
| 9626 | } |
| 9627 | } else { |
| 9628 | // Create a table lookup. |
| 9629 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 9630 | |
| 9631 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 9632 | |
| 9633 | // Remove the bias. |
| 9634 | vixl32::Register key_reg; |
| 9635 | if (lower_bound != 0) { |
| 9636 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 9637 | __ Sub(key_reg, value_reg, lower_bound); |
| 9638 | } else { |
| 9639 | key_reg = value_reg; |
| 9640 | } |
| 9641 | |
| 9642 | // Check whether the value is in the table, jump to default block if not. |
| 9643 | __ Cmp(key_reg, num_entries - 1); |
| 9644 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 9645 | |
Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9646 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9647 | vixl32::Register jump_offset = temps.Acquire(); |
| 9648 | |
| 9649 | // Load jump offset from the table. |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9650 | { |
| 9651 | const size_t jump_size = switch_instr->GetNumEntries() * sizeof(int32_t); |
| 9652 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9653 | (vixl32::kMaxInstructionSizeInBytes * 4) + jump_size, |
| 9654 | CodeBufferCheckScope::kMaximumSize); |
| 9655 | __ adr(table_base, jump_table->GetTableStartLabel()); |
| 9656 | __ ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9657 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9658 | // Jump to target block by branching to table_base(pc related) + offset. |
| 9659 | vixl32::Register target_address = table_base; |
| 9660 | __ add(target_address, table_base, jump_offset); |
| 9661 | __ bx(target_address); |
Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 9662 | |
Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9663 | jump_table->EmitTable(codegen_); |
| 9664 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9665 | } |
| 9666 | } |
| 9667 | |
Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9668 | // Copy the result of a call into the given target. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9669 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, DataType::Type type) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9670 | if (!trg.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9671 | DCHECK_EQ(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9672 | return; |
| 9673 | } |
| 9674 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9675 | DCHECK_NE(type, DataType::Type::kVoid); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9676 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9677 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9678 | if (return_loc.Equals(trg)) { |
| 9679 | return; |
| 9680 | } |
| 9681 | |
| 9682 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 9683 | // with the last branch. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9684 | if (type == DataType::Type::kInt64) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9685 | TODO_VIXL32(FATAL); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9686 | } else if (type == DataType::Type::kFloat64) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9687 | TODO_VIXL32(FATAL); |
| 9688 | } else { |
| 9689 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9690 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9691 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 9692 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9693 | } |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9694 | } |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9695 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9696 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9697 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9698 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9699 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9700 | locations->SetOut(Location::RequiresRegister()); |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9701 | } |
| 9702 | |
xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9703 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9704 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 9705 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9706 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 9707 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9708 | OutputRegister(instruction), |
| 9709 | InputRegisterAt(instruction, 0), |
| 9710 | method_offset); |
| 9711 | } else { |
| 9712 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 9713 | instruction->GetIndex(), kArmPointerSize)); |
| 9714 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9715 | OutputRegister(instruction), |
| 9716 | InputRegisterAt(instruction, 0), |
| 9717 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 9718 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9719 | OutputRegister(instruction), |
| 9720 | OutputRegister(instruction), |
| 9721 | method_offset); |
| 9722 | } |
Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9723 | } |
| 9724 | |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9725 | static void PatchJitRootUse(uint8_t* code, |
| 9726 | const uint8_t* roots_data, |
| 9727 | VIXLUInt32Literal* literal, |
| 9728 | uint64_t index_in_table) { |
| 9729 | DCHECK(literal->IsBound()); |
| 9730 | uint32_t literal_offset = literal->GetLocation(); |
| 9731 | uintptr_t address = |
| 9732 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9733 | uint8_t* data = code + literal_offset; |
| 9734 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9735 | } |
| 9736 | |
| 9737 | void CodeGeneratorARMVIXL::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9738 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9739 | const StringReference& string_reference = entry.first; |
| 9740 | VIXLUInt32Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9741 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9742 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9743 | } |
| 9744 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9745 | const TypeReference& type_reference = entry.first; |
| 9746 | VIXLUInt32Literal* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9747 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9748 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9749 | } |
| 9750 | } |
| 9751 | |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9752 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 9753 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 9754 | vixl32::Register out) { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9755 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9756 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 9757 | CodeBufferCheckScope::kMaximumSize); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9758 | // TODO(VIXL): Think about using mov instead of movw. |
| 9759 | __ bind(&labels->movw_label); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9760 | __ movw(out, /* operand= */ 0u); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9761 | __ bind(&labels->movt_label); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9762 | __ movt(out, /* operand= */ 0u); |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9763 | __ bind(&labels->add_pc_label); |
| 9764 | __ add(out, out, pc); |
| 9765 | } |
| 9766 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9767 | #undef __ |
| 9768 | #undef QUICK_ENTRY_POINT |
| 9769 | #undef TODO_VIXL32 |
| 9770 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9771 | #define __ assembler.GetVIXLAssembler()-> |
| 9772 | |
| 9773 | static void EmitGrayCheckAndFastPath(ArmVIXLAssembler& assembler, |
| 9774 | vixl32::Register base_reg, |
| 9775 | vixl32::MemOperand& lock_word, |
| 9776 | vixl32::Label* slow_path, |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9777 | int32_t raw_ldr_offset, |
| 9778 | vixl32::Label* throw_npe = nullptr) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9779 | // Load the lock word containing the rb_state. |
| 9780 | __ Ldr(ip, lock_word); |
| 9781 | // 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] | 9782 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9783 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 9784 | __ Tst(ip, Operand(LockWord::kReadBarrierStateMaskShifted)); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9785 | __ B(ne, slow_path, /* is_far_target= */ false); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9786 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 9787 | if (throw_npe != nullptr) { |
| 9788 | __ Bind(throw_npe); |
| 9789 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9790 | __ Add(lr, lr, raw_ldr_offset); |
| 9791 | // Introduce a dependency on the lock_word including rb_state, |
| 9792 | // to prevent load-load reordering, and without using |
| 9793 | // a memory barrier (which would be more expensive). |
| 9794 | __ Add(base_reg, base_reg, Operand(ip, LSR, 32)); |
| 9795 | __ Bx(lr); // And return back to the function. |
| 9796 | // Note: The fake dependency is unnecessary for the slow path. |
| 9797 | } |
| 9798 | |
| 9799 | // Load the read barrier introspection entrypoint in register `entrypoint` |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9800 | static vixl32::Register LoadReadBarrierMarkIntrospectionEntrypoint(ArmVIXLAssembler& assembler) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9801 | // The register where the read barrier introspection entrypoint is loaded |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9802 | // is the marking register. We clobber it here and the entrypoint restores it to 1. |
| 9803 | vixl32::Register entrypoint = mr; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9804 | // entrypoint = Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 9805 | DCHECK_EQ(ip.GetCode(), 12u); |
| 9806 | const int32_t entry_point_offset = |
| 9807 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ip.GetCode()); |
| 9808 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9809 | return entrypoint; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9810 | } |
| 9811 | |
| 9812 | void CodeGeneratorARMVIXL::CompileBakerReadBarrierThunk(ArmVIXLAssembler& assembler, |
| 9813 | uint32_t encoded_data, |
| 9814 | /*out*/ std::string* debug_name) { |
| 9815 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 9816 | switch (kind) { |
| 9817 | case BakerReadBarrierKind::kField: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9818 | vixl32::Register base_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 9819 | CheckValidReg(base_reg.GetCode()); |
| 9820 | vixl32::Register holder_reg(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9821 | CheckValidReg(holder_reg.GetCode()); |
| 9822 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 9823 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 9824 | temps.Exclude(ip); |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 9825 | // In the case of a field load, if `base_reg` differs from |
| 9826 | // `holder_reg`, the offset was too large and we must have emitted (during the construction |
| 9827 | // of the HIR graph, see `art::HInstructionBuilder::BuildInstanceFieldAccess`) and preserved |
| 9828 | // (see `art::PrepareForRegisterAllocation::VisitNullCheck`) an explicit null check before |
| 9829 | // the load. Otherwise, for implicit null checks, we need to null-check the holder as we do |
| 9830 | // not necessarily do that check before going to the thunk. |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9831 | vixl32::Label throw_npe_label; |
| 9832 | vixl32::Label* throw_npe = nullptr; |
| 9833 | if (GetCompilerOptions().GetImplicitNullChecks() && holder_reg.Is(base_reg)) { |
| 9834 | throw_npe = &throw_npe_label; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9835 | __ CompareAndBranchIfZero(holder_reg, throw_npe, /* is_far_target= */ false); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9836 | } |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9837 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 9838 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 9839 | // to load the reference and call the entrypoint that performs further checks on the |
| 9840 | // reference and marks it if needed. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9841 | vixl32::Label slow_path; |
| 9842 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
| 9843 | const int32_t raw_ldr_offset = (width == BakerReadBarrierWidth::kWide) |
| 9844 | ? BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET |
| 9845 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET; |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9846 | EmitGrayCheckAndFastPath( |
| 9847 | assembler, base_reg, lock_word, &slow_path, raw_ldr_offset, throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9848 | __ Bind(&slow_path); |
| 9849 | const int32_t ldr_offset = /* Thumb state adjustment (LR contains Thumb state). */ -1 + |
| 9850 | raw_ldr_offset; |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9851 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9852 | if (width == BakerReadBarrierWidth::kWide) { |
| 9853 | MemOperand ldr_half_address(lr, ldr_offset + 2); |
| 9854 | __ Ldrh(ip, ldr_half_address); // Load the LDR immediate half-word with "Rt | imm12". |
| 9855 | __ Ubfx(ip, ip, 0, 12); // Extract the offset imm12. |
| 9856 | __ Ldr(ip, MemOperand(base_reg, ip)); // Load the reference. |
| 9857 | } else { |
| 9858 | MemOperand ldr_address(lr, ldr_offset); |
| 9859 | __ Ldrh(ip, ldr_address); // Load the LDR immediate, encoding T1. |
| 9860 | __ Add(ep_reg, // Adjust the entrypoint address to the entrypoint |
| 9861 | ep_reg, // for narrow LDR. |
| 9862 | Operand(BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_ENTRYPOINT_OFFSET)); |
| 9863 | __ Ubfx(ip, ip, 6, 5); // Extract the imm5, i.e. offset / 4. |
| 9864 | __ Ldr(ip, MemOperand(base_reg, ip, LSL, 2)); // Load the reference. |
| 9865 | } |
| 9866 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 9867 | __ Bx(ep_reg); // Jump to the entrypoint. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9868 | break; |
| 9869 | } |
| 9870 | case BakerReadBarrierKind::kArray: { |
| 9871 | vixl32::Register base_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 9872 | CheckValidReg(base_reg.GetCode()); |
| 9873 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9874 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9875 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 9876 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 9877 | temps.Exclude(ip); |
| 9878 | vixl32::Label slow_path; |
| 9879 | int32_t data_offset = |
| 9880 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 9881 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 9882 | DCHECK_LT(lock_word.GetOffsetImmediate(), 0); |
| 9883 | const int32_t raw_ldr_offset = BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET; |
| 9884 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, raw_ldr_offset); |
| 9885 | __ Bind(&slow_path); |
| 9886 | const int32_t ldr_offset = /* Thumb state adjustment (LR contains Thumb state). */ -1 + |
| 9887 | raw_ldr_offset; |
| 9888 | MemOperand ldr_address(lr, ldr_offset + 2); |
| 9889 | __ Ldrb(ip, ldr_address); // Load the LDR (register) byte with "00 | imm2 | Rm", |
| 9890 | // i.e. Rm+32 because the scale in imm2 is 2. |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9891 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9892 | __ Bfi(ep_reg, ip, 3, 6); // Insert ip to the entrypoint address to create |
| 9893 | // a switch case target based on the index register. |
| 9894 | __ Mov(ip, base_reg); // Move the base register to ip0. |
| 9895 | __ Bx(ep_reg); // Jump to the entrypoint's array switch case. |
| 9896 | break; |
| 9897 | } |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9898 | case BakerReadBarrierKind::kGcRoot: |
| 9899 | case BakerReadBarrierKind::kUnsafeCas: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9900 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 9901 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 9902 | // otherwise return the reference (or the extracted forwarding address). |
| 9903 | // There is no gray bit check for GC roots. |
| 9904 | vixl32::Register root_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 9905 | CheckValidReg(root_reg.GetCode()); |
| 9906 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9907 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9908 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 9909 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 9910 | temps.Exclude(ip); |
| 9911 | vixl32::Label return_label, not_marked, forwarding_address; |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9912 | __ CompareAndBranchIfZero(root_reg, &return_label, /* is_far_target= */ false); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9913 | MemOperand lock_word(root_reg, mirror::Object::MonitorOffset().Int32Value()); |
| 9914 | __ Ldr(ip, lock_word); |
| 9915 | __ Tst(ip, LockWord::kMarkBitStateMaskShifted); |
| 9916 | __ B(eq, ¬_marked); |
| 9917 | __ Bind(&return_label); |
| 9918 | __ Bx(lr); |
| 9919 | __ Bind(¬_marked); |
| 9920 | static_assert(LockWord::kStateShift == 30 && LockWord::kStateForwardingAddress == 3, |
| 9921 | "To use 'CMP ip, #modified-immediate; BHS', we need the lock word state in " |
| 9922 | " the highest bits and the 'forwarding address' state to have all bits set"); |
| 9923 | __ Cmp(ip, Operand(0xc0000000)); |
| 9924 | __ B(hs, &forwarding_address); |
Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9925 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9926 | // Adjust the art_quick_read_barrier_mark_introspection address in kBakerCcEntrypointRegister |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9927 | // to one of art_quick_read_barrier_mark_introspection_{gc_roots_{wide,narrow},unsafe_cas}. |
| 9928 | DCHECK(kind != BakerReadBarrierKind::kUnsafeCas || width == BakerReadBarrierWidth::kWide); |
| 9929 | int32_t entrypoint_offset = |
| 9930 | (kind == BakerReadBarrierKind::kGcRoot) |
| 9931 | ? (width == BakerReadBarrierWidth::kWide) |
| 9932 | ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_ENTRYPOINT_OFFSET |
| 9933 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_ENTRYPOINT_OFFSET |
| 9934 | : BAKER_MARK_INTROSPECTION_UNSAFE_CAS_ENTRYPOINT_OFFSET; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9935 | __ Add(ep_reg, ep_reg, Operand(entrypoint_offset)); |
| 9936 | __ Mov(ip, root_reg); |
| 9937 | __ Bx(ep_reg); |
| 9938 | __ Bind(&forwarding_address); |
| 9939 | __ Lsl(root_reg, ip, LockWord::kForwardingAddressShift); |
| 9940 | __ Bx(lr); |
| 9941 | break; |
| 9942 | } |
| 9943 | default: |
| 9944 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 9945 | UNREACHABLE(); |
| 9946 | } |
| 9947 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9948 | // For JIT, the slow path is considered part of the compiled method, |
Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 9949 | // so JIT should pass null as `debug_name`. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 9950 | DCHECK(!GetCompilerOptions().IsJitCompiler() || debug_name == nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9951 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9952 | std::ostringstream oss; |
| 9953 | oss << "BakerReadBarrierThunk"; |
| 9954 | switch (kind) { |
| 9955 | case BakerReadBarrierKind::kField: |
| 9956 | oss << "Field"; |
| 9957 | if (BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide) { |
| 9958 | oss << "Wide"; |
| 9959 | } |
| 9960 | oss << "_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 9961 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 9962 | break; |
| 9963 | case BakerReadBarrierKind::kArray: |
| 9964 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 9965 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9966 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9967 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 9968 | break; |
| 9969 | case BakerReadBarrierKind::kGcRoot: |
| 9970 | oss << "GcRoot"; |
| 9971 | if (BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide) { |
| 9972 | oss << "Wide"; |
| 9973 | } |
| 9974 | oss << "_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 9975 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9976 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9977 | break; |
Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9978 | case BakerReadBarrierKind::kUnsafeCas: |
| 9979 | oss << "UnsafeCas_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 9980 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9981 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9982 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 9983 | break; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9984 | } |
| 9985 | *debug_name = oss.str(); |
| 9986 | } |
| 9987 | } |
| 9988 | |
| 9989 | #undef __ |
| 9990 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9991 | } // namespace arm |
| 9992 | } // namespace art |