Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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_arm64.h" |
| 18 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 19 | #include "aarch64/assembler-aarch64.h" |
| 20 | #include "aarch64/registers-aarch64.h" |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 21 | #include "arch/arm64/asm_support_arm64.h" |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 22 | #include "arch/arm64/instruction_set_features_arm64.h" |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 23 | #include "arch/arm64/jni_frame_arm64.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 24 | #include "art_method-inl.h" |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 25 | #include "base/bit_utils.h" |
| 26 | #include "base/bit_utils_iterator.h" |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 27 | #include "class_root-inl.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 28 | #include "class_table.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 29 | #include "code_generator_utils.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 30 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 31 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 32 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 33 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 34 | #include "heap_poisoning.h" |
Nicolas Geoffray | 4313ccb | 2020-08-26 17:01:15 +0100 | [diff] [blame] | 35 | #include "interpreter/mterp/nterp.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 36 | #include "intrinsics.h" |
| 37 | #include "intrinsics_arm64.h" |
Ulya Trafimovich | ec696e5 | 2022-01-26 10:21:32 +0000 | [diff] [blame] | 38 | #include "intrinsics_utils.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 39 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 40 | #include "lock_word.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 41 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 42 | #include "mirror/class-inl.h" |
Vladimir Marko | 2d98dc2 | 2020-10-01 11:21:37 +0000 | [diff] [blame] | 43 | #include "mirror/var_handle.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 44 | #include "offsets.h" |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 45 | #include "optimizing/common_arm64.h" |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 46 | #include "optimizing/nodes.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 47 | #include "thread.h" |
| 48 | #include "utils/arm64/assembler_arm64.h" |
| 49 | #include "utils/assembler.h" |
| 50 | #include "utils/stack_checks.h" |
| 51 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 52 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 53 | using vixl::ExactAssemblyScope; |
| 54 | using vixl::CodeBufferCheckScope; |
| 55 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 56 | |
| 57 | #ifdef __ |
| 58 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 59 | #endif |
| 60 | |
VladimĂr Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame] | 61 | namespace art HIDDEN { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 62 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 63 | template<class MirrorType> |
| 64 | class GcRoot; |
| 65 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 66 | namespace arm64 { |
| 67 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 68 | using helpers::ARM64EncodableConstantOrRegister; |
| 69 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 70 | using helpers::CPURegisterFrom; |
| 71 | using helpers::DRegisterFrom; |
| 72 | using helpers::FPRegisterFrom; |
| 73 | using helpers::HeapOperand; |
| 74 | using helpers::HeapOperandFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 75 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 76 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 77 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 78 | using helpers::InputRegisterAt; |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 79 | using helpers::Int64FromLocation; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 80 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 81 | using helpers::LocationFrom; |
| 82 | using helpers::OperandFromMemOperand; |
| 83 | using helpers::OutputCPURegister; |
| 84 | using helpers::OutputFPRegister; |
| 85 | using helpers::OutputRegister; |
| 86 | using helpers::RegisterFrom; |
| 87 | using helpers::StackOperandFrom; |
| 88 | using helpers::VIXLRegCodeFromART; |
| 89 | using helpers::WRegisterFrom; |
| 90 | using helpers::XRegisterFrom; |
| 91 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 92 | // The compare/jump sequence will generate about (1.5 * num_entries + 3) instructions. While jump |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 93 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 94 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 95 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 96 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 97 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 98 | // offset < 16KiB. For offsets >= 16KiB, the load shall be emitted as two or more instructions. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 99 | // For the Baker read barrier implementation using link-time generated thunks we need to split |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 100 | // the offset explicitly. |
| 101 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 102 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 103 | inline Condition ARM64Condition(IfCondition cond) { |
| 104 | switch (cond) { |
| 105 | case kCondEQ: return eq; |
| 106 | case kCondNE: return ne; |
| 107 | case kCondLT: return lt; |
| 108 | case kCondLE: return le; |
| 109 | case kCondGT: return gt; |
| 110 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 111 | case kCondB: return lo; |
| 112 | case kCondBE: return ls; |
| 113 | case kCondA: return hi; |
| 114 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 115 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 116 | LOG(FATAL) << "Unreachable"; |
| 117 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 120 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 121 | // The ARM64 condition codes can express all the necessary branches, see the |
| 122 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 123 | // There is no dex instruction or HIR that would need the missing conditions |
| 124 | // "equal or unordered" or "not equal". |
| 125 | switch (cond) { |
| 126 | case kCondEQ: return eq; |
| 127 | case kCondNE: return ne /* unordered */; |
| 128 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 129 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 130 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 131 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 132 | default: |
| 133 | LOG(FATAL) << "UNREACHABLE"; |
| 134 | UNREACHABLE(); |
| 135 | } |
| 136 | } |
| 137 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 138 | Location ARM64ReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 139 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 140 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 141 | // but we use the exact registers for clarity. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 142 | if (return_type == DataType::Type::kFloat32) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 143 | return LocationFrom(s0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 144 | } else if (return_type == DataType::Type::kFloat64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 145 | return LocationFrom(d0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 146 | } else if (return_type == DataType::Type::kInt64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 147 | return LocationFrom(x0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 148 | } else if (return_type == DataType::Type::kVoid) { |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 149 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 150 | } else { |
| 151 | return LocationFrom(w0); |
| 152 | } |
| 153 | } |
| 154 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 155 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 156 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 157 | } |
| 158 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 159 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 160 | InvokeRuntimeCallingConvention calling_convention; |
| 161 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 162 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 163 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 164 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 165 | DataType::Type::kReference).GetCode()); |
| 166 | return caller_saves; |
| 167 | } |
| 168 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 169 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 170 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 171 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 172 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 173 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 174 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 175 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 176 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 177 | // If the register holds an object, update the stack mask. |
| 178 | if (locations->RegisterContainsObject(i)) { |
| 179 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 180 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 181 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 182 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 183 | saved_core_stack_offsets_[i] = stack_offset; |
| 184 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 185 | } |
| 186 | |
Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 187 | const size_t fp_reg_size = codegen->GetSlowPathFPWidth(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 188 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 189 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 190 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 191 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 192 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 193 | stack_offset += fp_reg_size; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 194 | } |
| 195 | |
Artem Serov | 55ab7e8 | 2020-04-27 21:02:28 +0100 | [diff] [blame] | 196 | InstructionCodeGeneratorARM64* visitor = |
| 197 | down_cast<CodeGeneratorARM64*>(codegen)->GetInstructionCodeGeneratorArm64(); |
| 198 | visitor->SaveLiveRegistersHelper(locations, codegen->GetFirstRegisterSlotInSlowPath()); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Artem Serov | 55ab7e8 | 2020-04-27 21:02:28 +0100 | [diff] [blame] | 202 | InstructionCodeGeneratorARM64* visitor = |
| 203 | down_cast<CodeGeneratorARM64*>(codegen)->GetInstructionCodeGeneratorArm64(); |
| 204 | visitor->RestoreLiveRegistersHelper(locations, codegen->GetFirstRegisterSlotInSlowPath()); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 205 | } |
| 206 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 207 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 208 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 209 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 210 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 211 | void EmitNativeCode(CodeGenerator* codegen) override { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 212 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 213 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 214 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 215 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 216 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 217 | // Live registers will be restored in the catch block if caught. |
| 218 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 219 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 220 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 221 | // move resolver. |
| 222 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 223 | codegen->EmitParallelMoves(locations->InAt(0), |
| 224 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 225 | DataType::Type::kInt32, |
| 226 | locations->InAt(1), |
| 227 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 228 | DataType::Type::kInt32); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 229 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 230 | ? kQuickThrowStringBounds |
| 231 | : kQuickThrowArrayBounds; |
| 232 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 233 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 234 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 235 | } |
| 236 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 237 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 238 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 239 | const char* GetDescription() const override { return "BoundsCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 240 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 241 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 242 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 243 | }; |
| 244 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 245 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 246 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 247 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 248 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 249 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 250 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 251 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 252 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 253 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 256 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 257 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 258 | const char* GetDescription() const override { return "DivZeroCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 259 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 260 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 261 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 262 | }; |
| 263 | |
| 264 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 265 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 266 | LoadClassSlowPathARM64(HLoadClass* cls, HInstruction* at) |
| 267 | : SlowPathCodeARM64(at), cls_(cls) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 268 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 269 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 272 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 273 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 274 | Location out = locations->Out(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 275 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 276 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 277 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 278 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 279 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 280 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 281 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 282 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 283 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 284 | if (must_resolve_type) { |
Santiago Aboy Solanes | a0232ad | 2021-11-08 17:00:06 +0000 | [diff] [blame] | 285 | DCHECK(IsSameDexFile(cls_->GetDexFile(), arm64_codegen->GetGraph()->GetDexFile()) || |
Santiago Aboy Solanes | 69a87e3 | 2022-03-08 16:43:54 +0000 | [diff] [blame] | 286 | arm64_codegen->GetCompilerOptions().WithinOatFile(&cls_->GetDexFile()) || |
| 287 | ContainsElement(Runtime::Current()->GetClassLinker()->GetBootClassPath(), |
| 288 | &cls_->GetDexFile())); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 289 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 290 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 291 | if (cls_->NeedsAccessCheck()) { |
| 292 | CheckEntrypointTypes<kQuickResolveTypeAndVerifyAccess, void*, uint32_t>(); |
| 293 | arm64_codegen->InvokeRuntime(kQuickResolveTypeAndVerifyAccess, instruction_, dex_pc, this); |
| 294 | } else { |
| 295 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| 296 | arm64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 297 | } |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 298 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 299 | } else { |
| 300 | DCHECK(must_do_clinit); |
| 301 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 302 | arm64_codegen->MoveLocation(LocationFrom(calling_convention.GetRegisterAt(0)), |
| 303 | source, |
| 304 | cls_->GetType()); |
| 305 | } |
| 306 | if (must_do_clinit) { |
| 307 | arm64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 308 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 309 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 310 | |
| 311 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 312 | if (out.IsValid()) { |
| 313 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 314 | DataType::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 315 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 316 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 317 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 318 | __ B(GetExitLabel()); |
| 319 | } |
| 320 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 321 | const char* GetDescription() const override { return "LoadClassSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 322 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 323 | private: |
| 324 | // The class this slow path will load. |
| 325 | HLoadClass* const cls_; |
| 326 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 327 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 328 | }; |
| 329 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 330 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 331 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 332 | explicit LoadStringSlowPathARM64(HLoadString* instruction) |
| 333 | : SlowPathCodeARM64(instruction) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 334 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 335 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 336 | LocationSummary* locations = instruction_->GetLocations(); |
| 337 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 338 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 339 | |
| 340 | __ Bind(GetEntryLabel()); |
| 341 | SaveLiveRegisters(codegen, locations); |
| 342 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 343 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 344 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 345 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 346 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 347 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 348 | DataType::Type type = instruction_->GetType(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 349 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 350 | |
| 351 | RestoreLiveRegisters(codegen, locations); |
| 352 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 353 | __ B(GetExitLabel()); |
| 354 | } |
| 355 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 356 | const char* GetDescription() const override { return "LoadStringSlowPathARM64"; } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 357 | |
| 358 | private: |
| 359 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 360 | }; |
| 361 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 362 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 363 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 364 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 365 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 366 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 367 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 368 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 369 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 370 | // Live registers will be restored in the catch block if caught. |
| 371 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 372 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 373 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 374 | instruction_, |
| 375 | instruction_->GetDexPc(), |
| 376 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 377 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 378 | } |
| 379 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 380 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 381 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 382 | const char* GetDescription() const override { return "NullCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 383 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 384 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 385 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 386 | }; |
| 387 | |
| 388 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 389 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 390 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 391 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 392 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 393 | void EmitNativeCode(CodeGenerator* codegen) override { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 394 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 395 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 396 | __ Bind(GetEntryLabel()); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 397 | SaveLiveRegisters(codegen, locations); // Only saves live vector regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 398 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 399 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 400 | RestoreLiveRegisters(codegen, locations); // Only restores live vector regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 401 | if (successor_ == nullptr) { |
| 402 | __ B(GetReturnLabel()); |
| 403 | } else { |
| 404 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 405 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 406 | } |
| 407 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 408 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 409 | DCHECK(successor_ == nullptr); |
| 410 | return &return_label_; |
| 411 | } |
| 412 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 413 | HBasicBlock* GetSuccessor() const { |
| 414 | return successor_; |
| 415 | } |
| 416 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 417 | const char* GetDescription() const override { return "SuspendCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 418 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 419 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 420 | // If not null, the block to branch to after the suspend check. |
| 421 | HBasicBlock* const successor_; |
| 422 | |
| 423 | // If `successor_` is null, the label to branch to after the suspend check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 424 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 425 | |
| 426 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 427 | }; |
| 428 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 429 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 430 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 431 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 432 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 433 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 434 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 435 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 436 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 437 | DCHECK(instruction_->IsCheckCast() |
| 438 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 439 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 440 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 441 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 442 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 443 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 444 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 445 | SaveLiveRegisters(codegen, locations); |
| 446 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 447 | |
| 448 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 449 | // move resolver. |
| 450 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 451 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 452 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 453 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 454 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 455 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 456 | DataType::Type::kReference); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 457 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 458 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 459 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 460 | DataType::Type ret_type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 461 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 462 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 463 | } else { |
| 464 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 465 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 466 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 467 | } |
| 468 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 469 | if (!is_fatal_) { |
| 470 | RestoreLiveRegisters(codegen, locations); |
| 471 | __ B(GetExitLabel()); |
| 472 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 475 | const char* GetDescription() const override { return "TypeCheckSlowPathARM64"; } |
| 476 | bool IsFatal() const override { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 477 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 478 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 479 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 480 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 481 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 482 | }; |
| 483 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 484 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 485 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 486 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 487 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 488 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 489 | void EmitNativeCode(CodeGenerator* codegen) override { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 490 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 491 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 492 | LocationSummary* locations = instruction_->GetLocations(); |
| 493 | SaveLiveRegisters(codegen, locations); |
| 494 | InvokeRuntimeCallingConvention calling_convention; |
| 495 | __ Mov(calling_convention.GetRegisterAt(0), |
| 496 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 497 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 498 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 501 | const char* GetDescription() const override { return "DeoptimizationSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 502 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 503 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 504 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 505 | }; |
| 506 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 507 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 508 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 509 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 510 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 511 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 512 | LocationSummary* locations = instruction_->GetLocations(); |
| 513 | __ Bind(GetEntryLabel()); |
| 514 | SaveLiveRegisters(codegen, locations); |
| 515 | |
| 516 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 517 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 518 | parallel_move.AddMove( |
| 519 | locations->InAt(0), |
| 520 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 521 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 522 | nullptr); |
| 523 | parallel_move.AddMove( |
| 524 | locations->InAt(1), |
| 525 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 526 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 527 | nullptr); |
| 528 | parallel_move.AddMove( |
| 529 | locations->InAt(2), |
| 530 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 531 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 532 | nullptr); |
| 533 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 534 | |
| 535 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 536 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 537 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 538 | RestoreLiveRegisters(codegen, locations); |
| 539 | __ B(GetExitLabel()); |
| 540 | } |
| 541 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 542 | const char* GetDescription() const override { return "ArraySetSlowPathARM64"; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 543 | |
| 544 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 545 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 546 | }; |
| 547 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 548 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 549 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 550 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 551 | |
| 552 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 553 | // underlying code buffer and we have generated the jump table with right size. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 554 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 555 | num_entries * sizeof(int32_t), |
| 556 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 557 | |
| 558 | __ Bind(&table_start_); |
| 559 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 560 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 561 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 562 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 563 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 564 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 565 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 566 | Literal<int32_t> literal(jump_offset); |
| 567 | __ place(&literal); |
| 568 | } |
| 569 | } |
| 570 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 571 | // Slow path generating a read barrier for a heap reference. |
| 572 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 573 | public: |
| 574 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 575 | Location out, |
| 576 | Location ref, |
| 577 | Location obj, |
| 578 | uint32_t offset, |
| 579 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 580 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 581 | out_(out), |
| 582 | ref_(ref), |
| 583 | obj_(obj), |
| 584 | offset_(offset), |
| 585 | index_(index) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 586 | DCHECK(gUseReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 587 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 588 | // has been overwritten by (or after) the heap object reference load |
| 589 | // to be instrumented, e.g.: |
| 590 | // |
| 591 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 592 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 593 | // |
| 594 | // In that case, we have lost the information about the original |
| 595 | // object, and the emitted read barrier cannot work properly. |
| 596 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 597 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 598 | } |
| 599 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 600 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 601 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 602 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 603 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 604 | DCHECK(locations->CanCall()); |
| 605 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 606 | DCHECK(instruction_->IsInstanceFieldGet() || |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 607 | instruction_->IsPredicatedInstanceFieldGet() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 608 | instruction_->IsStaticFieldGet() || |
| 609 | instruction_->IsArrayGet() || |
| 610 | instruction_->IsInstanceOf() || |
| 611 | instruction_->IsCheckCast() || |
Vladimir Marko | a41ea27 | 2020-09-07 15:24:36 +0000 | [diff] [blame] | 612 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 613 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 614 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 615 | // The read barrier instrumentation of object ArrayGet |
| 616 | // instructions does not support the HIntermediateAddress |
| 617 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 618 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 619 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 620 | |
| 621 | __ Bind(GetEntryLabel()); |
| 622 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 623 | SaveLiveRegisters(codegen, locations); |
| 624 | |
| 625 | // We may have to change the index's value, but as `index_` is a |
| 626 | // constant member (like other "inputs" of this slow path), |
| 627 | // introduce a copy of it, `index`. |
| 628 | Location index = index_; |
| 629 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 630 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 631 | if (instruction_->IsArrayGet()) { |
| 632 | // Compute the actual memory offset and store it in `index`. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 633 | Register index_reg = RegisterFrom(index_, DataType::Type::kInt32); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 634 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 635 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 636 | // We are about to change the value of `index_reg` (see the |
| 637 | // calls to vixl::MacroAssembler::Lsl and |
| 638 | // vixl::MacroAssembler::Mov below), but it has |
| 639 | // not been saved by the previous call to |
| 640 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 641 | // callee-save register -- |
| 642 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 643 | // callee-save registers, as it has been designed with the |
| 644 | // assumption that callee-save registers are supposed to be |
| 645 | // handled by the called function. So, as a callee-save |
| 646 | // register, `index_reg` _would_ eventually be saved onto |
| 647 | // the stack, but it would be too late: we would have |
| 648 | // changed its value earlier. Therefore, we manually save |
| 649 | // it here into another freely available register, |
| 650 | // `free_reg`, chosen of course among the caller-save |
| 651 | // registers (as a callee-save `free_reg` register would |
| 652 | // exhibit the same problem). |
| 653 | // |
| 654 | // Note we could have requested a temporary register from |
| 655 | // the register allocator instead; but we prefer not to, as |
| 656 | // this is a slow path, and we know we can find a |
| 657 | // caller-save register that is available. |
| 658 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 659 | __ Mov(free_reg.W(), index_reg); |
| 660 | index_reg = free_reg; |
| 661 | index = LocationFrom(index_reg); |
| 662 | } else { |
| 663 | // The initial register stored in `index_` has already been |
| 664 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 665 | // (as it is not a callee-save register), so we can freely |
| 666 | // use it. |
| 667 | } |
| 668 | // Shifting the index value contained in `index_reg` by the scale |
| 669 | // factor (2) cannot overflow in practice, as the runtime is |
| 670 | // unable to allocate object arrays with a size larger than |
| 671 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 672 | __ Lsl(index_reg, index_reg, DataType::SizeShift(type)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 673 | static_assert( |
| 674 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 675 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 676 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 677 | } else { |
Ulya Trafimovich | ec696e5 | 2022-01-26 10:21:32 +0000 | [diff] [blame] | 678 | // In the case of the following intrinsics `index_` is not shifted by a scale factor of 2 |
| 679 | // (as in the case of ArrayGet), as it is actually an offset to an object field within an |
| 680 | // object. |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 681 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 682 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
Ulya Trafimovich | ec696e5 | 2022-01-26 10:21:32 +0000 | [diff] [blame] | 683 | HInvoke* invoke = instruction_->AsInvoke(); |
| 684 | DCHECK(IsUnsafeGetObject(invoke) || |
| 685 | IsVarHandleGet(invoke) || |
| 686 | IsUnsafeCASObject(invoke) || |
| 687 | IsVarHandleCASFamily(invoke)) << invoke->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 688 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 689 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
| 693 | // We're moving two or three locations to locations that could |
| 694 | // overlap, so we need a parallel move resolver. |
| 695 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 696 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 697 | parallel_move.AddMove(ref_, |
| 698 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 699 | type, |
| 700 | nullptr); |
| 701 | parallel_move.AddMove(obj_, |
| 702 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 703 | type, |
| 704 | nullptr); |
| 705 | if (index.IsValid()) { |
| 706 | parallel_move.AddMove(index, |
| 707 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 708 | DataType::Type::kInt32, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 709 | nullptr); |
| 710 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 711 | } else { |
| 712 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 713 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 714 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 715 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 716 | instruction_, |
| 717 | instruction_->GetDexPc(), |
| 718 | this); |
| 719 | CheckEntrypointTypes< |
| 720 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 721 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 722 | |
| 723 | RestoreLiveRegisters(codegen, locations); |
| 724 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 725 | __ B(GetExitLabel()); |
| 726 | } |
| 727 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 728 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 729 | |
| 730 | private: |
| 731 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 732 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 733 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 734 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 735 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 736 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 737 | } |
| 738 | } |
| 739 | // We shall never fail to find a free caller-save register, as |
| 740 | // there are more than two core caller-save registers on ARM64 |
| 741 | // (meaning it is possible to find one which is different from |
| 742 | // `ref` and `obj`). |
| 743 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 744 | LOG(FATAL) << "Could not find a free register"; |
| 745 | UNREACHABLE(); |
| 746 | } |
| 747 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 748 | const Location out_; |
| 749 | const Location ref_; |
| 750 | const Location obj_; |
| 751 | const uint32_t offset_; |
| 752 | // An additional location containing an index to an array. |
| 753 | // Only used for HArrayGet and the UnsafeGetObject & |
| 754 | // UnsafeGetObjectVolatile intrinsics. |
| 755 | const Location index_; |
| 756 | |
| 757 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 758 | }; |
| 759 | |
| 760 | // Slow path generating a read barrier for a GC root. |
| 761 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 762 | public: |
| 763 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 764 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 765 | DCHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 766 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 767 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 768 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 769 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 770 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 771 | DCHECK(locations->CanCall()); |
| 772 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Vladimir Marko | a41ea27 | 2020-09-07 15:24:36 +0000 | [diff] [blame] | 773 | DCHECK(instruction_->IsLoadClass() || |
| 774 | instruction_->IsLoadString() || |
| 775 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 776 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 777 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 778 | |
| 779 | __ Bind(GetEntryLabel()); |
| 780 | SaveLiveRegisters(codegen, locations); |
| 781 | |
| 782 | InvokeRuntimeCallingConvention calling_convention; |
| 783 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 784 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 785 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 786 | // thus we need a 64-bit move here, and we cannot use |
| 787 | // |
| 788 | // arm64_codegen->MoveLocation( |
| 789 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 790 | // root_, |
| 791 | // type); |
| 792 | // |
| 793 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 794 | // reference type (`DataType::Type::kReference`). |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 795 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 796 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 797 | instruction_, |
| 798 | instruction_->GetDexPc(), |
| 799 | this); |
| 800 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 801 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 802 | |
| 803 | RestoreLiveRegisters(codegen, locations); |
| 804 | __ B(GetExitLabel()); |
| 805 | } |
| 806 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 807 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathARM64"; } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 808 | |
| 809 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 810 | const Location out_; |
| 811 | const Location root_; |
| 812 | |
| 813 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 814 | }; |
| 815 | |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 816 | class MethodEntryExitHooksSlowPathARM64 : public SlowPathCodeARM64 { |
| 817 | public: |
| 818 | explicit MethodEntryExitHooksSlowPathARM64(HInstruction* instruction) |
| 819 | : SlowPathCodeARM64(instruction) {} |
| 820 | |
| 821 | void EmitNativeCode(CodeGenerator* codegen) override { |
| 822 | LocationSummary* locations = instruction_->GetLocations(); |
| 823 | QuickEntrypointEnum entry_point = |
| 824 | (instruction_->IsMethodEntryHook()) ? kQuickMethodEntryHook : kQuickMethodExitHook; |
| 825 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 826 | __ Bind(GetEntryLabel()); |
| 827 | SaveLiveRegisters(codegen, locations); |
Mythri Alle | bab6beb | 2022-10-21 13:28:05 +0000 | [diff] [blame] | 828 | if (instruction_->IsMethodExitHook()) { |
| 829 | __ Mov(vixl::aarch64::x4, arm64_codegen->GetFrameSize()); |
| 830 | } |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 831 | arm64_codegen->InvokeRuntime(entry_point, instruction_, instruction_->GetDexPc(), this); |
| 832 | RestoreLiveRegisters(codegen, locations); |
| 833 | __ B(GetExitLabel()); |
| 834 | } |
| 835 | |
| 836 | const char* GetDescription() const override { |
| 837 | return "MethodEntryExitHooksSlowPath"; |
| 838 | } |
| 839 | |
| 840 | private: |
| 841 | DISALLOW_COPY_AND_ASSIGN(MethodEntryExitHooksSlowPathARM64); |
| 842 | }; |
| 843 | |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 844 | class CompileOptimizedSlowPathARM64 : public SlowPathCodeARM64 { |
| 845 | public: |
| 846 | CompileOptimizedSlowPathARM64() : SlowPathCodeARM64(/* instruction= */ nullptr) {} |
| 847 | |
| 848 | void EmitNativeCode(CodeGenerator* codegen) override { |
| 849 | uint32_t entrypoint_offset = |
| 850 | GetThreadOffset<kArm64PointerSize>(kQuickCompileOptimized).Int32Value(); |
| 851 | __ Bind(GetEntryLabel()); |
| 852 | __ Ldr(lr, MemOperand(tr, entrypoint_offset)); |
| 853 | // Note: we don't record the call here (and therefore don't generate a stack |
| 854 | // map), as the entrypoint should never be suspended. |
| 855 | __ Blr(lr); |
| 856 | __ B(GetExitLabel()); |
| 857 | } |
| 858 | |
| 859 | const char* GetDescription() const override { |
| 860 | return "CompileOptimizedSlowPath"; |
| 861 | } |
| 862 | |
| 863 | private: |
| 864 | DISALLOW_COPY_AND_ASSIGN(CompileOptimizedSlowPathARM64); |
| 865 | }; |
| 866 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 867 | #undef __ |
| 868 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 869 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 870 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 871 | if (type == DataType::Type::kVoid) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 872 | LOG(FATAL) << "Unreachable type " << type; |
| 873 | } |
| 874 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 875 | if (DataType::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 876 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 877 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 878 | } else if (!DataType::IsFloatingPointType(type) && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 879 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 880 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 881 | } else { |
| 882 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 883 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 884 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 885 | } |
| 886 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 887 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 888 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 889 | return next_location; |
| 890 | } |
| 891 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 892 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 893 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 894 | } |
| 895 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 896 | Location CriticalNativeCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
| 897 | DCHECK_NE(type, DataType::Type::kReference); |
| 898 | |
| 899 | Location location = Location::NoLocation(); |
| 900 | if (DataType::IsFloatingPointType(type)) { |
| 901 | if (fpr_index_ < kParameterFPRegistersLength) { |
| 902 | location = LocationFrom(kParameterFPRegisters[fpr_index_]); |
| 903 | ++fpr_index_; |
| 904 | } |
| 905 | } else { |
| 906 | // Native ABI uses the same registers as managed, except that the method register x0 |
| 907 | // is a normal argument. |
| 908 | if (gpr_index_ < 1u + kParameterCoreRegistersLength) { |
| 909 | location = LocationFrom(gpr_index_ == 0u ? x0 : kParameterCoreRegisters[gpr_index_ - 1u]); |
| 910 | ++gpr_index_; |
| 911 | } |
| 912 | } |
| 913 | if (location.IsInvalid()) { |
| 914 | if (DataType::Is64BitType(type)) { |
| 915 | location = Location::DoubleStackSlot(stack_offset_); |
| 916 | } else { |
| 917 | location = Location::StackSlot(stack_offset_); |
| 918 | } |
| 919 | stack_offset_ += kFramePointerSize; |
| 920 | |
| 921 | if (for_register_allocation_) { |
| 922 | location = Location::Any(); |
| 923 | } |
| 924 | } |
| 925 | return location; |
| 926 | } |
| 927 | |
| 928 | Location CriticalNativeCallingConventionVisitorARM64::GetReturnLocation(DataType::Type type) const { |
| 929 | // We perform conversion to the managed ABI return register after the call if needed. |
| 930 | InvokeDexCallingConventionVisitorARM64 dex_calling_convention; |
| 931 | return dex_calling_convention.GetReturnLocation(type); |
| 932 | } |
| 933 | |
| 934 | Location CriticalNativeCallingConventionVisitorARM64::GetMethodLocation() const { |
| 935 | // Pass the method in the hidden argument x15. |
| 936 | return Location::RegisterLocation(x15.GetCode()); |
| 937 | } |
| 938 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 939 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 940 | const CompilerOptions& compiler_options, |
| 941 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 942 | : CodeGenerator(graph, |
| 943 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 944 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 945 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 946 | callee_saved_core_registers.GetList(), |
| 947 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 948 | compiler_options, |
| 949 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 950 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 951 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 952 | location_builder_neon_(graph, this), |
| 953 | instruction_visitor_neon_(graph, this), |
| 954 | location_builder_sve_(graph, this), |
| 955 | instruction_visitor_sve_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 956 | move_resolver_(graph->GetAllocator(), this), |
Artem Serov | aa6f483 | 2018-11-21 18:57:54 +0000 | [diff] [blame] | 957 | assembler_(graph->GetAllocator(), |
| 958 | compiler_options.GetInstructionSetFeatures()->AsArm64InstructionSetFeatures()), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 959 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 960 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 961 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 962 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 963 | public_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 964 | package_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 965 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 966 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 967 | boot_image_jni_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 968 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 969 | call_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 970 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 971 | uint32_literals_(std::less<uint32_t>(), |
| 972 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 973 | uint64_literals_(std::less<uint64_t>(), |
| 974 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 975 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 976 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 977 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 978 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 979 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 980 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 981 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 982 | AddAllocatedRegister(LocationFrom(lr)); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 983 | |
| 984 | bool use_sve = ShouldUseSVE(); |
| 985 | if (use_sve) { |
| 986 | location_builder_ = &location_builder_sve_; |
| 987 | instruction_visitor_ = &instruction_visitor_sve_; |
| 988 | } else { |
| 989 | location_builder_ = &location_builder_neon_; |
| 990 | instruction_visitor_ = &instruction_visitor_neon_; |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | bool CodeGeneratorARM64::ShouldUseSVE() const { |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 995 | return GetInstructionSetFeatures().HasSVE(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 996 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 997 | |
Artem Serov | 55ab7e8 | 2020-04-27 21:02:28 +0100 | [diff] [blame] | 998 | size_t CodeGeneratorARM64::GetSIMDRegisterWidth() const { |
| 999 | return SupportsPredicatedSIMD() |
| 1000 | ? GetInstructionSetFeatures().GetSVEVectorLength() / kBitsPerByte |
| 1001 | : vixl::aarch64::kQRegSizeInBytes; |
| 1002 | } |
| 1003 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1004 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1005 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1006 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1007 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1008 | jump_table->EmitTable(this); |
| 1009 | } |
| 1010 | } |
| 1011 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1012 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1013 | EmitJumpTables(); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1014 | |
| 1015 | // Emit JIT baker read barrier slow paths. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 1016 | DCHECK(GetCompilerOptions().IsJitCompiler() || jit_baker_read_barrier_slow_paths_.empty()); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1017 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 1018 | uint32_t encoded_data = entry.first; |
| 1019 | vixl::aarch64::Label* slow_path_entry = &entry.second.label; |
| 1020 | __ Bind(slow_path_entry); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1021 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name= */ nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1024 | // Ensure we emit the literal pool. |
| 1025 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1026 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1027 | CodeGenerator::Finalize(allocator); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1028 | |
| 1029 | // Verify Baker read barrier linker patches. |
| 1030 | if (kIsDebugBuild) { |
| 1031 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 1032 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 1033 | DCHECK(info.label.IsBound()); |
| 1034 | uint32_t literal_offset = info.label.GetLocation(); |
| 1035 | DCHECK_ALIGNED(literal_offset, 4u); |
| 1036 | |
| 1037 | auto GetInsn = [&code](uint32_t offset) { |
| 1038 | DCHECK_ALIGNED(offset, 4u); |
| 1039 | return |
| 1040 | (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 1041 | (static_cast<uint32_t>(code[offset + 1]) << 8) + |
| 1042 | (static_cast<uint32_t>(code[offset + 2]) << 16)+ |
| 1043 | (static_cast<uint32_t>(code[offset + 3]) << 24); |
| 1044 | }; |
| 1045 | |
| 1046 | const uint32_t encoded_data = info.custom_data; |
| 1047 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 1048 | // Check that the next instruction matches the expected LDR. |
| 1049 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1050 | case BakerReadBarrierKind::kField: |
| 1051 | case BakerReadBarrierKind::kAcquire: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1052 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1053 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1054 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1055 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1056 | if (kind == BakerReadBarrierKind::kField) { |
| 1057 | // LDR (immediate) with correct base_reg. |
| 1058 | CHECK_EQ(next_insn & 0xffc003e0u, 0xb9400000u | (base_reg << 5)); |
| 1059 | } else { |
| 1060 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 1061 | // LDAR with correct base_reg. |
| 1062 | CHECK_EQ(next_insn & 0xffffffe0u, 0x88dffc00u | (base_reg << 5)); |
| 1063 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1064 | break; |
| 1065 | } |
| 1066 | case BakerReadBarrierKind::kArray: { |
| 1067 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1068 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 1069 | // LDR (register) with the correct base_reg, size=10 (32-bit), option=011 (extend = LSL), |
| 1070 | // and S=1 (shift amount = 2 for 32-bit version), i.e. LDR Wt, [Xn, Xm, LSL #2]. |
| 1071 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1072 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1073 | CHECK_EQ(next_insn & 0xffe0ffe0u, 0xb8607800u | (base_reg << 5)); |
| 1074 | CheckValidReg((next_insn >> 16) & 0x1f); // Check index register |
| 1075 | break; |
| 1076 | } |
| 1077 | case BakerReadBarrierKind::kGcRoot: { |
| 1078 | DCHECK_GE(literal_offset, 4u); |
| 1079 | uint32_t prev_insn = GetInsn(literal_offset - 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1080 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 1081 | // Usually LDR (immediate) with correct root_reg but |
Vladimir Marko | c8178f5 | 2020-11-24 10:38:16 +0000 | [diff] [blame] | 1082 | // we may have a "MOV marked, old_value" for intrinsic CAS. |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 1083 | if ((prev_insn & 0xffe0ffff) != (0x2a0003e0 | root_reg)) { // MOV? |
| 1084 | CHECK_EQ(prev_insn & 0xffc0001fu, 0xb9400000u | root_reg); // LDR? |
| 1085 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1086 | break; |
| 1087 | } |
| 1088 | default: |
| 1089 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 1090 | UNREACHABLE(); |
| 1091 | } |
| 1092 | } |
| 1093 | } |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1096 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1097 | // Note: There are 6 kinds of moves: |
| 1098 | // 1. constant -> GPR/FPR (non-cycle) |
| 1099 | // 2. constant -> stack (non-cycle) |
| 1100 | // 3. GPR/FPR -> GPR/FPR |
| 1101 | // 4. GPR/FPR -> stack |
| 1102 | // 5. stack -> GPR/FPR |
| 1103 | // 6. stack -> stack (non-cycle) |
| 1104 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1105 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1106 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1107 | // dependency. |
| 1108 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1109 | } |
| 1110 | |
| 1111 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1112 | vixl_temps_.Close(); |
| 1113 | } |
| 1114 | |
| 1115 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1116 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1117 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1118 | || kind == Location::kSIMDStackSlot); |
| 1119 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1120 | ? Location::kFpuRegister |
| 1121 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1122 | Location scratch = GetScratchLocation(kind); |
| 1123 | if (!scratch.Equals(Location::NoLocation())) { |
| 1124 | return scratch; |
| 1125 | } |
| 1126 | // Allocate from VIXL temp registers. |
| 1127 | if (kind == Location::kRegister) { |
| 1128 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1129 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1130 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1131 | scratch = codegen_->GetGraph()->HasSIMD() |
| 1132 | ? codegen_->GetInstructionCodeGeneratorArm64()->AllocateSIMDScratchLocation(&vixl_temps_) |
| 1133 | : LocationFrom(vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1134 | } |
| 1135 | AddScratchLocation(scratch); |
| 1136 | return scratch; |
| 1137 | } |
| 1138 | |
| 1139 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1140 | if (loc.IsRegister()) { |
| 1141 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1142 | } else { |
| 1143 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1144 | if (codegen_->GetGraph()->HasSIMD()) { |
| 1145 | codegen_->GetInstructionCodeGeneratorArm64()->FreeSIMDScratchLocation(loc, &vixl_temps_); |
| 1146 | } else { |
| 1147 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1148 | } |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1149 | } |
| 1150 | RemoveScratchLocation(loc); |
| 1151 | } |
| 1152 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1153 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1154 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1155 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 1158 | void LocationsBuilderARM64::VisitMethodExitHook(HMethodExitHook* method_hook) { |
| 1159 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| 1160 | LocationSummary(method_hook, LocationSummary::kCallOnSlowPath); |
| 1161 | DataType::Type return_type = method_hook->InputAt(0)->GetType(); |
| 1162 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
| 1163 | } |
| 1164 | |
| 1165 | void InstructionCodeGeneratorARM64::GenerateMethodEntryExitHook(HInstruction* instruction) { |
| 1166 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1167 | UseScratchRegisterScope temps(masm); |
| 1168 | Register temp = temps.AcquireX(); |
| 1169 | Register value = temps.AcquireW(); |
| 1170 | |
| 1171 | SlowPathCodeARM64* slow_path = |
| 1172 | new (codegen_->GetScopedAllocator()) MethodEntryExitHooksSlowPathARM64(instruction); |
| 1173 | codegen_->AddSlowPath(slow_path); |
| 1174 | |
Mythri Alle | 5eff6b3 | 2022-11-04 10:57:53 +0000 | [diff] [blame] | 1175 | if (instruction->IsMethodExitHook()) { |
| 1176 | // Check if we are required to check if the caller needs a deoptimization. Strictly speaking it |
| 1177 | // would be sufficient to check if CheckCallerForDeopt bit is set. Though it is faster to check |
| 1178 | // if it is just non-zero. kCHA bit isn't used in debuggable runtimes as cha optimization is |
| 1179 | // disabled in debuggable runtime. The other bit is used when this method itself requires a |
| 1180 | // deoptimization due to redefinition. So it is safe to just check for non-zero value here. |
| 1181 | __ Ldr(value, MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1182 | __ Cbnz(value, slow_path->GetEntryLabel()); |
| 1183 | } |
| 1184 | |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 1185 | uint64_t address = reinterpret_cast64<uint64_t>(Runtime::Current()->GetInstrumentation()); |
Mythri Alle | 5b263ae | 2022-10-21 15:07:44 +0000 | [diff] [blame] | 1186 | MemberOffset offset = instruction->IsMethodExitHook() ? |
Mythri Alle | 5eff6b3 | 2022-11-04 10:57:53 +0000 | [diff] [blame] | 1187 | instrumentation::Instrumentation::HaveMethodExitListenersOffset() : |
Mythri Alle | 5b263ae | 2022-10-21 15:07:44 +0000 | [diff] [blame] | 1188 | instrumentation::Instrumentation::HaveMethodEntryListenersOffset(); |
| 1189 | __ Mov(temp, address + offset.Int32Value()); |
Mythri Alle | 9575c12 | 2021-11-12 12:04:41 +0000 | [diff] [blame] | 1190 | __ Ldrb(value, MemOperand(temp, 0)); |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 1191 | __ Cbnz(value, slow_path->GetEntryLabel()); |
| 1192 | __ Bind(slow_path->GetExitLabel()); |
| 1193 | } |
| 1194 | |
| 1195 | void InstructionCodeGeneratorARM64::VisitMethodExitHook(HMethodExitHook* instruction) { |
| 1196 | DCHECK(codegen_->GetCompilerOptions().IsJitCompiler() && GetGraph()->IsDebuggable()); |
| 1197 | DCHECK(codegen_->RequiresCurrentMethod()); |
| 1198 | GenerateMethodEntryExitHook(instruction); |
| 1199 | } |
| 1200 | |
| 1201 | void LocationsBuilderARM64::VisitMethodEntryHook(HMethodEntryHook* method_hook) { |
| 1202 | new (GetGraph()->GetAllocator()) LocationSummary(method_hook, LocationSummary::kCallOnSlowPath); |
| 1203 | } |
| 1204 | |
| 1205 | void InstructionCodeGeneratorARM64::VisitMethodEntryHook(HMethodEntryHook* instruction) { |
| 1206 | DCHECK(codegen_->GetCompilerOptions().IsJitCompiler() && GetGraph()->IsDebuggable()); |
| 1207 | DCHECK(codegen_->RequiresCurrentMethod()); |
| 1208 | GenerateMethodEntryExitHook(instruction); |
| 1209 | } |
| 1210 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1211 | void CodeGeneratorARM64::MaybeIncrementHotness(bool is_frame_entry) { |
| 1212 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1213 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1214 | UseScratchRegisterScope temps(masm); |
| 1215 | Register counter = temps.AcquireX(); |
| 1216 | Register method = is_frame_entry ? kArtMethodRegister : temps.AcquireX(); |
| 1217 | if (!is_frame_entry) { |
| 1218 | __ Ldr(method, MemOperand(sp, 0)); |
| 1219 | } |
| 1220 | __ Ldrh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
Nicolas Geoffray | 61673dc | 2021-11-06 13:58:31 +0000 | [diff] [blame] | 1221 | vixl::aarch64::Label done; |
| 1222 | DCHECK_EQ(0u, interpreter::kNterpHotnessValue); |
| 1223 | __ Cbz(counter, &done); |
| 1224 | __ Add(counter, counter, -1); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1225 | __ Strh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
Nicolas Geoffray | 61673dc | 2021-11-06 13:58:31 +0000 | [diff] [blame] | 1226 | __ Bind(&done); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 1230 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) CompileOptimizedSlowPathARM64(); |
| 1231 | AddSlowPath(slow_path); |
| 1232 | ProfilingInfo* info = GetGraph()->GetProfilingInfo(); |
| 1233 | DCHECK(info != nullptr); |
| 1234 | DCHECK(!HasEmptyFrame()); |
| 1235 | uint64_t address = reinterpret_cast64<uint64_t>(info); |
| 1236 | vixl::aarch64::Label done; |
| 1237 | UseScratchRegisterScope temps(masm); |
| 1238 | Register temp = temps.AcquireX(); |
| 1239 | Register counter = temps.AcquireW(); |
| 1240 | __ Ldr(temp, DeduplicateUint64Literal(address)); |
| 1241 | __ Ldrh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 1242 | __ Cbz(counter, slow_path->GetEntryLabel()); |
| 1243 | __ Add(counter, counter, -1); |
| 1244 | __ Strh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 1245 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1246 | } |
| 1247 | } |
| 1248 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1249 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1250 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | ab3f8d2 | 2022-07-23 15:49:51 +0000 | [diff] [blame] | 1251 | |
| 1252 | // Check if we need to generate the clinit check. We will jump to the |
| 1253 | // resolution stub if the class is not initialized and the executing thread is |
| 1254 | // not the thread initializing it. |
| 1255 | // We do this before constructing the frame to get the correct stack trace if |
| 1256 | // an exception is thrown. |
| 1257 | if (GetCompilerOptions().ShouldCompileWithClinitCheck(GetGraph()->GetArtMethod())) { |
| 1258 | UseScratchRegisterScope temps(masm); |
| 1259 | vixl::aarch64::Label resolution; |
Nicolas Geoffray | f853790 | 2022-09-13 15:22:29 +0100 | [diff] [blame] | 1260 | vixl::aarch64::Label memory_barrier; |
Nicolas Geoffray | ab3f8d2 | 2022-07-23 15:49:51 +0000 | [diff] [blame] | 1261 | |
| 1262 | Register temp1 = temps.AcquireW(); |
| 1263 | Register temp2 = temps.AcquireW(); |
| 1264 | |
| 1265 | // Check if we're visibly initialized. |
| 1266 | |
| 1267 | // We don't emit a read barrier here to save on code size. We rely on the |
| 1268 | // resolution trampoline to do a suspend check before re-entering this code. |
| 1269 | __ Ldr(temp1, MemOperand(kArtMethodRegister, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 1270 | __ Ldrb(temp2, HeapOperand(temp1, status_byte_offset)); |
| 1271 | __ Cmp(temp2, shifted_visibly_initialized_value); |
| 1272 | __ B(hs, &frame_entry_label_); |
| 1273 | |
Nicolas Geoffray | f853790 | 2022-09-13 15:22:29 +0100 | [diff] [blame] | 1274 | // Check if we're initialized and jump to code that does a memory barrier if |
| 1275 | // so. |
| 1276 | __ Cmp(temp2, shifted_initialized_value); |
| 1277 | __ B(hs, &memory_barrier); |
| 1278 | |
Nicolas Geoffray | ab3f8d2 | 2022-07-23 15:49:51 +0000 | [diff] [blame] | 1279 | // Check if we're initializing and the thread initializing is the one |
| 1280 | // executing the code. |
| 1281 | __ Cmp(temp2, shifted_initializing_value); |
| 1282 | __ B(lo, &resolution); |
| 1283 | |
| 1284 | __ Ldr(temp1, HeapOperand(temp1, mirror::Class::ClinitThreadIdOffset().Int32Value())); |
| 1285 | __ Ldr(temp2, MemOperand(tr, Thread::TidOffset<kArm64PointerSize>().Int32Value())); |
| 1286 | __ Cmp(temp1, temp2); |
| 1287 | __ B(eq, &frame_entry_label_); |
| 1288 | __ Bind(&resolution); |
| 1289 | |
| 1290 | // Jump to the resolution stub. |
| 1291 | ThreadOffset64 entrypoint_offset = |
| 1292 | GetThreadOffset<kArm64PointerSize>(kQuickQuickResolutionTrampoline); |
| 1293 | __ Ldr(temp1.X(), MemOperand(tr, entrypoint_offset.Int32Value())); |
| 1294 | __ Br(temp1.X()); |
Nicolas Geoffray | f853790 | 2022-09-13 15:22:29 +0100 | [diff] [blame] | 1295 | |
| 1296 | __ Bind(&memory_barrier); |
| 1297 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Nicolas Geoffray | ab3f8d2 | 2022-07-23 15:49:51 +0000 | [diff] [blame] | 1298 | } |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1299 | __ Bind(&frame_entry_label_); |
| 1300 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1301 | bool do_overflow_check = |
| 1302 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1303 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1304 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1305 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1306 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1307 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1308 | { |
| 1309 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1310 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1311 | kInstructionSize, |
| 1312 | CodeBufferCheckScope::kExactSize); |
| 1313 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1314 | RecordPcInfo(nullptr, 0); |
| 1315 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1316 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1317 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1318 | if (!HasEmptyFrame()) { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1319 | // Stack layout: |
| 1320 | // sp[frame_size - 8] : lr. |
| 1321 | // ... : other preserved core registers. |
| 1322 | // ... : other preserved fp registers. |
| 1323 | // ... : reserved frame space. |
| 1324 | // sp[0] : current method. |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1325 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1326 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1327 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1328 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1329 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1330 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1331 | |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1332 | // Save the current method if we need it, or if using STP reduces code |
| 1333 | // size. Note that we do not do this in HCurrentMethod, as the |
| 1334 | // instruction might have been removed in the SSA graph. |
| 1335 | CPURegister lowest_spill; |
| 1336 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1337 | // If there is no gap between the method and the lowest core spill, use |
| 1338 | // aligned STP pre-index to store both. Max difference is 512. We do |
| 1339 | // that to reduce code size even if we do not have to save the method. |
| 1340 | DCHECK_LE(frame_size, 512); // 32 core registers are only 256 bytes. |
| 1341 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1342 | __ Stp(kArtMethodRegister, lowest_spill, MemOperand(sp, -frame_size, PreIndex)); |
| 1343 | } else if (RequiresCurrentMethod()) { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1344 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1345 | } else { |
| 1346 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1347 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1348 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1349 | if (lowest_spill.IsValid()) { |
| 1350 | GetAssembler()->cfi().RelOffset(DWARFReg(lowest_spill), core_spills_offset); |
| 1351 | core_spills_offset += kXRegSizeInBytes; |
| 1352 | } |
| 1353 | GetAssembler()->SpillRegisters(preserved_core_registers, core_spills_offset); |
| 1354 | GetAssembler()->SpillRegisters(preserved_fp_registers, fp_spills_offset); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1355 | |
| 1356 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1357 | // Initialize should_deoptimize flag to 0. |
| 1358 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1359 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1360 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1361 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1362 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1363 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1367 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1368 | if (!HasEmptyFrame()) { |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1369 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1370 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1371 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1372 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1373 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1374 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
| 1375 | |
| 1376 | CPURegister lowest_spill; |
| 1377 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1378 | // If there is no gap between the method and the lowest core spill, use |
| 1379 | // aligned LDP pre-index to pop both. Max difference is 504. We do |
| 1380 | // that to reduce code size even though the loaded method is unused. |
| 1381 | DCHECK_LE(frame_size, 504); // 32 core registers are only 256 bytes. |
| 1382 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1383 | core_spills_offset += kXRegSizeInBytes; |
| 1384 | } |
| 1385 | GetAssembler()->UnspillRegisters(preserved_fp_registers, fp_spills_offset); |
| 1386 | GetAssembler()->UnspillRegisters(preserved_core_registers, core_spills_offset); |
| 1387 | if (lowest_spill.IsValid()) { |
| 1388 | __ Ldp(xzr, lowest_spill, MemOperand(sp, frame_size, PostIndex)); |
| 1389 | GetAssembler()->cfi().Restore(DWARFReg(lowest_spill)); |
| 1390 | } else { |
| 1391 | __ Drop(frame_size); |
| 1392 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1393 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1394 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1395 | __ Ret(); |
| 1396 | GetAssembler()->cfi().RestoreState(); |
| 1397 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1398 | } |
| 1399 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1400 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1401 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1402 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1403 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1404 | } |
| 1405 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1406 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1407 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1408 | GetNumberOfFloatingPointRegisters())); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1409 | return CPURegList(CPURegister::kVRegister, kDRegSize, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1410 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1411 | } |
| 1412 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1413 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1414 | __ Bind(GetLabelOf(block)); |
| 1415 | } |
| 1416 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1417 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1418 | DCHECK(location.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1419 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1420 | } |
| 1421 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1422 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1423 | if (location.IsRegister()) { |
| 1424 | locations->AddTemp(location); |
| 1425 | } else { |
| 1426 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1427 | } |
| 1428 | } |
| 1429 | |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 1430 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool emit_null_check) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1431 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1432 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1433 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1434 | vixl::aarch64::Label done; |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 1435 | if (emit_null_check) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1436 | __ Cbz(value, &done); |
| 1437 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1438 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1439 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1440 | // Calculate the offset (in the card table) of the card corresponding to |
| 1441 | // `object`. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1442 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1443 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 1444 | // `object`'s card. |
| 1445 | // |
| 1446 | // Register `card` contains the address of the card table. Note that the card |
| 1447 | // table's base is biased during its creation so that it always starts at an |
| 1448 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 1449 | // art::gc::accounting::CardTable::Create). Therefore the STRB instruction |
| 1450 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 1451 | // (located at `card + object >> kCardShift`). |
| 1452 | // |
| 1453 | // This dual use of the value in register `card` (1. to calculate the location |
| 1454 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 1455 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1456 | __ Strb(card, MemOperand(card, temp.X())); |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 1457 | if (emit_null_check) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1458 | __ Bind(&done); |
| 1459 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1460 | } |
| 1461 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1462 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1463 | // Blocked core registers: |
| 1464 | // lr : Runtime reserved. |
| 1465 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1466 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1467 | // ip1 : VIXL core temp. |
| 1468 | // ip0 : VIXL core temp. |
Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1469 | // x18 : Platform register. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1470 | // |
| 1471 | // Blocked fp registers: |
| 1472 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1473 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1474 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1475 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1476 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1477 | } |
Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1478 | blocked_core_registers_[X18] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1479 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1480 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1481 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1482 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1483 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1484 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1485 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1486 | // Stubs do not save callee-save floating point registers. If the graph |
| 1487 | // is debuggable, we need to deal with these registers differently. For |
| 1488 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1489 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1490 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1491 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1492 | } |
| 1493 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1494 | } |
| 1495 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1496 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1497 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1498 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1499 | return kArm64WordSize; |
| 1500 | } |
| 1501 | |
| 1502 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1503 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1504 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1505 | return kArm64WordSize; |
| 1506 | } |
| 1507 | |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1508 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1509 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1510 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1511 | << "use SaveRestoreLiveRegistersHelper"; |
| 1512 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1515 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1516 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1517 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1518 | << "use SaveRestoreLiveRegistersHelper"; |
| 1519 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1522 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1523 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1527 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1528 | } |
| 1529 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1530 | const Arm64InstructionSetFeatures& CodeGeneratorARM64::GetInstructionSetFeatures() const { |
| 1531 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArm64InstructionSetFeatures(); |
| 1532 | } |
| 1533 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1534 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1535 | if (constant->IsIntConstant()) { |
| 1536 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1537 | } else if (constant->IsLongConstant()) { |
| 1538 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1539 | } else if (constant->IsNullConstant()) { |
| 1540 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1541 | } else if (constant->IsFloatConstant()) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1542 | __ Fmov(VRegister(destination), constant->AsFloatConstant()->GetValue()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1543 | } else { |
| 1544 | DCHECK(constant->IsDoubleConstant()); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1545 | __ Fmov(VRegister(destination), constant->AsDoubleConstant()->GetValue()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1546 | } |
| 1547 | } |
| 1548 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1549 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1550 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1551 | DCHECK(constant.IsConstant()); |
| 1552 | HConstant* cst = constant.GetConstant(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1553 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1554 | // Null is mapped to a core W register, which we associate with kPrimInt. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1555 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1556 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1557 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1558 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1561 | // Allocate a scratch register from the VIXL pool, querying first |
| 1562 | // the floating-point register pool, and then the core register |
| 1563 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1564 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1565 | // using a different allocation strategy. |
| 1566 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1567 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1568 | int size_in_bits) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1569 | return masm->GetScratchVRegisterList()->IsEmpty() |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1570 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1571 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1572 | } |
| 1573 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1574 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1575 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1576 | DataType::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1577 | if (source.Equals(destination)) { |
| 1578 | return; |
| 1579 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1580 | |
| 1581 | // A valid move can always be inferred from the destination and source |
| 1582 | // locations. When moving from and to a register, the argument type can be |
| 1583 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1584 | // checks the coherency of the locations and the type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1585 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1586 | |
| 1587 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1588 | if (unspecified_type) { |
| 1589 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1590 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1591 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1592 | || src_cst->IsFloatConstant() |
| 1593 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1594 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1595 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1596 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1597 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1598 | // type is appropriate. Else the source is a register, and since the |
| 1599 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1600 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1601 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1602 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1603 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1604 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1605 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1606 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1607 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1608 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1609 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1610 | } else if (source.IsSIMDStackSlot()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1611 | GetInstructionCodeGeneratorArm64()->LoadSIMDRegFromStack(destination, source); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1612 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1613 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1614 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1615 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1616 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1617 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1618 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1619 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1620 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1621 | ? DataType::Type::kInt64 |
| 1622 | : DataType::Type::kInt32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1623 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1624 | } |
| 1625 | } else { |
| 1626 | DCHECK(source.IsFpuRegister()); |
| 1627 | if (destination.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1628 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1629 | ? DataType::Type::kFloat64 |
| 1630 | : DataType::Type::kFloat32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1631 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1632 | } else { |
| 1633 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1634 | if (GetGraph()->HasSIMD()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1635 | GetInstructionCodeGeneratorArm64()->MoveSIMDRegToSIMDReg(destination, source); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1636 | } else { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1637 | __ Fmov(VRegister(dst), FPRegisterFrom(source, dst_type)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1638 | } |
| 1639 | } |
| 1640 | } |
| 1641 | } else if (destination.IsSIMDStackSlot()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1642 | GetInstructionCodeGeneratorArm64()->MoveToSIMDStackSlot(destination, source); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1643 | } else { // The destination is not a register. It must be a stack slot. |
| 1644 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1645 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1646 | if (unspecified_type) { |
| 1647 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1648 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1649 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1650 | dst_type = |
| 1651 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1652 | } |
| 1653 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1654 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1655 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1656 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1657 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1658 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1659 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1660 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1661 | HConstant* src_cst = source.GetConstant(); |
| 1662 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1663 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1664 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1665 | ? Register(xzr) |
| 1666 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1667 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1668 | if (src_cst->IsIntConstant()) { |
| 1669 | temp = temps.AcquireW(); |
| 1670 | } else if (src_cst->IsLongConstant()) { |
| 1671 | temp = temps.AcquireX(); |
| 1672 | } else if (src_cst->IsFloatConstant()) { |
| 1673 | temp = temps.AcquireS(); |
| 1674 | } else { |
| 1675 | DCHECK(src_cst->IsDoubleConstant()); |
| 1676 | temp = temps.AcquireD(); |
| 1677 | } |
| 1678 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1679 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1680 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1681 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1682 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1683 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1684 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1685 | // Use any scratch register (a core or a floating-point one) |
| 1686 | // from VIXL scratch register pools as a temporary. |
| 1687 | // |
| 1688 | // We used to only use the FP scratch register pool, but in some |
| 1689 | // rare cases the only register from this pool (D31) would |
| 1690 | // already be used (e.g. within a ParallelMove instruction, when |
| 1691 | // a move is blocked by a another move requiring a scratch FP |
| 1692 | // register, which would reserve D31). To prevent this issue, we |
| 1693 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1694 | // |
| 1695 | // Also, we start by asking for a FP scratch register first, as the |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1696 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1697 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1698 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1699 | // allocates core scratch registers first. |
| 1700 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1701 | GetVIXLAssembler(), |
| 1702 | &temps, |
| 1703 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1704 | __ Ldr(temp, StackOperandFrom(source)); |
| 1705 | __ Str(temp, StackOperandFrom(destination)); |
| 1706 | } |
| 1707 | } |
| 1708 | } |
| 1709 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1710 | void CodeGeneratorARM64::Load(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1711 | CPURegister dst, |
| 1712 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1713 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1714 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1715 | case DataType::Type::kUint8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1716 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1717 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1718 | case DataType::Type::kInt8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1719 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1720 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1721 | case DataType::Type::kUint16: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1722 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1723 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1724 | case DataType::Type::kInt16: |
| 1725 | __ Ldrsh(Register(dst), src); |
| 1726 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1727 | case DataType::Type::kInt32: |
| 1728 | case DataType::Type::kReference: |
| 1729 | case DataType::Type::kInt64: |
| 1730 | case DataType::Type::kFloat32: |
| 1731 | case DataType::Type::kFloat64: |
| 1732 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1733 | __ Ldr(dst, src); |
| 1734 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1735 | case DataType::Type::kUint32: |
| 1736 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1737 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1738 | LOG(FATAL) << "Unreachable type " << type; |
| 1739 | } |
| 1740 | } |
| 1741 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1742 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 1743 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1744 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1745 | const MemOperand& src, |
| 1746 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1747 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1748 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1749 | Register temp_base = temps.AcquireX(); |
| 1750 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1751 | DCHECK(!src.IsPreIndex()); |
| 1752 | DCHECK(!src.IsPostIndex()); |
| 1753 | |
| 1754 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1755 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1756 | { |
| 1757 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1758 | MemOperand base = MemOperand(temp_base); |
| 1759 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1760 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1761 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1762 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1763 | { |
| 1764 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1765 | __ ldarb(Register(dst), base); |
| 1766 | if (needs_null_check) { |
| 1767 | MaybeRecordImplicitNullCheck(instruction); |
| 1768 | } |
| 1769 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1770 | if (type == DataType::Type::kInt8) { |
| 1771 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1772 | } |
| 1773 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1774 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1775 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1776 | { |
| 1777 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1778 | __ ldarh(Register(dst), base); |
| 1779 | if (needs_null_check) { |
| 1780 | MaybeRecordImplicitNullCheck(instruction); |
| 1781 | } |
| 1782 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1783 | if (type == DataType::Type::kInt16) { |
| 1784 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 1785 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1786 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1787 | case DataType::Type::kInt32: |
| 1788 | case DataType::Type::kReference: |
| 1789 | case DataType::Type::kInt64: |
| 1790 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1791 | { |
| 1792 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1793 | __ ldar(Register(dst), base); |
| 1794 | if (needs_null_check) { |
| 1795 | MaybeRecordImplicitNullCheck(instruction); |
| 1796 | } |
| 1797 | } |
| 1798 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1799 | case DataType::Type::kFloat32: |
| 1800 | case DataType::Type::kFloat64: { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1801 | DCHECK(dst.IsFPRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1802 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1803 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1804 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1805 | { |
| 1806 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1807 | __ ldar(temp, base); |
| 1808 | if (needs_null_check) { |
| 1809 | MaybeRecordImplicitNullCheck(instruction); |
| 1810 | } |
| 1811 | } |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1812 | __ Fmov(VRegister(dst), temp); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1813 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1814 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1815 | case DataType::Type::kUint32: |
| 1816 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1817 | case DataType::Type::kVoid: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1818 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1819 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1820 | } |
| 1821 | } |
| 1822 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1823 | void CodeGeneratorARM64::Store(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1824 | CPURegister src, |
| 1825 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1826 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1827 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1828 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1829 | case DataType::Type::kInt8: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1830 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1831 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1832 | case DataType::Type::kUint16: |
| 1833 | case DataType::Type::kInt16: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1834 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1835 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1836 | case DataType::Type::kInt32: |
| 1837 | case DataType::Type::kReference: |
| 1838 | case DataType::Type::kInt64: |
| 1839 | case DataType::Type::kFloat32: |
| 1840 | case DataType::Type::kFloat64: |
| 1841 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1842 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1843 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1844 | case DataType::Type::kUint32: |
| 1845 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1846 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1847 | LOG(FATAL) << "Unreachable type " << type; |
| 1848 | } |
| 1849 | } |
| 1850 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1851 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1852 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1853 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1854 | const MemOperand& dst, |
| 1855 | bool needs_null_check) { |
| 1856 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1857 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1858 | Register temp_base = temps.AcquireX(); |
| 1859 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1860 | DCHECK(!dst.IsPreIndex()); |
| 1861 | DCHECK(!dst.IsPostIndex()); |
| 1862 | |
| 1863 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1864 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1865 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1866 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1867 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1868 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1869 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1870 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1871 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1872 | { |
| 1873 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1874 | __ stlrb(Register(src), base); |
| 1875 | if (needs_null_check) { |
| 1876 | MaybeRecordImplicitNullCheck(instruction); |
| 1877 | } |
| 1878 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1879 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1880 | case DataType::Type::kUint16: |
| 1881 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1882 | { |
| 1883 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1884 | __ stlrh(Register(src), base); |
| 1885 | if (needs_null_check) { |
| 1886 | MaybeRecordImplicitNullCheck(instruction); |
| 1887 | } |
| 1888 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1889 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1890 | case DataType::Type::kInt32: |
| 1891 | case DataType::Type::kReference: |
| 1892 | case DataType::Type::kInt64: |
| 1893 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1894 | { |
| 1895 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1896 | __ stlr(Register(src), base); |
| 1897 | if (needs_null_check) { |
| 1898 | MaybeRecordImplicitNullCheck(instruction); |
| 1899 | } |
| 1900 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1901 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1902 | case DataType::Type::kFloat32: |
| 1903 | case DataType::Type::kFloat64: { |
| 1904 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1905 | Register temp_src; |
| 1906 | if (src.IsZero()) { |
| 1907 | // The zero register is used to avoid synthesizing zero constants. |
| 1908 | temp_src = Register(src); |
| 1909 | } else { |
| 1910 | DCHECK(src.IsFPRegister()); |
| 1911 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1912 | __ Fmov(temp_src, VRegister(src)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1913 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1914 | { |
| 1915 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1916 | __ stlr(temp_src, base); |
| 1917 | if (needs_null_check) { |
| 1918 | MaybeRecordImplicitNullCheck(instruction); |
| 1919 | } |
| 1920 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1921 | break; |
| 1922 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1923 | case DataType::Type::kUint32: |
| 1924 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1925 | case DataType::Type::kVoid: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1926 | LOG(FATAL) << "Unreachable type " << type; |
| 1927 | } |
| 1928 | } |
| 1929 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1930 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1931 | HInstruction* instruction, |
| 1932 | uint32_t dex_pc, |
| 1933 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1934 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1935 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1936 | ThreadOffset64 entrypoint_offset = GetThreadOffset<kArm64PointerSize>(entrypoint); |
| 1937 | // Reduce code size for AOT by using shared trampolines for slow path runtime calls across the |
| 1938 | // entire oat file. This adds an extra branch and we do not want to slow down the main path. |
| 1939 | // 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] | 1940 | if (slow_path == nullptr || GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1941 | __ Ldr(lr, MemOperand(tr, entrypoint_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1942 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 1943 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1944 | __ blr(lr); |
| 1945 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1946 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1947 | } |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1948 | } else { |
| 1949 | // Ensure the pc position is recorded immediately after the `bl` instruction. |
| 1950 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1951 | EmitEntrypointThunkCall(entrypoint_offset); |
| 1952 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1953 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1954 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1955 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1956 | } |
| 1957 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1958 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1959 | HInstruction* instruction, |
| 1960 | SlowPathCode* slow_path) { |
| 1961 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1962 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1963 | __ Blr(lr); |
| 1964 | } |
| 1965 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1966 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1967 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1968 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1969 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1970 | |
Vladimir Marko | 2bb44fe | 2019-10-04 12:28:14 +0100 | [diff] [blame] | 1971 | // CMP (immediate) is limited to imm12 or imm12<<12, so we would need to materialize |
| 1972 | // the constant 0xf0000000 for comparison with the full 32-bit field. To reduce the code |
| 1973 | // size, load only the high byte of the field and compare with 0xf0. |
| 1974 | // Note: The same code size could be achieved with LDR+MNV(asr #24)+CBNZ but benchmarks |
| 1975 | // show that this pattern is slower (tested on little cores). |
| 1976 | __ Ldrb(temp, HeapOperand(class_reg, status_byte_offset)); |
| 1977 | __ Cmp(temp, shifted_visibly_initialized_value); |
| 1978 | __ B(lo, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1979 | __ Bind(slow_path->GetExitLabel()); |
| 1980 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1981 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 1982 | void InstructionCodeGeneratorARM64::GenerateBitstringTypeCheckCompare( |
| 1983 | HTypeCheckInstruction* check, vixl::aarch64::Register temp) { |
| 1984 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 1985 | uint32_t mask = check->GetBitstringMask(); |
| 1986 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 1987 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 1988 | |
| 1989 | if (mask_bits == 16u) { |
| 1990 | // Load only the bitstring part of the status word. |
| 1991 | __ Ldrh(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1992 | } else { |
| 1993 | // /* uint32_t */ temp = temp->status_ |
| 1994 | __ Ldr(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1995 | // Extract the bitstring bits. |
| 1996 | __ Ubfx(temp, temp, 0, mask_bits); |
| 1997 | } |
| 1998 | // Compare the bitstring bits to `path_to_root`. |
| 1999 | __ Cmp(temp, path_to_root); |
| 2000 | } |
| 2001 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2002 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2003 | BarrierType type = BarrierAll; |
| 2004 | |
| 2005 | switch (kind) { |
| 2006 | case MemBarrierKind::kAnyAny: |
| 2007 | case MemBarrierKind::kAnyStore: { |
| 2008 | type = BarrierAll; |
| 2009 | break; |
| 2010 | } |
| 2011 | case MemBarrierKind::kLoadAny: { |
| 2012 | type = BarrierReads; |
| 2013 | break; |
| 2014 | } |
| 2015 | case MemBarrierKind::kStoreStore: { |
| 2016 | type = BarrierWrites; |
| 2017 | break; |
| 2018 | } |
| 2019 | default: |
| 2020 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2021 | } |
| 2022 | __ Dmb(InnerShareable, type); |
| 2023 | } |
| 2024 | |
Vladimir Marko | 7039c11 | 2018-04-05 17:59:39 +0100 | [diff] [blame] | 2025 | bool CodeGeneratorARM64::CanUseImplicitSuspendCheck() const { |
| 2026 | // Use implicit suspend checks if requested in compiler options unless there are SIMD |
| 2027 | // instructions in the graph. The implicit suspend check saves all FP registers as |
| 2028 | // 64-bit (in line with the calling convention) but SIMD instructions can use 128-bit |
| 2029 | // registers, so they need to be saved in an explicit slow path. |
| 2030 | return GetCompilerOptions().GetImplicitSuspendChecks() && !GetGraph()->HasSIMD(); |
| 2031 | } |
| 2032 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2033 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2034 | HBasicBlock* successor) { |
Stelios Ioannou | c54cc7c | 2021-07-09 17:06:03 +0100 | [diff] [blame] | 2035 | if (instruction->IsNoOp()) { |
| 2036 | if (successor != nullptr) { |
| 2037 | __ B(codegen_->GetLabelOf(successor)); |
| 2038 | } |
| 2039 | return; |
| 2040 | } |
| 2041 | |
Vladimir Marko | 7039c11 | 2018-04-05 17:59:39 +0100 | [diff] [blame] | 2042 | if (codegen_->CanUseImplicitSuspendCheck()) { |
| 2043 | __ Ldr(kImplicitSuspendCheckRegister, MemOperand(kImplicitSuspendCheckRegister)); |
| 2044 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Vladimir Marko | e45883e | 2022-01-11 12:38:35 +0000 | [diff] [blame] | 2045 | if (successor != nullptr) { |
| 2046 | __ B(codegen_->GetLabelOf(successor)); |
| 2047 | } |
Vladimir Marko | 7039c11 | 2018-04-05 17:59:39 +0100 | [diff] [blame] | 2048 | return; |
| 2049 | } |
| 2050 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2051 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2052 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2053 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2054 | slow_path = |
| 2055 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2056 | instruction->SetSlowPath(slow_path); |
| 2057 | codegen_->AddSlowPath(slow_path); |
| 2058 | if (successor != nullptr) { |
| 2059 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2060 | } |
| 2061 | } else { |
| 2062 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2063 | } |
| 2064 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2065 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2066 | Register temp = temps.AcquireW(); |
| 2067 | |
Vladimir Marko | ddf4fd3 | 2021-11-22 16:31:57 +0000 | [diff] [blame] | 2068 | __ Ldr(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 2069 | __ Tst(temp, Thread::SuspendOrCheckpointRequestFlags()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2070 | if (successor == nullptr) { |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 2071 | __ B(ne, slow_path->GetEntryLabel()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2072 | __ Bind(slow_path->GetReturnLabel()); |
| 2073 | } else { |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 2074 | __ B(eq, codegen_->GetLabelOf(successor)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2075 | __ B(slow_path->GetEntryLabel()); |
| 2076 | // slow_path will return to GetLabelOf(successor). |
| 2077 | } |
| 2078 | } |
| 2079 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2080 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2081 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2082 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2083 | assembler_(codegen->GetAssembler()), |
| 2084 | codegen_(codegen) {} |
| 2085 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2086 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2087 | DCHECK_EQ(instr->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2088 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2089 | DataType::Type type = instr->GetResultType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2090 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2091 | case DataType::Type::kInt32: |
| 2092 | case DataType::Type::kInt64: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2093 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2094 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2095 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2096 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2097 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2098 | case DataType::Type::kFloat32: |
| 2099 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2100 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2101 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2102 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2103 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2104 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2105 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2106 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2107 | } |
| 2108 | } |
| 2109 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2110 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2111 | const FieldInfo& field_info) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2112 | DCHECK(instruction->IsInstanceFieldGet() || |
| 2113 | instruction->IsStaticFieldGet() || |
| 2114 | instruction->IsPredicatedInstanceFieldGet()); |
| 2115 | |
| 2116 | bool is_predicated = instruction->IsPredicatedInstanceFieldGet(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2117 | |
| 2118 | bool object_field_get_with_read_barrier = |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2119 | gUseReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2120 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2121 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2122 | object_field_get_with_read_barrier |
| 2123 | ? LocationSummary::kCallOnSlowPath |
| 2124 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2125 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2126 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 2127 | // We need a temporary register for the read barrier load in |
| 2128 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2129 | // only if the field is volatile or the offset is too big. |
| 2130 | if (field_info.IsVolatile() || |
| 2131 | field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2132 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2133 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2134 | } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2135 | // Input for object receiver. |
| 2136 | locations->SetInAt(is_predicated ? 1 : 0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2137 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2138 | if (is_predicated) { |
| 2139 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2140 | locations->SetOut(Location::SameAsFirstInput()); |
| 2141 | } else { |
| 2142 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2143 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2144 | } else { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2145 | if (is_predicated) { |
| 2146 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2147 | locations->SetOut(Location::SameAsFirstInput()); |
| 2148 | } else { |
| 2149 | // The output overlaps for an object field get when read barriers |
| 2150 | // are enabled: we do not want the load to overwrite the object's |
| 2151 | // location, as we need it to emit the read barrier. |
| 2152 | locations->SetOut(Location::RequiresRegister(), |
| 2153 | object_field_get_with_read_barrier ? Location::kOutputOverlap |
| 2154 | : Location::kNoOutputOverlap); |
| 2155 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2160 | const FieldInfo& field_info) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2161 | DCHECK(instruction->IsInstanceFieldGet() || |
| 2162 | instruction->IsStaticFieldGet() || |
| 2163 | instruction->IsPredicatedInstanceFieldGet()); |
| 2164 | bool is_predicated = instruction->IsPredicatedInstanceFieldGet(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2165 | LocationSummary* locations = instruction->GetLocations(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2166 | uint32_t receiver_input = is_predicated ? 1 : 0; |
| 2167 | Location base_loc = locations->InAt(receiver_input); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2168 | Location out = locations->Out(); |
| 2169 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2170 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 2171 | DataType::Type load_type = instruction->GetType(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2172 | MemOperand field = |
| 2173 | HeapOperand(InputRegisterAt(instruction, receiver_input), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2174 | |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2175 | if (gUseReadBarrier && kUseBakerReadBarrier && |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2176 | load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2177 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2178 | // /* HeapReference<Object> */ out = *(base + offset) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2179 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2180 | Location maybe_temp = |
| 2181 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2182 | // Note that potential implicit null checks are handled in this |
| 2183 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2184 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2185 | instruction, |
| 2186 | out, |
| 2187 | base, |
| 2188 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2189 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2190 | /* needs_null_check= */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2191 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2192 | } else { |
| 2193 | // General case. |
| 2194 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2195 | // Note that a potential implicit null check is handled in this |
| 2196 | // CodeGeneratorARM64::LoadAcquire call. |
| 2197 | // NB: LoadAcquire will record the pc info if needed. |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 2198 | codegen_->LoadAcquire(instruction, |
| 2199 | load_type, |
| 2200 | OutputCPURegister(instruction), |
| 2201 | field, |
| 2202 | /* needs_null_check= */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2203 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2204 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2205 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2206 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2207 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2208 | } |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2209 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2210 | // If read barriers are enabled, emit read barriers other than |
| 2211 | // Baker's using a slow path (and also unpoison the loaded |
| 2212 | // reference, if heap poisoning is enabled). |
| 2213 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2214 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2215 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2219 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2220 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2221 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2222 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2223 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2224 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2225 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2226 | } else { |
| 2227 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2228 | } |
| 2229 | } |
| 2230 | |
| 2231 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2232 | const FieldInfo& field_info, |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 2233 | bool value_can_be_null, |
| 2234 | WriteBarrierKind write_barrier_kind) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2235 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2236 | bool is_predicated = |
| 2237 | instruction->IsInstanceFieldSet() && instruction->AsInstanceFieldSet()->GetIsPredicatedSet(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2238 | |
| 2239 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2240 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2241 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2242 | Offset offset = field_info.GetFieldOffset(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2243 | DataType::Type field_type = field_info.GetFieldType(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2244 | std::optional<vixl::aarch64::Label> pred_is_null; |
| 2245 | if (is_predicated) { |
| 2246 | pred_is_null.emplace(); |
| 2247 | __ Cbz(obj, &*pred_is_null); |
| 2248 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2249 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2250 | { |
| 2251 | // We use a block to end the scratch scope before the write barrier, thus |
| 2252 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2253 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2254 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2255 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2256 | DCHECK(value.IsW()); |
| 2257 | Register temp = temps.AcquireW(); |
| 2258 | __ Mov(temp, value.W()); |
| 2259 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2260 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2261 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2262 | |
| 2263 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2264 | codegen_->StoreRelease( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2265 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check= */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2266 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2267 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2268 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2269 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2270 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2271 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2272 | } |
| 2273 | |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 2274 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)) && |
| 2275 | write_barrier_kind != WriteBarrierKind::kDontEmit) { |
| 2276 | codegen_->MarkGCCard( |
| 2277 | obj, |
| 2278 | Register(value), |
| 2279 | value_can_be_null && write_barrier_kind == WriteBarrierKind::kEmitWithNullCheck); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2280 | } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2281 | |
| 2282 | if (is_predicated) { |
| 2283 | __ Bind(&*pred_is_null); |
| 2284 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2285 | } |
| 2286 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2287 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2288 | DataType::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2289 | |
| 2290 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2291 | case DataType::Type::kInt32: |
| 2292 | case DataType::Type::kInt64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2293 | Register dst = OutputRegister(instr); |
| 2294 | Register lhs = InputRegisterAt(instr, 0); |
| 2295 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2296 | if (instr->IsAdd()) { |
| 2297 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2298 | } else if (instr->IsAnd()) { |
| 2299 | __ And(dst, lhs, rhs); |
| 2300 | } else if (instr->IsOr()) { |
| 2301 | __ Orr(dst, lhs, rhs); |
| 2302 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2303 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2304 | } else if (instr->IsRor()) { |
| 2305 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2306 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2307 | __ Ror(dst, lhs, shift); |
| 2308 | } else { |
| 2309 | // Ensure shift distance is in the same size register as the result. If |
| 2310 | // we are rotating a long and the shift comes in a w register originally, |
| 2311 | // we don't need to sxtw for use as an x since the shift distances are |
| 2312 | // all & reg_bits - 1. |
| 2313 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2314 | } |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2315 | } else if (instr->IsMin() || instr->IsMax()) { |
| 2316 | __ Cmp(lhs, rhs); |
| 2317 | __ Csel(dst, lhs, rhs, instr->IsMin() ? lt : gt); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2318 | } else { |
| 2319 | DCHECK(instr->IsXor()); |
| 2320 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2321 | } |
| 2322 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2323 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2324 | case DataType::Type::kFloat32: |
| 2325 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 2326 | VRegister dst = OutputFPRegister(instr); |
| 2327 | VRegister lhs = InputFPRegisterAt(instr, 0); |
| 2328 | VRegister rhs = InputFPRegisterAt(instr, 1); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2329 | if (instr->IsAdd()) { |
| 2330 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2331 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2332 | __ Fsub(dst, lhs, rhs); |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2333 | } else if (instr->IsMin()) { |
| 2334 | __ Fmin(dst, lhs, rhs); |
| 2335 | } else if (instr->IsMax()) { |
| 2336 | __ Fmax(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2337 | } else { |
| 2338 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2339 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2340 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2341 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2342 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2343 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2344 | } |
| 2345 | } |
| 2346 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2347 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2348 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2349 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2350 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2351 | DataType::Type type = instr->GetResultType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2352 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2353 | case DataType::Type::kInt32: |
| 2354 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2355 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2356 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2357 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2358 | break; |
| 2359 | } |
| 2360 | default: |
| 2361 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2366 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2367 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2368 | DataType::Type type = instr->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2369 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2370 | case DataType::Type::kInt32: |
| 2371 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2372 | Register dst = OutputRegister(instr); |
| 2373 | Register lhs = InputRegisterAt(instr, 0); |
| 2374 | Operand rhs = InputOperandAt(instr, 1); |
| 2375 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2376 | uint32_t shift_value = rhs.GetImmediate() & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2377 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2378 | if (instr->IsShl()) { |
| 2379 | __ Lsl(dst, lhs, shift_value); |
| 2380 | } else if (instr->IsShr()) { |
| 2381 | __ Asr(dst, lhs, shift_value); |
| 2382 | } else { |
| 2383 | __ Lsr(dst, lhs, shift_value); |
| 2384 | } |
| 2385 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2386 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2387 | |
| 2388 | if (instr->IsShl()) { |
| 2389 | __ Lsl(dst, lhs, rhs_reg); |
| 2390 | } else if (instr->IsShr()) { |
| 2391 | __ Asr(dst, lhs, rhs_reg); |
| 2392 | } else { |
| 2393 | __ Lsr(dst, lhs, rhs_reg); |
| 2394 | } |
| 2395 | } |
| 2396 | break; |
| 2397 | } |
| 2398 | default: |
| 2399 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2400 | } |
| 2401 | } |
| 2402 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2403 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2404 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2408 | HandleBinaryOp(instruction); |
| 2409 | } |
| 2410 | |
| 2411 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2412 | HandleBinaryOp(instruction); |
| 2413 | } |
| 2414 | |
| 2415 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2416 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2417 | } |
| 2418 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2419 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2420 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2421 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2422 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2423 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2424 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2425 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2426 | } |
| 2427 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2428 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2429 | Register dst = OutputRegister(instr); |
| 2430 | Register lhs = InputRegisterAt(instr, 0); |
| 2431 | Register rhs = InputRegisterAt(instr, 1); |
| 2432 | |
| 2433 | switch (instr->GetOpKind()) { |
| 2434 | case HInstruction::kAnd: |
| 2435 | __ Bic(dst, lhs, rhs); |
| 2436 | break; |
| 2437 | case HInstruction::kOr: |
| 2438 | __ Orn(dst, lhs, rhs); |
| 2439 | break; |
| 2440 | case HInstruction::kXor: |
| 2441 | __ Eon(dst, lhs, rhs); |
| 2442 | break; |
| 2443 | default: |
| 2444 | LOG(FATAL) << "Unreachable"; |
| 2445 | } |
| 2446 | } |
| 2447 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2448 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2449 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2450 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2451 | instruction->GetType() == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2452 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2453 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2454 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2455 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2456 | } else { |
| 2457 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2458 | } |
| 2459 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2460 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2461 | } |
| 2462 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2463 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2464 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2465 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2466 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2467 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2468 | Register out = OutputRegister(instruction); |
| 2469 | Register left; |
| 2470 | if (kind != HInstruction::kNeg) { |
| 2471 | left = InputRegisterAt(instruction, 0); |
| 2472 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2473 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2474 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2475 | // conversion) can have a different type from the current instruction's type, |
| 2476 | // so we manually indicate the type. |
| 2477 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2478 | Operand right_operand(0); |
| 2479 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2480 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2481 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2482 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2483 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2484 | right_operand = Operand(right_reg, |
| 2485 | helpers::ShiftFromOpKind(op_kind), |
| 2486 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | // Logical binary operations do not support extension operations in the |
| 2490 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2491 | // the extension as a separate instruction. |
| 2492 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
Santiago Aboy Solanes | 872ec72 | 2022-02-18 14:10:25 +0000 | [diff] [blame] | 2493 | DCHECK_IMPLIES(right_operand.IsExtendedRegister(), |
| 2494 | kind != HInstruction::kAnd && kind != HInstruction::kOr && |
| 2495 | kind != HInstruction::kXor && kind != HInstruction::kNeg); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2496 | switch (kind) { |
| 2497 | case HInstruction::kAdd: |
| 2498 | __ Add(out, left, right_operand); |
| 2499 | break; |
| 2500 | case HInstruction::kAnd: |
| 2501 | __ And(out, left, right_operand); |
| 2502 | break; |
| 2503 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2504 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2505 | __ Neg(out, right_operand); |
| 2506 | break; |
| 2507 | case HInstruction::kOr: |
| 2508 | __ Orr(out, left, right_operand); |
| 2509 | break; |
| 2510 | case HInstruction::kSub: |
| 2511 | __ Sub(out, left, right_operand); |
| 2512 | break; |
| 2513 | case HInstruction::kXor: |
| 2514 | __ Eor(out, left, right_operand); |
| 2515 | break; |
| 2516 | default: |
| 2517 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2518 | UNREACHABLE(); |
| 2519 | } |
| 2520 | } |
| 2521 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2522 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2523 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2524 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2525 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2526 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2527 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2528 | } |
| 2529 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2530 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2531 | __ Add(OutputRegister(instruction), |
| 2532 | InputRegisterAt(instruction, 0), |
| 2533 | Operand(InputOperandAt(instruction, 1))); |
| 2534 | } |
| 2535 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2536 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2537 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2538 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2539 | |
| 2540 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2541 | |
| 2542 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2543 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2544 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2545 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2546 | // loop. |
| 2547 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2548 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2549 | : Location::RequiresRegister()); |
| 2550 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2551 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2552 | } |
| 2553 | |
| 2554 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2555 | HIntermediateAddressIndex* instruction) { |
| 2556 | Register index_reg = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2557 | uint32_t shift = Int64FromLocation(instruction->GetLocations()->InAt(2)); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2558 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2559 | |
| 2560 | if (shift == 0) { |
| 2561 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2562 | } else { |
| 2563 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2564 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2565 | } |
| 2566 | } |
| 2567 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2568 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2569 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2570 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2571 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2572 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2573 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2574 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2575 | // Don't allocate register for Mneg instruction. |
| 2576 | } else { |
| 2577 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2578 | Location::RequiresRegister()); |
| 2579 | } |
| 2580 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2581 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2582 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2583 | } |
| 2584 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2585 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2586 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2587 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2588 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2589 | |
| 2590 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2591 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2592 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2593 | if (instr->GetType() == DataType::Type::kInt64 && |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2594 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2595 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Florian Mayer | 6f572b7 | 2022-01-10 13:03:57 -0800 | [diff] [blame] | 2596 | ptrdiff_t off = masm->GetCursorOffset(); |
| 2597 | if (off >= static_cast<ptrdiff_t>(kInstructionSize) && |
| 2598 | masm->GetInstructionAt(off - static_cast<ptrdiff_t>(kInstructionSize))->IsLoadOrStore()) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2599 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2600 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2601 | __ nop(); |
| 2602 | } |
| 2603 | } |
| 2604 | |
| 2605 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2606 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2607 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2608 | } else { |
| 2609 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2610 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2611 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2612 | __ Mneg(res, mul_left, mul_right); |
| 2613 | } else { |
| 2614 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2615 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2616 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2617 | } |
| 2618 | } |
| 2619 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2620 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2621 | bool object_array_get_with_read_barrier = |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2622 | gUseReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2623 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2624 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2625 | object_array_get_with_read_barrier |
| 2626 | ? LocationSummary::kCallOnSlowPath |
| 2627 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2628 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2629 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2630 | if (instruction->GetIndex()->IsConstant()) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2631 | // Array loads with constant index are treated as field loads. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2632 | // We need a temporary register for the read barrier load in |
| 2633 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2634 | // only if the offset is too big. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2635 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2636 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2637 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2638 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2639 | locations->AddTemp(FixedTempLocation()); |
| 2640 | } |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2641 | } else if (!instruction->GetArray()->IsIntermediateAddress()) { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2642 | // We need a non-scratch temporary for the array data pointer in |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2643 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier() for the case with no |
| 2644 | // intermediate address. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2645 | locations->AddTemp(Location::RequiresRegister()); |
| 2646 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2647 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2648 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2649 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2650 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2651 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2652 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2653 | // The output overlaps in the case of an object array get with |
| 2654 | // read barriers enabled: we do not want the move to overwrite the |
| 2655 | // array's location, as we need it to emit the read barrier. |
| 2656 | locations->SetOut( |
| 2657 | Location::RequiresRegister(), |
| 2658 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2659 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2663 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2664 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2665 | LocationSummary* locations = instruction->GetLocations(); |
| 2666 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2667 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2668 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2669 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2670 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2671 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2672 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2673 | |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2674 | // The non-Baker read barrier instrumentation of object ArrayGet instructions |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2675 | // does not support the HIntermediateAddress instruction. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2676 | DCHECK(!((type == DataType::Type::kReference) && |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2677 | instruction->GetArray()->IsIntermediateAddress() && |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2678 | gUseReadBarrier && |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2679 | !kUseBakerReadBarrier)); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2680 | |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2681 | if (type == DataType::Type::kReference && gUseReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2682 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2683 | // Note that a potential implicit null check is handled in the |
| 2684 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2685 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2686 | if (index.IsConstant()) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2687 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2688 | // Array load with a constant index can be treated as a field load. |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2689 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2690 | Location maybe_temp = |
| 2691 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2692 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2693 | out, |
| 2694 | obj.W(), |
| 2695 | offset, |
| 2696 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2697 | /* needs_null_check= */ false, |
| 2698 | /* use_load_acquire= */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2699 | } else { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2700 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2701 | instruction, out, obj.W(), offset, index, /* needs_null_check= */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2702 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2703 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2704 | // General case. |
| 2705 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2706 | Register length; |
| 2707 | if (maybe_compressed_char_at) { |
| 2708 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2709 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2710 | { |
| 2711 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2712 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2713 | |
| 2714 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2715 | DCHECK_LT(count_offset, offset); |
| 2716 | int64_t adjusted_offset = |
| 2717 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2718 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2719 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2720 | } else { |
| 2721 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2722 | } |
| 2723 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2724 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2725 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2726 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2727 | if (maybe_compressed_char_at) { |
| 2728 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2729 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2730 | "Expecting 0=compressed, 1=uncompressed"); |
| 2731 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2732 | __ Ldrb(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2733 | HeapOperand(obj, offset + Int64FromLocation(index))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2734 | __ B(&done); |
| 2735 | __ Bind(&uncompressed_load); |
| 2736 | __ Ldrh(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2737 | HeapOperand(obj, offset + (Int64FromLocation(index) << 1))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2738 | __ Bind(&done); |
| 2739 | } else { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2740 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2741 | source = HeapOperand(obj, offset); |
| 2742 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2743 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2744 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2745 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2746 | // We do not need to compute the intermediate address from the array: the |
| 2747 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2748 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2749 | if (kIsDebugBuild) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2750 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2751 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2752 | } |
| 2753 | temp = obj; |
| 2754 | } else { |
| 2755 | __ Add(temp, obj, offset); |
| 2756 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2757 | if (maybe_compressed_char_at) { |
| 2758 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2759 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2760 | "Expecting 0=compressed, 1=uncompressed"); |
| 2761 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2762 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2763 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2764 | __ B(&done); |
| 2765 | __ Bind(&uncompressed_load); |
| 2766 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2767 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2768 | __ Bind(&done); |
| 2769 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2770 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2771 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2772 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2773 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2774 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2775 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2776 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2777 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2778 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2779 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2780 | if (type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2781 | static_assert( |
| 2782 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2783 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2784 | Location obj_loc = locations->InAt(0); |
| 2785 | if (index.IsConstant()) { |
| 2786 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2787 | } else { |
| 2788 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2789 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2790 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2791 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2792 | } |
| 2793 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2794 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2795 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2796 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2797 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2801 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2802 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2803 | { |
| 2804 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2805 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2806 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2807 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2808 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2809 | // Mask out compression flag from String's array length. |
| 2810 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2811 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2812 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2813 | } |
| 2814 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2815 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2816 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2817 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2818 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2819 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2820 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2821 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2822 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2823 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2824 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2825 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2826 | } else if (DataType::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2827 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2828 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2829 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2830 | } |
| 2831 | } |
| 2832 | |
| 2833 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2834 | DataType::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2835 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2836 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2837 | bool needs_write_barrier = |
| 2838 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2839 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2840 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2841 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2842 | CPURegister source = value; |
| 2843 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2844 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2845 | MemOperand destination = HeapOperand(array); |
| 2846 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2847 | |
| 2848 | if (!needs_write_barrier) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2849 | DCHECK(!needs_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2850 | if (index.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2851 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2852 | destination = HeapOperand(array, offset); |
| 2853 | } else { |
| 2854 | UseScratchRegisterScope temps(masm); |
| 2855 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2856 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2857 | // We do not need to compute the intermediate address from the array: the |
| 2858 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2859 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2860 | if (kIsDebugBuild) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2861 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2862 | DCHECK(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2863 | } |
| 2864 | temp = array; |
| 2865 | } else { |
| 2866 | __ Add(temp, array, offset); |
| 2867 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2868 | destination = HeapOperand(temp, |
| 2869 | XRegisterFrom(index), |
| 2870 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2871 | DataType::SizeShift(value_type)); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2872 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2873 | { |
| 2874 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2875 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2876 | codegen_->Store(value_type, value, destination); |
| 2877 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2878 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2879 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2880 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2881 | |
| 2882 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 2883 | vixl::aarch64::Label do_store; |
| 2884 | if (can_value_be_null) { |
| 2885 | __ Cbz(Register(value), &do_store); |
| 2886 | } |
| 2887 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2888 | SlowPathCodeARM64* slow_path = nullptr; |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2889 | if (needs_type_check) { |
| 2890 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
| 2891 | codegen_->AddSlowPath(slow_path); |
| 2892 | |
| 2893 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2894 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2895 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2896 | |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2897 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2898 | Register temp = temps.AcquireSameSizeAs(array); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2899 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2900 | |
| 2901 | // Note that when Baker read barriers are enabled, the type |
| 2902 | // checks are performed without read barriers. This is fine, |
| 2903 | // even in the case where a class object is in the from-space |
| 2904 | // after the flip, as a comparison involving such a type would |
| 2905 | // not produce a false positive; it may of course produce a |
| 2906 | // false negative, in which case we would take the ArraySet |
| 2907 | // slow path. |
| 2908 | |
| 2909 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2910 | { |
| 2911 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2912 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2913 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2914 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2915 | } |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2916 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2917 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2918 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2919 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2920 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2921 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2922 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2923 | // nor `temp2`, as we are comparing two poisoned references. |
| 2924 | __ Cmp(temp, temp2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2925 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2926 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2927 | vixl::aarch64::Label do_put; |
| 2928 | __ B(eq, &do_put); |
| 2929 | // If heap poisoning is enabled, the `temp` reference has |
| 2930 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2931 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2932 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2933 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2934 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2935 | // If heap poisoning is enabled, no need to unpoison |
| 2936 | // `temp`, as we are comparing against null below. |
| 2937 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2938 | __ Bind(&do_put); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 2939 | } else { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2940 | __ B(ne, slow_path->GetEntryLabel()); |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2941 | } |
| 2942 | } |
| 2943 | |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 2944 | if (instruction->GetWriteBarrierKind() != WriteBarrierKind::kDontEmit) { |
| 2945 | DCHECK_EQ(instruction->GetWriteBarrierKind(), WriteBarrierKind::kEmitNoNullCheck) |
| 2946 | << " Already null checked so we shouldn't do it again."; |
| 2947 | codegen_->MarkGCCard(array, value.W(), /* emit_null_check= */ false); |
| 2948 | } |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2949 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2950 | if (can_value_be_null) { |
| 2951 | DCHECK(do_store.IsLinked()); |
| 2952 | __ Bind(&do_store); |
| 2953 | } |
| 2954 | |
| 2955 | UseScratchRegisterScope temps(masm); |
| 2956 | if (kPoisonHeapReferences) { |
| 2957 | Register temp_source = temps.AcquireSameSizeAs(array); |
| 2958 | DCHECK(value.IsW()); |
| 2959 | __ Mov(temp_source, value.W()); |
| 2960 | GetAssembler()->PoisonHeapReference(temp_source); |
| 2961 | source = temp_source; |
| 2962 | } |
| 2963 | |
| 2964 | if (index.IsConstant()) { |
| 2965 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
| 2966 | destination = HeapOperand(array, offset); |
| 2967 | } else { |
| 2968 | Register temp_base = temps.AcquireSameSizeAs(array); |
| 2969 | __ Add(temp_base, array, offset); |
| 2970 | destination = HeapOperand(temp_base, |
| 2971 | XRegisterFrom(index), |
| 2972 | LSL, |
| 2973 | DataType::SizeShift(value_type)); |
| 2974 | } |
| 2975 | |
| 2976 | { |
| 2977 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2978 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2979 | __ Str(source, destination); |
| 2980 | |
| 2981 | if (can_value_be_null || !needs_type_check) { |
| 2982 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2983 | } |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | if (slow_path != nullptr) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2987 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2988 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2989 | } |
| 2990 | } |
| 2991 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2992 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2993 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2994 | InvokeRuntimeCallingConvention calling_convention; |
| 2995 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 2996 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 2997 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2998 | |
| 2999 | // If both index and length are constant, we can check the bounds statically and |
| 3000 | // generate code accordingly. We want to make sure we generate constant locations |
| 3001 | // in that case, regardless of whether they are encodable in the comparison or not. |
| 3002 | HInstruction* index = instruction->InputAt(0); |
| 3003 | HInstruction* length = instruction->InputAt(1); |
| 3004 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 3005 | locations->SetInAt(0, both_const |
| 3006 | ? Location::ConstantLocation(index->AsConstant()) |
| 3007 | : ARM64EncodableConstantOrRegister(index, instruction)); |
| 3008 | locations->SetInAt(1, both_const |
| 3009 | ? Location::ConstantLocation(length->AsConstant()) |
| 3010 | : ARM64EncodableConstantOrRegister(length, instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 3014 | LocationSummary* locations = instruction->GetLocations(); |
| 3015 | Location index_loc = locations->InAt(0); |
| 3016 | Location length_loc = locations->InAt(1); |
| 3017 | |
| 3018 | int cmp_first_input = 0; |
| 3019 | int cmp_second_input = 1; |
| 3020 | Condition cond = hs; |
| 3021 | |
| 3022 | if (index_loc.IsConstant()) { |
| 3023 | int64_t index = Int64FromLocation(index_loc); |
| 3024 | if (length_loc.IsConstant()) { |
| 3025 | int64_t length = Int64FromLocation(length_loc); |
| 3026 | if (index < 0 || index >= length) { |
| 3027 | BoundsCheckSlowPathARM64* slow_path = |
| 3028 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
| 3029 | codegen_->AddSlowPath(slow_path); |
| 3030 | __ B(slow_path->GetEntryLabel()); |
| 3031 | } else { |
| 3032 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 3033 | // However, some optimization after BCE may have generated this, and we should not |
| 3034 | // generate a bounds check if it is a valid range. |
| 3035 | } |
| 3036 | return; |
| 3037 | } |
| 3038 | // Only the index is constant: change the order of the operands and commute the condition |
| 3039 | // so we can use an immediate constant for the index (only the second input to a cmp |
| 3040 | // instruction can be an immediate). |
| 3041 | cmp_first_input = 1; |
| 3042 | cmp_second_input = 0; |
| 3043 | cond = ls; |
| 3044 | } |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3045 | BoundsCheckSlowPathARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3046 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 3047 | __ Cmp(InputRegisterAt(instruction, cmp_first_input), |
| 3048 | InputOperandAt(instruction, cmp_second_input)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3049 | codegen_->AddSlowPath(slow_path); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 3050 | __ B(slow_path->GetEntryLabel(), cond); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3051 | } |
| 3052 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3053 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3054 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3055 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3056 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3057 | if (check->HasUses()) { |
| 3058 | locations->SetOut(Location::SameAsFirstInput()); |
| 3059 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 3060 | // Rely on the type initialization to save everything we need. |
| 3061 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3065 | // We assume the class is not null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 3066 | SlowPathCodeARM64* slow_path = |
| 3067 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(check->GetLoadClass(), check); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3068 | codegen_->AddSlowPath(slow_path); |
| 3069 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3070 | } |
| 3071 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3072 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3073 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3074 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3075 | } |
| 3076 | |
| 3077 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 3078 | VRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3079 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3080 | if (rhs_loc.IsConstant()) { |
| 3081 | // 0.0 is the only immediate that can be encoded directly in |
| 3082 | // an FCMP instruction. |
| 3083 | // |
| 3084 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3085 | // specify that in a floating-point comparison, positive zero |
| 3086 | // and negative zero are considered equal, so we can use the |
| 3087 | // literal 0.0 for both cases here. |
| 3088 | // |
| 3089 | // Note however that some methods (Float.equal, Float.compare, |
| 3090 | // Float.compareTo, Double.equal, Double.compare, |
| 3091 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3092 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3093 | // -0.0. So if we ever translate calls to these methods into a |
| 3094 | // HCompare instruction, we must handle the -0.0 case with |
| 3095 | // care here. |
| 3096 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3097 | __ Fcmp(lhs_reg, 0.0); |
| 3098 | } else { |
| 3099 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3100 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3101 | } |
| 3102 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3103 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3104 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3105 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3106 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3107 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3108 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3109 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3110 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3111 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3112 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3113 | case DataType::Type::kInt32: |
| 3114 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3115 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3116 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3117 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3118 | break; |
| 3119 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3120 | case DataType::Type::kFloat32: |
| 3121 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3122 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3123 | locations->SetInAt(1, |
| 3124 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3125 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3126 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3127 | locations->SetOut(Location::RequiresRegister()); |
| 3128 | break; |
| 3129 | } |
| 3130 | default: |
| 3131 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3136 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3137 | |
| 3138 | // 0 if: left == right |
| 3139 | // 1 if: left > right |
| 3140 | // -1 if: left < right |
| 3141 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3142 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3143 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3144 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3145 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3146 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3147 | case DataType::Type::kInt32: |
| 3148 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3149 | Register result = OutputRegister(compare); |
| 3150 | Register left = InputRegisterAt(compare, 0); |
| 3151 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3152 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3153 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3154 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3155 | break; |
| 3156 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3157 | case DataType::Type::kFloat32: |
| 3158 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3159 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3160 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3161 | __ Cset(result, ne); |
| 3162 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3163 | break; |
| 3164 | } |
| 3165 | default: |
| 3166 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3167 | } |
| 3168 | } |
| 3169 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3170 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3171 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3172 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3173 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3174 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3175 | locations->SetInAt(1, |
| 3176 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3177 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3178 | : Location::RequiresFpuRegister()); |
| 3179 | } else { |
| 3180 | // Integer cases. |
| 3181 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3182 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3183 | } |
| 3184 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3185 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3186 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3187 | } |
| 3188 | } |
| 3189 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3190 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3191 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3192 | return; |
| 3193 | } |
| 3194 | |
| 3195 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3196 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3197 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3198 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3199 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3200 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3201 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3202 | } else { |
| 3203 | // Integer cases. |
| 3204 | Register lhs = InputRegisterAt(instruction, 0); |
| 3205 | Operand rhs = InputOperandAt(instruction, 1); |
| 3206 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3207 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3208 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3212 | M(Equal) \ |
| 3213 | M(NotEqual) \ |
| 3214 | M(LessThan) \ |
| 3215 | M(LessThanOrEqual) \ |
| 3216 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3217 | M(GreaterThanOrEqual) \ |
| 3218 | M(Below) \ |
| 3219 | M(BelowOrEqual) \ |
| 3220 | M(Above) \ |
| 3221 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3222 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3223 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3224 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3225 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3226 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3227 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3228 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3229 | void InstructionCodeGeneratorARM64::GenerateIntDivForPower2Denom(HDiv* instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3230 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3231 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3232 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 3233 | |
| 3234 | Register out = OutputRegister(instruction); |
| 3235 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3236 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3237 | Register final_dividend; |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3238 | if (HasNonNegativeOrMinIntInputAt(instruction, 0)) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3239 | // No need to adjust the result for non-negative dividends or the INT32_MIN/INT64_MIN dividends. |
| 3240 | // NOTE: The generated code for HDiv correctly works for the INT32_MIN/INT64_MIN dividends: |
| 3241 | // imm == 2 |
| 3242 | // add out, dividend(0x80000000), dividend(0x80000000), lsr #31 => out = 0x80000001 |
| 3243 | // asr out, out(0x80000001), #1 => out = 0xc0000000 |
| 3244 | // This is the same as 'asr out, 0x80000000, #1' |
| 3245 | // |
| 3246 | // imm > 2 |
| 3247 | // add temp, dividend(0x80000000), imm - 1 => temp = 0b10..01..1, where the number |
| 3248 | // of the rightmost 1s is ctz_imm. |
| 3249 | // cmp dividend(0x80000000), 0 => N = 1, V = 0 (lt is true) |
| 3250 | // csel out, temp(0b10..01..1), dividend(0x80000000), lt => out = 0b10..01..1 |
| 3251 | // asr out, out(0b10..01..1), #ctz_imm => out = 0b1..10..0, where the number of the |
| 3252 | // leftmost 1s is ctz_imm + 1. |
| 3253 | // This is the same as 'asr out, dividend(0x80000000), #ctz_imm'. |
| 3254 | // |
| 3255 | // imm == INT32_MIN |
| 3256 | // add tmp, dividend(0x80000000), #0x7fffffff => tmp = -1 |
| 3257 | // cmp dividend(0x80000000), 0 => N = 1, V = 0 (lt is true) |
| 3258 | // csel out, temp(-1), dividend(0x80000000), lt => out = -1 |
| 3259 | // neg out, out(-1), asr #31 => out = 1 |
| 3260 | // This is the same as 'neg out, dividend(0x80000000), asr #31'. |
| 3261 | final_dividend = dividend; |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3262 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3263 | if (abs_imm == 2) { |
| 3264 | int bits = DataType::Size(instruction->GetResultType()) * kBitsPerByte; |
| 3265 | __ Add(out, dividend, Operand(dividend, LSR, bits - 1)); |
| 3266 | } else { |
| 3267 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3268 | Register temp = temps.AcquireSameSizeAs(out); |
| 3269 | __ Add(temp, dividend, abs_imm - 1); |
| 3270 | __ Cmp(dividend, 0); |
| 3271 | __ Csel(out, temp, dividend, lt); |
| 3272 | } |
| 3273 | final_dividend = out; |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3274 | } |
| 3275 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3276 | int ctz_imm = CTZ(abs_imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3277 | if (imm > 0) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3278 | __ Asr(out, final_dividend, ctz_imm); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3279 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3280 | __ Neg(out, Operand(final_dividend, ASR, ctz_imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3281 | } |
| 3282 | } |
| 3283 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3284 | // Return true if the magic number was modified by subtracting 2^32(Int32 div) or 2^64(Int64 div). |
| 3285 | // So dividend needs to be added. |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3286 | static inline bool NeedToAddDividend(int64_t magic_number, int64_t divisor) { |
| 3287 | return divisor > 0 && magic_number < 0; |
| 3288 | } |
| 3289 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3290 | // Return true if the magic number was modified by adding 2^32(Int32 div) or 2^64(Int64 div). |
| 3291 | // So dividend needs to be subtracted. |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3292 | static inline bool NeedToSubDividend(int64_t magic_number, int64_t divisor) { |
| 3293 | return divisor < 0 && magic_number > 0; |
| 3294 | } |
| 3295 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3296 | // Generate code which increments the value in register 'in' by 1 if the value is negative. |
| 3297 | // It is done with 'add out, in, in, lsr #31 or #63'. |
| 3298 | // If the value is a result of an operation setting the N flag, CINC MI can be used |
| 3299 | // instead of ADD. 'use_cond_inc' controls this. |
| 3300 | void InstructionCodeGeneratorARM64::GenerateIncrementNegativeByOne( |
| 3301 | Register out, |
| 3302 | Register in, |
| 3303 | bool use_cond_inc) { |
| 3304 | if (use_cond_inc) { |
| 3305 | __ Cinc(out, in, mi); |
| 3306 | } else { |
| 3307 | __ Add(out, in, Operand(in, LSR, in.GetSizeInBits() - 1)); |
| 3308 | } |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3309 | } |
| 3310 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3311 | // Helper to generate code producing the result of HRem with a constant divisor. |
| 3312 | void InstructionCodeGeneratorARM64::GenerateResultRemWithAnyConstant( |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3313 | Register out, |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3314 | Register dividend, |
| 3315 | Register quotient, |
| 3316 | int64_t divisor, |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3317 | UseScratchRegisterScope* temps_scope) { |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3318 | Register temp_imm = temps_scope->AcquireSameSizeAs(out); |
| 3319 | __ Mov(temp_imm, divisor); |
| 3320 | __ Msub(out, quotient, temp_imm, dividend); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3321 | } |
| 3322 | |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3323 | // Helper to generate code for HDiv/HRem instructions when a dividend is non-negative and |
| 3324 | // a divisor is a positive constant, not power of 2. |
| 3325 | void InstructionCodeGeneratorARM64::GenerateInt64UnsignedDivRemWithAnyPositiveConstant( |
| 3326 | HBinaryOperation* instruction) { |
| 3327 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3328 | DCHECK(instruction->GetResultType() == DataType::Type::kInt64); |
| 3329 | |
| 3330 | LocationSummary* locations = instruction->GetLocations(); |
| 3331 | Location second = locations->InAt(1); |
| 3332 | DCHECK(second.IsConstant()); |
| 3333 | |
| 3334 | Register out = OutputRegister(instruction); |
| 3335 | Register dividend = InputRegisterAt(instruction, 0); |
| 3336 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3337 | DCHECK_GT(imm, 0); |
| 3338 | |
| 3339 | int64_t magic; |
| 3340 | int shift; |
| 3341 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ true, &magic, &shift); |
| 3342 | |
| 3343 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3344 | Register temp = temps.AcquireSameSizeAs(out); |
| 3345 | |
| 3346 | auto generate_unsigned_div_code = [this, magic, shift](Register out, |
| 3347 | Register dividend, |
| 3348 | Register temp) { |
| 3349 | // temp = get_high(dividend * magic) |
| 3350 | __ Mov(temp, magic); |
| 3351 | if (magic > 0 && shift == 0) { |
| 3352 | __ Smulh(out, dividend, temp); |
| 3353 | } else { |
| 3354 | __ Smulh(temp, dividend, temp); |
| 3355 | if (magic < 0) { |
| 3356 | // The negative magic means that the multiplier m is greater than INT64_MAX. |
| 3357 | // In such a case shift is never 0. See the proof in |
| 3358 | // InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant. |
| 3359 | __ Add(temp, temp, dividend); |
| 3360 | } |
| 3361 | DCHECK_NE(shift, 0); |
| 3362 | __ Lsr(out, temp, shift); |
| 3363 | } |
| 3364 | }; |
| 3365 | |
| 3366 | if (instruction->IsDiv()) { |
| 3367 | generate_unsigned_div_code(out, dividend, temp); |
| 3368 | } else { |
| 3369 | generate_unsigned_div_code(temp, dividend, temp); |
| 3370 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3371 | } |
| 3372 | } |
| 3373 | |
| 3374 | // Helper to generate code for HDiv/HRem instructions for any dividend and a constant divisor |
| 3375 | // (not power of 2). |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3376 | void InstructionCodeGeneratorARM64::GenerateInt64DivRemWithAnyConstant( |
| 3377 | HBinaryOperation* instruction) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3378 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3379 | DCHECK(instruction->GetResultType() == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3380 | |
| 3381 | LocationSummary* locations = instruction->GetLocations(); |
| 3382 | Location second = locations->InAt(1); |
| 3383 | DCHECK(second.IsConstant()); |
| 3384 | |
| 3385 | Register out = OutputRegister(instruction); |
| 3386 | Register dividend = InputRegisterAt(instruction, 0); |
| 3387 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3388 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3389 | int64_t magic; |
| 3390 | int shift; |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3391 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ true, &magic, &shift); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3392 | |
| 3393 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3394 | Register temp = temps.AcquireSameSizeAs(out); |
| 3395 | |
| 3396 | // temp = get_high(dividend * magic) |
| 3397 | __ Mov(temp, magic); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3398 | __ Smulh(temp, dividend, temp); |
| 3399 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3400 | // The multiplication result might need some corrections to be finalized. |
| 3401 | // The last correction is to increment by 1, if the result is negative. |
| 3402 | // Currently it is done with 'add result, temp_result, temp_result, lsr #31 or #63'. |
| 3403 | // Such ADD usually has latency 2, e.g. on Cortex-A55. |
| 3404 | // However if one of the corrections is ADD or SUB, the sign can be detected |
| 3405 | // with ADDS/SUBS. They set the N flag if the result is negative. |
| 3406 | // This allows to use CINC MI which has latency 1. |
| 3407 | bool use_cond_inc = false; |
| 3408 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3409 | // Some combinations of magic_number and the divisor require to correct the result. |
| 3410 | // Check whether the correction is needed. |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3411 | if (NeedToAddDividend(magic, imm)) { |
| 3412 | __ Adds(temp, temp, dividend); |
| 3413 | use_cond_inc = true; |
| 3414 | } else if (NeedToSubDividend(magic, imm)) { |
| 3415 | __ Subs(temp, temp, dividend); |
| 3416 | use_cond_inc = true; |
| 3417 | } |
| 3418 | |
| 3419 | if (shift != 0) { |
| 3420 | __ Asr(temp, temp, shift); |
| 3421 | } |
| 3422 | |
| 3423 | if (instruction->IsRem()) { |
| 3424 | GenerateIncrementNegativeByOne(temp, temp, use_cond_inc); |
| 3425 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3426 | } else { |
| 3427 | GenerateIncrementNegativeByOne(out, temp, use_cond_inc); |
| 3428 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3429 | } |
| 3430 | |
| 3431 | void InstructionCodeGeneratorARM64::GenerateInt32DivRemWithAnyConstant( |
| 3432 | HBinaryOperation* instruction) { |
| 3433 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3434 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 3435 | |
| 3436 | LocationSummary* locations = instruction->GetLocations(); |
| 3437 | Location second = locations->InAt(1); |
| 3438 | DCHECK(second.IsConstant()); |
| 3439 | |
| 3440 | Register out = OutputRegister(instruction); |
| 3441 | Register dividend = InputRegisterAt(instruction, 0); |
| 3442 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3443 | |
| 3444 | int64_t magic; |
| 3445 | int shift; |
| 3446 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| 3447 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3448 | Register temp = temps.AcquireSameSizeAs(out); |
| 3449 | |
| 3450 | // temp = get_high(dividend * magic) |
| 3451 | __ Mov(temp, magic); |
| 3452 | __ Smull(temp.X(), dividend, temp); |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3453 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3454 | // The multiplication result might need some corrections to be finalized. |
| 3455 | // The last correction is to increment by 1, if the result is negative. |
| 3456 | // Currently it is done with 'add result, temp_result, temp_result, lsr #31 or #63'. |
| 3457 | // Such ADD usually has latency 2, e.g. on Cortex-A55. |
| 3458 | // However if one of the corrections is ADD or SUB, the sign can be detected |
| 3459 | // with ADDS/SUBS. They set the N flag if the result is negative. |
| 3460 | // This allows to use CINC MI which has latency 1. |
| 3461 | bool use_cond_inc = false; |
| 3462 | |
| 3463 | // ADD/SUB correction is performed in the high 32 bits |
| 3464 | // as high 32 bits are ignored because type are kInt32. |
| 3465 | if (NeedToAddDividend(magic, imm)) { |
| 3466 | __ Adds(temp.X(), temp.X(), Operand(dividend.X(), LSL, 32)); |
| 3467 | use_cond_inc = true; |
| 3468 | } else if (NeedToSubDividend(magic, imm)) { |
| 3469 | __ Subs(temp.X(), temp.X(), Operand(dividend.X(), LSL, 32)); |
| 3470 | use_cond_inc = true; |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3471 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3472 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3473 | // Extract the result from the high 32 bits and apply the final right shift. |
| 3474 | DCHECK_LT(shift, 32); |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3475 | if (imm > 0 && HasNonNegativeInputAt(instruction, 0)) { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 3476 | // No need to adjust the result for a non-negative dividend and a positive divisor. |
| 3477 | if (instruction->IsDiv()) { |
| 3478 | __ Lsr(out.X(), temp.X(), 32 + shift); |
| 3479 | } else { |
| 3480 | __ Lsr(temp.X(), temp.X(), 32 + shift); |
| 3481 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3482 | } |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3483 | } else { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 3484 | __ Asr(temp.X(), temp.X(), 32 + shift); |
| 3485 | |
| 3486 | if (instruction->IsRem()) { |
| 3487 | GenerateIncrementNegativeByOne(temp, temp, use_cond_inc); |
| 3488 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3489 | } else { |
| 3490 | GenerateIncrementNegativeByOne(out, temp, use_cond_inc); |
| 3491 | } |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3492 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3493 | } |
| 3494 | |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3495 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction, |
| 3496 | int64_t divisor) { |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3497 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3498 | if (instruction->GetResultType() == DataType::Type::kInt64) { |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3499 | if (divisor > 0 && HasNonNegativeInputAt(instruction, 0)) { |
| 3500 | GenerateInt64UnsignedDivRemWithAnyPositiveConstant(instruction); |
| 3501 | } else { |
| 3502 | GenerateInt64DivRemWithAnyConstant(instruction); |
| 3503 | } |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3504 | } else { |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3505 | GenerateInt32DivRemWithAnyConstant(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3506 | } |
| 3507 | } |
| 3508 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3509 | void InstructionCodeGeneratorARM64::GenerateIntDivForConstDenom(HDiv *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3510 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3511 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3512 | if (imm == 0) { |
| 3513 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3514 | return; |
| 3515 | } |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3516 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3517 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3518 | GenerateIntDivForPower2Denom(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3519 | } else { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3520 | // Cases imm == -1 or imm == 1 are handled by InstructionSimplifier. |
| 3521 | DCHECK(imm < -2 || imm > 2) << imm; |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3522 | GenerateDivRemWithAnyConstant(instruction, imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3523 | } |
| 3524 | } |
| 3525 | |
| 3526 | void InstructionCodeGeneratorARM64::GenerateIntDiv(HDiv *instruction) { |
| 3527 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 3528 | << instruction->GetResultType(); |
| 3529 | |
| 3530 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 3531 | GenerateIntDivForConstDenom(instruction); |
| 3532 | } else { |
| 3533 | Register out = OutputRegister(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3534 | Register dividend = InputRegisterAt(instruction, 0); |
| 3535 | Register divisor = InputRegisterAt(instruction, 1); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3536 | __ Sdiv(out, dividend, divisor); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3537 | } |
| 3538 | } |
| 3539 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3540 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3541 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3542 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3543 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3544 | case DataType::Type::kInt32: |
| 3545 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3546 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3547 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3548 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3549 | break; |
| 3550 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3551 | case DataType::Type::kFloat32: |
| 3552 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3553 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3554 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3555 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3556 | break; |
| 3557 | |
| 3558 | default: |
| 3559 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3560 | } |
| 3561 | } |
| 3562 | |
| 3563 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3564 | DataType::Type type = div->GetResultType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3565 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3566 | case DataType::Type::kInt32: |
| 3567 | case DataType::Type::kInt64: |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3568 | GenerateIntDiv(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3569 | break; |
| 3570 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3571 | case DataType::Type::kFloat32: |
| 3572 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3573 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3574 | break; |
| 3575 | |
| 3576 | default: |
| 3577 | LOG(FATAL) << "Unexpected div type " << type; |
| 3578 | } |
| 3579 | } |
| 3580 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3581 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3582 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3583 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3584 | } |
| 3585 | |
| 3586 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3587 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3588 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3589 | codegen_->AddSlowPath(slow_path); |
| 3590 | Location value = instruction->GetLocations()->InAt(0); |
| 3591 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3592 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3593 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3594 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3595 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3596 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3597 | } |
| 3598 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3599 | if (value.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3600 | int64_t divisor = Int64FromLocation(value); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3601 | if (divisor == 0) { |
| 3602 | __ B(slow_path->GetEntryLabel()); |
| 3603 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3604 | // A division by a non-null constant is valid. We don't need to perform |
| 3605 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3606 | } |
| 3607 | } else { |
| 3608 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3609 | } |
| 3610 | } |
| 3611 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3612 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3613 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3614 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3615 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3616 | } |
| 3617 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3618 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3619 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3620 | // Will be generated at use site. |
| 3621 | } |
| 3622 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3623 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3624 | exit->SetLocations(nullptr); |
| 3625 | } |
| 3626 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3627 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3628 | } |
| 3629 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3630 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3631 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3632 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3633 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3634 | } |
| 3635 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3636 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3637 | // Will be generated at use site. |
| 3638 | } |
| 3639 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3640 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3641 | if (successor->IsExitBlock()) { |
| 3642 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3643 | return; // no code needed |
| 3644 | } |
| 3645 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3646 | HBasicBlock* block = got->GetBlock(); |
| 3647 | HInstruction* previous = got->GetPrevious(); |
| 3648 | HLoopInformation* info = block->GetLoopInformation(); |
| 3649 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3650 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 3651 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3652 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
Vladimir Marko | e45883e | 2022-01-11 12:38:35 +0000 | [diff] [blame] | 3653 | return; // `GenerateSuspendCheck()` emitted the jump. |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3654 | } |
| 3655 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3656 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3657 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3658 | } |
| 3659 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3660 | __ B(codegen_->GetLabelOf(successor)); |
| 3661 | } |
| 3662 | } |
| 3663 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3664 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3665 | got->SetLocations(nullptr); |
| 3666 | } |
| 3667 | |
| 3668 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3669 | HandleGoto(got, got->GetSuccessor()); |
| 3670 | } |
| 3671 | |
| 3672 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3673 | try_boundary->SetLocations(nullptr); |
| 3674 | } |
| 3675 | |
| 3676 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3677 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3678 | if (!successor->IsExitBlock()) { |
| 3679 | HandleGoto(try_boundary, successor); |
| 3680 | } |
| 3681 | } |
| 3682 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3683 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3684 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3685 | vixl::aarch64::Label* true_target, |
| 3686 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3687 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3688 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3689 | if (true_target == nullptr && false_target == nullptr) { |
| 3690 | // Nothing to do. The code always falls through. |
| 3691 | return; |
| 3692 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3693 | // Constant condition, statically compared against "true" (integer value 1). |
| 3694 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3695 | if (true_target != nullptr) { |
| 3696 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3697 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3698 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3699 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3700 | if (false_target != nullptr) { |
| 3701 | __ B(false_target); |
| 3702 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3703 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3704 | return; |
| 3705 | } |
| 3706 | |
| 3707 | // The following code generates these patterns: |
| 3708 | // (1) true_target == nullptr && false_target != nullptr |
| 3709 | // - opposite condition true => branch to false_target |
| 3710 | // (2) true_target != nullptr && false_target == nullptr |
| 3711 | // - condition true => branch to true_target |
| 3712 | // (3) true_target != nullptr && false_target != nullptr |
| 3713 | // - condition true => branch to true_target |
| 3714 | // - branch to false_target |
| 3715 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3716 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3717 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3718 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3719 | if (true_target == nullptr) { |
| 3720 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3721 | } else { |
| 3722 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3723 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3724 | } else { |
| 3725 | // The condition instruction has not been materialized, use its inputs as |
| 3726 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3727 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3728 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3729 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3730 | if (DataType::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3731 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3732 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3733 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3734 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3735 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3736 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3737 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3738 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3739 | // Integer cases. |
| 3740 | Register lhs = InputRegisterAt(condition, 0); |
| 3741 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3742 | |
| 3743 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3744 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3745 | if (true_target == nullptr) { |
| 3746 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3747 | non_fallthrough_target = false_target; |
| 3748 | } else { |
| 3749 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3750 | non_fallthrough_target = true_target; |
| 3751 | } |
| 3752 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3753 | if ((arm64_cond == eq || arm64_cond == ne || arm64_cond == lt || arm64_cond == ge) && |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3754 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3755 | switch (arm64_cond) { |
| 3756 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3757 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3758 | break; |
| 3759 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3760 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3761 | break; |
| 3762 | case lt: |
| 3763 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3764 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3765 | break; |
| 3766 | case ge: |
| 3767 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3768 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3769 | break; |
| 3770 | default: |
| 3771 | // Without the `static_cast` the compiler throws an error for |
| 3772 | // `-Werror=sign-promo`. |
| 3773 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3774 | } |
| 3775 | } else { |
| 3776 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3777 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3778 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3779 | } |
| 3780 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3781 | |
| 3782 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3783 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3784 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3785 | __ B(false_target); |
| 3786 | } |
| 3787 | } |
| 3788 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3789 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3790 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3791 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3792 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3793 | } |
| 3794 | } |
| 3795 | |
| 3796 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3797 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3798 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3799 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3800 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3801 | true_target = nullptr; |
| 3802 | } |
| 3803 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3804 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3805 | false_target = nullptr; |
| 3806 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3807 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3811 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3812 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3813 | InvokeRuntimeCallingConvention calling_convention; |
| 3814 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3815 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3816 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3817 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3818 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3819 | } |
| 3820 | } |
| 3821 | |
| 3822 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3823 | SlowPathCodeARM64* slow_path = |
| 3824 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3825 | GenerateTestAndBranch(deoptimize, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3826 | /* condition_input_index= */ 0, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3827 | slow_path->GetEntryLabel(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3828 | /* false_target= */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3829 | } |
| 3830 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3831 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3832 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3833 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3834 | locations->SetOut(Location::RequiresRegister()); |
| 3835 | } |
| 3836 | |
| 3837 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3838 | __ Ldr(OutputRegister(flag), |
| 3839 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3840 | } |
| 3841 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3842 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3843 | return condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3844 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3845 | } |
| 3846 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3847 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3848 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3849 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3850 | : ARM64Condition(cond); |
| 3851 | } |
| 3852 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3853 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3854 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3855 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3856 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3857 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3858 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3859 | } else { |
| 3860 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3861 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3862 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3863 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3864 | // Ask VIXL whether we should synthesize constants in registers. |
| 3865 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3866 | Operand true_op = is_true_value_constant ? |
| 3867 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3868 | Operand false_op = is_false_value_constant ? |
| 3869 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3870 | bool true_value_in_register = false; |
| 3871 | bool false_value_in_register = false; |
| 3872 | MacroAssembler::GetCselSynthesisInformation( |
| 3873 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3874 | true_value_in_register |= !is_true_value_constant; |
| 3875 | false_value_in_register |= !is_false_value_constant; |
| 3876 | |
| 3877 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3878 | : Location::ConstantLocation(cst_true_value)); |
| 3879 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3880 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3881 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3882 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3883 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3884 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3885 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3886 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3887 | } |
| 3888 | |
| 3889 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3890 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3891 | Condition csel_cond; |
| 3892 | |
| 3893 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3894 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3895 | // Use the condition flags set by the previous instruction. |
| 3896 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3897 | } else { |
| 3898 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3899 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3900 | } |
| 3901 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3902 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3903 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3904 | } else { |
| 3905 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3906 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3907 | } |
| 3908 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3909 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3910 | __ Fcsel(OutputFPRegister(select), |
| 3911 | InputFPRegisterAt(select, 1), |
| 3912 | InputFPRegisterAt(select, 0), |
| 3913 | csel_cond); |
| 3914 | } else { |
| 3915 | __ Csel(OutputRegister(select), |
| 3916 | InputOperandAt(select, 1), |
| 3917 | InputOperandAt(select, 0), |
| 3918 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3919 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3920 | } |
| 3921 | |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 3922 | void LocationsBuilderARM64::VisitNop(HNop* nop) { |
| 3923 | new (GetGraph()->GetAllocator()) LocationSummary(nop); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3924 | } |
| 3925 | |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 3926 | void InstructionCodeGeneratorARM64::VisitNop(HNop*) { |
| 3927 | // The environment recording already happened in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3928 | } |
| 3929 | |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3930 | void CodeGeneratorARM64::IncreaseFrame(size_t adjustment) { |
| 3931 | __ Claim(adjustment); |
| 3932 | GetAssembler()->cfi().AdjustCFAOffset(adjustment); |
| 3933 | } |
| 3934 | |
| 3935 | void CodeGeneratorARM64::DecreaseFrame(size_t adjustment) { |
| 3936 | __ Drop(adjustment); |
| 3937 | GetAssembler()->cfi().AdjustCFAOffset(-adjustment); |
| 3938 | } |
| 3939 | |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3940 | void CodeGeneratorARM64::GenerateNop() { |
| 3941 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3942 | } |
| 3943 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 3944 | void LocationsBuilderARM64::VisitPredicatedInstanceFieldGet( |
| 3945 | HPredicatedInstanceFieldGet* instruction) { |
| 3946 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3947 | } |
| 3948 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3949 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3950 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3951 | } |
| 3952 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 3953 | void InstructionCodeGeneratorARM64::VisitPredicatedInstanceFieldGet( |
| 3954 | HPredicatedInstanceFieldGet* instruction) { |
| 3955 | vixl::aarch64::Label finish; |
| 3956 | __ Cbz(InputRegisterAt(instruction, 1), &finish); |
| 3957 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3958 | __ Bind(&finish); |
| 3959 | } |
| 3960 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3961 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3962 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3966 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3967 | } |
| 3968 | |
| 3969 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 3970 | HandleFieldSet(instruction, |
| 3971 | instruction->GetFieldInfo(), |
| 3972 | instruction->GetValueCanBeNull(), |
| 3973 | instruction->GetWriteBarrierKind()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3974 | } |
| 3975 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3976 | // Temp is used for read barrier. |
| 3977 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 3978 | if (gUseReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3979 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3980 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3981 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3982 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3983 | return 1; |
| 3984 | } |
| 3985 | return 0; |
| 3986 | } |
| 3987 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3988 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3989 | // interface pointer, one for loading the current interface. |
| 3990 | // The other checks have one temp for loading the object's class. |
| 3991 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3992 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3993 | return 3; |
| 3994 | } |
| 3995 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3996 | } |
| 3997 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3998 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3999 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4000 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4001 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4002 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4003 | case TypeCheckKind::kExactCheck: |
| 4004 | case TypeCheckKind::kAbstractClassCheck: |
| 4005 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4006 | case TypeCheckKind::kArrayObjectCheck: { |
| 4007 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 4008 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 4009 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4010 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4011 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4012 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4013 | case TypeCheckKind::kUnresolvedCheck: |
| 4014 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4015 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4016 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4017 | case TypeCheckKind::kBitstringCheck: |
| 4018 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4019 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4020 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4021 | LocationSummary* locations = |
| 4022 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4023 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4024 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4025 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4026 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4027 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 4028 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 4029 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 4030 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 4031 | } else { |
| 4032 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4033 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4034 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 4035 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 4036 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4037 | // Add temps if necessary for read barriers. |
| 4038 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4039 | } |
| 4040 | |
| 4041 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4042 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4043 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4044 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4045 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4046 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 4047 | ? Register() |
| 4048 | : InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4049 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4050 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4051 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 4052 | DCHECK_LE(num_temps, 1u); |
| 4053 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4054 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4055 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4056 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4057 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4058 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4059 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4060 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4061 | |
| 4062 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4063 | // Avoid null check if we know `obj` is not null. |
| 4064 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4065 | __ Cbz(obj, &zero); |
| 4066 | } |
| 4067 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4068 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4069 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4070 | ReadBarrierOption read_barrier_option = |
| 4071 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4072 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4073 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4074 | out_loc, |
| 4075 | obj_loc, |
| 4076 | class_offset, |
| 4077 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4078 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4079 | __ Cmp(out, cls); |
| 4080 | __ Cset(out, eq); |
| 4081 | if (zero.IsLinked()) { |
| 4082 | __ B(&done); |
| 4083 | } |
| 4084 | break; |
| 4085 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4086 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4087 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4088 | ReadBarrierOption read_barrier_option = |
| 4089 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4090 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4091 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4092 | out_loc, |
| 4093 | obj_loc, |
| 4094 | class_offset, |
| 4095 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4096 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4097 | // If the class is abstract, we eagerly fetch the super class of the |
| 4098 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4099 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4100 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4101 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4102 | GenerateReferenceLoadOneRegister(instruction, |
| 4103 | out_loc, |
| 4104 | super_offset, |
| 4105 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4106 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4107 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4108 | __ Cbz(out, &done); |
| 4109 | __ Cmp(out, cls); |
| 4110 | __ B(ne, &loop); |
| 4111 | __ Mov(out, 1); |
| 4112 | if (zero.IsLinked()) { |
| 4113 | __ B(&done); |
| 4114 | } |
| 4115 | break; |
| 4116 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4117 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4118 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4119 | ReadBarrierOption read_barrier_option = |
| 4120 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4121 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4122 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4123 | out_loc, |
| 4124 | obj_loc, |
| 4125 | class_offset, |
| 4126 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4127 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4128 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4129 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4130 | __ Bind(&loop); |
| 4131 | __ Cmp(out, cls); |
| 4132 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4133 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4134 | GenerateReferenceLoadOneRegister(instruction, |
| 4135 | out_loc, |
| 4136 | super_offset, |
| 4137 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4138 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4139 | __ Cbnz(out, &loop); |
| 4140 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4141 | __ B(&done); |
| 4142 | __ Bind(&success); |
| 4143 | __ Mov(out, 1); |
| 4144 | if (zero.IsLinked()) { |
| 4145 | __ B(&done); |
| 4146 | } |
| 4147 | break; |
| 4148 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4149 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4150 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4151 | ReadBarrierOption read_barrier_option = |
| 4152 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4153 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4154 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4155 | out_loc, |
| 4156 | obj_loc, |
| 4157 | class_offset, |
| 4158 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4159 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4160 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4161 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4162 | __ Cmp(out, cls); |
| 4163 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4164 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4165 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4166 | GenerateReferenceLoadOneRegister(instruction, |
| 4167 | out_loc, |
| 4168 | component_offset, |
| 4169 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4170 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4171 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4172 | __ Cbz(out, &done); |
| 4173 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4174 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4175 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4176 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4177 | __ Mov(out, 1); |
| 4178 | __ B(&done); |
| 4179 | break; |
| 4180 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4181 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4182 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4183 | // No read barrier since the slow path will retry upon failure. |
| 4184 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4185 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4186 | out_loc, |
| 4187 | obj_loc, |
| 4188 | class_offset, |
| 4189 | maybe_temp_loc, |
| 4190 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4191 | __ Cmp(out, cls); |
| 4192 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4193 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4194 | instruction, /* is_fatal= */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4195 | codegen_->AddSlowPath(slow_path); |
| 4196 | __ B(ne, slow_path->GetEntryLabel()); |
| 4197 | __ Mov(out, 1); |
| 4198 | if (zero.IsLinked()) { |
| 4199 | __ B(&done); |
| 4200 | } |
| 4201 | break; |
| 4202 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4203 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4204 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4205 | case TypeCheckKind::kInterfaceCheck: { |
| 4206 | // Note that we indeed only call on slow path, but we always go |
| 4207 | // into the slow path for the unresolved and interface check |
| 4208 | // cases. |
| 4209 | // |
| 4210 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4211 | // entry point without resorting to a type checking slow path |
| 4212 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4213 | // require to assign fixed registers for the inputs of this |
| 4214 | // HInstanceOf instruction (following the runtime calling |
| 4215 | // convention), which might be cluttered by the potential first |
| 4216 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4217 | // |
| 4218 | // TODO: Introduce a new runtime entry point taking the object |
| 4219 | // to test (instead of its class) as argument, and let it deal |
| 4220 | // with the read barrier issues. This will let us refactor this |
| 4221 | // case of the `switch` code as it was previously (with a direct |
| 4222 | // call to the runtime not using a type checking slow path). |
| 4223 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4224 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4225 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4226 | instruction, /* is_fatal= */ false); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4227 | codegen_->AddSlowPath(slow_path); |
| 4228 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4229 | if (zero.IsLinked()) { |
| 4230 | __ B(&done); |
| 4231 | } |
| 4232 | break; |
| 4233 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4234 | |
| 4235 | case TypeCheckKind::kBitstringCheck: { |
| 4236 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4237 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4238 | out_loc, |
| 4239 | obj_loc, |
| 4240 | class_offset, |
| 4241 | maybe_temp_loc, |
| 4242 | kWithoutReadBarrier); |
| 4243 | |
| 4244 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 4245 | __ Cset(out, eq); |
| 4246 | if (zero.IsLinked()) { |
| 4247 | __ B(&done); |
| 4248 | } |
| 4249 | break; |
| 4250 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4251 | } |
| 4252 | |
| 4253 | if (zero.IsLinked()) { |
| 4254 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4255 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4256 | } |
| 4257 | |
| 4258 | if (done.IsLinked()) { |
| 4259 | __ Bind(&done); |
| 4260 | } |
| 4261 | |
| 4262 | if (slow_path != nullptr) { |
| 4263 | __ Bind(slow_path->GetExitLabel()); |
| 4264 | } |
| 4265 | } |
| 4266 | |
| 4267 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4268 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4269 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4270 | LocationSummary* locations = |
| 4271 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4272 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4273 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 4274 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 4275 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 4276 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 4277 | } else { |
| 4278 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4279 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4280 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4281 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4282 | } |
| 4283 | |
| 4284 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4285 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4286 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4287 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4288 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4289 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 4290 | ? Register() |
| 4291 | : InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4292 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4293 | DCHECK_GE(num_temps, 1u); |
| 4294 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4295 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4296 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4297 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4298 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4299 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4300 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4301 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4302 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4303 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4304 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4305 | const uint32_t object_array_data_offset = |
| 4306 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4307 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4308 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4309 | SlowPathCodeARM64* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4310 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4311 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4312 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4313 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4314 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4315 | // Avoid null check if we know obj is not null. |
| 4316 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4317 | __ Cbz(obj, &done); |
| 4318 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4319 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4320 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4321 | case TypeCheckKind::kExactCheck: |
| 4322 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4323 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4324 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4325 | temp_loc, |
| 4326 | obj_loc, |
| 4327 | class_offset, |
| 4328 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4329 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4330 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4331 | __ Cmp(temp, cls); |
| 4332 | // Jump to slow path for throwing the exception or doing a |
| 4333 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4334 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4335 | break; |
| 4336 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4337 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4338 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4339 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4340 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4341 | temp_loc, |
| 4342 | obj_loc, |
| 4343 | class_offset, |
| 4344 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4345 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4346 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4347 | // If the class is abstract, we eagerly fetch the super class of the |
| 4348 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4349 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4350 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4351 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4352 | GenerateReferenceLoadOneRegister(instruction, |
| 4353 | temp_loc, |
| 4354 | super_offset, |
| 4355 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4356 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4357 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4358 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4359 | // exception. |
| 4360 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4361 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4362 | __ Cmp(temp, cls); |
| 4363 | __ B(ne, &loop); |
| 4364 | break; |
| 4365 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4366 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4367 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4368 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4369 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4370 | temp_loc, |
| 4371 | obj_loc, |
| 4372 | class_offset, |
| 4373 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4374 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4375 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4376 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4377 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4378 | __ Bind(&loop); |
| 4379 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4380 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4381 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4382 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4383 | GenerateReferenceLoadOneRegister(instruction, |
| 4384 | temp_loc, |
| 4385 | super_offset, |
| 4386 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4387 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4388 | |
| 4389 | // If the class reference currently in `temp` is not null, jump |
| 4390 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4391 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4392 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4393 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4394 | break; |
| 4395 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4396 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4397 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4398 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4399 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4400 | temp_loc, |
| 4401 | obj_loc, |
| 4402 | class_offset, |
| 4403 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4404 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4405 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4406 | // Do an exact check. |
| 4407 | __ Cmp(temp, cls); |
| 4408 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4409 | |
| 4410 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4411 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4412 | GenerateReferenceLoadOneRegister(instruction, |
| 4413 | temp_loc, |
| 4414 | component_offset, |
| 4415 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4416 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4417 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4418 | // If the component type is null, jump to the slow path to throw the exception. |
| 4419 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4420 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4421 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4422 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4423 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4424 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4425 | break; |
| 4426 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4427 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4428 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4429 | // We always go into the type check slow path for the unresolved check cases. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4430 | // |
| 4431 | // We cannot directly call the CheckCast runtime entry point |
| 4432 | // without resorting to a type checking slow path here (i.e. by |
| 4433 | // calling InvokeRuntime directly), as it would require to |
| 4434 | // assign fixed registers for the inputs of this HInstanceOf |
| 4435 | // instruction (following the runtime calling convention), which |
| 4436 | // might be cluttered by the potential first read barrier |
| 4437 | // emission at the beginning of this method. |
| 4438 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4439 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4440 | case TypeCheckKind::kInterfaceCheck: { |
| 4441 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4442 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4443 | temp_loc, |
| 4444 | obj_loc, |
| 4445 | class_offset, |
| 4446 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4447 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4448 | |
| 4449 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4450 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4451 | temp_loc, |
| 4452 | temp_loc, |
| 4453 | iftable_offset, |
| 4454 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4455 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4456 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4457 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4458 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4459 | vixl::aarch64::Label start_loop; |
| 4460 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4461 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4462 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4463 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4464 | // Go to next interface. |
| 4465 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4466 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4467 | // Compare the classes and continue the loop if they do not match. |
| 4468 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4469 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4470 | break; |
| 4471 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4472 | |
| 4473 | case TypeCheckKind::kBitstringCheck: { |
| 4474 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4475 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4476 | temp_loc, |
| 4477 | obj_loc, |
| 4478 | class_offset, |
| 4479 | maybe_temp2_loc, |
| 4480 | kWithoutReadBarrier); |
| 4481 | |
| 4482 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 4483 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 4484 | break; |
| 4485 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4486 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4487 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4488 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4489 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4490 | } |
| 4491 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4492 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4493 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4494 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4495 | } |
| 4496 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4497 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4498 | // Will be generated at use site. |
| 4499 | } |
| 4500 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4501 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4502 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4503 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4504 | } |
| 4505 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4506 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4507 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4508 | } |
| 4509 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4510 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4511 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4512 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4513 | // the method_idx. |
| 4514 | HandleInvoke(invoke); |
| 4515 | } |
| 4516 | |
| 4517 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4518 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4519 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4520 | } |
| 4521 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4522 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4523 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4524 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4525 | } |
| 4526 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4527 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4528 | HandleInvoke(invoke); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4529 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 4530 | // We cannot request ip1 as it's blocked by the register allocator. |
| 4531 | invoke->GetLocations()->SetInAt(invoke->GetNumberOfArguments() - 1, Location::Any()); |
| 4532 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4533 | } |
| 4534 | |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4535 | void CodeGeneratorARM64::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 4536 | Register klass) { |
| 4537 | DCHECK_EQ(klass.GetCode(), 0u); |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4538 | // We know the destination of an intrinsic, so no need to record inline |
| 4539 | // caches. |
| 4540 | if (!instruction->GetLocations()->Intrinsified() && |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 4541 | GetGraph()->IsCompilingBaseline() && |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4542 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4543 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 4544 | ProfilingInfo* info = GetGraph()->GetProfilingInfo(); |
| 4545 | DCHECK(info != nullptr); |
| 4546 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 4547 | uint64_t address = reinterpret_cast64<uint64_t>(cache); |
| 4548 | vixl::aarch64::Label done; |
| 4549 | __ Mov(x8, address); |
| 4550 | __ Ldr(x9, MemOperand(x8, InlineCache::ClassesOffset().Int32Value())); |
| 4551 | // Fast path for a monomorphic cache. |
| 4552 | __ Cmp(klass, x9); |
| 4553 | __ B(eq, &done); |
| 4554 | InvokeRuntime(kQuickUpdateInlineCache, instruction, instruction->GetDexPc()); |
| 4555 | __ Bind(&done); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4556 | } |
| 4557 | } |
| 4558 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4559 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4560 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4561 | LocationSummary* locations = invoke->GetLocations(); |
| 4562 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4563 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4564 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4565 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4566 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4567 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4568 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4569 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4570 | { |
| 4571 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4572 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4573 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4574 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4575 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4576 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4577 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4578 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4579 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4580 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4581 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4582 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4583 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4584 | // emit a read barrier for the previous class reference load. |
| 4585 | // However this is not required in practice, as this is an |
| 4586 | // intermediate/temporary reference and because the current |
| 4587 | // concurrent copying collector keeps the from-space memory |
| 4588 | // intact/accessible until the end of the marking phase (the |
| 4589 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4590 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4591 | |
| 4592 | // If we're compiling baseline, update the inline cache. |
| 4593 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4594 | |
| 4595 | // The register ip1 is required to be used for the hidden argument in |
| 4596 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
| 4597 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4598 | UseScratchRegisterScope scratch_scope(masm); |
| 4599 | scratch_scope.Exclude(ip1); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4600 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 4601 | Location interface_method = locations->InAt(invoke->GetNumberOfArguments() - 1); |
| 4602 | if (interface_method.IsStackSlot()) { |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 4603 | __ Ldr(ip1, StackOperandFrom(interface_method)); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4604 | } else { |
| 4605 | __ Mov(ip1, XRegisterFrom(interface_method)); |
| 4606 | } |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 4607 | // If the load kind is through a runtime call, we will pass the method we |
| 4608 | // fetch the IMT, which will either be a no-op if we don't hit the conflict |
| 4609 | // stub, or will make us always go through the trampoline when there is a |
| 4610 | // conflict. |
| 4611 | } else if (invoke->GetHiddenArgumentLoadKind() != MethodLoadKind::kRuntimeCall) { |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4612 | codegen_->LoadMethod( |
| 4613 | invoke->GetHiddenArgumentLoadKind(), Location::RegisterLocation(ip1.GetCode()), invoke); |
| 4614 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4615 | |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4616 | __ Ldr(temp, |
| 4617 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4618 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4619 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4620 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4621 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 4622 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRuntimeCall) { |
| 4623 | // We pass the method from the IMT in case of a conflict. This will ensure |
| 4624 | // we go into the runtime to resolve the actual method. |
| 4625 | __ Mov(ip1, temp); |
| 4626 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4627 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4628 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4629 | |
| 4630 | { |
| 4631 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4632 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4633 | |
| 4634 | // lr(); |
| 4635 | __ blr(lr); |
| 4636 | DCHECK(!codegen_->IsLeafMethod()); |
| 4637 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4638 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4639 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4640 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4644 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4645 | if (intrinsic.TryDispatch(invoke)) { |
| 4646 | return; |
| 4647 | } |
| 4648 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4649 | HandleInvoke(invoke); |
| 4650 | } |
| 4651 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4652 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4653 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4654 | // art::PrepareForRegisterAllocation. |
| 4655 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4656 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4657 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4658 | if (intrinsic.TryDispatch(invoke)) { |
| 4659 | return; |
| 4660 | } |
| 4661 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4662 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4663 | CriticalNativeCallingConventionVisitorARM64 calling_convention_visitor( |
| 4664 | /*for_register_allocation=*/ true); |
| 4665 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 4666 | } else { |
| 4667 | HandleInvoke(invoke); |
| 4668 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4669 | } |
| 4670 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4671 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4672 | if (invoke->GetLocations()->Intrinsified()) { |
| 4673 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4674 | intrinsic.Dispatch(invoke); |
| 4675 | return true; |
| 4676 | } |
| 4677 | return false; |
| 4678 | } |
| 4679 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4680 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4681 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4682 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4683 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4684 | return desired_dispatch_info; |
| 4685 | } |
| 4686 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4687 | void CodeGeneratorARM64::LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke) { |
| 4688 | switch (load_kind) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4689 | case MethodLoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4690 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4691 | // Add ADRP with its PC-relative method patch. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4692 | vixl::aarch64::Label* adrp_label = |
| 4693 | NewBootImageMethodPatch(invoke->GetResolvedMethodReference()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4694 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4695 | // Add ADD with its PC-relative method patch. |
| 4696 | vixl::aarch64::Label* add_label = |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4697 | NewBootImageMethodPatch(invoke->GetResolvedMethodReference(), adrp_label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4698 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4699 | break; |
| 4700 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4701 | case MethodLoadKind::kBootImageRelRo: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4702 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 4703 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
| 4704 | LoadBootImageRelRoEntry(WRegisterFrom(temp), boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4705 | break; |
| 4706 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4707 | case MethodLoadKind::kBssEntry: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4708 | // Add ADRP with its PC-relative .bss entry patch. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4709 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(invoke->GetMethodReference()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4710 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4711 | // Add LDR with its PC-relative .bss entry patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4712 | vixl::aarch64::Label* ldr_label = |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4713 | NewMethodBssEntryPatch(invoke->GetMethodReference(), adrp_label); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 4714 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4715 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4716 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4717 | } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4718 | case MethodLoadKind::kJitDirectAddress: { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4719 | // Load method address from literal pool. |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4720 | __ Ldr(XRegisterFrom(temp), |
| 4721 | DeduplicateUint64Literal(reinterpret_cast<uint64_t>(invoke->GetResolvedMethod()))); |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4722 | break; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4723 | } |
| 4724 | case MethodLoadKind::kRuntimeCall: { |
| 4725 | // Test situation, don't do anything. |
| 4726 | break; |
| 4727 | } |
| 4728 | default: { |
| 4729 | LOG(FATAL) << "Load kind should have already been handled " << load_kind; |
| 4730 | UNREACHABLE(); |
| 4731 | } |
| 4732 | } |
| 4733 | } |
| 4734 | |
| 4735 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4736 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| 4737 | // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention. |
| 4738 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4739 | switch (invoke->GetMethodLoadKind()) { |
| 4740 | case MethodLoadKind::kStringInit: { |
| 4741 | uint32_t offset = |
| 4742 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4743 | // temp = thread->string_init_entrypoint |
| 4744 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
| 4745 | break; |
| 4746 | } |
| 4747 | case MethodLoadKind::kRecursive: { |
| 4748 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
| 4749 | break; |
| 4750 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4751 | case MethodLoadKind::kRuntimeCall: { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4752 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4753 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4754 | } |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4755 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
| 4756 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| 4757 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
| 4758 | // Do not materialize the method pointer, load directly the entrypoint. |
| 4759 | // Add ADRP with its PC-relative JNI entrypoint patch. |
| 4760 | vixl::aarch64::Label* adrp_label = |
| 4761 | NewBootImageJniEntrypointPatch(invoke->GetResolvedMethodReference()); |
| 4762 | EmitAdrpPlaceholder(adrp_label, lr); |
| 4763 | // Add the LDR with its PC-relative method patch. |
| 4764 | vixl::aarch64::Label* add_label = |
| 4765 | NewBootImageJniEntrypointPatch(invoke->GetResolvedMethodReference(), adrp_label); |
| 4766 | EmitLdrOffsetPlaceholder(add_label, lr, lr); |
| 4767 | break; |
| 4768 | } |
| 4769 | FALLTHROUGH_INTENDED; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4770 | default: { |
| 4771 | LoadMethod(invoke->GetMethodLoadKind(), temp, invoke); |
| 4772 | break; |
| 4773 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4774 | } |
| 4775 | |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4776 | auto call_lr = [&]() { |
| 4777 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4778 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4779 | kInstructionSize, |
| 4780 | CodeBufferCheckScope::kExactSize); |
| 4781 | // lr() |
| 4782 | __ blr(lr); |
| 4783 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4784 | }; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4785 | switch (invoke->GetCodePtrLocation()) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4786 | case CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4787 | { |
Nicolas Geoffray | 282795c | 2021-09-24 18:16:41 +0100 | [diff] [blame] | 4788 | DCHECK(!GetGraph()->HasShouldDeoptimizeFlag()); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4789 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4790 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4791 | kInstructionSize, |
| 4792 | CodeBufferCheckScope::kExactSize); |
| 4793 | __ bl(&frame_entry_label_); |
| 4794 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4795 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4796 | break; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4797 | case CodePtrLocation::kCallCriticalNative: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4798 | size_t out_frame_size = |
| 4799 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorARM64, |
| 4800 | kAapcs64StackAlignment, |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 4801 | GetCriticalNativeDirectCallFrameSize>(invoke); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4802 | if (invoke->GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative) { |
| 4803 | call_lr(); |
| 4804 | } else { |
| 4805 | // LR = callee_method->ptr_sized_fields_.data_; // EntryPointFromJni |
| 4806 | MemberOffset offset = ArtMethod::EntryPointFromJniOffset(kArm64PointerSize); |
| 4807 | __ Ldr(lr, MemOperand(XRegisterFrom(callee_method), offset.Int32Value())); |
| 4808 | // lr() |
| 4809 | call_lr(); |
| 4810 | } |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4811 | // Zero-/sign-extend the result when needed due to native and managed ABI mismatch. |
| 4812 | switch (invoke->GetType()) { |
| 4813 | case DataType::Type::kBool: |
| 4814 | __ Ubfx(w0, w0, 0, 8); |
| 4815 | break; |
| 4816 | case DataType::Type::kInt8: |
| 4817 | __ Sbfx(w0, w0, 0, 8); |
| 4818 | break; |
| 4819 | case DataType::Type::kUint16: |
| 4820 | __ Ubfx(w0, w0, 0, 16); |
| 4821 | break; |
| 4822 | case DataType::Type::kInt16: |
| 4823 | __ Sbfx(w0, w0, 0, 16); |
| 4824 | break; |
| 4825 | case DataType::Type::kInt32: |
| 4826 | case DataType::Type::kInt64: |
| 4827 | case DataType::Type::kFloat32: |
| 4828 | case DataType::Type::kFloat64: |
| 4829 | case DataType::Type::kVoid: |
| 4830 | break; |
| 4831 | default: |
| 4832 | DCHECK(false) << invoke->GetType(); |
| 4833 | break; |
| 4834 | } |
| 4835 | if (out_frame_size != 0u) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 4836 | DecreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4837 | } |
| 4838 | break; |
| 4839 | } |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4840 | case CodePtrLocation::kCallArtMethod: { |
| 4841 | // LR = callee_method->ptr_sized_fields_.entry_point_from_quick_compiled_code_; |
| 4842 | MemberOffset offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
| 4843 | __ Ldr(lr, MemOperand(XRegisterFrom(callee_method), offset.Int32Value())); |
| 4844 | // lr() |
| 4845 | call_lr(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4846 | break; |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4847 | } |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4848 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4849 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4850 | DCHECK(!IsLeafMethod()); |
| 4851 | } |
| 4852 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4853 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4854 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4855 | // Use the calling convention instead of the location of the receiver, as |
| 4856 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4857 | // slow path, the arguments have been moved to the right place, so here we are |
| 4858 | // guaranteed that the receiver is the first register of the calling convention. |
| 4859 | InvokeDexCallingConvention calling_convention; |
| 4860 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4861 | Register temp = XRegisterFrom(temp_in); |
| 4862 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4863 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4864 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4865 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4866 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4867 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4868 | |
| 4869 | { |
| 4870 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4871 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4872 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4873 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4874 | MaybeRecordImplicitNullCheck(invoke); |
| 4875 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4876 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4877 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4878 | // intermediate/temporary reference and because the current |
| 4879 | // concurrent copying collector keeps the from-space memory |
| 4880 | // intact/accessible until the end of the marking phase (the |
| 4881 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4882 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4883 | |
| 4884 | // If we're compiling baseline, update the inline cache. |
| 4885 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4886 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4887 | // temp = temp->GetMethodAt(method_offset); |
| 4888 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4889 | // lr = temp->GetEntryPoint(); |
| 4890 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4891 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4892 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4893 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4894 | // lr(); |
| 4895 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4896 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4897 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4898 | } |
| 4899 | |
Vladimir Marko | 9922f00 | 2020-06-08 15:05:15 +0100 | [diff] [blame] | 4900 | void CodeGeneratorARM64::MoveFromReturnRegister(Location trg, DataType::Type type) { |
| 4901 | if (!trg.IsValid()) { |
| 4902 | DCHECK(type == DataType::Type::kVoid); |
| 4903 | return; |
| 4904 | } |
| 4905 | |
| 4906 | DCHECK_NE(type, DataType::Type::kVoid); |
| 4907 | |
| 4908 | if (DataType::IsIntegralType(type) || type == DataType::Type::kReference) { |
| 4909 | Register trg_reg = RegisterFrom(trg, type); |
| 4910 | Register res_reg = RegisterFrom(ARM64ReturnLocation(type), type); |
| 4911 | __ Mov(trg_reg, res_reg, kDiscardForSameWReg); |
| 4912 | } else { |
| 4913 | VRegister trg_reg = FPRegisterFrom(trg, type); |
| 4914 | VRegister res_reg = FPRegisterFrom(ARM64ReturnLocation(type), type); |
| 4915 | __ Fmov(trg_reg, res_reg); |
| 4916 | } |
| 4917 | } |
| 4918 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4919 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 4920 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
| 4921 | if (intrinsic.TryDispatch(invoke)) { |
| 4922 | return; |
| 4923 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4924 | HandleInvoke(invoke); |
| 4925 | } |
| 4926 | |
| 4927 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 4928 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4929 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| 4930 | return; |
| 4931 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4932 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4933 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4934 | } |
| 4935 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4936 | void LocationsBuilderARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4937 | HandleInvoke(invoke); |
| 4938 | } |
| 4939 | |
| 4940 | void InstructionCodeGeneratorARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4941 | codegen_->GenerateInvokeCustomCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4942 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4943 | } |
| 4944 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4945 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageIntrinsicPatch( |
| 4946 | uint32_t intrinsic_data, |
| 4947 | vixl::aarch64::Label* adrp_label) { |
| 4948 | return NewPcRelativePatch( |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4949 | /* dex_file= */ nullptr, intrinsic_data, adrp_label, &boot_image_other_patches_); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4950 | } |
| 4951 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4952 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageRelRoPatch( |
| 4953 | uint32_t boot_image_offset, |
| 4954 | vixl::aarch64::Label* adrp_label) { |
| 4955 | return NewPcRelativePatch( |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4956 | /* dex_file= */ nullptr, boot_image_offset, adrp_label, &boot_image_other_patches_); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4957 | } |
| 4958 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4959 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageMethodPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4960 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4961 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4962 | return NewPcRelativePatch( |
| 4963 | target_method.dex_file, target_method.index, adrp_label, &boot_image_method_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4964 | } |
| 4965 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4966 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4967 | MethodReference target_method, |
| 4968 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4969 | return NewPcRelativePatch( |
| 4970 | target_method.dex_file, target_method.index, adrp_label, &method_bss_entry_patches_); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4971 | } |
| 4972 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4973 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageTypePatch( |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4974 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4975 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4976 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4977 | return NewPcRelativePatch(&dex_file, type_index.index_, adrp_label, &boot_image_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4978 | } |
| 4979 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4980 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 4981 | HLoadClass* load_class, |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4982 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 4983 | const DexFile& dex_file = load_class->GetDexFile(); |
| 4984 | dex::TypeIndex type_index = load_class->GetTypeIndex(); |
| 4985 | ArenaDeque<PcRelativePatchInfo>* patches = nullptr; |
| 4986 | switch (load_class->GetLoadKind()) { |
| 4987 | case HLoadClass::LoadKind::kBssEntry: |
| 4988 | patches = &type_bss_entry_patches_; |
| 4989 | break; |
| 4990 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 4991 | patches = &public_type_bss_entry_patches_; |
| 4992 | break; |
| 4993 | case HLoadClass::LoadKind::kBssEntryPackage: |
| 4994 | patches = &package_type_bss_entry_patches_; |
| 4995 | break; |
| 4996 | default: |
| 4997 | LOG(FATAL) << "Unexpected load kind: " << load_class->GetLoadKind(); |
| 4998 | UNREACHABLE(); |
| 4999 | } |
| 5000 | return NewPcRelativePatch(&dex_file, type_index.index_, adrp_label, patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5001 | } |
| 5002 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5003 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageStringPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5004 | const DexFile& dex_file, |
| 5005 | dex::StringIndex string_index, |
| 5006 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5007 | return NewPcRelativePatch( |
| 5008 | &dex_file, string_index.index_, adrp_label, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5009 | } |
| 5010 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5011 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 5012 | const DexFile& dex_file, |
| 5013 | dex::StringIndex string_index, |
| 5014 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5015 | return NewPcRelativePatch(&dex_file, string_index.index_, adrp_label, &string_bss_entry_patches_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5016 | } |
| 5017 | |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5018 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageJniEntrypointPatch( |
| 5019 | MethodReference target_method, |
| 5020 | vixl::aarch64::Label* adrp_label) { |
| 5021 | return NewPcRelativePatch( |
| 5022 | target_method.dex_file, target_method.index, adrp_label, &boot_image_jni_entrypoint_patches_); |
| 5023 | } |
| 5024 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5025 | void CodeGeneratorARM64::EmitEntrypointThunkCall(ThreadOffset64 entrypoint_offset) { |
| 5026 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5027 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5028 | call_entrypoint_patches_.emplace_back(/*dex_file*/ nullptr, entrypoint_offset.Uint32Value()); |
| 5029 | vixl::aarch64::Label* bl_label = &call_entrypoint_patches_.back().label; |
| 5030 | __ bind(bl_label); |
| 5031 | __ bl(static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 5032 | } |
| 5033 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 5034 | void CodeGeneratorARM64::EmitBakerReadBarrierCbnz(uint32_t custom_data) { |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 5035 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5036 | if (GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 5037 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 5038 | vixl::aarch64::Label* slow_path_entry = &it->second.label; |
| 5039 | __ cbnz(mr, slow_path_entry); |
| 5040 | } else { |
| 5041 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 5042 | vixl::aarch64::Label* cbnz_label = &baker_read_barrier_patches_.back().label; |
| 5043 | __ bind(cbnz_label); |
| 5044 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 5045 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5046 | } |
| 5047 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5048 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5049 | const DexFile* dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5050 | uint32_t offset_or_index, |
| 5051 | vixl::aarch64::Label* adrp_label, |
| 5052 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5053 | // Add a patch entry and return the label. |
| 5054 | patches->emplace_back(dex_file, offset_or_index); |
| 5055 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5056 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5057 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 5058 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 5059 | return label; |
| 5060 | } |
| 5061 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5062 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 5063 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5064 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5065 | } |
| 5066 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5067 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5068 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5069 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5070 | return jit_string_patches_.GetOrCreate( |
| 5071 | StringReference(&dex_file, string_index), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5072 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5073 | } |
| 5074 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5075 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5076 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5077 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5078 | return jit_class_patches_.GetOrCreate( |
| 5079 | TypeReference(&dex_file, type_index), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5080 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5081 | } |
| 5082 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5083 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 5084 | vixl::aarch64::Register reg) { |
| 5085 | DCHECK(reg.IsX()); |
| 5086 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 5087 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5088 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5089 | } |
| 5090 | |
| 5091 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 5092 | vixl::aarch64::Register out, |
| 5093 | vixl::aarch64::Register base) { |
| 5094 | DCHECK(out.IsX()); |
| 5095 | DCHECK(base.IsX()); |
| 5096 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 5097 | __ Bind(fixup_label); |
| 5098 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 5099 | } |
| 5100 | |
| 5101 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 5102 | vixl::aarch64::Register out, |
| 5103 | vixl::aarch64::Register base) { |
| 5104 | DCHECK(base.IsX()); |
| 5105 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 5106 | __ Bind(fixup_label); |
| 5107 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 5108 | } |
| 5109 | |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5110 | void CodeGeneratorARM64::LoadBootImageRelRoEntry(vixl::aarch64::Register reg, |
| 5111 | uint32_t boot_image_offset) { |
| 5112 | DCHECK(reg.IsW()); |
| 5113 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5114 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_offset); |
| 5115 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 5116 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| 5117 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| 5118 | EmitLdrOffsetPlaceholder(ldr_label, reg.W(), reg.X()); |
| 5119 | } |
| 5120 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5121 | void CodeGeneratorARM64::LoadBootImageAddress(vixl::aarch64::Register reg, |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5122 | uint32_t boot_image_reference) { |
| 5123 | if (GetCompilerOptions().IsBootImage()) { |
| 5124 | // Add ADRP with its PC-relative type patch. |
| 5125 | vixl::aarch64::Label* adrp_label = NewBootImageIntrinsicPatch(boot_image_reference); |
| 5126 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 5127 | // Add ADD with its PC-relative type patch. |
| 5128 | vixl::aarch64::Label* add_label = NewBootImageIntrinsicPatch(boot_image_reference, adrp_label); |
| 5129 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 5130 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5131 | LoadBootImageRelRoEntry(reg, boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5132 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5133 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5134 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 5135 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5136 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5137 | __ Ldr(reg.W(), DeduplicateBootImageAddressLiteral(reinterpret_cast<uintptr_t>(address))); |
| 5138 | } |
| 5139 | } |
| 5140 | |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 5141 | void CodeGeneratorARM64::LoadTypeForBootImageIntrinsic(vixl::aarch64::Register reg, |
| 5142 | TypeReference target_type) { |
| 5143 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5144 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 5145 | // Add ADRP with its PC-relative type patch. |
| 5146 | vixl::aarch64::Label* adrp_label = |
| 5147 | NewBootImageTypePatch(*target_type.dex_file, target_type.TypeIndex()); |
| 5148 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 5149 | // Add ADD with its PC-relative type patch. |
| 5150 | vixl::aarch64::Label* add_label = |
| 5151 | NewBootImageTypePatch(*target_type.dex_file, target_type.TypeIndex(), adrp_label); |
| 5152 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
| 5153 | } |
| 5154 | |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5155 | void CodeGeneratorARM64::LoadIntrinsicDeclaringClass(vixl::aarch64::Register reg, HInvoke* invoke) { |
| 5156 | DCHECK_NE(invoke->GetIntrinsic(), Intrinsics::kNone); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5157 | if (GetCompilerOptions().IsBootImage()) { |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5158 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5159 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 5160 | LoadTypeForBootImageIntrinsic(reg, TypeReference(target_method.dex_file, type_idx)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5161 | } else { |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5162 | uint32_t boot_image_offset = GetBootImageOffsetOfIntrinsicDeclaringClass(invoke); |
| 5163 | LoadBootImageAddress(reg, boot_image_offset); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5164 | } |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5165 | } |
| 5166 | |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 5167 | void CodeGeneratorARM64::LoadClassRootForIntrinsic(vixl::aarch64::Register reg, |
| 5168 | ClassRoot class_root) { |
| 5169 | if (GetCompilerOptions().IsBootImage()) { |
| 5170 | ScopedObjectAccess soa(Thread::Current()); |
| 5171 | ObjPtr<mirror::Class> klass = GetClassRoot(class_root); |
| 5172 | TypeReference target_type(&klass->GetDexFile(), klass->GetDexTypeIndex()); |
| 5173 | LoadTypeForBootImageIntrinsic(reg, target_type); |
| 5174 | } else { |
| 5175 | uint32_t boot_image_offset = GetBootImageOffset(class_root); |
| 5176 | LoadBootImageAddress(reg, boot_image_offset); |
| 5177 | } |
| 5178 | } |
| 5179 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5180 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5181 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 5182 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5183 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5184 | for (const PcRelativePatchInfo& info : infos) { |
| 5185 | linker_patches->push_back(Factory(info.label.GetLocation(), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5186 | info.target_dex_file, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5187 | info.pc_insn_label->GetLocation(), |
| 5188 | info.offset_or_index)); |
| 5189 | } |
| 5190 | } |
| 5191 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5192 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 5193 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 5194 | const DexFile* target_dex_file, |
| 5195 | uint32_t pc_insn_offset, |
| 5196 | uint32_t boot_image_offset) { |
| 5197 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 5198 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5199 | } |
| 5200 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5201 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5202 | DCHECK(linker_patches->empty()); |
| 5203 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5204 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5205 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5206 | boot_image_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5207 | type_bss_entry_patches_.size() + |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5208 | public_type_bss_entry_patches_.size() + |
| 5209 | package_type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5210 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5211 | string_bss_entry_patches_.size() + |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5212 | boot_image_jni_entrypoint_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5213 | boot_image_other_patches_.size() + |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5214 | call_entrypoint_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5215 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5216 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5217 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5218 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5219 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5220 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5221 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5222 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5223 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5224 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5225 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5226 | DCHECK(boot_image_type_patches_.empty()); |
| 5227 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5228 | } |
| 5229 | if (GetCompilerOptions().IsBootImage()) { |
| 5230 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 5231 | boot_image_other_patches_, linker_patches); |
| 5232 | } else { |
| 5233 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 5234 | boot_image_other_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5235 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5236 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5237 | method_bss_entry_patches_, linker_patches); |
| 5238 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5239 | type_bss_entry_patches_, linker_patches); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5240 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PublicTypeBssEntryPatch>( |
| 5241 | public_type_bss_entry_patches_, linker_patches); |
| 5242 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PackageTypeBssEntryPatch>( |
| 5243 | package_type_bss_entry_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5244 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5245 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5246 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeJniEntrypointPatch>( |
| 5247 | boot_image_jni_entrypoint_patches_, linker_patches); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5248 | for (const PatchInfo<vixl::aarch64::Label>& info : call_entrypoint_patches_) { |
| 5249 | DCHECK(info.target_dex_file == nullptr); |
| 5250 | linker_patches->push_back(linker::LinkerPatch::CallEntrypointPatch( |
| 5251 | info.label.GetLocation(), info.offset_or_index)); |
| 5252 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5253 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5254 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 5255 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5256 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5257 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5258 | } |
| 5259 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5260 | bool CodeGeneratorARM64::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5261 | return patch.GetType() == linker::LinkerPatch::Type::kCallEntrypoint || |
| 5262 | patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5263 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 5264 | } |
| 5265 | |
| 5266 | void CodeGeneratorARM64::EmitThunkCode(const linker::LinkerPatch& patch, |
| 5267 | /*out*/ ArenaVector<uint8_t>* code, |
| 5268 | /*out*/ std::string* debug_name) { |
| 5269 | Arm64Assembler assembler(GetGraph()->GetAllocator()); |
| 5270 | switch (patch.GetType()) { |
| 5271 | case linker::LinkerPatch::Type::kCallRelative: { |
| 5272 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 5273 | // to the generic JNI and interpreter trampolines. |
| 5274 | Offset offset(ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 5275 | kArm64PointerSize).Int32Value()); |
| 5276 | assembler.JumpTo(ManagedRegister(arm64::X0), offset, ManagedRegister(arm64::IP0)); |
David Srbecky | 889da94 | 2021-04-30 13:03:14 +0100 | [diff] [blame] | 5277 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5278 | *debug_name = "MethodCallThunk"; |
| 5279 | } |
| 5280 | break; |
| 5281 | } |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5282 | case linker::LinkerPatch::Type::kCallEntrypoint: { |
| 5283 | Offset offset(patch.EntrypointOffset()); |
| 5284 | assembler.JumpTo(ManagedRegister(arm64::TR), offset, ManagedRegister(arm64::IP0)); |
David Srbecky | 889da94 | 2021-04-30 13:03:14 +0100 | [diff] [blame] | 5285 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5286 | *debug_name = "EntrypointCallThunk_" + std::to_string(offset.Uint32Value()); |
| 5287 | } |
| 5288 | break; |
| 5289 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5290 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| 5291 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 5292 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 5293 | break; |
| 5294 | } |
| 5295 | default: |
| 5296 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 5297 | UNREACHABLE(); |
| 5298 | } |
| 5299 | |
| 5300 | // Ensure we emit the literal pool if any. |
| 5301 | assembler.FinalizeCode(); |
| 5302 | code->resize(assembler.CodeSize()); |
| 5303 | MemoryRegion code_region(code->data(), code->size()); |
| 5304 | assembler.FinalizeInstructions(code_region); |
| 5305 | } |
| 5306 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5307 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 5308 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5309 | value, |
| 5310 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 5311 | } |
| 5312 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5313 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5314 | return uint64_literals_.GetOrCreate( |
| 5315 | value, |
| 5316 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5317 | } |
| 5318 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5319 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5320 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5321 | // art::PrepareForRegisterAllocation. |
| 5322 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5323 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5324 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5325 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5326 | return; |
| 5327 | } |
| 5328 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5329 | LocationSummary* locations = invoke->GetLocations(); |
| 5330 | codegen_->GenerateStaticOrDirectCall( |
| 5331 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5332 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5333 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5334 | } |
| 5335 | |
| 5336 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5337 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5338 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5339 | return; |
| 5340 | } |
| 5341 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5342 | { |
| 5343 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 5344 | // are no pools emitted. |
| 5345 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 5346 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 5347 | DCHECK(!codegen_->IsLeafMethod()); |
| 5348 | } |
| 5349 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5350 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5351 | } |
| 5352 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5353 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 5354 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5355 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5356 | case HLoadClass::LoadKind::kInvalid: |
| 5357 | LOG(FATAL) << "UNREACHABLE"; |
| 5358 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5359 | case HLoadClass::LoadKind::kReferrersClass: |
| 5360 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5361 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5362 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5363 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5364 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 5365 | case HLoadClass::LoadKind::kBssEntryPackage: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5366 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5367 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5368 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5369 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5370 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5371 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5372 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5373 | break; |
| 5374 | } |
| 5375 | return desired_class_load_kind; |
| 5376 | } |
| 5377 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5378 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5379 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5380 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5381 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5382 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5383 | cls, |
| 5384 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5385 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5386 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5387 | return; |
| 5388 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5389 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 5390 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 5391 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5392 | |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5393 | const bool requires_read_barrier = gUseReadBarrier && !cls->IsInBootImage(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5394 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5395 | ? LocationSummary::kCallOnSlowPath |
| 5396 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5397 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5398 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5399 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5400 | } |
| 5401 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5402 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5403 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5404 | } |
| 5405 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5406 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5407 | if (!gUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5408 | // 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] | 5409 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5410 | } else { |
| 5411 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5412 | } |
| 5413 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5414 | } |
| 5415 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5416 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5417 | // move. |
| 5418 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5419 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5420 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5421 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5422 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5423 | return; |
| 5424 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5425 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 5426 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 5427 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5428 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5429 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5430 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5431 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5432 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5433 | ? kWithoutReadBarrier |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5434 | : gCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5435 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5436 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5437 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5438 | DCHECK(!cls->CanCallRuntime()); |
| 5439 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5440 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5441 | Register current_method = InputRegisterAt(cls, 0); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5442 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5443 | out_loc, |
| 5444 | current_method, |
| 5445 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5446 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5447 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5448 | break; |
| 5449 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5450 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5451 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 5452 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5453 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5454 | // Add ADRP with its PC-relative type patch. |
| 5455 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5456 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5457 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5458 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5459 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5460 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5461 | codegen_->NewBootImageTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5462 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5463 | break; |
| 5464 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5465 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5466 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5467 | uint32_t boot_image_offset = CodeGenerator::GetBootImageOffset(cls); |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5468 | codegen_->LoadBootImageRelRoEntry(out.W(), boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5469 | break; |
| 5470 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5471 | case HLoadClass::LoadKind::kBssEntry: |
| 5472 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 5473 | case HLoadClass::LoadKind::kBssEntryPackage: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5474 | // Add ADRP with its PC-relative Class .bss entry patch. |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5475 | vixl::aarch64::Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5476 | vixl::aarch64::Label* adrp_label = codegen_->NewBssEntryTypePatch(cls); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5477 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5478 | // Add LDR with its PC-relative Class .bss entry patch. |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5479 | vixl::aarch64::Label* ldr_label = codegen_->NewBssEntryTypePatch(cls, adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5480 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5481 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5482 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5483 | out_loc, |
| 5484 | temp, |
| 5485 | /* offset placeholder */ 0u, |
| 5486 | ldr_label, |
| 5487 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5488 | generate_null_check = true; |
| 5489 | break; |
| 5490 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5491 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 5492 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 5493 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 5494 | DCHECK_NE(address, 0u); |
| 5495 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5496 | break; |
| 5497 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5498 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5499 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5500 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5501 | cls->GetClass())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5502 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5503 | out_loc, |
| 5504 | out.X(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5505 | /* offset= */ 0, |
| 5506 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5507 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5508 | break; |
| 5509 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5510 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5511 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5512 | LOG(FATAL) << "UNREACHABLE"; |
| 5513 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5514 | } |
| 5515 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5516 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5517 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5518 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 5519 | SlowPathCodeARM64* slow_path = |
| 5520 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5521 | codegen_->AddSlowPath(slow_path); |
| 5522 | if (generate_null_check) { |
| 5523 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5524 | } |
| 5525 | if (cls->MustGenerateClinitCheck()) { |
| 5526 | GenerateClassInitializationCheck(slow_path, out); |
| 5527 | } else { |
| 5528 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5529 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5530 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5531 | } |
| 5532 | } |
| 5533 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 5534 | void LocationsBuilderARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5535 | InvokeRuntimeCallingConvention calling_convention; |
| 5536 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5537 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 5538 | } |
| 5539 | |
| 5540 | void InstructionCodeGeneratorARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5541 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 5542 | } |
| 5543 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 5544 | void LocationsBuilderARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5545 | InvokeRuntimeCallingConvention calling_convention; |
| 5546 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5547 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 5548 | } |
| 5549 | |
| 5550 | void InstructionCodeGeneratorARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5551 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 5552 | } |
| 5553 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5554 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5555 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5556 | } |
| 5557 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5558 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5559 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5560 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5561 | locations->SetOut(Location::RequiresRegister()); |
| 5562 | } |
| 5563 | |
| 5564 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5565 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5566 | } |
| 5567 | |
| 5568 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5569 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5570 | } |
| 5571 | |
| 5572 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5573 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5574 | } |
| 5575 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5576 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5577 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5578 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5579 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5580 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5581 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5582 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5583 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5584 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5585 | case HLoadString::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5586 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5587 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5588 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5589 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5590 | } |
| 5591 | return desired_string_load_kind; |
| 5592 | } |
| 5593 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5594 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5595 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5596 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5597 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5598 | InvokeRuntimeCallingConvention calling_convention; |
| 5599 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5600 | } else { |
| 5601 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5602 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5603 | if (!gUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5604 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 5605 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5606 | } else { |
| 5607 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5608 | } |
| 5609 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5610 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5611 | } |
| 5612 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5613 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5614 | // move. |
| 5615 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5616 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5617 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5618 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5619 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5620 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5621 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 5622 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5623 | // Add ADRP with its PC-relative String patch. |
| 5624 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5625 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5626 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5627 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5628 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5629 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5630 | codegen_->NewBootImageStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5631 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5632 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5633 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5634 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5635 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5636 | uint32_t boot_image_offset = CodeGenerator::GetBootImageOffset(load); |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5637 | codegen_->LoadBootImageRelRoEntry(out.W(), boot_image_offset); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5638 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5639 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5640 | case HLoadString::LoadKind::kBssEntry: { |
| 5641 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5642 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5643 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5644 | Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5645 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5646 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5647 | // Add LDR with its PC-relative String .bss entry patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5648 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5649 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5650 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5651 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5652 | codegen_->GenerateGcRootFieldLoad(load, |
| 5653 | out_loc, |
| 5654 | temp, |
| 5655 | /* offset placeholder */ 0u, |
| 5656 | ldr_label, |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5657 | gCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5658 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5659 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5660 | codegen_->AddSlowPath(slow_path); |
| 5661 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5662 | __ Bind(slow_path->GetExitLabel()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5663 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5664 | return; |
| 5665 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5666 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 5667 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 5668 | DCHECK_NE(address, 0u); |
| 5669 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5670 | return; |
| 5671 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5672 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5673 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5674 | load->GetStringIndex(), |
| 5675 | load->GetString())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5676 | codegen_->GenerateGcRootFieldLoad(load, |
| 5677 | out_loc, |
| 5678 | out.X(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5679 | /* offset= */ 0, |
| 5680 | /* fixup_label= */ nullptr, |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5681 | gCompilerReadBarrierOption); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5682 | return; |
| 5683 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5684 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5685 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5686 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5687 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5688 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5689 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5690 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5691 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5692 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5693 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5694 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5695 | } |
| 5696 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5697 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5698 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5699 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5700 | } |
| 5701 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5702 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5703 | // Will be generated at use site. |
| 5704 | } |
| 5705 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5706 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5707 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5708 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5709 | InvokeRuntimeCallingConvention calling_convention; |
| 5710 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5711 | } |
| 5712 | |
| 5713 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5714 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5715 | instruction, |
| 5716 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5717 | if (instruction->IsEnter()) { |
| 5718 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5719 | } else { |
| 5720 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5721 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5722 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5723 | } |
| 5724 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5725 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5726 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5727 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5728 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5729 | case DataType::Type::kInt32: |
| 5730 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5731 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5732 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5733 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5734 | break; |
| 5735 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5736 | case DataType::Type::kFloat32: |
| 5737 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5738 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5739 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5740 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5741 | break; |
| 5742 | |
| 5743 | default: |
| 5744 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5745 | } |
| 5746 | } |
| 5747 | |
| 5748 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5749 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5750 | case DataType::Type::kInt32: |
| 5751 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5752 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5753 | break; |
| 5754 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5755 | case DataType::Type::kFloat32: |
| 5756 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5757 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5758 | break; |
| 5759 | |
| 5760 | default: |
| 5761 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5762 | } |
| 5763 | } |
| 5764 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5765 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5766 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5767 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5768 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5769 | case DataType::Type::kInt32: |
| 5770 | case DataType::Type::kInt64: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5771 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5772 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5773 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5774 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5775 | case DataType::Type::kFloat32: |
| 5776 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5777 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5778 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5779 | break; |
| 5780 | |
| 5781 | default: |
| 5782 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5783 | } |
| 5784 | } |
| 5785 | |
| 5786 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5787 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5788 | case DataType::Type::kInt32: |
| 5789 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5790 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5791 | break; |
| 5792 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5793 | case DataType::Type::kFloat32: |
| 5794 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5795 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5796 | break; |
| 5797 | |
| 5798 | default: |
| 5799 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5800 | } |
| 5801 | } |
| 5802 | |
| 5803 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5804 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5805 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5806 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5807 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5808 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5809 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5810 | } |
| 5811 | |
| 5812 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5813 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5814 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5815 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5816 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5817 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5818 | } |
| 5819 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5820 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5821 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5822 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5823 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5824 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5825 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5829 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5830 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5831 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5832 | } |
| 5833 | |
| 5834 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5835 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5836 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5837 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5841 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5842 | case DataType::Type::kInt32: |
| 5843 | case DataType::Type::kInt64: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5844 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5845 | break; |
| 5846 | |
| 5847 | default: |
| 5848 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5849 | } |
| 5850 | } |
| 5851 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5852 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5853 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5854 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5855 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5856 | } |
| 5857 | |
| 5858 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5859 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5860 | } |
| 5861 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5862 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5863 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5864 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5865 | } |
| 5866 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5867 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5868 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5869 | return; |
| 5870 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5871 | { |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 5872 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5873 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5874 | Location obj = instruction->GetLocations()->InAt(0); |
| 5875 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5876 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5877 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5878 | } |
| 5879 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5880 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5881 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5882 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5883 | |
| 5884 | LocationSummary* locations = instruction->GetLocations(); |
| 5885 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5886 | |
| 5887 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5888 | } |
| 5889 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5890 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5891 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5892 | } |
| 5893 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5894 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5895 | HandleBinaryOp(instruction); |
| 5896 | } |
| 5897 | |
| 5898 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5899 | HandleBinaryOp(instruction); |
| 5900 | } |
| 5901 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5902 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5903 | LOG(FATAL) << "Unreachable"; |
| 5904 | } |
| 5905 | |
| 5906 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5907 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5908 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5909 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5910 | // The back edge will generate the suspend check. |
| 5911 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5912 | } |
| 5913 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5914 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5915 | } |
| 5916 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5917 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5918 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5919 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5920 | if (location.IsStackSlot()) { |
| 5921 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5922 | } else if (location.IsDoubleStackSlot()) { |
| 5923 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5924 | } |
| 5925 | locations->SetOut(location); |
| 5926 | } |
| 5927 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5928 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5929 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5930 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5931 | } |
| 5932 | |
| 5933 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5934 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5935 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5936 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5937 | } |
| 5938 | |
| 5939 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5940 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5941 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5942 | } |
| 5943 | |
| 5944 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5945 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5946 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5947 | locations->SetInAt(i, Location::Any()); |
| 5948 | } |
| 5949 | locations->SetOut(Location::Any()); |
| 5950 | } |
| 5951 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5952 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5953 | LOG(FATAL) << "Unreachable"; |
| 5954 | } |
| 5955 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5956 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5957 | DataType::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5958 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5959 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5960 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5961 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5962 | |
| 5963 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5964 | case DataType::Type::kInt32: |
| 5965 | case DataType::Type::kInt64: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5966 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5967 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5968 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5969 | break; |
| 5970 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5971 | case DataType::Type::kFloat32: |
| 5972 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5973 | InvokeRuntimeCallingConvention calling_convention; |
| 5974 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5975 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5976 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5977 | |
| 5978 | break; |
| 5979 | } |
| 5980 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5981 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5982 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5983 | } |
| 5984 | } |
| 5985 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5986 | void InstructionCodeGeneratorARM64::GenerateIntRemForPower2Denom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5987 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5988 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 5989 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 5990 | |
| 5991 | Register out = OutputRegister(instruction); |
| 5992 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5993 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 5994 | if (HasNonNegativeOrMinIntInputAt(instruction, 0)) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 5995 | // No need to adjust the result for non-negative dividends or the INT32_MIN/INT64_MIN dividends. |
| 5996 | // NOTE: The generated code for HRem correctly works for the INT32_MIN/INT64_MIN dividends. |
| 5997 | // INT*_MIN % imm must be 0 for any imm of power 2. 'and' works only with bits |
| 5998 | // 0..30 (Int32 case)/0..62 (Int64 case) of a dividend. For INT32_MIN/INT64_MIN they are zeros. |
| 5999 | // So 'and' always produces zero. |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 6000 | __ And(out, dividend, abs_imm - 1); |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 6001 | } else { |
| 6002 | if (abs_imm == 2) { |
| 6003 | __ Cmp(dividend, 0); |
| 6004 | __ And(out, dividend, 1); |
| 6005 | __ Csneg(out, out, out, ge); |
| 6006 | } else { |
| 6007 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6008 | Register temp = temps.AcquireSameSizeAs(out); |
| 6009 | |
| 6010 | __ Negs(temp, dividend); |
| 6011 | __ And(out, dividend, abs_imm - 1); |
| 6012 | __ And(temp, temp, abs_imm - 1); |
| 6013 | __ Csneg(out, out, temp, mi); |
| 6014 | } |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 6015 | } |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 6016 | } |
| 6017 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 6018 | void InstructionCodeGeneratorARM64::GenerateIntRemForConstDenom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 6019 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 6020 | |
| 6021 | if (imm == 0) { |
| 6022 | // Do not generate anything. |
| 6023 | // DivZeroCheck would prevent any code to be executed. |
| 6024 | return; |
| 6025 | } |
| 6026 | |
Evgeny Astigeevich | f58dc65 | 2018-06-25 17:54:07 +0100 | [diff] [blame] | 6027 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 6028 | // Cases imm == -1 or imm == 1 are handled in constant folding by |
| 6029 | // InstructionWithAbsorbingInputSimplifier. |
| 6030 | // If the cases have survided till code generation they are handled in |
| 6031 | // GenerateIntRemForPower2Denom becauses -1 and 1 are the power of 2 (2^0). |
| 6032 | // The correct code is generated for them, just more instructions. |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 6033 | GenerateIntRemForPower2Denom(instruction); |
| 6034 | } else { |
| 6035 | DCHECK(imm < -2 || imm > 2) << imm; |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 6036 | GenerateDivRemWithAnyConstant(instruction, imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 6037 | } |
| 6038 | } |
| 6039 | |
| 6040 | void InstructionCodeGeneratorARM64::GenerateIntRem(HRem* instruction) { |
| 6041 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 6042 | << instruction->GetResultType(); |
| 6043 | |
| 6044 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 6045 | GenerateIntRemForConstDenom(instruction); |
| 6046 | } else { |
| 6047 | Register out = OutputRegister(instruction); |
| 6048 | Register dividend = InputRegisterAt(instruction, 0); |
| 6049 | Register divisor = InputRegisterAt(instruction, 1); |
| 6050 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6051 | Register temp = temps.AcquireSameSizeAs(out); |
| 6052 | __ Sdiv(temp, dividend, divisor); |
| 6053 | __ Msub(out, temp, divisor, dividend); |
| 6054 | } |
| 6055 | } |
| 6056 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6057 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6058 | DataType::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 6059 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6060 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6061 | case DataType::Type::kInt32: |
| 6062 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 6063 | GenerateIntRem(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6064 | break; |
| 6065 | } |
| 6066 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6067 | case DataType::Type::kFloat32: |
| 6068 | case DataType::Type::kFloat64: { |
| 6069 | QuickEntrypointEnum entrypoint = |
| 6070 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 6071 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6072 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6073 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 6074 | } else { |
| 6075 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 6076 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 6077 | break; |
| 6078 | } |
| 6079 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6080 | default: |
| 6081 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 6082 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6083 | } |
| 6084 | } |
| 6085 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6086 | void LocationsBuilderARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 6087 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6088 | } |
| 6089 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6090 | void InstructionCodeGeneratorARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 6091 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6092 | } |
| 6093 | |
| 6094 | void LocationsBuilderARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 6095 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6096 | } |
| 6097 | |
| 6098 | void InstructionCodeGeneratorARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 6099 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6100 | } |
| 6101 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 6102 | void LocationsBuilderARM64::VisitAbs(HAbs* abs) { |
| 6103 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 6104 | switch (abs->GetResultType()) { |
| 6105 | case DataType::Type::kInt32: |
| 6106 | case DataType::Type::kInt64: |
| 6107 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6108 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6109 | break; |
| 6110 | case DataType::Type::kFloat32: |
| 6111 | case DataType::Type::kFloat64: |
| 6112 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6113 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6114 | break; |
| 6115 | default: |
| 6116 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 6117 | } |
| 6118 | } |
| 6119 | |
| 6120 | void InstructionCodeGeneratorARM64::VisitAbs(HAbs* abs) { |
| 6121 | switch (abs->GetResultType()) { |
| 6122 | case DataType::Type::kInt32: |
| 6123 | case DataType::Type::kInt64: { |
| 6124 | Register in_reg = InputRegisterAt(abs, 0); |
| 6125 | Register out_reg = OutputRegister(abs); |
| 6126 | __ Cmp(in_reg, Operand(0)); |
| 6127 | __ Cneg(out_reg, in_reg, lt); |
| 6128 | break; |
| 6129 | } |
| 6130 | case DataType::Type::kFloat32: |
| 6131 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 6132 | VRegister in_reg = InputFPRegisterAt(abs, 0); |
| 6133 | VRegister out_reg = OutputFPRegister(abs); |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 6134 | __ Fabs(out_reg, in_reg); |
| 6135 | break; |
| 6136 | } |
| 6137 | default: |
| 6138 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 6139 | } |
| 6140 | } |
| 6141 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6142 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 6143 | constructor_fence->SetLocations(nullptr); |
| 6144 | } |
| 6145 | |
| 6146 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 6147 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 6148 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 6149 | } |
| 6150 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6151 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6152 | memory_barrier->SetLocations(nullptr); |
| 6153 | } |
| 6154 | |
| 6155 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6156 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6157 | } |
| 6158 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6159 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6160 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6161 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 6162 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6163 | } |
| 6164 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 6165 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* ret) { |
| 6166 | if (GetGraph()->IsCompilingOsr()) { |
| 6167 | // To simplify callers of an OSR method, we put the return value in both |
| 6168 | // floating point and core register. |
| 6169 | switch (ret->InputAt(0)->GetType()) { |
| 6170 | case DataType::Type::kFloat32: |
| 6171 | __ Fmov(w0, s0); |
| 6172 | break; |
| 6173 | case DataType::Type::kFloat64: |
| 6174 | __ Fmov(x0, d0); |
| 6175 | break; |
| 6176 | default: |
| 6177 | break; |
| 6178 | } |
| 6179 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6180 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6181 | } |
| 6182 | |
| 6183 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 6184 | instruction->SetLocations(nullptr); |
| 6185 | } |
| 6186 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6187 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6188 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6189 | } |
| 6190 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6191 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 6192 | HandleBinaryOp(ror); |
| 6193 | } |
| 6194 | |
| 6195 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 6196 | HandleBinaryOp(ror); |
| 6197 | } |
| 6198 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6199 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 6200 | HandleShift(shl); |
| 6201 | } |
| 6202 | |
| 6203 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 6204 | HandleShift(shl); |
| 6205 | } |
| 6206 | |
| 6207 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 6208 | HandleShift(shr); |
| 6209 | } |
| 6210 | |
| 6211 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 6212 | HandleShift(shr); |
| 6213 | } |
| 6214 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6215 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6216 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6217 | } |
| 6218 | |
| 6219 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6220 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6221 | } |
| 6222 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6223 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6224 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6225 | } |
| 6226 | |
| 6227 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 6228 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6229 | } |
| 6230 | |
| 6231 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 6232 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6233 | } |
| 6234 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6235 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Santiago Aboy Solanes | d422960 | 2023-01-03 16:20:50 +0000 | [diff] [blame] | 6236 | HandleFieldSet(instruction, |
| 6237 | instruction->GetFieldInfo(), |
| 6238 | instruction->GetValueCanBeNull(), |
| 6239 | instruction->GetWriteBarrierKind()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6240 | } |
| 6241 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 6242 | void LocationsBuilderARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6243 | codegen_->CreateStringBuilderAppendLocations(instruction, LocationFrom(x0)); |
| 6244 | } |
| 6245 | |
| 6246 | void InstructionCodeGeneratorARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6247 | __ Mov(w0, instruction->GetFormat()->GetValue()); |
| 6248 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 6249 | } |
| 6250 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6251 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 6252 | HUnresolvedInstanceFieldGet* instruction) { |
| 6253 | FieldAccessCallingConventionARM64 calling_convention; |
| 6254 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6255 | instruction, instruction->GetFieldType(), calling_convention); |
| 6256 | } |
| 6257 | |
| 6258 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 6259 | HUnresolvedInstanceFieldGet* instruction) { |
| 6260 | FieldAccessCallingConventionARM64 calling_convention; |
| 6261 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6262 | instruction->GetFieldType(), |
| 6263 | instruction->GetFieldIndex(), |
| 6264 | instruction->GetDexPc(), |
| 6265 | calling_convention); |
| 6266 | } |
| 6267 | |
| 6268 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 6269 | HUnresolvedInstanceFieldSet* instruction) { |
| 6270 | FieldAccessCallingConventionARM64 calling_convention; |
| 6271 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6272 | instruction, instruction->GetFieldType(), calling_convention); |
| 6273 | } |
| 6274 | |
| 6275 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 6276 | HUnresolvedInstanceFieldSet* instruction) { |
| 6277 | FieldAccessCallingConventionARM64 calling_convention; |
| 6278 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6279 | instruction->GetFieldType(), |
| 6280 | instruction->GetFieldIndex(), |
| 6281 | instruction->GetDexPc(), |
| 6282 | calling_convention); |
| 6283 | } |
| 6284 | |
| 6285 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 6286 | HUnresolvedStaticFieldGet* instruction) { |
| 6287 | FieldAccessCallingConventionARM64 calling_convention; |
| 6288 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6289 | instruction, instruction->GetFieldType(), calling_convention); |
| 6290 | } |
| 6291 | |
| 6292 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 6293 | HUnresolvedStaticFieldGet* instruction) { |
| 6294 | FieldAccessCallingConventionARM64 calling_convention; |
| 6295 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6296 | instruction->GetFieldType(), |
| 6297 | instruction->GetFieldIndex(), |
| 6298 | instruction->GetDexPc(), |
| 6299 | calling_convention); |
| 6300 | } |
| 6301 | |
| 6302 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 6303 | HUnresolvedStaticFieldSet* instruction) { |
| 6304 | FieldAccessCallingConventionARM64 calling_convention; |
| 6305 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6306 | instruction, instruction->GetFieldType(), calling_convention); |
| 6307 | } |
| 6308 | |
| 6309 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 6310 | HUnresolvedStaticFieldSet* instruction) { |
| 6311 | FieldAccessCallingConventionARM64 calling_convention; |
| 6312 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6313 | instruction->GetFieldType(), |
| 6314 | instruction->GetFieldIndex(), |
| 6315 | instruction->GetDexPc(), |
| 6316 | calling_convention); |
| 6317 | } |
| 6318 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6319 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6320 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6321 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 6322 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6323 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6324 | // registers in full width (since the runtime only saves/restores lower part). |
| 6325 | locations->SetCustomSlowPathCallerSaves( |
| 6326 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6327 | } |
| 6328 | |
| 6329 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6330 | HBasicBlock* block = instruction->GetBlock(); |
| 6331 | if (block->GetLoopInformation() != nullptr) { |
| 6332 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6333 | // The back edge will generate the suspend check. |
| 6334 | return; |
| 6335 | } |
| 6336 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6337 | // The goto will generate the suspend check. |
| 6338 | return; |
| 6339 | } |
| 6340 | GenerateSuspendCheck(instruction, nullptr); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6341 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6342 | } |
| 6343 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6344 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6345 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6346 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6347 | InvokeRuntimeCallingConvention calling_convention; |
| 6348 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6349 | } |
| 6350 | |
| 6351 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 6352 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 6353 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6354 | } |
| 6355 | |
| 6356 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 6357 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6358 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6359 | DataType::Type input_type = conversion->GetInputType(); |
| 6360 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6361 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6362 | << input_type << " -> " << result_type; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6363 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 6364 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6365 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6366 | } |
| 6367 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6368 | if (DataType::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6369 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6370 | } else { |
| 6371 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6372 | } |
| 6373 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6374 | if (DataType::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6375 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6376 | } else { |
| 6377 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6378 | } |
| 6379 | } |
| 6380 | |
| 6381 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6382 | DataType::Type result_type = conversion->GetResultType(); |
| 6383 | DataType::Type input_type = conversion->GetInputType(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6384 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6385 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6386 | << input_type << " -> " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6387 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6388 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 6389 | int result_size = DataType::Size(result_type); |
| 6390 | int input_size = DataType::Size(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6391 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6392 | Register output = OutputRegister(conversion); |
| 6393 | Register source = InputRegisterAt(conversion, 0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6394 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 6395 | // 'int' values are used directly as W registers, discarding the top |
| 6396 | // bits, so we don't need to sign-extend and can just perform a move. |
| 6397 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 6398 | // top 32 bits of the target register. We theoretically could leave those |
| 6399 | // bits unchanged, but we would have to make sure that no code uses a |
| 6400 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 6401 | // zero. |
| 6402 | __ Mov(output.W(), source.W()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6403 | } else if (DataType::IsUnsignedType(result_type) || |
| 6404 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 6405 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6406 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6407 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6408 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6409 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6410 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6411 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 6412 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6413 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6414 | } else if (DataType::IsFloatingPointType(result_type) && |
| 6415 | DataType::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6416 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 6417 | } else { |
| 6418 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6419 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6420 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6421 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6422 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6423 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 6424 | HandleShift(ushr); |
| 6425 | } |
| 6426 | |
| 6427 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 6428 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6429 | } |
| 6430 | |
| 6431 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 6432 | HandleBinaryOp(instruction); |
| 6433 | } |
| 6434 | |
| 6435 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 6436 | HandleBinaryOp(instruction); |
| 6437 | } |
| 6438 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6439 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6440 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6441 | LOG(FATAL) << "Unreachable"; |
| 6442 | } |
| 6443 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6444 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6445 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6446 | LOG(FATAL) << "Unreachable"; |
| 6447 | } |
| 6448 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6449 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6450 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6451 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6452 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6453 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6454 | } |
| 6455 | |
| 6456 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6457 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6458 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6459 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 6460 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6461 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6462 | // Roughly set 16 as max average assemblies generated per HIR in a graph. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6463 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6464 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 6465 | // make sure we don't emit it if the target may run out of range. |
| 6466 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 6467 | // ranges and emit the tables only as required. |
| 6468 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6469 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6470 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6471 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 6472 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 6473 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6474 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6475 | Register temp = temps.AcquireW(); |
| 6476 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 6477 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6478 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6479 | // Jump to successors[0] if value == lower_bound. |
| 6480 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 6481 | int32_t last_index = 0; |
| 6482 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6483 | __ Subs(temp, temp, Operand(2)); |
| 6484 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6485 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6486 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6487 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6488 | } |
| 6489 | if (num_entries - last_index == 2) { |
| 6490 | // The last missing case_value. |
| 6491 | __ Cmp(temp, Operand(1)); |
| 6492 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6493 | } |
| 6494 | |
| 6495 | // And the default for any other value. |
| 6496 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6497 | __ B(codegen_->GetLabelOf(default_block)); |
| 6498 | } |
| 6499 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 6500 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6501 | |
| 6502 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6503 | |
| 6504 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 6505 | // registers, we are free to block one. |
| 6506 | Register temp_w = temps.AcquireW(); |
| 6507 | Register index; |
| 6508 | // Remove the bias. |
| 6509 | if (lower_bound != 0) { |
| 6510 | index = temp_w; |
| 6511 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 6512 | } else { |
| 6513 | index = value_reg; |
| 6514 | } |
| 6515 | |
| 6516 | // Jump to default block if index is out of the range. |
| 6517 | __ Cmp(index, Operand(num_entries)); |
| 6518 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 6519 | |
| 6520 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 6521 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 6522 | // register pressure. |
| 6523 | Register table_base = temps.AcquireX(); |
| 6524 | // Load jump offset from the table. |
| 6525 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 6526 | Register jump_offset = temp_w; |
| 6527 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 6528 | |
| 6529 | // Jump to target block by branching to table_base(pc related) + offset. |
| 6530 | Register target_address = table_base; |
| 6531 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 6532 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6533 | } |
| 6534 | } |
| 6535 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6536 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 6537 | HInstruction* instruction, |
| 6538 | Location out, |
| 6539 | uint32_t offset, |
| 6540 | Location maybe_temp, |
| 6541 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6542 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6543 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6544 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6545 | CHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6546 | if (kUseBakerReadBarrier) { |
| 6547 | // Load with fast path based Baker's read barrier. |
| 6548 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6549 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6550 | out, |
| 6551 | out_reg, |
| 6552 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6553 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6554 | /* needs_null_check= */ false, |
| 6555 | /* use_load_acquire= */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6556 | } else { |
| 6557 | // Load with slow path based read barrier. |
| 6558 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6559 | // in the following move operation, as we will need it for the |
| 6560 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6561 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6562 | __ Mov(temp_reg, out_reg); |
| 6563 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6564 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6565 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6566 | } |
| 6567 | } else { |
| 6568 | // Plain load with no read barrier. |
| 6569 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6570 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6571 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6572 | } |
| 6573 | } |
| 6574 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6575 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 6576 | HInstruction* instruction, |
| 6577 | Location out, |
| 6578 | Location obj, |
| 6579 | uint32_t offset, |
| 6580 | Location maybe_temp, |
| 6581 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6582 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6583 | Register out_reg = RegisterFrom(out, type); |
| 6584 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6585 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6586 | CHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6587 | if (kUseBakerReadBarrier) { |
| 6588 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6589 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6590 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6591 | out, |
| 6592 | obj_reg, |
| 6593 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6594 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6595 | /* needs_null_check= */ false, |
| 6596 | /* use_load_acquire= */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6597 | } else { |
| 6598 | // Load with slow path based read barrier. |
| 6599 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6600 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6601 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6602 | } |
| 6603 | } else { |
| 6604 | // Plain load with no read barrier. |
| 6605 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6606 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6607 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6608 | } |
| 6609 | } |
| 6610 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6611 | void CodeGeneratorARM64::GenerateGcRootFieldLoad( |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6612 | HInstruction* instruction, |
| 6613 | Location root, |
| 6614 | Register obj, |
| 6615 | uint32_t offset, |
| 6616 | vixl::aarch64::Label* fixup_label, |
| 6617 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6618 | DCHECK(fixup_label == nullptr || offset == 0u); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6619 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6620 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6621 | DCHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6622 | if (kUseBakerReadBarrier) { |
| 6623 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6624 | // Baker's read barrier are used. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6625 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6626 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6627 | // the Marking Register) to decide whether we need to enter |
| 6628 | // the slow path to mark the GC root. |
| 6629 | // |
| 6630 | // We use shared thunks for the slow path; shared within the method |
| 6631 | // for JIT, across methods for AOT. That thunk checks the reference |
| 6632 | // and jumps to the entrypoint if needed. |
| 6633 | // |
| 6634 | // lr = &return_address; |
| 6635 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6636 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6637 | // goto gc_root_thunk<root_reg>(lr) |
| 6638 | // } |
| 6639 | // return_address: |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6640 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6641 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6642 | DCHECK(temps.IsAvailable(ip0)); |
| 6643 | DCHECK(temps.IsAvailable(ip1)); |
| 6644 | temps.Exclude(ip0, ip1); |
| 6645 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6646 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6647 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6648 | vixl::aarch64::Label return_address; |
| 6649 | __ adr(lr, &return_address); |
| 6650 | if (fixup_label != nullptr) { |
| 6651 | __ bind(fixup_label); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6652 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6653 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6654 | "GC root LDR must be 2 instructions (8B) before the return address label."); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6655 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6656 | EmitBakerReadBarrierCbnz(custom_data); |
| 6657 | __ bind(&return_address); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6658 | } else { |
| 6659 | // GC root loaded through a slow path for read barriers other |
| 6660 | // than Baker's. |
| 6661 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6662 | if (fixup_label == nullptr) { |
| 6663 | __ Add(root_reg.X(), obj.X(), offset); |
| 6664 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6665 | EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6666 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6667 | // /* mirror::Object* */ root = root->Read() |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6668 | GenerateReadBarrierForRootSlow(instruction, root, root); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6669 | } |
| 6670 | } else { |
| 6671 | // Plain GC root load with no read barrier. |
| 6672 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6673 | if (fixup_label == nullptr) { |
| 6674 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6675 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6676 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6677 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6678 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6679 | // do not have to unpoison `root_reg` here. |
| 6680 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6681 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6682 | } |
| 6683 | |
Vladimir Marko | c8178f5 | 2020-11-24 10:38:16 +0000 | [diff] [blame] | 6684 | void CodeGeneratorARM64::GenerateIntrinsicCasMoveWithBakerReadBarrier( |
| 6685 | vixl::aarch64::Register marked_old_value, |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6686 | vixl::aarch64::Register old_value) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6687 | DCHECK(gUseReadBarrier); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6688 | DCHECK(kUseBakerReadBarrier); |
| 6689 | |
| 6690 | // Similar to the Baker RB path in GenerateGcRootFieldLoad(), with a MOV instead of LDR. |
Vladimir Marko | c8178f5 | 2020-11-24 10:38:16 +0000 | [diff] [blame] | 6691 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(marked_old_value.GetCode()); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6692 | |
| 6693 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6694 | vixl::aarch64::Label return_address; |
| 6695 | __ adr(lr, &return_address); |
| 6696 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6697 | "GC root LDR must be 2 instructions (8B) before the return address label."); |
Vladimir Marko | c8178f5 | 2020-11-24 10:38:16 +0000 | [diff] [blame] | 6698 | __ mov(marked_old_value, old_value); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6699 | EmitBakerReadBarrierCbnz(custom_data); |
| 6700 | __ bind(&return_address); |
| 6701 | } |
| 6702 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6703 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6704 | Location ref, |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6705 | vixl::aarch64::Register obj, |
| 6706 | const vixl::aarch64::MemOperand& src, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6707 | bool needs_null_check, |
| 6708 | bool use_load_acquire) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6709 | DCHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6710 | DCHECK(kUseBakerReadBarrier); |
| 6711 | |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6712 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6713 | // Marking Register) to decide whether we need to enter the slow |
| 6714 | // path to mark the reference. Then, in the slow path, check the |
| 6715 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6716 | // decide whether to mark `ref` or not. |
| 6717 | // |
| 6718 | // We use shared thunks for the slow path; shared within the method |
| 6719 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6720 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6721 | // it creates a fake dependency and returns to the LDR instruction. |
| 6722 | // |
| 6723 | // lr = &gray_return_address; |
| 6724 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6725 | // goto field_thunk<holder_reg, base_reg, use_load_acquire>(lr) |
| 6726 | // } |
| 6727 | // not_gray_return_address: |
| 6728 | // // Original reference load. If the offset is too large to fit |
| 6729 | // // into LDR, we use an adjusted base register here. |
| 6730 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 6731 | // gray_return_address: |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6732 | |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6733 | DCHECK(src.GetAddrMode() == vixl::aarch64::Offset); |
| 6734 | DCHECK_ALIGNED(src.GetOffset(), sizeof(mirror::HeapReference<mirror::Object>)); |
| 6735 | |
| 6736 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6737 | DCHECK(temps.IsAvailable(ip0)); |
| 6738 | DCHECK(temps.IsAvailable(ip1)); |
| 6739 | temps.Exclude(ip0, ip1); |
| 6740 | uint32_t custom_data = use_load_acquire |
| 6741 | ? EncodeBakerReadBarrierAcquireData(src.GetBaseRegister().GetCode(), obj.GetCode()) |
| 6742 | : EncodeBakerReadBarrierFieldData(src.GetBaseRegister().GetCode(), obj.GetCode()); |
| 6743 | |
| 6744 | { |
| 6745 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6746 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6747 | vixl::aarch64::Label return_address; |
| 6748 | __ adr(lr, &return_address); |
| 6749 | EmitBakerReadBarrierCbnz(custom_data); |
| 6750 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6751 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6752 | " 2 instructions (8B) for heap poisoning."); |
| 6753 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 6754 | if (use_load_acquire) { |
| 6755 | DCHECK_EQ(src.GetOffset(), 0); |
| 6756 | __ ldar(ref_reg, src); |
| 6757 | } else { |
| 6758 | __ ldr(ref_reg, src); |
| 6759 | } |
| 6760 | if (needs_null_check) { |
| 6761 | MaybeRecordImplicitNullCheck(instruction); |
| 6762 | } |
| 6763 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6764 | // macro instructions disallowed in ExactAssemblyScope. |
| 6765 | if (kPoisonHeapReferences) { |
| 6766 | __ neg(ref_reg, Operand(ref_reg)); |
| 6767 | } |
| 6768 | __ bind(&return_address); |
| 6769 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6770 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6771 | } |
| 6772 | |
| 6773 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6774 | Location ref, |
| 6775 | Register obj, |
| 6776 | uint32_t offset, |
| 6777 | Location maybe_temp, |
| 6778 | bool needs_null_check, |
| 6779 | bool use_load_acquire) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6780 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6781 | Register base = obj; |
| 6782 | if (use_load_acquire) { |
| 6783 | DCHECK(maybe_temp.IsRegister()); |
| 6784 | base = WRegisterFrom(maybe_temp); |
| 6785 | __ Add(base, obj, offset); |
| 6786 | offset = 0u; |
| 6787 | } else if (offset >= kReferenceLoadMinFarOffset) { |
| 6788 | DCHECK(maybe_temp.IsRegister()); |
| 6789 | base = WRegisterFrom(maybe_temp); |
| 6790 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6791 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6792 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6793 | } |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6794 | MemOperand src(base.X(), offset); |
| 6795 | GenerateFieldLoadWithBakerReadBarrier( |
| 6796 | instruction, ref, obj, src, needs_null_check, use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6797 | } |
| 6798 | |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6799 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HArrayGet* instruction, |
| 6800 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6801 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6802 | uint32_t data_offset, |
| 6803 | Location index, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6804 | bool needs_null_check) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6805 | DCHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6806 | DCHECK(kUseBakerReadBarrier); |
| 6807 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6808 | static_assert( |
| 6809 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6810 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6811 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6812 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6813 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6814 | // Marking Register) to decide whether we need to enter the slow |
| 6815 | // path to mark the reference. Then, in the slow path, check the |
| 6816 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6817 | // decide whether to mark `ref` or not. |
| 6818 | // |
| 6819 | // We use shared thunks for the slow path; shared within the method |
| 6820 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6821 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6822 | // it creates a fake dependency and returns to the LDR instruction. |
| 6823 | // |
| 6824 | // lr = &gray_return_address; |
| 6825 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6826 | // goto array_thunk<base_reg>(lr) |
| 6827 | // } |
| 6828 | // not_gray_return_address: |
| 6829 | // // Original reference load. If the offset is too large to fit |
| 6830 | // // into LDR, we use an adjusted base register here. |
| 6831 | // HeapReference<mirror::Object> reference = data[index]; |
| 6832 | // gray_return_address: |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6833 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6834 | DCHECK(index.IsValid()); |
| 6835 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 6836 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6837 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6838 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6839 | DCHECK(temps.IsAvailable(ip0)); |
| 6840 | DCHECK(temps.IsAvailable(ip1)); |
| 6841 | temps.Exclude(ip0, ip1); |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6842 | |
| 6843 | Register temp; |
| 6844 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 6845 | // We do not need to compute the intermediate address from the array: the |
| 6846 | // input instruction has done it already. See the comment in |
| 6847 | // `TryExtractArrayAccessAddress()`. |
| 6848 | if (kIsDebugBuild) { |
| 6849 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 6850 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 6851 | } |
| 6852 | temp = obj; |
| 6853 | } else { |
| 6854 | temp = WRegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 6855 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
| 6856 | } |
| 6857 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6858 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(temp.GetCode()); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6859 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6860 | { |
| 6861 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6862 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6863 | vixl::aarch64::Label return_address; |
| 6864 | __ adr(lr, &return_address); |
| 6865 | EmitBakerReadBarrierCbnz(custom_data); |
| 6866 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6867 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6868 | " 2 instructions (8B) for heap poisoning."); |
| 6869 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6870 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6871 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6872 | // macro instructions disallowed in ExactAssemblyScope. |
| 6873 | if (kPoisonHeapReferences) { |
| 6874 | __ neg(ref_reg, Operand(ref_reg)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6875 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6876 | __ bind(&return_address); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6877 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6878 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6879 | } |
| 6880 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6881 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6882 | // The following condition is a compile-time one, so it does not have a run-time cost. |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6883 | if (kIsDebugBuild && gUseReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6884 | // The following condition is a run-time one; it is executed after the |
| 6885 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6886 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6887 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6888 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6889 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6890 | } |
| 6891 | } |
| 6892 | } |
| 6893 | |
Vladimir Marko | 1bff99f | 2020-11-02 15:07:33 +0000 | [diff] [blame] | 6894 | SlowPathCodeARM64* CodeGeneratorARM64::AddReadBarrierSlowPath(HInstruction* instruction, |
| 6895 | Location out, |
| 6896 | Location ref, |
| 6897 | Location obj, |
| 6898 | uint32_t offset, |
| 6899 | Location index) { |
| 6900 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
| 6901 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6902 | AddSlowPath(slow_path); |
| 6903 | return slow_path; |
| 6904 | } |
| 6905 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6906 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6907 | Location out, |
| 6908 | Location ref, |
| 6909 | Location obj, |
| 6910 | uint32_t offset, |
| 6911 | Location index) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6912 | DCHECK(gUseReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6913 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6914 | // Insert a slow path based read barrier *after* the reference load. |
| 6915 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6916 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6917 | // reference will be carried out by the runtime within the slow |
| 6918 | // path. |
| 6919 | // |
| 6920 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6921 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6922 | // not used by the artReadBarrierSlow entry point. |
| 6923 | // |
| 6924 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 1bff99f | 2020-11-02 15:07:33 +0000 | [diff] [blame] | 6925 | SlowPathCodeARM64* slow_path = AddReadBarrierSlowPath(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6926 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6927 | __ B(slow_path->GetEntryLabel()); |
| 6928 | __ Bind(slow_path->GetExitLabel()); |
| 6929 | } |
| 6930 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6931 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6932 | Location out, |
| 6933 | Location ref, |
| 6934 | Location obj, |
| 6935 | uint32_t offset, |
| 6936 | Location index) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6937 | if (gUseReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6938 | // Baker's read barriers shall be handled by the fast path |
| 6939 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6940 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6941 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6942 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6943 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6944 | } else if (kPoisonHeapReferences) { |
| 6945 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6946 | } |
| 6947 | } |
| 6948 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6949 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6950 | Location out, |
| 6951 | Location root) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6952 | DCHECK(gUseReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6953 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6954 | // Insert a slow path based read barrier *after* the GC root load. |
| 6955 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6956 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6957 | // not need to do anything special for this here. |
| 6958 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6959 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6960 | AddSlowPath(slow_path); |
| 6961 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6962 | __ B(slow_path->GetEntryLabel()); |
| 6963 | __ Bind(slow_path->GetExitLabel()); |
| 6964 | } |
| 6965 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6966 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6967 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6968 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6969 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6970 | locations->SetOut(Location::RequiresRegister()); |
| 6971 | } |
| 6972 | |
| 6973 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6974 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6975 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6976 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6977 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6978 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6979 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6980 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6981 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6982 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6983 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6984 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6985 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6986 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6987 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6988 | } |
| 6989 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6990 | static void PatchJitRootUse(uint8_t* code, |
| 6991 | const uint8_t* roots_data, |
| 6992 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6993 | uint64_t index_in_table) { |
| 6994 | uint32_t literal_offset = literal->GetOffset(); |
| 6995 | uintptr_t address = |
| 6996 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6997 | uint8_t* data = code + literal_offset; |
| 6998 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6999 | } |
| 7000 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7001 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7002 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7003 | const StringReference& string_reference = entry.first; |
| 7004 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7005 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7006 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7007 | } |
| 7008 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7009 | const TypeReference& type_reference = entry.first; |
| 7010 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7011 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7012 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7013 | } |
| 7014 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7015 | |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 7016 | MemOperand InstructionCodeGeneratorARM64::VecNEONAddress( |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 7017 | HVecMemoryOperation* instruction, |
| 7018 | UseScratchRegisterScope* temps_scope, |
| 7019 | size_t size, |
| 7020 | bool is_string_char_at, |
| 7021 | /*out*/ Register* scratch) { |
| 7022 | LocationSummary* locations = instruction->GetLocations(); |
| 7023 | Register base = InputRegisterAt(instruction, 0); |
| 7024 | |
| 7025 | if (instruction->InputAt(1)->IsIntermediateAddressIndex()) { |
| 7026 | DCHECK(!is_string_char_at); |
| 7027 | return MemOperand(base.X(), InputRegisterAt(instruction, 1).X()); |
| 7028 | } |
| 7029 | |
| 7030 | Location index = locations->InAt(1); |
| 7031 | uint32_t offset = is_string_char_at |
| 7032 | ? mirror::String::ValueOffset().Uint32Value() |
| 7033 | : mirror::Array::DataOffset(size).Uint32Value(); |
| 7034 | size_t shift = ComponentSizeShiftWidth(size); |
| 7035 | |
| 7036 | // HIntermediateAddress optimization is only applied for scalar ArrayGet and ArraySet. |
| 7037 | DCHECK(!instruction->InputAt(0)->IsIntermediateAddress()); |
| 7038 | |
| 7039 | if (index.IsConstant()) { |
| 7040 | offset += Int64FromLocation(index) << shift; |
| 7041 | return HeapOperand(base, offset); |
| 7042 | } else { |
| 7043 | *scratch = temps_scope->AcquireSameSizeAs(base); |
| 7044 | __ Add(*scratch, base, Operand(WRegisterFrom(index), LSL, shift)); |
| 7045 | return HeapOperand(*scratch, offset); |
| 7046 | } |
| 7047 | } |
| 7048 | |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 7049 | SVEMemOperand InstructionCodeGeneratorARM64::VecSVEAddress( |
| 7050 | HVecMemoryOperation* instruction, |
| 7051 | UseScratchRegisterScope* temps_scope, |
| 7052 | size_t size, |
| 7053 | bool is_string_char_at, |
| 7054 | /*out*/ Register* scratch) { |
| 7055 | LocationSummary* locations = instruction->GetLocations(); |
| 7056 | Register base = InputRegisterAt(instruction, 0); |
| 7057 | Location index = locations->InAt(1); |
| 7058 | |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 7059 | DCHECK(!instruction->InputAt(1)->IsIntermediateAddressIndex()); |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 7060 | DCHECK(!index.IsConstant()); |
| 7061 | |
| 7062 | uint32_t offset = is_string_char_at |
| 7063 | ? mirror::String::ValueOffset().Uint32Value() |
| 7064 | : mirror::Array::DataOffset(size).Uint32Value(); |
| 7065 | size_t shift = ComponentSizeShiftWidth(size); |
| 7066 | |
Raphael Gault | 0700b69 | 2020-09-30 08:33:10 +0000 | [diff] [blame] | 7067 | if (instruction->InputAt(0)->IsIntermediateAddress()) { |
| 7068 | return SVEMemOperand(base.X(), XRegisterFrom(index), LSL, shift); |
| 7069 | } |
| 7070 | |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 7071 | *scratch = temps_scope->AcquireSameSizeAs(base); |
| 7072 | __ Add(*scratch, base, offset); |
| 7073 | return SVEMemOperand(scratch->X(), XRegisterFrom(index), LSL, shift); |
| 7074 | } |
| 7075 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 7076 | #undef __ |
| 7077 | #undef QUICK_ENTRY_POINT |
| 7078 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7079 | #define __ assembler.GetVIXLAssembler()-> |
| 7080 | |
| 7081 | static void EmitGrayCheckAndFastPath(arm64::Arm64Assembler& assembler, |
| 7082 | vixl::aarch64::Register base_reg, |
| 7083 | vixl::aarch64::MemOperand& lock_word, |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7084 | vixl::aarch64::Label* slow_path, |
| 7085 | vixl::aarch64::Label* throw_npe = nullptr) { |
Tamas Kaman | f4655e5 | 2023-02-10 11:28:40 +0100 | [diff] [blame] | 7086 | vixl::aarch64::Label throw_npe_cont; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7087 | // Load the lock word containing the rb_state. |
| 7088 | __ Ldr(ip0.W(), lock_word); |
| 7089 | // 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] | 7090 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7091 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7092 | __ Tbnz(ip0.W(), LockWord::kReadBarrierStateShift, slow_path); |
| 7093 | static_assert( |
| 7094 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET, |
| 7095 | "Field and array LDR offsets must be the same to reuse the same code."); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7096 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 7097 | if (throw_npe != nullptr) { |
Tamas Kaman | f4655e5 | 2023-02-10 11:28:40 +0100 | [diff] [blame] | 7098 | __ Bind(&throw_npe_cont); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7099 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7100 | // Adjust the return address back to the LDR (1 instruction; 2 for heap poisoning). |
| 7101 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 7102 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 7103 | " 2 instructions (8B) for heap poisoning."); |
| 7104 | __ Add(lr, lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 7105 | // Introduce a dependency on the lock_word including rb_state, |
| 7106 | // to prevent load-load reordering, and without using |
| 7107 | // a memory barrier (which would be more expensive). |
| 7108 | __ Add(base_reg, base_reg, Operand(ip0, LSR, 32)); |
| 7109 | __ Br(lr); // And return back to the function. |
Tamas Kaman | f4655e5 | 2023-02-10 11:28:40 +0100 | [diff] [blame] | 7110 | if (throw_npe != nullptr) { |
| 7111 | // Clear IP0 before returning to the fast path. |
| 7112 | __ Bind(throw_npe); |
| 7113 | __ Mov(ip0.X(), xzr); |
| 7114 | __ B(&throw_npe_cont); |
| 7115 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7116 | // Note: The fake dependency is unnecessary for the slow path. |
| 7117 | } |
| 7118 | |
| 7119 | // Load the read barrier introspection entrypoint in register `entrypoint`. |
| 7120 | static void LoadReadBarrierMarkIntrospectionEntrypoint(arm64::Arm64Assembler& assembler, |
| 7121 | vixl::aarch64::Register entrypoint) { |
| 7122 | // entrypoint = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 7123 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 7124 | const int32_t entry_point_offset = |
| 7125 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 7126 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| 7127 | } |
| 7128 | |
| 7129 | void CodeGeneratorARM64::CompileBakerReadBarrierThunk(Arm64Assembler& assembler, |
| 7130 | uint32_t encoded_data, |
| 7131 | /*out*/ std::string* debug_name) { |
| 7132 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 7133 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 7134 | case BakerReadBarrierKind::kField: |
| 7135 | case BakerReadBarrierKind::kAcquire: { |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 7136 | Register base_reg = |
| 7137 | vixl::aarch64::XRegister(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7138 | CheckValidReg(base_reg.GetCode()); |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 7139 | Register holder_reg = |
| 7140 | vixl::aarch64::XRegister(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7141 | CheckValidReg(holder_reg.GetCode()); |
| 7142 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 7143 | temps.Exclude(ip0, ip1); |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 7144 | // In the case of a field load (with relaxed semantic), if `base_reg` differs from |
| 7145 | // `holder_reg`, the offset was too large and we must have emitted (during the construction |
| 7146 | // of the HIR graph, see `art::HInstructionBuilder::BuildInstanceFieldAccess`) and preserved |
| 7147 | // (see `art::PrepareForRegisterAllocation::VisitNullCheck`) an explicit null check before |
| 7148 | // the load. Otherwise, for implicit null checks, we need to null-check the holder as we do |
| 7149 | // not necessarily do that check before going to the thunk. |
| 7150 | // |
| 7151 | // In the case of a field load with load-acquire semantics (where `base_reg` always differs |
| 7152 | // from `holder_reg`), we also need an explicit null check when implicit null checks are |
| 7153 | // allowed, as we do not emit one before going to the thunk. |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7154 | vixl::aarch64::Label throw_npe_label; |
| 7155 | vixl::aarch64::Label* throw_npe = nullptr; |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 7156 | if (GetCompilerOptions().GetImplicitNullChecks() && |
| 7157 | (holder_reg.Is(base_reg) || (kind == BakerReadBarrierKind::kAcquire))) { |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7158 | throw_npe = &throw_npe_label; |
| 7159 | __ Cbz(holder_reg.W(), throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7160 | } |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7161 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 7162 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 7163 | // to load the reference and call the entrypoint that performs further checks on the |
| 7164 | // reference and marks it if needed. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7165 | vixl::aarch64::Label slow_path; |
| 7166 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7167 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7168 | __ Bind(&slow_path); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 7169 | if (kind == BakerReadBarrierKind::kField) { |
| 7170 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 7171 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (immediate) unsigned offset. |
| 7172 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 7173 | __ Ubfx(ip0.W(), ip0.W(), 10, 12); // Extract the offset. |
| 7174 | __ Ldr(ip0.W(), MemOperand(base_reg, ip0, LSL, 2)); // Load the reference. |
| 7175 | } else { |
| 7176 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 7177 | DCHECK(!base_reg.Is(holder_reg)); |
| 7178 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 7179 | __ Ldar(ip0.W(), MemOperand(base_reg)); |
| 7180 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7181 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 7182 | __ Br(ip1); // Jump to the entrypoint. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7183 | break; |
| 7184 | } |
| 7185 | case BakerReadBarrierKind::kArray: { |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 7186 | Register base_reg = |
| 7187 | vixl::aarch64::XRegister(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7188 | CheckValidReg(base_reg.GetCode()); |
| 7189 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7190 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7191 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 7192 | temps.Exclude(ip0, ip1); |
| 7193 | vixl::aarch64::Label slow_path; |
| 7194 | int32_t data_offset = |
| 7195 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 7196 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 7197 | DCHECK_LT(lock_word.GetOffset(), 0); |
| 7198 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path); |
| 7199 | __ Bind(&slow_path); |
| 7200 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| 7201 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (register) unsigned offset. |
| 7202 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 7203 | __ Ubfx(ip0, ip0, 16, 6); // Extract the index register, plus 32 (bit 21 is set). |
| 7204 | __ Bfi(ip1, ip0, 3, 6); // Insert ip0 to the entrypoint address to create |
| 7205 | // a switch case target based on the index register. |
| 7206 | __ Mov(ip0, base_reg); // Move the base register to ip0. |
| 7207 | __ Br(ip1); // Jump to the entrypoint's array switch case. |
| 7208 | break; |
| 7209 | } |
| 7210 | case BakerReadBarrierKind::kGcRoot: { |
| 7211 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 7212 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 7213 | // otherwise return the reference (or the extracted forwarding address). |
| 7214 | // There is no gray bit check for GC roots. |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 7215 | Register root_reg = |
| 7216 | vixl::aarch64::WRegister(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7217 | CheckValidReg(root_reg.GetCode()); |
| 7218 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7219 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7220 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 7221 | temps.Exclude(ip0, ip1); |
| 7222 | vixl::aarch64::Label return_label, not_marked, forwarding_address; |
| 7223 | __ Cbz(root_reg, &return_label); |
| 7224 | MemOperand lock_word(root_reg.X(), mirror::Object::MonitorOffset().Int32Value()); |
| 7225 | __ Ldr(ip0.W(), lock_word); |
| 7226 | __ Tbz(ip0.W(), LockWord::kMarkBitStateShift, ¬_marked); |
| 7227 | __ Bind(&return_label); |
| 7228 | __ Br(lr); |
| 7229 | __ Bind(¬_marked); |
| 7230 | __ Tst(ip0.W(), Operand(ip0.W(), LSL, 1)); |
| 7231 | __ B(&forwarding_address, mi); |
| 7232 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 7233 | // Adjust the art_quick_read_barrier_mark_introspection address in IP1 to |
| 7234 | // art_quick_read_barrier_mark_introspection_gc_roots. |
| 7235 | __ Add(ip1, ip1, Operand(BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET)); |
| 7236 | __ Mov(ip0.W(), root_reg); |
| 7237 | __ Br(ip1); |
| 7238 | __ Bind(&forwarding_address); |
| 7239 | __ Lsl(root_reg, ip0.W(), LockWord::kForwardingAddressShift); |
| 7240 | __ Br(lr); |
| 7241 | break; |
| 7242 | } |
| 7243 | default: |
| 7244 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 7245 | UNREACHABLE(); |
| 7246 | } |
| 7247 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 7248 | // For JIT, the slow path is considered part of the compiled method, |
Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 7249 | // so JIT should pass null as `debug_name`. |
Santiago Aboy Solanes | 872ec72 | 2022-02-18 14:10:25 +0000 | [diff] [blame] | 7250 | DCHECK_IMPLIES(GetCompilerOptions().IsJitCompiler(), debug_name == nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 7251 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7252 | std::ostringstream oss; |
| 7253 | oss << "BakerReadBarrierThunk"; |
| 7254 | switch (kind) { |
| 7255 | case BakerReadBarrierKind::kField: |
| 7256 | oss << "Field_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 7257 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 7258 | break; |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 7259 | case BakerReadBarrierKind::kAcquire: |
| 7260 | oss << "Acquire_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 7261 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 7262 | break; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7263 | case BakerReadBarrierKind::kArray: |
| 7264 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 7265 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7266 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7267 | break; |
| 7268 | case BakerReadBarrierKind::kGcRoot: |
| 7269 | oss << "GcRoot_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 7270 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7271 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7272 | break; |
| 7273 | } |
| 7274 | *debug_name = oss.str(); |
| 7275 | } |
| 7276 | } |
| 7277 | |
| 7278 | #undef __ |
| 7279 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 7280 | } // namespace arm64 |
| 7281 | } // namespace art |