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" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 46 | #include "thread.h" |
| 47 | #include "utils/arm64/assembler_arm64.h" |
| 48 | #include "utils/assembler.h" |
| 49 | #include "utils/stack_checks.h" |
| 50 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 51 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 52 | using vixl::ExactAssemblyScope; |
| 53 | using vixl::CodeBufferCheckScope; |
| 54 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 55 | |
| 56 | #ifdef __ |
| 57 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 58 | #endif |
| 59 | |
VladimĂr Marko | 434d968 | 2022-11-04 14:04:17 +0000 | [diff] [blame^] | 60 | namespace art HIDDEN { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 61 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 62 | template<class MirrorType> |
| 63 | class GcRoot; |
| 64 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 65 | namespace arm64 { |
| 66 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 67 | using helpers::ARM64EncodableConstantOrRegister; |
| 68 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 | using helpers::CPURegisterFrom; |
| 70 | using helpers::DRegisterFrom; |
| 71 | using helpers::FPRegisterFrom; |
| 72 | using helpers::HeapOperand; |
| 73 | using helpers::HeapOperandFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 74 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 75 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 76 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 77 | using helpers::InputRegisterAt; |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 78 | using helpers::Int64FromLocation; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 79 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 80 | using helpers::LocationFrom; |
| 81 | using helpers::OperandFromMemOperand; |
| 82 | using helpers::OutputCPURegister; |
| 83 | using helpers::OutputFPRegister; |
| 84 | using helpers::OutputRegister; |
| 85 | using helpers::RegisterFrom; |
| 86 | using helpers::StackOperandFrom; |
| 87 | using helpers::VIXLRegCodeFromART; |
| 88 | using helpers::WRegisterFrom; |
| 89 | using helpers::XRegisterFrom; |
| 90 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 91 | // 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] | 92 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 93 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 94 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 95 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 96 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 97 | // 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] | 98 | // 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] | 99 | // the offset explicitly. |
| 100 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 101 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 102 | inline Condition ARM64Condition(IfCondition cond) { |
| 103 | switch (cond) { |
| 104 | case kCondEQ: return eq; |
| 105 | case kCondNE: return ne; |
| 106 | case kCondLT: return lt; |
| 107 | case kCondLE: return le; |
| 108 | case kCondGT: return gt; |
| 109 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 110 | case kCondB: return lo; |
| 111 | case kCondBE: return ls; |
| 112 | case kCondA: return hi; |
| 113 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 114 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 115 | LOG(FATAL) << "Unreachable"; |
| 116 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 117 | } |
| 118 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 119 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 120 | // The ARM64 condition codes can express all the necessary branches, see the |
| 121 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 122 | // There is no dex instruction or HIR that would need the missing conditions |
| 123 | // "equal or unordered" or "not equal". |
| 124 | switch (cond) { |
| 125 | case kCondEQ: return eq; |
| 126 | case kCondNE: return ne /* unordered */; |
| 127 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 128 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 129 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 130 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 131 | default: |
| 132 | LOG(FATAL) << "UNREACHABLE"; |
| 133 | UNREACHABLE(); |
| 134 | } |
| 135 | } |
| 136 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 137 | Location ARM64ReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 138 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 139 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 140 | // but we use the exact registers for clarity. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 141 | if (return_type == DataType::Type::kFloat32) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 142 | return LocationFrom(s0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 143 | } else if (return_type == DataType::Type::kFloat64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 144 | return LocationFrom(d0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 145 | } else if (return_type == DataType::Type::kInt64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 146 | return LocationFrom(x0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 147 | } else if (return_type == DataType::Type::kVoid) { |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 148 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 149 | } else { |
| 150 | return LocationFrom(w0); |
| 151 | } |
| 152 | } |
| 153 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 154 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 155 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 156 | } |
| 157 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 158 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 159 | InvokeRuntimeCallingConvention calling_convention; |
| 160 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 161 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 162 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 163 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 164 | DataType::Type::kReference).GetCode()); |
| 165 | return caller_saves; |
| 166 | } |
| 167 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 168 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 169 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 170 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 171 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 172 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 173 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 174 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 175 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 176 | // If the register holds an object, update the stack mask. |
| 177 | if (locations->RegisterContainsObject(i)) { |
| 178 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 179 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 180 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 181 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 182 | saved_core_stack_offsets_[i] = stack_offset; |
| 183 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 184 | } |
| 185 | |
Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 186 | const size_t fp_reg_size = codegen->GetSlowPathFPWidth(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 187 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 188 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 189 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 190 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 191 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 192 | stack_offset += fp_reg_size; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 193 | } |
| 194 | |
Artem Serov | 55ab7e8 | 2020-04-27 21:02:28 +0100 | [diff] [blame] | 195 | InstructionCodeGeneratorARM64* visitor = |
| 196 | down_cast<CodeGeneratorARM64*>(codegen)->GetInstructionCodeGeneratorArm64(); |
| 197 | visitor->SaveLiveRegistersHelper(locations, codegen->GetFirstRegisterSlotInSlowPath()); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Artem Serov | 55ab7e8 | 2020-04-27 21:02:28 +0100 | [diff] [blame] | 201 | InstructionCodeGeneratorARM64* visitor = |
| 202 | down_cast<CodeGeneratorARM64*>(codegen)->GetInstructionCodeGeneratorArm64(); |
| 203 | visitor->RestoreLiveRegistersHelper(locations, codegen->GetFirstRegisterSlotInSlowPath()); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 204 | } |
| 205 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 206 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 207 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 208 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 209 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 210 | void EmitNativeCode(CodeGenerator* codegen) override { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 211 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 212 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 213 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 214 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 215 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 216 | // Live registers will be restored in the catch block if caught. |
| 217 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 218 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 219 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 220 | // move resolver. |
| 221 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 222 | codegen->EmitParallelMoves(locations->InAt(0), |
| 223 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 224 | DataType::Type::kInt32, |
| 225 | locations->InAt(1), |
| 226 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 227 | DataType::Type::kInt32); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 228 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 229 | ? kQuickThrowStringBounds |
| 230 | : kQuickThrowArrayBounds; |
| 231 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 232 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 233 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 234 | } |
| 235 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 236 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 237 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 238 | const char* GetDescription() const override { return "BoundsCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 239 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 240 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 241 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 242 | }; |
| 243 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 244 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 245 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 246 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 247 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 248 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 249 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 250 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 251 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 252 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 255 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 256 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 257 | const char* GetDescription() const override { return "DivZeroCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 258 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 259 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 260 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 261 | }; |
| 262 | |
| 263 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 264 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 265 | LoadClassSlowPathARM64(HLoadClass* cls, HInstruction* at) |
| 266 | : SlowPathCodeARM64(at), cls_(cls) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 267 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 268 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 271 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 272 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 273 | Location out = locations->Out(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 274 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 275 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 276 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 277 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 278 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 279 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 280 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 281 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 282 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 283 | if (must_resolve_type) { |
Santiago Aboy Solanes | a0232ad | 2021-11-08 17:00:06 +0000 | [diff] [blame] | 284 | DCHECK(IsSameDexFile(cls_->GetDexFile(), arm64_codegen->GetGraph()->GetDexFile()) || |
Santiago Aboy Solanes | 69a87e3 | 2022-03-08 16:43:54 +0000 | [diff] [blame] | 285 | arm64_codegen->GetCompilerOptions().WithinOatFile(&cls_->GetDexFile()) || |
| 286 | ContainsElement(Runtime::Current()->GetClassLinker()->GetBootClassPath(), |
| 287 | &cls_->GetDexFile())); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 288 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 289 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 290 | if (cls_->NeedsAccessCheck()) { |
| 291 | CheckEntrypointTypes<kQuickResolveTypeAndVerifyAccess, void*, uint32_t>(); |
| 292 | arm64_codegen->InvokeRuntime(kQuickResolveTypeAndVerifyAccess, instruction_, dex_pc, this); |
| 293 | } else { |
| 294 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| 295 | arm64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 296 | } |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 297 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 298 | } else { |
| 299 | DCHECK(must_do_clinit); |
| 300 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 301 | arm64_codegen->MoveLocation(LocationFrom(calling_convention.GetRegisterAt(0)), |
| 302 | source, |
| 303 | cls_->GetType()); |
| 304 | } |
| 305 | if (must_do_clinit) { |
| 306 | arm64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 307 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 308 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 309 | |
| 310 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 311 | if (out.IsValid()) { |
| 312 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 313 | DataType::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 314 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 315 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 316 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 317 | __ B(GetExitLabel()); |
| 318 | } |
| 319 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 320 | const char* GetDescription() const override { return "LoadClassSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 321 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 322 | private: |
| 323 | // The class this slow path will load. |
| 324 | HLoadClass* const cls_; |
| 325 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 326 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 327 | }; |
| 328 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 329 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 330 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 331 | explicit LoadStringSlowPathARM64(HLoadString* instruction) |
| 332 | : SlowPathCodeARM64(instruction) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 333 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 334 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 335 | LocationSummary* locations = instruction_->GetLocations(); |
| 336 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 337 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 338 | |
| 339 | __ Bind(GetEntryLabel()); |
| 340 | SaveLiveRegisters(codegen, locations); |
| 341 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 342 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 343 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 344 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 345 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 346 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 347 | DataType::Type type = instruction_->GetType(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 348 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 349 | |
| 350 | RestoreLiveRegisters(codegen, locations); |
| 351 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 352 | __ B(GetExitLabel()); |
| 353 | } |
| 354 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 355 | const char* GetDescription() const override { return "LoadStringSlowPathARM64"; } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 356 | |
| 357 | private: |
| 358 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 359 | }; |
| 360 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 361 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 362 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 363 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 364 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 365 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 366 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 367 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 368 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 369 | // Live registers will be restored in the catch block if caught. |
| 370 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 371 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 372 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 373 | instruction_, |
| 374 | instruction_->GetDexPc(), |
| 375 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 376 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 377 | } |
| 378 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 379 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 380 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 381 | const char* GetDescription() const override { return "NullCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 382 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 383 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 384 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 385 | }; |
| 386 | |
| 387 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 388 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 389 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 390 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 391 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 392 | void EmitNativeCode(CodeGenerator* codegen) override { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 393 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 394 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 395 | __ Bind(GetEntryLabel()); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 396 | SaveLiveRegisters(codegen, locations); // Only saves live vector regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 397 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 398 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 399 | RestoreLiveRegisters(codegen, locations); // Only restores live vector regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 400 | if (successor_ == nullptr) { |
| 401 | __ B(GetReturnLabel()); |
| 402 | } else { |
| 403 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 404 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 405 | } |
| 406 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 407 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 408 | DCHECK(successor_ == nullptr); |
| 409 | return &return_label_; |
| 410 | } |
| 411 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 412 | HBasicBlock* GetSuccessor() const { |
| 413 | return successor_; |
| 414 | } |
| 415 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 416 | const char* GetDescription() const override { return "SuspendCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 417 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 418 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 419 | // If not null, the block to branch to after the suspend check. |
| 420 | HBasicBlock* const successor_; |
| 421 | |
| 422 | // 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] | 423 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 424 | |
| 425 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 426 | }; |
| 427 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 428 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 429 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 430 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 431 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 432 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 433 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 434 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 435 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 436 | DCHECK(instruction_->IsCheckCast() |
| 437 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 438 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 439 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 440 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 441 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 442 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 443 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 444 | SaveLiveRegisters(codegen, locations); |
| 445 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 446 | |
| 447 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 448 | // move resolver. |
| 449 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 450 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 451 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 452 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 453 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 454 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 455 | DataType::Type::kReference); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 456 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 457 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 458 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 459 | DataType::Type ret_type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 460 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 461 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 462 | } else { |
| 463 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 464 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 465 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 468 | if (!is_fatal_) { |
| 469 | RestoreLiveRegisters(codegen, locations); |
| 470 | __ B(GetExitLabel()); |
| 471 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 474 | const char* GetDescription() const override { return "TypeCheckSlowPathARM64"; } |
| 475 | bool IsFatal() const override { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 476 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 477 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 478 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 479 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 480 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 481 | }; |
| 482 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 483 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 484 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 485 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 486 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 487 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 488 | void EmitNativeCode(CodeGenerator* codegen) override { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 489 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 490 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 491 | LocationSummary* locations = instruction_->GetLocations(); |
| 492 | SaveLiveRegisters(codegen, locations); |
| 493 | InvokeRuntimeCallingConvention calling_convention; |
| 494 | __ Mov(calling_convention.GetRegisterAt(0), |
| 495 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 496 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 497 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 500 | const char* GetDescription() const override { return "DeoptimizationSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 501 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 502 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 503 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 504 | }; |
| 505 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 506 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 507 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 508 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 509 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 510 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 511 | LocationSummary* locations = instruction_->GetLocations(); |
| 512 | __ Bind(GetEntryLabel()); |
| 513 | SaveLiveRegisters(codegen, locations); |
| 514 | |
| 515 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 516 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 517 | parallel_move.AddMove( |
| 518 | locations->InAt(0), |
| 519 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 520 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 521 | nullptr); |
| 522 | parallel_move.AddMove( |
| 523 | locations->InAt(1), |
| 524 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 525 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 526 | nullptr); |
| 527 | parallel_move.AddMove( |
| 528 | locations->InAt(2), |
| 529 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 530 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 531 | nullptr); |
| 532 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 533 | |
| 534 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 535 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 536 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 537 | RestoreLiveRegisters(codegen, locations); |
| 538 | __ B(GetExitLabel()); |
| 539 | } |
| 540 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 541 | const char* GetDescription() const override { return "ArraySetSlowPathARM64"; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 542 | |
| 543 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 544 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 545 | }; |
| 546 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 547 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 548 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 549 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 550 | |
| 551 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 552 | // 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] | 553 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 554 | num_entries * sizeof(int32_t), |
| 555 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 556 | |
| 557 | __ Bind(&table_start_); |
| 558 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 559 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 560 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 561 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 562 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 563 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 564 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 565 | Literal<int32_t> literal(jump_offset); |
| 566 | __ place(&literal); |
| 567 | } |
| 568 | } |
| 569 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 570 | // Slow path generating a read barrier for a heap reference. |
| 571 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 572 | public: |
| 573 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 574 | Location out, |
| 575 | Location ref, |
| 576 | Location obj, |
| 577 | uint32_t offset, |
| 578 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 579 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 580 | out_(out), |
| 581 | ref_(ref), |
| 582 | obj_(obj), |
| 583 | offset_(offset), |
| 584 | index_(index) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 585 | DCHECK(gUseReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 586 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 587 | // has been overwritten by (or after) the heap object reference load |
| 588 | // to be instrumented, e.g.: |
| 589 | // |
| 590 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 591 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 592 | // |
| 593 | // In that case, we have lost the information about the original |
| 594 | // object, and the emitted read barrier cannot work properly. |
| 595 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 596 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 597 | } |
| 598 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 599 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 600 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 601 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 602 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 603 | DCHECK(locations->CanCall()); |
| 604 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 605 | DCHECK(instruction_->IsInstanceFieldGet() || |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 606 | instruction_->IsPredicatedInstanceFieldGet() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 607 | instruction_->IsStaticFieldGet() || |
| 608 | instruction_->IsArrayGet() || |
| 609 | instruction_->IsInstanceOf() || |
| 610 | instruction_->IsCheckCast() || |
Vladimir Marko | a41ea27 | 2020-09-07 15:24:36 +0000 | [diff] [blame] | 611 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 612 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 613 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 614 | // The read barrier instrumentation of object ArrayGet |
| 615 | // instructions does not support the HIntermediateAddress |
| 616 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 617 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 618 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 619 | |
| 620 | __ Bind(GetEntryLabel()); |
| 621 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 622 | SaveLiveRegisters(codegen, locations); |
| 623 | |
| 624 | // We may have to change the index's value, but as `index_` is a |
| 625 | // constant member (like other "inputs" of this slow path), |
| 626 | // introduce a copy of it, `index`. |
| 627 | Location index = index_; |
| 628 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 629 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 630 | if (instruction_->IsArrayGet()) { |
| 631 | // Compute the actual memory offset and store it in `index`. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 632 | Register index_reg = RegisterFrom(index_, DataType::Type::kInt32); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 633 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 634 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 635 | // We are about to change the value of `index_reg` (see the |
| 636 | // calls to vixl::MacroAssembler::Lsl and |
| 637 | // vixl::MacroAssembler::Mov below), but it has |
| 638 | // not been saved by the previous call to |
| 639 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 640 | // callee-save register -- |
| 641 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 642 | // callee-save registers, as it has been designed with the |
| 643 | // assumption that callee-save registers are supposed to be |
| 644 | // handled by the called function. So, as a callee-save |
| 645 | // register, `index_reg` _would_ eventually be saved onto |
| 646 | // the stack, but it would be too late: we would have |
| 647 | // changed its value earlier. Therefore, we manually save |
| 648 | // it here into another freely available register, |
| 649 | // `free_reg`, chosen of course among the caller-save |
| 650 | // registers (as a callee-save `free_reg` register would |
| 651 | // exhibit the same problem). |
| 652 | // |
| 653 | // Note we could have requested a temporary register from |
| 654 | // the register allocator instead; but we prefer not to, as |
| 655 | // this is a slow path, and we know we can find a |
| 656 | // caller-save register that is available. |
| 657 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 658 | __ Mov(free_reg.W(), index_reg); |
| 659 | index_reg = free_reg; |
| 660 | index = LocationFrom(index_reg); |
| 661 | } else { |
| 662 | // The initial register stored in `index_` has already been |
| 663 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 664 | // (as it is not a callee-save register), so we can freely |
| 665 | // use it. |
| 666 | } |
| 667 | // Shifting the index value contained in `index_reg` by the scale |
| 668 | // factor (2) cannot overflow in practice, as the runtime is |
| 669 | // unable to allocate object arrays with a size larger than |
| 670 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 671 | __ Lsl(index_reg, index_reg, DataType::SizeShift(type)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 672 | static_assert( |
| 673 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 674 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 675 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 676 | } else { |
Ulya Trafimovich | ec696e5 | 2022-01-26 10:21:32 +0000 | [diff] [blame] | 677 | // In the case of the following intrinsics `index_` is not shifted by a scale factor of 2 |
| 678 | // (as in the case of ArrayGet), as it is actually an offset to an object field within an |
| 679 | // object. |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 680 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 681 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
Ulya Trafimovich | ec696e5 | 2022-01-26 10:21:32 +0000 | [diff] [blame] | 682 | HInvoke* invoke = instruction_->AsInvoke(); |
| 683 | DCHECK(IsUnsafeGetObject(invoke) || |
| 684 | IsVarHandleGet(invoke) || |
| 685 | IsUnsafeCASObject(invoke) || |
| 686 | IsVarHandleCASFamily(invoke)) << invoke->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 687 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 688 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | |
| 692 | // We're moving two or three locations to locations that could |
| 693 | // overlap, so we need a parallel move resolver. |
| 694 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 695 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 696 | parallel_move.AddMove(ref_, |
| 697 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 698 | type, |
| 699 | nullptr); |
| 700 | parallel_move.AddMove(obj_, |
| 701 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 702 | type, |
| 703 | nullptr); |
| 704 | if (index.IsValid()) { |
| 705 | parallel_move.AddMove(index, |
| 706 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 707 | DataType::Type::kInt32, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 708 | nullptr); |
| 709 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 710 | } else { |
| 711 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 712 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 713 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 714 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 715 | instruction_, |
| 716 | instruction_->GetDexPc(), |
| 717 | this); |
| 718 | CheckEntrypointTypes< |
| 719 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 720 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 721 | |
| 722 | RestoreLiveRegisters(codegen, locations); |
| 723 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 724 | __ B(GetExitLabel()); |
| 725 | } |
| 726 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 727 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 728 | |
| 729 | private: |
| 730 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 731 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 732 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 733 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 734 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 735 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 736 | } |
| 737 | } |
| 738 | // We shall never fail to find a free caller-save register, as |
| 739 | // there are more than two core caller-save registers on ARM64 |
| 740 | // (meaning it is possible to find one which is different from |
| 741 | // `ref` and `obj`). |
| 742 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 743 | LOG(FATAL) << "Could not find a free register"; |
| 744 | UNREACHABLE(); |
| 745 | } |
| 746 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 747 | const Location out_; |
| 748 | const Location ref_; |
| 749 | const Location obj_; |
| 750 | const uint32_t offset_; |
| 751 | // An additional location containing an index to an array. |
| 752 | // Only used for HArrayGet and the UnsafeGetObject & |
| 753 | // UnsafeGetObjectVolatile intrinsics. |
| 754 | const Location index_; |
| 755 | |
| 756 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 757 | }; |
| 758 | |
| 759 | // Slow path generating a read barrier for a GC root. |
| 760 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 761 | public: |
| 762 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 763 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 764 | DCHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 765 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 766 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 767 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 768 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 769 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 770 | DCHECK(locations->CanCall()); |
| 771 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Vladimir Marko | a41ea27 | 2020-09-07 15:24:36 +0000 | [diff] [blame] | 772 | DCHECK(instruction_->IsLoadClass() || |
| 773 | instruction_->IsLoadString() || |
| 774 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 775 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 776 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 777 | |
| 778 | __ Bind(GetEntryLabel()); |
| 779 | SaveLiveRegisters(codegen, locations); |
| 780 | |
| 781 | InvokeRuntimeCallingConvention calling_convention; |
| 782 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 783 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 784 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 785 | // thus we need a 64-bit move here, and we cannot use |
| 786 | // |
| 787 | // arm64_codegen->MoveLocation( |
| 788 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 789 | // root_, |
| 790 | // type); |
| 791 | // |
| 792 | // 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] | 793 | // reference type (`DataType::Type::kReference`). |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 794 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 795 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 796 | instruction_, |
| 797 | instruction_->GetDexPc(), |
| 798 | this); |
| 799 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 800 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 801 | |
| 802 | RestoreLiveRegisters(codegen, locations); |
| 803 | __ B(GetExitLabel()); |
| 804 | } |
| 805 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 806 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathARM64"; } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 807 | |
| 808 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 809 | const Location out_; |
| 810 | const Location root_; |
| 811 | |
| 812 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 813 | }; |
| 814 | |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 815 | class MethodEntryExitHooksSlowPathARM64 : public SlowPathCodeARM64 { |
| 816 | public: |
| 817 | explicit MethodEntryExitHooksSlowPathARM64(HInstruction* instruction) |
| 818 | : SlowPathCodeARM64(instruction) {} |
| 819 | |
| 820 | void EmitNativeCode(CodeGenerator* codegen) override { |
| 821 | LocationSummary* locations = instruction_->GetLocations(); |
| 822 | QuickEntrypointEnum entry_point = |
| 823 | (instruction_->IsMethodEntryHook()) ? kQuickMethodEntryHook : kQuickMethodExitHook; |
| 824 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 825 | __ Bind(GetEntryLabel()); |
| 826 | SaveLiveRegisters(codegen, locations); |
Mythri Alle | bab6beb | 2022-10-21 13:28:05 +0000 | [diff] [blame] | 827 | if (instruction_->IsMethodExitHook()) { |
| 828 | __ Mov(vixl::aarch64::x4, arm64_codegen->GetFrameSize()); |
| 829 | } |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 830 | arm64_codegen->InvokeRuntime(entry_point, instruction_, instruction_->GetDexPc(), this); |
| 831 | RestoreLiveRegisters(codegen, locations); |
| 832 | __ B(GetExitLabel()); |
| 833 | } |
| 834 | |
| 835 | const char* GetDescription() const override { |
| 836 | return "MethodEntryExitHooksSlowPath"; |
| 837 | } |
| 838 | |
| 839 | private: |
| 840 | DISALLOW_COPY_AND_ASSIGN(MethodEntryExitHooksSlowPathARM64); |
| 841 | }; |
| 842 | |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 843 | class CompileOptimizedSlowPathARM64 : public SlowPathCodeARM64 { |
| 844 | public: |
| 845 | CompileOptimizedSlowPathARM64() : SlowPathCodeARM64(/* instruction= */ nullptr) {} |
| 846 | |
| 847 | void EmitNativeCode(CodeGenerator* codegen) override { |
| 848 | uint32_t entrypoint_offset = |
| 849 | GetThreadOffset<kArm64PointerSize>(kQuickCompileOptimized).Int32Value(); |
| 850 | __ Bind(GetEntryLabel()); |
| 851 | __ Ldr(lr, MemOperand(tr, entrypoint_offset)); |
| 852 | // Note: we don't record the call here (and therefore don't generate a stack |
| 853 | // map), as the entrypoint should never be suspended. |
| 854 | __ Blr(lr); |
| 855 | __ B(GetExitLabel()); |
| 856 | } |
| 857 | |
| 858 | const char* GetDescription() const override { |
| 859 | return "CompileOptimizedSlowPath"; |
| 860 | } |
| 861 | |
| 862 | private: |
| 863 | DISALLOW_COPY_AND_ASSIGN(CompileOptimizedSlowPathARM64); |
| 864 | }; |
| 865 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 866 | #undef __ |
| 867 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 868 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 869 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 870 | if (type == DataType::Type::kVoid) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 871 | LOG(FATAL) << "Unreachable type " << type; |
| 872 | } |
| 873 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 874 | if (DataType::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 875 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 876 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 877 | } else if (!DataType::IsFloatingPointType(type) && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 878 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 879 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 880 | } else { |
| 881 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 882 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 883 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 884 | } |
| 885 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 886 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 887 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 888 | return next_location; |
| 889 | } |
| 890 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 891 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 892 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 893 | } |
| 894 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 895 | Location CriticalNativeCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
| 896 | DCHECK_NE(type, DataType::Type::kReference); |
| 897 | |
| 898 | Location location = Location::NoLocation(); |
| 899 | if (DataType::IsFloatingPointType(type)) { |
| 900 | if (fpr_index_ < kParameterFPRegistersLength) { |
| 901 | location = LocationFrom(kParameterFPRegisters[fpr_index_]); |
| 902 | ++fpr_index_; |
| 903 | } |
| 904 | } else { |
| 905 | // Native ABI uses the same registers as managed, except that the method register x0 |
| 906 | // is a normal argument. |
| 907 | if (gpr_index_ < 1u + kParameterCoreRegistersLength) { |
| 908 | location = LocationFrom(gpr_index_ == 0u ? x0 : kParameterCoreRegisters[gpr_index_ - 1u]); |
| 909 | ++gpr_index_; |
| 910 | } |
| 911 | } |
| 912 | if (location.IsInvalid()) { |
| 913 | if (DataType::Is64BitType(type)) { |
| 914 | location = Location::DoubleStackSlot(stack_offset_); |
| 915 | } else { |
| 916 | location = Location::StackSlot(stack_offset_); |
| 917 | } |
| 918 | stack_offset_ += kFramePointerSize; |
| 919 | |
| 920 | if (for_register_allocation_) { |
| 921 | location = Location::Any(); |
| 922 | } |
| 923 | } |
| 924 | return location; |
| 925 | } |
| 926 | |
| 927 | Location CriticalNativeCallingConventionVisitorARM64::GetReturnLocation(DataType::Type type) const { |
| 928 | // We perform conversion to the managed ABI return register after the call if needed. |
| 929 | InvokeDexCallingConventionVisitorARM64 dex_calling_convention; |
| 930 | return dex_calling_convention.GetReturnLocation(type); |
| 931 | } |
| 932 | |
| 933 | Location CriticalNativeCallingConventionVisitorARM64::GetMethodLocation() const { |
| 934 | // Pass the method in the hidden argument x15. |
| 935 | return Location::RegisterLocation(x15.GetCode()); |
| 936 | } |
| 937 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 938 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 939 | const CompilerOptions& compiler_options, |
| 940 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 941 | : CodeGenerator(graph, |
| 942 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 943 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 944 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 945 | callee_saved_core_registers.GetList(), |
| 946 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 947 | compiler_options, |
| 948 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 949 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 950 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 951 | location_builder_neon_(graph, this), |
| 952 | instruction_visitor_neon_(graph, this), |
| 953 | location_builder_sve_(graph, this), |
| 954 | instruction_visitor_sve_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 955 | move_resolver_(graph->GetAllocator(), this), |
Artem Serov | aa6f483 | 2018-11-21 18:57:54 +0000 | [diff] [blame] | 956 | assembler_(graph->GetAllocator(), |
| 957 | compiler_options.GetInstructionSetFeatures()->AsArm64InstructionSetFeatures()), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 958 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 959 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 960 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 961 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 962 | public_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 963 | package_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 964 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 965 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 966 | boot_image_jni_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 967 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 968 | call_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 969 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 970 | uint32_literals_(std::less<uint32_t>(), |
| 971 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 972 | uint64_literals_(std::less<uint64_t>(), |
| 973 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 974 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 975 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 976 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 977 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 978 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 979 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 980 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 981 | AddAllocatedRegister(LocationFrom(lr)); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 982 | |
| 983 | bool use_sve = ShouldUseSVE(); |
| 984 | if (use_sve) { |
| 985 | location_builder_ = &location_builder_sve_; |
| 986 | instruction_visitor_ = &instruction_visitor_sve_; |
| 987 | } else { |
| 988 | location_builder_ = &location_builder_neon_; |
| 989 | instruction_visitor_ = &instruction_visitor_neon_; |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | bool CodeGeneratorARM64::ShouldUseSVE() const { |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 994 | return GetInstructionSetFeatures().HasSVE(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 995 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 996 | |
Artem Serov | 55ab7e8 | 2020-04-27 21:02:28 +0100 | [diff] [blame] | 997 | size_t CodeGeneratorARM64::GetSIMDRegisterWidth() const { |
| 998 | return SupportsPredicatedSIMD() |
| 999 | ? GetInstructionSetFeatures().GetSVEVectorLength() / kBitsPerByte |
| 1000 | : vixl::aarch64::kQRegSizeInBytes; |
| 1001 | } |
| 1002 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1003 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1004 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1005 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1006 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1007 | jump_table->EmitTable(this); |
| 1008 | } |
| 1009 | } |
| 1010 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1011 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1012 | EmitJumpTables(); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1013 | |
| 1014 | // Emit JIT baker read barrier slow paths. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 1015 | DCHECK(GetCompilerOptions().IsJitCompiler() || jit_baker_read_barrier_slow_paths_.empty()); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1016 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 1017 | uint32_t encoded_data = entry.first; |
| 1018 | vixl::aarch64::Label* slow_path_entry = &entry.second.label; |
| 1019 | __ Bind(slow_path_entry); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1020 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name= */ nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1023 | // Ensure we emit the literal pool. |
| 1024 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1025 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1026 | CodeGenerator::Finalize(allocator); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1027 | |
| 1028 | // Verify Baker read barrier linker patches. |
| 1029 | if (kIsDebugBuild) { |
| 1030 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 1031 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 1032 | DCHECK(info.label.IsBound()); |
| 1033 | uint32_t literal_offset = info.label.GetLocation(); |
| 1034 | DCHECK_ALIGNED(literal_offset, 4u); |
| 1035 | |
| 1036 | auto GetInsn = [&code](uint32_t offset) { |
| 1037 | DCHECK_ALIGNED(offset, 4u); |
| 1038 | return |
| 1039 | (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 1040 | (static_cast<uint32_t>(code[offset + 1]) << 8) + |
| 1041 | (static_cast<uint32_t>(code[offset + 2]) << 16)+ |
| 1042 | (static_cast<uint32_t>(code[offset + 3]) << 24); |
| 1043 | }; |
| 1044 | |
| 1045 | const uint32_t encoded_data = info.custom_data; |
| 1046 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 1047 | // Check that the next instruction matches the expected LDR. |
| 1048 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1049 | case BakerReadBarrierKind::kField: |
| 1050 | case BakerReadBarrierKind::kAcquire: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1051 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1052 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1053 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1054 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1055 | if (kind == BakerReadBarrierKind::kField) { |
| 1056 | // LDR (immediate) with correct base_reg. |
| 1057 | CHECK_EQ(next_insn & 0xffc003e0u, 0xb9400000u | (base_reg << 5)); |
| 1058 | } else { |
| 1059 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 1060 | // LDAR with correct base_reg. |
| 1061 | CHECK_EQ(next_insn & 0xffffffe0u, 0x88dffc00u | (base_reg << 5)); |
| 1062 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1063 | break; |
| 1064 | } |
| 1065 | case BakerReadBarrierKind::kArray: { |
| 1066 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1067 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 1068 | // LDR (register) with the correct base_reg, size=10 (32-bit), option=011 (extend = LSL), |
| 1069 | // and S=1 (shift amount = 2 for 32-bit version), i.e. LDR Wt, [Xn, Xm, LSL #2]. |
| 1070 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1071 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1072 | CHECK_EQ(next_insn & 0xffe0ffe0u, 0xb8607800u | (base_reg << 5)); |
| 1073 | CheckValidReg((next_insn >> 16) & 0x1f); // Check index register |
| 1074 | break; |
| 1075 | } |
| 1076 | case BakerReadBarrierKind::kGcRoot: { |
| 1077 | DCHECK_GE(literal_offset, 4u); |
| 1078 | uint32_t prev_insn = GetInsn(literal_offset - 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1079 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 1080 | // Usually LDR (immediate) with correct root_reg but |
Vladimir Marko | c8178f5 | 2020-11-24 10:38:16 +0000 | [diff] [blame] | 1081 | // we may have a "MOV marked, old_value" for intrinsic CAS. |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 1082 | if ((prev_insn & 0xffe0ffff) != (0x2a0003e0 | root_reg)) { // MOV? |
| 1083 | CHECK_EQ(prev_insn & 0xffc0001fu, 0xb9400000u | root_reg); // LDR? |
| 1084 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1085 | break; |
| 1086 | } |
| 1087 | default: |
| 1088 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 1089 | UNREACHABLE(); |
| 1090 | } |
| 1091 | } |
| 1092 | } |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1095 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1096 | // Note: There are 6 kinds of moves: |
| 1097 | // 1. constant -> GPR/FPR (non-cycle) |
| 1098 | // 2. constant -> stack (non-cycle) |
| 1099 | // 3. GPR/FPR -> GPR/FPR |
| 1100 | // 4. GPR/FPR -> stack |
| 1101 | // 5. stack -> GPR/FPR |
| 1102 | // 6. stack -> stack (non-cycle) |
| 1103 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1104 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1105 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1106 | // dependency. |
| 1107 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1108 | } |
| 1109 | |
| 1110 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1111 | vixl_temps_.Close(); |
| 1112 | } |
| 1113 | |
| 1114 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1115 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1116 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1117 | || kind == Location::kSIMDStackSlot); |
| 1118 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1119 | ? Location::kFpuRegister |
| 1120 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1121 | Location scratch = GetScratchLocation(kind); |
| 1122 | if (!scratch.Equals(Location::NoLocation())) { |
| 1123 | return scratch; |
| 1124 | } |
| 1125 | // Allocate from VIXL temp registers. |
| 1126 | if (kind == Location::kRegister) { |
| 1127 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1128 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1129 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1130 | scratch = codegen_->GetGraph()->HasSIMD() |
| 1131 | ? codegen_->GetInstructionCodeGeneratorArm64()->AllocateSIMDScratchLocation(&vixl_temps_) |
| 1132 | : LocationFrom(vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1133 | } |
| 1134 | AddScratchLocation(scratch); |
| 1135 | return scratch; |
| 1136 | } |
| 1137 | |
| 1138 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1139 | if (loc.IsRegister()) { |
| 1140 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1141 | } else { |
| 1142 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1143 | if (codegen_->GetGraph()->HasSIMD()) { |
| 1144 | codegen_->GetInstructionCodeGeneratorArm64()->FreeSIMDScratchLocation(loc, &vixl_temps_); |
| 1145 | } else { |
| 1146 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1147 | } |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1148 | } |
| 1149 | RemoveScratchLocation(loc); |
| 1150 | } |
| 1151 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1152 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1153 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1154 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 1157 | void LocationsBuilderARM64::VisitMethodExitHook(HMethodExitHook* method_hook) { |
| 1158 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| 1159 | LocationSummary(method_hook, LocationSummary::kCallOnSlowPath); |
| 1160 | DataType::Type return_type = method_hook->InputAt(0)->GetType(); |
| 1161 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
| 1162 | } |
| 1163 | |
| 1164 | void InstructionCodeGeneratorARM64::GenerateMethodEntryExitHook(HInstruction* instruction) { |
| 1165 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1166 | UseScratchRegisterScope temps(masm); |
| 1167 | Register temp = temps.AcquireX(); |
| 1168 | Register value = temps.AcquireW(); |
| 1169 | |
| 1170 | SlowPathCodeARM64* slow_path = |
| 1171 | new (codegen_->GetScopedAllocator()) MethodEntryExitHooksSlowPathARM64(instruction); |
| 1172 | codegen_->AddSlowPath(slow_path); |
| 1173 | |
| 1174 | uint64_t address = reinterpret_cast64<uint64_t>(Runtime::Current()->GetInstrumentation()); |
Mythri Alle | 5b263ae | 2022-10-21 15:07:44 +0000 | [diff] [blame] | 1175 | MemberOffset offset = instruction->IsMethodExitHook() ? |
| 1176 | instrumentation::Instrumentation::NeedsExitHooksOffset() : |
| 1177 | instrumentation::Instrumentation::HaveMethodEntryListenersOffset(); |
| 1178 | __ Mov(temp, address + offset.Int32Value()); |
Mythri Alle | 9575c12 | 2021-11-12 12:04:41 +0000 | [diff] [blame] | 1179 | __ Ldrb(value, MemOperand(temp, 0)); |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 1180 | __ Cbnz(value, slow_path->GetEntryLabel()); |
| 1181 | __ Bind(slow_path->GetExitLabel()); |
| 1182 | } |
| 1183 | |
| 1184 | void InstructionCodeGeneratorARM64::VisitMethodExitHook(HMethodExitHook* instruction) { |
| 1185 | DCHECK(codegen_->GetCompilerOptions().IsJitCompiler() && GetGraph()->IsDebuggable()); |
| 1186 | DCHECK(codegen_->RequiresCurrentMethod()); |
| 1187 | GenerateMethodEntryExitHook(instruction); |
| 1188 | } |
| 1189 | |
| 1190 | void LocationsBuilderARM64::VisitMethodEntryHook(HMethodEntryHook* method_hook) { |
| 1191 | new (GetGraph()->GetAllocator()) LocationSummary(method_hook, LocationSummary::kCallOnSlowPath); |
| 1192 | } |
| 1193 | |
| 1194 | void InstructionCodeGeneratorARM64::VisitMethodEntryHook(HMethodEntryHook* instruction) { |
| 1195 | DCHECK(codegen_->GetCompilerOptions().IsJitCompiler() && GetGraph()->IsDebuggable()); |
| 1196 | DCHECK(codegen_->RequiresCurrentMethod()); |
| 1197 | GenerateMethodEntryExitHook(instruction); |
| 1198 | } |
| 1199 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1200 | void CodeGeneratorARM64::MaybeIncrementHotness(bool is_frame_entry) { |
| 1201 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1202 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1203 | UseScratchRegisterScope temps(masm); |
| 1204 | Register counter = temps.AcquireX(); |
| 1205 | Register method = is_frame_entry ? kArtMethodRegister : temps.AcquireX(); |
| 1206 | if (!is_frame_entry) { |
| 1207 | __ Ldr(method, MemOperand(sp, 0)); |
| 1208 | } |
| 1209 | __ Ldrh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
Nicolas Geoffray | 61673dc | 2021-11-06 13:58:31 +0000 | [diff] [blame] | 1210 | vixl::aarch64::Label done; |
| 1211 | DCHECK_EQ(0u, interpreter::kNterpHotnessValue); |
| 1212 | __ Cbz(counter, &done); |
| 1213 | __ Add(counter, counter, -1); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1214 | __ Strh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
Nicolas Geoffray | 61673dc | 2021-11-06 13:58:31 +0000 | [diff] [blame] | 1215 | __ Bind(&done); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 1219 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) CompileOptimizedSlowPathARM64(); |
| 1220 | AddSlowPath(slow_path); |
| 1221 | ProfilingInfo* info = GetGraph()->GetProfilingInfo(); |
| 1222 | DCHECK(info != nullptr); |
| 1223 | DCHECK(!HasEmptyFrame()); |
| 1224 | uint64_t address = reinterpret_cast64<uint64_t>(info); |
| 1225 | vixl::aarch64::Label done; |
| 1226 | UseScratchRegisterScope temps(masm); |
| 1227 | Register temp = temps.AcquireX(); |
| 1228 | Register counter = temps.AcquireW(); |
| 1229 | __ Ldr(temp, DeduplicateUint64Literal(address)); |
| 1230 | __ Ldrh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 1231 | __ Cbz(counter, slow_path->GetEntryLabel()); |
| 1232 | __ Add(counter, counter, -1); |
| 1233 | __ Strh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 1234 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1235 | } |
| 1236 | } |
| 1237 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1238 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1239 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | ab3f8d2 | 2022-07-23 15:49:51 +0000 | [diff] [blame] | 1240 | |
| 1241 | // Check if we need to generate the clinit check. We will jump to the |
| 1242 | // resolution stub if the class is not initialized and the executing thread is |
| 1243 | // not the thread initializing it. |
| 1244 | // We do this before constructing the frame to get the correct stack trace if |
| 1245 | // an exception is thrown. |
| 1246 | if (GetCompilerOptions().ShouldCompileWithClinitCheck(GetGraph()->GetArtMethod())) { |
| 1247 | UseScratchRegisterScope temps(masm); |
| 1248 | vixl::aarch64::Label resolution; |
Nicolas Geoffray | f853790 | 2022-09-13 15:22:29 +0100 | [diff] [blame] | 1249 | vixl::aarch64::Label memory_barrier; |
Nicolas Geoffray | ab3f8d2 | 2022-07-23 15:49:51 +0000 | [diff] [blame] | 1250 | |
| 1251 | Register temp1 = temps.AcquireW(); |
| 1252 | Register temp2 = temps.AcquireW(); |
| 1253 | |
| 1254 | // Check if we're visibly initialized. |
| 1255 | |
| 1256 | // We don't emit a read barrier here to save on code size. We rely on the |
| 1257 | // resolution trampoline to do a suspend check before re-entering this code. |
| 1258 | __ Ldr(temp1, MemOperand(kArtMethodRegister, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 1259 | __ Ldrb(temp2, HeapOperand(temp1, status_byte_offset)); |
| 1260 | __ Cmp(temp2, shifted_visibly_initialized_value); |
| 1261 | __ B(hs, &frame_entry_label_); |
| 1262 | |
Nicolas Geoffray | f853790 | 2022-09-13 15:22:29 +0100 | [diff] [blame] | 1263 | // Check if we're initialized and jump to code that does a memory barrier if |
| 1264 | // so. |
| 1265 | __ Cmp(temp2, shifted_initialized_value); |
| 1266 | __ B(hs, &memory_barrier); |
| 1267 | |
Nicolas Geoffray | ab3f8d2 | 2022-07-23 15:49:51 +0000 | [diff] [blame] | 1268 | // Check if we're initializing and the thread initializing is the one |
| 1269 | // executing the code. |
| 1270 | __ Cmp(temp2, shifted_initializing_value); |
| 1271 | __ B(lo, &resolution); |
| 1272 | |
| 1273 | __ Ldr(temp1, HeapOperand(temp1, mirror::Class::ClinitThreadIdOffset().Int32Value())); |
| 1274 | __ Ldr(temp2, MemOperand(tr, Thread::TidOffset<kArm64PointerSize>().Int32Value())); |
| 1275 | __ Cmp(temp1, temp2); |
| 1276 | __ B(eq, &frame_entry_label_); |
| 1277 | __ Bind(&resolution); |
| 1278 | |
| 1279 | // Jump to the resolution stub. |
| 1280 | ThreadOffset64 entrypoint_offset = |
| 1281 | GetThreadOffset<kArm64PointerSize>(kQuickQuickResolutionTrampoline); |
| 1282 | __ Ldr(temp1.X(), MemOperand(tr, entrypoint_offset.Int32Value())); |
| 1283 | __ Br(temp1.X()); |
Nicolas Geoffray | f853790 | 2022-09-13 15:22:29 +0100 | [diff] [blame] | 1284 | |
| 1285 | __ Bind(&memory_barrier); |
| 1286 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Nicolas Geoffray | ab3f8d2 | 2022-07-23 15:49:51 +0000 | [diff] [blame] | 1287 | } |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1288 | __ Bind(&frame_entry_label_); |
| 1289 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1290 | bool do_overflow_check = |
| 1291 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1292 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1293 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1294 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1295 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1296 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1297 | { |
| 1298 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1299 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1300 | kInstructionSize, |
| 1301 | CodeBufferCheckScope::kExactSize); |
| 1302 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1303 | RecordPcInfo(nullptr, 0); |
| 1304 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1305 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1306 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1307 | if (!HasEmptyFrame()) { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1308 | // Stack layout: |
| 1309 | // sp[frame_size - 8] : lr. |
| 1310 | // ... : other preserved core registers. |
| 1311 | // ... : other preserved fp registers. |
| 1312 | // ... : reserved frame space. |
| 1313 | // sp[0] : current method. |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1314 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1315 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1316 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1317 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1318 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1319 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1320 | |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1321 | // Save the current method if we need it, or if using STP reduces code |
| 1322 | // size. Note that we do not do this in HCurrentMethod, as the |
| 1323 | // instruction might have been removed in the SSA graph. |
| 1324 | CPURegister lowest_spill; |
| 1325 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1326 | // If there is no gap between the method and the lowest core spill, use |
| 1327 | // aligned STP pre-index to store both. Max difference is 512. We do |
| 1328 | // that to reduce code size even if we do not have to save the method. |
| 1329 | DCHECK_LE(frame_size, 512); // 32 core registers are only 256 bytes. |
| 1330 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1331 | __ Stp(kArtMethodRegister, lowest_spill, MemOperand(sp, -frame_size, PreIndex)); |
| 1332 | } else if (RequiresCurrentMethod()) { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1333 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1334 | } else { |
| 1335 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1336 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1337 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1338 | if (lowest_spill.IsValid()) { |
| 1339 | GetAssembler()->cfi().RelOffset(DWARFReg(lowest_spill), core_spills_offset); |
| 1340 | core_spills_offset += kXRegSizeInBytes; |
| 1341 | } |
| 1342 | GetAssembler()->SpillRegisters(preserved_core_registers, core_spills_offset); |
| 1343 | GetAssembler()->SpillRegisters(preserved_fp_registers, fp_spills_offset); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1344 | |
| 1345 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1346 | // Initialize should_deoptimize flag to 0. |
| 1347 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1348 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1349 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1350 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1351 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1352 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1356 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1357 | if (!HasEmptyFrame()) { |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1358 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1359 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1360 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1361 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1362 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1363 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
| 1364 | |
| 1365 | CPURegister lowest_spill; |
| 1366 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1367 | // If there is no gap between the method and the lowest core spill, use |
| 1368 | // aligned LDP pre-index to pop both. Max difference is 504. We do |
| 1369 | // that to reduce code size even though the loaded method is unused. |
| 1370 | DCHECK_LE(frame_size, 504); // 32 core registers are only 256 bytes. |
| 1371 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1372 | core_spills_offset += kXRegSizeInBytes; |
| 1373 | } |
| 1374 | GetAssembler()->UnspillRegisters(preserved_fp_registers, fp_spills_offset); |
| 1375 | GetAssembler()->UnspillRegisters(preserved_core_registers, core_spills_offset); |
| 1376 | if (lowest_spill.IsValid()) { |
| 1377 | __ Ldp(xzr, lowest_spill, MemOperand(sp, frame_size, PostIndex)); |
| 1378 | GetAssembler()->cfi().Restore(DWARFReg(lowest_spill)); |
| 1379 | } else { |
| 1380 | __ Drop(frame_size); |
| 1381 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1382 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1383 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1384 | __ Ret(); |
| 1385 | GetAssembler()->cfi().RestoreState(); |
| 1386 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1387 | } |
| 1388 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1389 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1390 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1391 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1392 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1393 | } |
| 1394 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1395 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1396 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1397 | GetNumberOfFloatingPointRegisters())); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1398 | return CPURegList(CPURegister::kVRegister, kDRegSize, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1399 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1400 | } |
| 1401 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1402 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1403 | __ Bind(GetLabelOf(block)); |
| 1404 | } |
| 1405 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1406 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1407 | DCHECK(location.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1408 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1409 | } |
| 1410 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1411 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1412 | if (location.IsRegister()) { |
| 1413 | locations->AddTemp(location); |
| 1414 | } else { |
| 1415 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1416 | } |
| 1417 | } |
| 1418 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1419 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1420 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1421 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1422 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1423 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1424 | if (value_can_be_null) { |
| 1425 | __ Cbz(value, &done); |
| 1426 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1427 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1428 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1429 | // Calculate the offset (in the card table) of the card corresponding to |
| 1430 | // `object`. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1431 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1432 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 1433 | // `object`'s card. |
| 1434 | // |
| 1435 | // Register `card` contains the address of the card table. Note that the card |
| 1436 | // table's base is biased during its creation so that it always starts at an |
| 1437 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 1438 | // art::gc::accounting::CardTable::Create). Therefore the STRB instruction |
| 1439 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 1440 | // (located at `card + object >> kCardShift`). |
| 1441 | // |
| 1442 | // This dual use of the value in register `card` (1. to calculate the location |
| 1443 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 1444 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1445 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1446 | if (value_can_be_null) { |
| 1447 | __ Bind(&done); |
| 1448 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1449 | } |
| 1450 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1451 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1452 | // Blocked core registers: |
| 1453 | // lr : Runtime reserved. |
| 1454 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1455 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1456 | // ip1 : VIXL core temp. |
| 1457 | // ip0 : VIXL core temp. |
Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1458 | // x18 : Platform register. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1459 | // |
| 1460 | // Blocked fp registers: |
| 1461 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1462 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1463 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1464 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1465 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1466 | } |
Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1467 | blocked_core_registers_[X18] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1468 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1469 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1470 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1471 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1472 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1473 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1474 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1475 | // Stubs do not save callee-save floating point registers. If the graph |
| 1476 | // is debuggable, we need to deal with these registers differently. For |
| 1477 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1478 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1479 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1480 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1481 | } |
| 1482 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1483 | } |
| 1484 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1485 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1486 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1487 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1488 | return kArm64WordSize; |
| 1489 | } |
| 1490 | |
| 1491 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1492 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1493 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1494 | return kArm64WordSize; |
| 1495 | } |
| 1496 | |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1497 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1498 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1499 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1500 | << "use SaveRestoreLiveRegistersHelper"; |
| 1501 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1504 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1505 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1506 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1507 | << "use SaveRestoreLiveRegistersHelper"; |
| 1508 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1509 | } |
| 1510 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1511 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1512 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1516 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1517 | } |
| 1518 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1519 | const Arm64InstructionSetFeatures& CodeGeneratorARM64::GetInstructionSetFeatures() const { |
| 1520 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArm64InstructionSetFeatures(); |
| 1521 | } |
| 1522 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1523 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1524 | if (constant->IsIntConstant()) { |
| 1525 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1526 | } else if (constant->IsLongConstant()) { |
| 1527 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1528 | } else if (constant->IsNullConstant()) { |
| 1529 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1530 | } else if (constant->IsFloatConstant()) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1531 | __ Fmov(VRegister(destination), constant->AsFloatConstant()->GetValue()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1532 | } else { |
| 1533 | DCHECK(constant->IsDoubleConstant()); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1534 | __ Fmov(VRegister(destination), constant->AsDoubleConstant()->GetValue()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1535 | } |
| 1536 | } |
| 1537 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1538 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1539 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1540 | DCHECK(constant.IsConstant()); |
| 1541 | HConstant* cst = constant.GetConstant(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1542 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1543 | // 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] | 1544 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1545 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1546 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1547 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1550 | // Allocate a scratch register from the VIXL pool, querying first |
| 1551 | // the floating-point register pool, and then the core register |
| 1552 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1553 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1554 | // using a different allocation strategy. |
| 1555 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1556 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1557 | int size_in_bits) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1558 | return masm->GetScratchVRegisterList()->IsEmpty() |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1559 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1560 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1561 | } |
| 1562 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1563 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1564 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1565 | DataType::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1566 | if (source.Equals(destination)) { |
| 1567 | return; |
| 1568 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1569 | |
| 1570 | // A valid move can always be inferred from the destination and source |
| 1571 | // locations. When moving from and to a register, the argument type can be |
| 1572 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1573 | // checks the coherency of the locations and the type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1574 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1575 | |
| 1576 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1577 | if (unspecified_type) { |
| 1578 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1579 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1580 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1581 | || src_cst->IsFloatConstant() |
| 1582 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1583 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1584 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1585 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1586 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1587 | // type is appropriate. Else the source is a register, and since the |
| 1588 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1589 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1590 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1591 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1592 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1593 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1594 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1595 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1596 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1597 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1598 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1599 | } else if (source.IsSIMDStackSlot()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1600 | GetInstructionCodeGeneratorArm64()->LoadSIMDRegFromStack(destination, source); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1601 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1602 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1603 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1604 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1605 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1606 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1607 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1608 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1609 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1610 | ? DataType::Type::kInt64 |
| 1611 | : DataType::Type::kInt32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1612 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1613 | } |
| 1614 | } else { |
| 1615 | DCHECK(source.IsFpuRegister()); |
| 1616 | if (destination.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1617 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1618 | ? DataType::Type::kFloat64 |
| 1619 | : DataType::Type::kFloat32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1620 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1621 | } else { |
| 1622 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1623 | if (GetGraph()->HasSIMD()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1624 | GetInstructionCodeGeneratorArm64()->MoveSIMDRegToSIMDReg(destination, source); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1625 | } else { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1626 | __ Fmov(VRegister(dst), FPRegisterFrom(source, dst_type)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1627 | } |
| 1628 | } |
| 1629 | } |
| 1630 | } else if (destination.IsSIMDStackSlot()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1631 | GetInstructionCodeGeneratorArm64()->MoveToSIMDStackSlot(destination, source); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1632 | } else { // The destination is not a register. It must be a stack slot. |
| 1633 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1634 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1635 | if (unspecified_type) { |
| 1636 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1637 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1638 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1639 | dst_type = |
| 1640 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1641 | } |
| 1642 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1643 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1644 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1645 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1646 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1647 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1648 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1649 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1650 | HConstant* src_cst = source.GetConstant(); |
| 1651 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1652 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1653 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1654 | ? Register(xzr) |
| 1655 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1656 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1657 | if (src_cst->IsIntConstant()) { |
| 1658 | temp = temps.AcquireW(); |
| 1659 | } else if (src_cst->IsLongConstant()) { |
| 1660 | temp = temps.AcquireX(); |
| 1661 | } else if (src_cst->IsFloatConstant()) { |
| 1662 | temp = temps.AcquireS(); |
| 1663 | } else { |
| 1664 | DCHECK(src_cst->IsDoubleConstant()); |
| 1665 | temp = temps.AcquireD(); |
| 1666 | } |
| 1667 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1668 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1669 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1670 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1671 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1672 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1673 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1674 | // Use any scratch register (a core or a floating-point one) |
| 1675 | // from VIXL scratch register pools as a temporary. |
| 1676 | // |
| 1677 | // We used to only use the FP scratch register pool, but in some |
| 1678 | // rare cases the only register from this pool (D31) would |
| 1679 | // already be used (e.g. within a ParallelMove instruction, when |
| 1680 | // a move is blocked by a another move requiring a scratch FP |
| 1681 | // register, which would reserve D31). To prevent this issue, we |
| 1682 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1683 | // |
| 1684 | // 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] | 1685 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1686 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1687 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1688 | // allocates core scratch registers first. |
| 1689 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1690 | GetVIXLAssembler(), |
| 1691 | &temps, |
| 1692 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1693 | __ Ldr(temp, StackOperandFrom(source)); |
| 1694 | __ Str(temp, StackOperandFrom(destination)); |
| 1695 | } |
| 1696 | } |
| 1697 | } |
| 1698 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1699 | void CodeGeneratorARM64::Load(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1700 | CPURegister dst, |
| 1701 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1702 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1703 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1704 | case DataType::Type::kUint8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1705 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1706 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1707 | case DataType::Type::kInt8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1708 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1709 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1710 | case DataType::Type::kUint16: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1711 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1712 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1713 | case DataType::Type::kInt16: |
| 1714 | __ Ldrsh(Register(dst), src); |
| 1715 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1716 | case DataType::Type::kInt32: |
| 1717 | case DataType::Type::kReference: |
| 1718 | case DataType::Type::kInt64: |
| 1719 | case DataType::Type::kFloat32: |
| 1720 | case DataType::Type::kFloat64: |
| 1721 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1722 | __ Ldr(dst, src); |
| 1723 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1724 | case DataType::Type::kUint32: |
| 1725 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1726 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1727 | LOG(FATAL) << "Unreachable type " << type; |
| 1728 | } |
| 1729 | } |
| 1730 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1731 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 1732 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1733 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1734 | const MemOperand& src, |
| 1735 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1736 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1737 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1738 | Register temp_base = temps.AcquireX(); |
| 1739 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1740 | DCHECK(!src.IsPreIndex()); |
| 1741 | DCHECK(!src.IsPostIndex()); |
| 1742 | |
| 1743 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1744 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1745 | { |
| 1746 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1747 | MemOperand base = MemOperand(temp_base); |
| 1748 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1749 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1750 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1751 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1752 | { |
| 1753 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1754 | __ ldarb(Register(dst), base); |
| 1755 | if (needs_null_check) { |
| 1756 | MaybeRecordImplicitNullCheck(instruction); |
| 1757 | } |
| 1758 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1759 | if (type == DataType::Type::kInt8) { |
| 1760 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1761 | } |
| 1762 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1763 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1764 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1765 | { |
| 1766 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1767 | __ ldarh(Register(dst), base); |
| 1768 | if (needs_null_check) { |
| 1769 | MaybeRecordImplicitNullCheck(instruction); |
| 1770 | } |
| 1771 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1772 | if (type == DataType::Type::kInt16) { |
| 1773 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 1774 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1775 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1776 | case DataType::Type::kInt32: |
| 1777 | case DataType::Type::kReference: |
| 1778 | case DataType::Type::kInt64: |
| 1779 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1780 | { |
| 1781 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1782 | __ ldar(Register(dst), base); |
| 1783 | if (needs_null_check) { |
| 1784 | MaybeRecordImplicitNullCheck(instruction); |
| 1785 | } |
| 1786 | } |
| 1787 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1788 | case DataType::Type::kFloat32: |
| 1789 | case DataType::Type::kFloat64: { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1790 | DCHECK(dst.IsFPRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1791 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1792 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1793 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1794 | { |
| 1795 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1796 | __ ldar(temp, base); |
| 1797 | if (needs_null_check) { |
| 1798 | MaybeRecordImplicitNullCheck(instruction); |
| 1799 | } |
| 1800 | } |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1801 | __ Fmov(VRegister(dst), temp); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1802 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1803 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1804 | case DataType::Type::kUint32: |
| 1805 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1806 | case DataType::Type::kVoid: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1807 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1808 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1809 | } |
| 1810 | } |
| 1811 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1812 | void CodeGeneratorARM64::Store(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1813 | CPURegister src, |
| 1814 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1815 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1816 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1817 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1818 | case DataType::Type::kInt8: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1819 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1820 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1821 | case DataType::Type::kUint16: |
| 1822 | case DataType::Type::kInt16: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1823 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1824 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1825 | case DataType::Type::kInt32: |
| 1826 | case DataType::Type::kReference: |
| 1827 | case DataType::Type::kInt64: |
| 1828 | case DataType::Type::kFloat32: |
| 1829 | case DataType::Type::kFloat64: |
| 1830 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1831 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1832 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1833 | case DataType::Type::kUint32: |
| 1834 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1835 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1836 | LOG(FATAL) << "Unreachable type " << type; |
| 1837 | } |
| 1838 | } |
| 1839 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1840 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1841 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1842 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1843 | const MemOperand& dst, |
| 1844 | bool needs_null_check) { |
| 1845 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1846 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1847 | Register temp_base = temps.AcquireX(); |
| 1848 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1849 | DCHECK(!dst.IsPreIndex()); |
| 1850 | DCHECK(!dst.IsPostIndex()); |
| 1851 | |
| 1852 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1853 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1854 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1855 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1856 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1857 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1858 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1859 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1860 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1861 | { |
| 1862 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1863 | __ stlrb(Register(src), base); |
| 1864 | if (needs_null_check) { |
| 1865 | MaybeRecordImplicitNullCheck(instruction); |
| 1866 | } |
| 1867 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1868 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1869 | case DataType::Type::kUint16: |
| 1870 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1871 | { |
| 1872 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1873 | __ stlrh(Register(src), base); |
| 1874 | if (needs_null_check) { |
| 1875 | MaybeRecordImplicitNullCheck(instruction); |
| 1876 | } |
| 1877 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1878 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1879 | case DataType::Type::kInt32: |
| 1880 | case DataType::Type::kReference: |
| 1881 | case DataType::Type::kInt64: |
| 1882 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1883 | { |
| 1884 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1885 | __ stlr(Register(src), base); |
| 1886 | if (needs_null_check) { |
| 1887 | MaybeRecordImplicitNullCheck(instruction); |
| 1888 | } |
| 1889 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1890 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1891 | case DataType::Type::kFloat32: |
| 1892 | case DataType::Type::kFloat64: { |
| 1893 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1894 | Register temp_src; |
| 1895 | if (src.IsZero()) { |
| 1896 | // The zero register is used to avoid synthesizing zero constants. |
| 1897 | temp_src = Register(src); |
| 1898 | } else { |
| 1899 | DCHECK(src.IsFPRegister()); |
| 1900 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1901 | __ Fmov(temp_src, VRegister(src)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1902 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1903 | { |
| 1904 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1905 | __ stlr(temp_src, base); |
| 1906 | if (needs_null_check) { |
| 1907 | MaybeRecordImplicitNullCheck(instruction); |
| 1908 | } |
| 1909 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1910 | break; |
| 1911 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1912 | case DataType::Type::kUint32: |
| 1913 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1914 | case DataType::Type::kVoid: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1915 | LOG(FATAL) << "Unreachable type " << type; |
| 1916 | } |
| 1917 | } |
| 1918 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1919 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1920 | HInstruction* instruction, |
| 1921 | uint32_t dex_pc, |
| 1922 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1923 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1924 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1925 | ThreadOffset64 entrypoint_offset = GetThreadOffset<kArm64PointerSize>(entrypoint); |
| 1926 | // Reduce code size for AOT by using shared trampolines for slow path runtime calls across the |
| 1927 | // entire oat file. This adds an extra branch and we do not want to slow down the main path. |
| 1928 | // 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] | 1929 | if (slow_path == nullptr || GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1930 | __ Ldr(lr, MemOperand(tr, entrypoint_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1931 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 1932 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1933 | __ blr(lr); |
| 1934 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1935 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1936 | } |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1937 | } else { |
| 1938 | // Ensure the pc position is recorded immediately after the `bl` instruction. |
| 1939 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1940 | EmitEntrypointThunkCall(entrypoint_offset); |
| 1941 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1942 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1943 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1944 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1945 | } |
| 1946 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1947 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1948 | HInstruction* instruction, |
| 1949 | SlowPathCode* slow_path) { |
| 1950 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1951 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1952 | __ Blr(lr); |
| 1953 | } |
| 1954 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1955 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1956 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1957 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1958 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1959 | |
Vladimir Marko | 2bb44fe | 2019-10-04 12:28:14 +0100 | [diff] [blame] | 1960 | // CMP (immediate) is limited to imm12 or imm12<<12, so we would need to materialize |
| 1961 | // the constant 0xf0000000 for comparison with the full 32-bit field. To reduce the code |
| 1962 | // size, load only the high byte of the field and compare with 0xf0. |
| 1963 | // Note: The same code size could be achieved with LDR+MNV(asr #24)+CBNZ but benchmarks |
| 1964 | // show that this pattern is slower (tested on little cores). |
| 1965 | __ Ldrb(temp, HeapOperand(class_reg, status_byte_offset)); |
| 1966 | __ Cmp(temp, shifted_visibly_initialized_value); |
| 1967 | __ B(lo, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1968 | __ Bind(slow_path->GetExitLabel()); |
| 1969 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1970 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 1971 | void InstructionCodeGeneratorARM64::GenerateBitstringTypeCheckCompare( |
| 1972 | HTypeCheckInstruction* check, vixl::aarch64::Register temp) { |
| 1973 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 1974 | uint32_t mask = check->GetBitstringMask(); |
| 1975 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 1976 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 1977 | |
| 1978 | if (mask_bits == 16u) { |
| 1979 | // Load only the bitstring part of the status word. |
| 1980 | __ Ldrh(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1981 | } else { |
| 1982 | // /* uint32_t */ temp = temp->status_ |
| 1983 | __ Ldr(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1984 | // Extract the bitstring bits. |
| 1985 | __ Ubfx(temp, temp, 0, mask_bits); |
| 1986 | } |
| 1987 | // Compare the bitstring bits to `path_to_root`. |
| 1988 | __ Cmp(temp, path_to_root); |
| 1989 | } |
| 1990 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1991 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1992 | BarrierType type = BarrierAll; |
| 1993 | |
| 1994 | switch (kind) { |
| 1995 | case MemBarrierKind::kAnyAny: |
| 1996 | case MemBarrierKind::kAnyStore: { |
| 1997 | type = BarrierAll; |
| 1998 | break; |
| 1999 | } |
| 2000 | case MemBarrierKind::kLoadAny: { |
| 2001 | type = BarrierReads; |
| 2002 | break; |
| 2003 | } |
| 2004 | case MemBarrierKind::kStoreStore: { |
| 2005 | type = BarrierWrites; |
| 2006 | break; |
| 2007 | } |
| 2008 | default: |
| 2009 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2010 | } |
| 2011 | __ Dmb(InnerShareable, type); |
| 2012 | } |
| 2013 | |
Vladimir Marko | 7039c11 | 2018-04-05 17:59:39 +0100 | [diff] [blame] | 2014 | bool CodeGeneratorARM64::CanUseImplicitSuspendCheck() const { |
| 2015 | // Use implicit suspend checks if requested in compiler options unless there are SIMD |
| 2016 | // instructions in the graph. The implicit suspend check saves all FP registers as |
| 2017 | // 64-bit (in line with the calling convention) but SIMD instructions can use 128-bit |
| 2018 | // registers, so they need to be saved in an explicit slow path. |
| 2019 | return GetCompilerOptions().GetImplicitSuspendChecks() && !GetGraph()->HasSIMD(); |
| 2020 | } |
| 2021 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2022 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2023 | HBasicBlock* successor) { |
Stelios Ioannou | c54cc7c | 2021-07-09 17:06:03 +0100 | [diff] [blame] | 2024 | if (instruction->IsNoOp()) { |
| 2025 | if (successor != nullptr) { |
| 2026 | __ B(codegen_->GetLabelOf(successor)); |
| 2027 | } |
| 2028 | return; |
| 2029 | } |
| 2030 | |
Vladimir Marko | 7039c11 | 2018-04-05 17:59:39 +0100 | [diff] [blame] | 2031 | if (codegen_->CanUseImplicitSuspendCheck()) { |
| 2032 | __ Ldr(kImplicitSuspendCheckRegister, MemOperand(kImplicitSuspendCheckRegister)); |
| 2033 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Vladimir Marko | e45883e | 2022-01-11 12:38:35 +0000 | [diff] [blame] | 2034 | if (successor != nullptr) { |
| 2035 | __ B(codegen_->GetLabelOf(successor)); |
| 2036 | } |
Vladimir Marko | 7039c11 | 2018-04-05 17:59:39 +0100 | [diff] [blame] | 2037 | return; |
| 2038 | } |
| 2039 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2040 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2041 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2042 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2043 | slow_path = |
| 2044 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2045 | instruction->SetSlowPath(slow_path); |
| 2046 | codegen_->AddSlowPath(slow_path); |
| 2047 | if (successor != nullptr) { |
| 2048 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2049 | } |
| 2050 | } else { |
| 2051 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2052 | } |
| 2053 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2054 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2055 | Register temp = temps.AcquireW(); |
| 2056 | |
Vladimir Marko | ddf4fd3 | 2021-11-22 16:31:57 +0000 | [diff] [blame] | 2057 | __ Ldr(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 2058 | __ Tst(temp, Thread::SuspendOrCheckpointRequestFlags()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2059 | if (successor == nullptr) { |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 2060 | __ B(ne, slow_path->GetEntryLabel()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2061 | __ Bind(slow_path->GetReturnLabel()); |
| 2062 | } else { |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 2063 | __ B(eq, codegen_->GetLabelOf(successor)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2064 | __ B(slow_path->GetEntryLabel()); |
| 2065 | // slow_path will return to GetLabelOf(successor). |
| 2066 | } |
| 2067 | } |
| 2068 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2069 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2070 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2071 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2072 | assembler_(codegen->GetAssembler()), |
| 2073 | codegen_(codegen) {} |
| 2074 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2075 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2076 | DCHECK_EQ(instr->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2077 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2078 | DataType::Type type = instr->GetResultType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2079 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2080 | case DataType::Type::kInt32: |
| 2081 | case DataType::Type::kInt64: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2082 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2083 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2084 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2085 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2086 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2087 | case DataType::Type::kFloat32: |
| 2088 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2089 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2090 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2091 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2092 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2093 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2094 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2095 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2096 | } |
| 2097 | } |
| 2098 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2099 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2100 | const FieldInfo& field_info) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2101 | DCHECK(instruction->IsInstanceFieldGet() || |
| 2102 | instruction->IsStaticFieldGet() || |
| 2103 | instruction->IsPredicatedInstanceFieldGet()); |
| 2104 | |
| 2105 | bool is_predicated = instruction->IsPredicatedInstanceFieldGet(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2106 | |
| 2107 | bool object_field_get_with_read_barrier = |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2108 | gUseReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2109 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2110 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2111 | object_field_get_with_read_barrier |
| 2112 | ? LocationSummary::kCallOnSlowPath |
| 2113 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2114 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2115 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 2116 | // We need a temporary register for the read barrier load in |
| 2117 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2118 | // only if the field is volatile or the offset is too big. |
| 2119 | if (field_info.IsVolatile() || |
| 2120 | field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2121 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2122 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2123 | } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2124 | // Input for object receiver. |
| 2125 | locations->SetInAt(is_predicated ? 1 : 0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2126 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2127 | if (is_predicated) { |
| 2128 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2129 | locations->SetOut(Location::SameAsFirstInput()); |
| 2130 | } else { |
| 2131 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2132 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2133 | } else { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2134 | if (is_predicated) { |
| 2135 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2136 | locations->SetOut(Location::SameAsFirstInput()); |
| 2137 | } else { |
| 2138 | // The output overlaps for an object field get when read barriers |
| 2139 | // are enabled: we do not want the load to overwrite the object's |
| 2140 | // location, as we need it to emit the read barrier. |
| 2141 | locations->SetOut(Location::RequiresRegister(), |
| 2142 | object_field_get_with_read_barrier ? Location::kOutputOverlap |
| 2143 | : Location::kNoOutputOverlap); |
| 2144 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2149 | const FieldInfo& field_info) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2150 | DCHECK(instruction->IsInstanceFieldGet() || |
| 2151 | instruction->IsStaticFieldGet() || |
| 2152 | instruction->IsPredicatedInstanceFieldGet()); |
| 2153 | bool is_predicated = instruction->IsPredicatedInstanceFieldGet(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2154 | LocationSummary* locations = instruction->GetLocations(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2155 | uint32_t receiver_input = is_predicated ? 1 : 0; |
| 2156 | Location base_loc = locations->InAt(receiver_input); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2157 | Location out = locations->Out(); |
| 2158 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2159 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 2160 | DataType::Type load_type = instruction->GetType(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2161 | MemOperand field = |
| 2162 | HeapOperand(InputRegisterAt(instruction, receiver_input), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2163 | |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2164 | if (gUseReadBarrier && kUseBakerReadBarrier && |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2165 | load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2166 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2167 | // /* HeapReference<Object> */ out = *(base + offset) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2168 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2169 | Location maybe_temp = |
| 2170 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2171 | // Note that potential implicit null checks are handled in this |
| 2172 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2173 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2174 | instruction, |
| 2175 | out, |
| 2176 | base, |
| 2177 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2178 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2179 | /* needs_null_check= */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2180 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2181 | } else { |
| 2182 | // General case. |
| 2183 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2184 | // Note that a potential implicit null check is handled in this |
| 2185 | // CodeGeneratorARM64::LoadAcquire call. |
| 2186 | // NB: LoadAcquire will record the pc info if needed. |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 2187 | codegen_->LoadAcquire(instruction, |
| 2188 | load_type, |
| 2189 | OutputCPURegister(instruction), |
| 2190 | field, |
| 2191 | /* needs_null_check= */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2192 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2193 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2194 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2195 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2196 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2197 | } |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2198 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2199 | // If read barriers are enabled, emit read barriers other than |
| 2200 | // Baker's using a slow path (and also unpoison the loaded |
| 2201 | // reference, if heap poisoning is enabled). |
| 2202 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2203 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2204 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2208 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2209 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2210 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2211 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2212 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2213 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2214 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2215 | } else { |
| 2216 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2221 | const FieldInfo& field_info, |
| 2222 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2223 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2224 | bool is_predicated = |
| 2225 | instruction->IsInstanceFieldSet() && instruction->AsInstanceFieldSet()->GetIsPredicatedSet(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2226 | |
| 2227 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2228 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2229 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2230 | Offset offset = field_info.GetFieldOffset(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2231 | DataType::Type field_type = field_info.GetFieldType(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2232 | std::optional<vixl::aarch64::Label> pred_is_null; |
| 2233 | if (is_predicated) { |
| 2234 | pred_is_null.emplace(); |
| 2235 | __ Cbz(obj, &*pred_is_null); |
| 2236 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2237 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2238 | { |
| 2239 | // We use a block to end the scratch scope before the write barrier, thus |
| 2240 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2241 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2242 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2243 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2244 | DCHECK(value.IsW()); |
| 2245 | Register temp = temps.AcquireW(); |
| 2246 | __ Mov(temp, value.W()); |
| 2247 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2248 | source = temp; |
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 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2252 | codegen_->StoreRelease( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2253 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check= */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2254 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2255 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2256 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2257 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2258 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2259 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2263 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2264 | } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2265 | |
| 2266 | if (is_predicated) { |
| 2267 | __ Bind(&*pred_is_null); |
| 2268 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2269 | } |
| 2270 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2271 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2272 | DataType::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2273 | |
| 2274 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2275 | case DataType::Type::kInt32: |
| 2276 | case DataType::Type::kInt64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2277 | Register dst = OutputRegister(instr); |
| 2278 | Register lhs = InputRegisterAt(instr, 0); |
| 2279 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2280 | if (instr->IsAdd()) { |
| 2281 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2282 | } else if (instr->IsAnd()) { |
| 2283 | __ And(dst, lhs, rhs); |
| 2284 | } else if (instr->IsOr()) { |
| 2285 | __ Orr(dst, lhs, rhs); |
| 2286 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2287 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2288 | } else if (instr->IsRor()) { |
| 2289 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2290 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2291 | __ Ror(dst, lhs, shift); |
| 2292 | } else { |
| 2293 | // Ensure shift distance is in the same size register as the result. If |
| 2294 | // we are rotating a long and the shift comes in a w register originally, |
| 2295 | // we don't need to sxtw for use as an x since the shift distances are |
| 2296 | // all & reg_bits - 1. |
| 2297 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2298 | } |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2299 | } else if (instr->IsMin() || instr->IsMax()) { |
| 2300 | __ Cmp(lhs, rhs); |
| 2301 | __ Csel(dst, lhs, rhs, instr->IsMin() ? lt : gt); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2302 | } else { |
| 2303 | DCHECK(instr->IsXor()); |
| 2304 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2305 | } |
| 2306 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2307 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2308 | case DataType::Type::kFloat32: |
| 2309 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 2310 | VRegister dst = OutputFPRegister(instr); |
| 2311 | VRegister lhs = InputFPRegisterAt(instr, 0); |
| 2312 | VRegister rhs = InputFPRegisterAt(instr, 1); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2313 | if (instr->IsAdd()) { |
| 2314 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2315 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2316 | __ Fsub(dst, lhs, rhs); |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2317 | } else if (instr->IsMin()) { |
| 2318 | __ Fmin(dst, lhs, rhs); |
| 2319 | } else if (instr->IsMax()) { |
| 2320 | __ Fmax(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2321 | } else { |
| 2322 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2323 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2324 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2325 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2326 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2327 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2328 | } |
| 2329 | } |
| 2330 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2331 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2332 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2333 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2334 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2335 | DataType::Type type = instr->GetResultType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2336 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2337 | case DataType::Type::kInt32: |
| 2338 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2339 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2340 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2341 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2342 | break; |
| 2343 | } |
| 2344 | default: |
| 2345 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2346 | } |
| 2347 | } |
| 2348 | |
| 2349 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2350 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2351 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2352 | DataType::Type type = instr->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2353 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2354 | case DataType::Type::kInt32: |
| 2355 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2356 | Register dst = OutputRegister(instr); |
| 2357 | Register lhs = InputRegisterAt(instr, 0); |
| 2358 | Operand rhs = InputOperandAt(instr, 1); |
| 2359 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2360 | uint32_t shift_value = rhs.GetImmediate() & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2361 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2362 | if (instr->IsShl()) { |
| 2363 | __ Lsl(dst, lhs, shift_value); |
| 2364 | } else if (instr->IsShr()) { |
| 2365 | __ Asr(dst, lhs, shift_value); |
| 2366 | } else { |
| 2367 | __ Lsr(dst, lhs, shift_value); |
| 2368 | } |
| 2369 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2370 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2371 | |
| 2372 | if (instr->IsShl()) { |
| 2373 | __ Lsl(dst, lhs, rhs_reg); |
| 2374 | } else if (instr->IsShr()) { |
| 2375 | __ Asr(dst, lhs, rhs_reg); |
| 2376 | } else { |
| 2377 | __ Lsr(dst, lhs, rhs_reg); |
| 2378 | } |
| 2379 | } |
| 2380 | break; |
| 2381 | } |
| 2382 | default: |
| 2383 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2384 | } |
| 2385 | } |
| 2386 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2387 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2388 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2392 | HandleBinaryOp(instruction); |
| 2393 | } |
| 2394 | |
| 2395 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2396 | HandleBinaryOp(instruction); |
| 2397 | } |
| 2398 | |
| 2399 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2400 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2401 | } |
| 2402 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2403 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2404 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2405 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2406 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2407 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2408 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2409 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2410 | } |
| 2411 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2412 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2413 | Register dst = OutputRegister(instr); |
| 2414 | Register lhs = InputRegisterAt(instr, 0); |
| 2415 | Register rhs = InputRegisterAt(instr, 1); |
| 2416 | |
| 2417 | switch (instr->GetOpKind()) { |
| 2418 | case HInstruction::kAnd: |
| 2419 | __ Bic(dst, lhs, rhs); |
| 2420 | break; |
| 2421 | case HInstruction::kOr: |
| 2422 | __ Orn(dst, lhs, rhs); |
| 2423 | break; |
| 2424 | case HInstruction::kXor: |
| 2425 | __ Eon(dst, lhs, rhs); |
| 2426 | break; |
| 2427 | default: |
| 2428 | LOG(FATAL) << "Unreachable"; |
| 2429 | } |
| 2430 | } |
| 2431 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2432 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2433 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2434 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2435 | instruction->GetType() == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2436 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2437 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2438 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2439 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2440 | } else { |
| 2441 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2442 | } |
| 2443 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2444 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2445 | } |
| 2446 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2447 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2448 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2449 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2450 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2451 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2452 | Register out = OutputRegister(instruction); |
| 2453 | Register left; |
| 2454 | if (kind != HInstruction::kNeg) { |
| 2455 | left = InputRegisterAt(instruction, 0); |
| 2456 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2457 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2458 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2459 | // conversion) can have a different type from the current instruction's type, |
| 2460 | // so we manually indicate the type. |
| 2461 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2462 | Operand right_operand(0); |
| 2463 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2464 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2465 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2466 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2467 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2468 | right_operand = Operand(right_reg, |
| 2469 | helpers::ShiftFromOpKind(op_kind), |
| 2470 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | // Logical binary operations do not support extension operations in the |
| 2474 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2475 | // the extension as a separate instruction. |
| 2476 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
Santiago Aboy Solanes | 872ec72 | 2022-02-18 14:10:25 +0000 | [diff] [blame] | 2477 | DCHECK_IMPLIES(right_operand.IsExtendedRegister(), |
| 2478 | kind != HInstruction::kAnd && kind != HInstruction::kOr && |
| 2479 | kind != HInstruction::kXor && kind != HInstruction::kNeg); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2480 | switch (kind) { |
| 2481 | case HInstruction::kAdd: |
| 2482 | __ Add(out, left, right_operand); |
| 2483 | break; |
| 2484 | case HInstruction::kAnd: |
| 2485 | __ And(out, left, right_operand); |
| 2486 | break; |
| 2487 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2488 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2489 | __ Neg(out, right_operand); |
| 2490 | break; |
| 2491 | case HInstruction::kOr: |
| 2492 | __ Orr(out, left, right_operand); |
| 2493 | break; |
| 2494 | case HInstruction::kSub: |
| 2495 | __ Sub(out, left, right_operand); |
| 2496 | break; |
| 2497 | case HInstruction::kXor: |
| 2498 | __ Eor(out, left, right_operand); |
| 2499 | break; |
| 2500 | default: |
| 2501 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2502 | UNREACHABLE(); |
| 2503 | } |
| 2504 | } |
| 2505 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2506 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2507 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2508 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2509 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2510 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2511 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2512 | } |
| 2513 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2514 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2515 | __ Add(OutputRegister(instruction), |
| 2516 | InputRegisterAt(instruction, 0), |
| 2517 | Operand(InputOperandAt(instruction, 1))); |
| 2518 | } |
| 2519 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2520 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2521 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2522 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2523 | |
| 2524 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2525 | |
| 2526 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2527 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2528 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2529 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2530 | // loop. |
| 2531 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2532 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2533 | : Location::RequiresRegister()); |
| 2534 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2535 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2536 | } |
| 2537 | |
| 2538 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2539 | HIntermediateAddressIndex* instruction) { |
| 2540 | Register index_reg = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2541 | uint32_t shift = Int64FromLocation(instruction->GetLocations()->InAt(2)); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2542 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2543 | |
| 2544 | if (shift == 0) { |
| 2545 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2546 | } else { |
| 2547 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2548 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2549 | } |
| 2550 | } |
| 2551 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2552 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2553 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2554 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2555 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2556 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2557 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2558 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2559 | // Don't allocate register for Mneg instruction. |
| 2560 | } else { |
| 2561 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2562 | Location::RequiresRegister()); |
| 2563 | } |
| 2564 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2565 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2566 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2567 | } |
| 2568 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2569 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2570 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2571 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2572 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2573 | |
| 2574 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2575 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2576 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2577 | if (instr->GetType() == DataType::Type::kInt64 && |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2578 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2579 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Florian Mayer | 6f572b7 | 2022-01-10 13:03:57 -0800 | [diff] [blame] | 2580 | ptrdiff_t off = masm->GetCursorOffset(); |
| 2581 | if (off >= static_cast<ptrdiff_t>(kInstructionSize) && |
| 2582 | masm->GetInstructionAt(off - static_cast<ptrdiff_t>(kInstructionSize))->IsLoadOrStore()) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2583 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2584 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2585 | __ nop(); |
| 2586 | } |
| 2587 | } |
| 2588 | |
| 2589 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2590 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2591 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2592 | } else { |
| 2593 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2594 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2595 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2596 | __ Mneg(res, mul_left, mul_right); |
| 2597 | } else { |
| 2598 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2599 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2600 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2601 | } |
| 2602 | } |
| 2603 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2604 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2605 | bool object_array_get_with_read_barrier = |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2606 | gUseReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2607 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2608 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2609 | object_array_get_with_read_barrier |
| 2610 | ? LocationSummary::kCallOnSlowPath |
| 2611 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2612 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2613 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2614 | if (instruction->GetIndex()->IsConstant()) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2615 | // Array loads with constant index are treated as field loads. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2616 | // We need a temporary register for the read barrier load in |
| 2617 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2618 | // only if the offset is too big. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2619 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2620 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2621 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2622 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2623 | locations->AddTemp(FixedTempLocation()); |
| 2624 | } |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2625 | } else if (!instruction->GetArray()->IsIntermediateAddress()) { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2626 | // We need a non-scratch temporary for the array data pointer in |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2627 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier() for the case with no |
| 2628 | // intermediate address. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2629 | locations->AddTemp(Location::RequiresRegister()); |
| 2630 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2631 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2632 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2633 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2634 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2635 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2636 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2637 | // The output overlaps in the case of an object array get with |
| 2638 | // read barriers enabled: we do not want the move to overwrite the |
| 2639 | // array's location, as we need it to emit the read barrier. |
| 2640 | locations->SetOut( |
| 2641 | Location::RequiresRegister(), |
| 2642 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2643 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2647 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2648 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2649 | LocationSummary* locations = instruction->GetLocations(); |
| 2650 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2651 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2652 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2653 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2654 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2655 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2656 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2657 | |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2658 | // The non-Baker read barrier instrumentation of object ArrayGet instructions |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2659 | // does not support the HIntermediateAddress instruction. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2660 | DCHECK(!((type == DataType::Type::kReference) && |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2661 | instruction->GetArray()->IsIntermediateAddress() && |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2662 | gUseReadBarrier && |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2663 | !kUseBakerReadBarrier)); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2664 | |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2665 | if (type == DataType::Type::kReference && gUseReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2666 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2667 | // Note that a potential implicit null check is handled in the |
| 2668 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2669 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2670 | if (index.IsConstant()) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2671 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2672 | // 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] | 2673 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2674 | Location maybe_temp = |
| 2675 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2676 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2677 | out, |
| 2678 | obj.W(), |
| 2679 | offset, |
| 2680 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2681 | /* needs_null_check= */ false, |
| 2682 | /* use_load_acquire= */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2683 | } else { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2684 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2685 | instruction, out, obj.W(), offset, index, /* needs_null_check= */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2686 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2687 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2688 | // General case. |
| 2689 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2690 | Register length; |
| 2691 | if (maybe_compressed_char_at) { |
| 2692 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2693 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2694 | { |
| 2695 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2696 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2697 | |
| 2698 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2699 | DCHECK_LT(count_offset, offset); |
| 2700 | int64_t adjusted_offset = |
| 2701 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2702 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2703 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2704 | } else { |
| 2705 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2706 | } |
| 2707 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2708 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2709 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2710 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2711 | if (maybe_compressed_char_at) { |
| 2712 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2713 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2714 | "Expecting 0=compressed, 1=uncompressed"); |
| 2715 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2716 | __ Ldrb(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2717 | HeapOperand(obj, offset + Int64FromLocation(index))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2718 | __ B(&done); |
| 2719 | __ Bind(&uncompressed_load); |
| 2720 | __ Ldrh(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2721 | HeapOperand(obj, offset + (Int64FromLocation(index) << 1))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2722 | __ Bind(&done); |
| 2723 | } else { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2724 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2725 | source = HeapOperand(obj, offset); |
| 2726 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2727 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2728 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2729 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2730 | // We do not need to compute the intermediate address from the array: the |
| 2731 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2732 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2733 | if (kIsDebugBuild) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2734 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2735 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2736 | } |
| 2737 | temp = obj; |
| 2738 | } else { |
| 2739 | __ Add(temp, obj, offset); |
| 2740 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2741 | if (maybe_compressed_char_at) { |
| 2742 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2743 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2744 | "Expecting 0=compressed, 1=uncompressed"); |
| 2745 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2746 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2747 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2748 | __ B(&done); |
| 2749 | __ Bind(&uncompressed_load); |
| 2750 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2751 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2752 | __ Bind(&done); |
| 2753 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2754 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2755 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2756 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2757 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2758 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2759 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2760 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2761 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2762 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2763 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2764 | if (type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2765 | static_assert( |
| 2766 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2767 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2768 | Location obj_loc = locations->InAt(0); |
| 2769 | if (index.IsConstant()) { |
| 2770 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2771 | } else { |
| 2772 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2773 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2774 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2775 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2776 | } |
| 2777 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2778 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2779 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2780 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2781 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2782 | } |
| 2783 | |
| 2784 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2785 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2786 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2787 | { |
| 2788 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2789 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2790 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2791 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2792 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2793 | // Mask out compression flag from String's array length. |
| 2794 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2795 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2796 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2797 | } |
| 2798 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2799 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2800 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2801 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2802 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2803 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2804 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2805 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2806 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2807 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2808 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2809 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2810 | } else if (DataType::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2811 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2812 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2813 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2818 | DataType::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2819 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2820 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2821 | bool needs_write_barrier = |
| 2822 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2823 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2824 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2825 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2826 | CPURegister source = value; |
| 2827 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2828 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2829 | MemOperand destination = HeapOperand(array); |
| 2830 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2831 | |
| 2832 | if (!needs_write_barrier) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2833 | DCHECK(!needs_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2834 | if (index.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2835 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2836 | destination = HeapOperand(array, offset); |
| 2837 | } else { |
| 2838 | UseScratchRegisterScope temps(masm); |
| 2839 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2840 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2841 | // We do not need to compute the intermediate address from the array: the |
| 2842 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2843 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2844 | if (kIsDebugBuild) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2845 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2846 | DCHECK(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2847 | } |
| 2848 | temp = array; |
| 2849 | } else { |
| 2850 | __ Add(temp, array, offset); |
| 2851 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2852 | destination = HeapOperand(temp, |
| 2853 | XRegisterFrom(index), |
| 2854 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2855 | DataType::SizeShift(value_type)); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2856 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2857 | { |
| 2858 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2859 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2860 | codegen_->Store(value_type, value, destination); |
| 2861 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2862 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2863 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2864 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2865 | |
| 2866 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 2867 | vixl::aarch64::Label do_store; |
| 2868 | if (can_value_be_null) { |
| 2869 | __ Cbz(Register(value), &do_store); |
| 2870 | } |
| 2871 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2872 | SlowPathCodeARM64* slow_path = nullptr; |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2873 | if (needs_type_check) { |
| 2874 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
| 2875 | codegen_->AddSlowPath(slow_path); |
| 2876 | |
| 2877 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2878 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2879 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2880 | |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2881 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2882 | Register temp = temps.AcquireSameSizeAs(array); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2883 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2884 | |
| 2885 | // Note that when Baker read barriers are enabled, the type |
| 2886 | // checks are performed without read barriers. This is fine, |
| 2887 | // even in the case where a class object is in the from-space |
| 2888 | // after the flip, as a comparison involving such a type would |
| 2889 | // not produce a false positive; it may of course produce a |
| 2890 | // false negative, in which case we would take the ArraySet |
| 2891 | // slow path. |
| 2892 | |
| 2893 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2894 | { |
| 2895 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2896 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2897 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2898 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2899 | } |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2900 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2901 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2902 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2903 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2904 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2905 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2906 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2907 | // nor `temp2`, as we are comparing two poisoned references. |
| 2908 | __ Cmp(temp, temp2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2909 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2910 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2911 | vixl::aarch64::Label do_put; |
| 2912 | __ B(eq, &do_put); |
| 2913 | // If heap poisoning is enabled, the `temp` reference has |
| 2914 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2915 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2916 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2917 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2918 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2919 | // If heap poisoning is enabled, no need to unpoison |
| 2920 | // `temp`, as we are comparing against null below. |
| 2921 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2922 | __ Bind(&do_put); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 2923 | } else { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2924 | __ B(ne, slow_path->GetEntryLabel()); |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2925 | } |
| 2926 | } |
| 2927 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2928 | codegen_->MarkGCCard(array, value.W(), /* value_can_be_null= */ false); |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2929 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2930 | if (can_value_be_null) { |
| 2931 | DCHECK(do_store.IsLinked()); |
| 2932 | __ Bind(&do_store); |
| 2933 | } |
| 2934 | |
| 2935 | UseScratchRegisterScope temps(masm); |
| 2936 | if (kPoisonHeapReferences) { |
| 2937 | Register temp_source = temps.AcquireSameSizeAs(array); |
| 2938 | DCHECK(value.IsW()); |
| 2939 | __ Mov(temp_source, value.W()); |
| 2940 | GetAssembler()->PoisonHeapReference(temp_source); |
| 2941 | source = temp_source; |
| 2942 | } |
| 2943 | |
| 2944 | if (index.IsConstant()) { |
| 2945 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
| 2946 | destination = HeapOperand(array, offset); |
| 2947 | } else { |
| 2948 | Register temp_base = temps.AcquireSameSizeAs(array); |
| 2949 | __ Add(temp_base, array, offset); |
| 2950 | destination = HeapOperand(temp_base, |
| 2951 | XRegisterFrom(index), |
| 2952 | LSL, |
| 2953 | DataType::SizeShift(value_type)); |
| 2954 | } |
| 2955 | |
| 2956 | { |
| 2957 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2958 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2959 | __ Str(source, destination); |
| 2960 | |
| 2961 | if (can_value_be_null || !needs_type_check) { |
| 2962 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2963 | } |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | if (slow_path != nullptr) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2967 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2968 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2969 | } |
| 2970 | } |
| 2971 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2972 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2973 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2974 | InvokeRuntimeCallingConvention calling_convention; |
| 2975 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 2976 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 2977 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2978 | |
| 2979 | // If both index and length are constant, we can check the bounds statically and |
| 2980 | // generate code accordingly. We want to make sure we generate constant locations |
| 2981 | // in that case, regardless of whether they are encodable in the comparison or not. |
| 2982 | HInstruction* index = instruction->InputAt(0); |
| 2983 | HInstruction* length = instruction->InputAt(1); |
| 2984 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 2985 | locations->SetInAt(0, both_const |
| 2986 | ? Location::ConstantLocation(index->AsConstant()) |
| 2987 | : ARM64EncodableConstantOrRegister(index, instruction)); |
| 2988 | locations->SetInAt(1, both_const |
| 2989 | ? Location::ConstantLocation(length->AsConstant()) |
| 2990 | : ARM64EncodableConstantOrRegister(length, instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2991 | } |
| 2992 | |
| 2993 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2994 | LocationSummary* locations = instruction->GetLocations(); |
| 2995 | Location index_loc = locations->InAt(0); |
| 2996 | Location length_loc = locations->InAt(1); |
| 2997 | |
| 2998 | int cmp_first_input = 0; |
| 2999 | int cmp_second_input = 1; |
| 3000 | Condition cond = hs; |
| 3001 | |
| 3002 | if (index_loc.IsConstant()) { |
| 3003 | int64_t index = Int64FromLocation(index_loc); |
| 3004 | if (length_loc.IsConstant()) { |
| 3005 | int64_t length = Int64FromLocation(length_loc); |
| 3006 | if (index < 0 || index >= length) { |
| 3007 | BoundsCheckSlowPathARM64* slow_path = |
| 3008 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
| 3009 | codegen_->AddSlowPath(slow_path); |
| 3010 | __ B(slow_path->GetEntryLabel()); |
| 3011 | } else { |
| 3012 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 3013 | // However, some optimization after BCE may have generated this, and we should not |
| 3014 | // generate a bounds check if it is a valid range. |
| 3015 | } |
| 3016 | return; |
| 3017 | } |
| 3018 | // Only the index is constant: change the order of the operands and commute the condition |
| 3019 | // so we can use an immediate constant for the index (only the second input to a cmp |
| 3020 | // instruction can be an immediate). |
| 3021 | cmp_first_input = 1; |
| 3022 | cmp_second_input = 0; |
| 3023 | cond = ls; |
| 3024 | } |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3025 | BoundsCheckSlowPathARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3026 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 3027 | __ Cmp(InputRegisterAt(instruction, cmp_first_input), |
| 3028 | InputOperandAt(instruction, cmp_second_input)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3029 | codegen_->AddSlowPath(slow_path); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 3030 | __ B(slow_path->GetEntryLabel(), cond); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3031 | } |
| 3032 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3033 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3034 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3035 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3036 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3037 | if (check->HasUses()) { |
| 3038 | locations->SetOut(Location::SameAsFirstInput()); |
| 3039 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 3040 | // Rely on the type initialization to save everything we need. |
| 3041 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3042 | } |
| 3043 | |
| 3044 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3045 | // We assume the class is not null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 3046 | SlowPathCodeARM64* slow_path = |
| 3047 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(check->GetLoadClass(), check); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3048 | codegen_->AddSlowPath(slow_path); |
| 3049 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3050 | } |
| 3051 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3052 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3053 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3054 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3055 | } |
| 3056 | |
| 3057 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 3058 | VRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3059 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3060 | if (rhs_loc.IsConstant()) { |
| 3061 | // 0.0 is the only immediate that can be encoded directly in |
| 3062 | // an FCMP instruction. |
| 3063 | // |
| 3064 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3065 | // specify that in a floating-point comparison, positive zero |
| 3066 | // and negative zero are considered equal, so we can use the |
| 3067 | // literal 0.0 for both cases here. |
| 3068 | // |
| 3069 | // Note however that some methods (Float.equal, Float.compare, |
| 3070 | // Float.compareTo, Double.equal, Double.compare, |
| 3071 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3072 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3073 | // -0.0. So if we ever translate calls to these methods into a |
| 3074 | // HCompare instruction, we must handle the -0.0 case with |
| 3075 | // care here. |
| 3076 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3077 | __ Fcmp(lhs_reg, 0.0); |
| 3078 | } else { |
| 3079 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3080 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3081 | } |
| 3082 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3083 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3084 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3085 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3086 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3087 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3088 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3089 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3090 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3091 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3092 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3093 | case DataType::Type::kInt32: |
| 3094 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3095 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3096 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3097 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3098 | break; |
| 3099 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3100 | case DataType::Type::kFloat32: |
| 3101 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3102 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3103 | locations->SetInAt(1, |
| 3104 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3105 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3106 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3107 | locations->SetOut(Location::RequiresRegister()); |
| 3108 | break; |
| 3109 | } |
| 3110 | default: |
| 3111 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3116 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3117 | |
| 3118 | // 0 if: left == right |
| 3119 | // 1 if: left > right |
| 3120 | // -1 if: left < right |
| 3121 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3122 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3123 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3124 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3125 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3126 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3127 | case DataType::Type::kInt32: |
| 3128 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3129 | Register result = OutputRegister(compare); |
| 3130 | Register left = InputRegisterAt(compare, 0); |
| 3131 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3132 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3133 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3134 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3135 | break; |
| 3136 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3137 | case DataType::Type::kFloat32: |
| 3138 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3139 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3140 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3141 | __ Cset(result, ne); |
| 3142 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3143 | break; |
| 3144 | } |
| 3145 | default: |
| 3146 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3147 | } |
| 3148 | } |
| 3149 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3150 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3151 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3152 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3153 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3154 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3155 | locations->SetInAt(1, |
| 3156 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3157 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3158 | : Location::RequiresFpuRegister()); |
| 3159 | } else { |
| 3160 | // Integer cases. |
| 3161 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3162 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3163 | } |
| 3164 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3165 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3166 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3167 | } |
| 3168 | } |
| 3169 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3170 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3171 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3172 | return; |
| 3173 | } |
| 3174 | |
| 3175 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3176 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3177 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3178 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3179 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3180 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3181 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3182 | } else { |
| 3183 | // Integer cases. |
| 3184 | Register lhs = InputRegisterAt(instruction, 0); |
| 3185 | Operand rhs = InputOperandAt(instruction, 1); |
| 3186 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3187 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3188 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3192 | M(Equal) \ |
| 3193 | M(NotEqual) \ |
| 3194 | M(LessThan) \ |
| 3195 | M(LessThanOrEqual) \ |
| 3196 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3197 | M(GreaterThanOrEqual) \ |
| 3198 | M(Below) \ |
| 3199 | M(BelowOrEqual) \ |
| 3200 | M(Above) \ |
| 3201 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3202 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3203 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3204 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3205 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3206 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3207 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3208 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3209 | void InstructionCodeGeneratorARM64::GenerateIntDivForPower2Denom(HDiv* instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3210 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3211 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3212 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 3213 | |
| 3214 | Register out = OutputRegister(instruction); |
| 3215 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3216 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3217 | Register final_dividend; |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3218 | if (HasNonNegativeOrMinIntInputAt(instruction, 0)) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3219 | // No need to adjust the result for non-negative dividends or the INT32_MIN/INT64_MIN dividends. |
| 3220 | // NOTE: The generated code for HDiv correctly works for the INT32_MIN/INT64_MIN dividends: |
| 3221 | // imm == 2 |
| 3222 | // add out, dividend(0x80000000), dividend(0x80000000), lsr #31 => out = 0x80000001 |
| 3223 | // asr out, out(0x80000001), #1 => out = 0xc0000000 |
| 3224 | // This is the same as 'asr out, 0x80000000, #1' |
| 3225 | // |
| 3226 | // imm > 2 |
| 3227 | // add temp, dividend(0x80000000), imm - 1 => temp = 0b10..01..1, where the number |
| 3228 | // of the rightmost 1s is ctz_imm. |
| 3229 | // cmp dividend(0x80000000), 0 => N = 1, V = 0 (lt is true) |
| 3230 | // csel out, temp(0b10..01..1), dividend(0x80000000), lt => out = 0b10..01..1 |
| 3231 | // asr out, out(0b10..01..1), #ctz_imm => out = 0b1..10..0, where the number of the |
| 3232 | // leftmost 1s is ctz_imm + 1. |
| 3233 | // This is the same as 'asr out, dividend(0x80000000), #ctz_imm'. |
| 3234 | // |
| 3235 | // imm == INT32_MIN |
| 3236 | // add tmp, dividend(0x80000000), #0x7fffffff => tmp = -1 |
| 3237 | // cmp dividend(0x80000000), 0 => N = 1, V = 0 (lt is true) |
| 3238 | // csel out, temp(-1), dividend(0x80000000), lt => out = -1 |
| 3239 | // neg out, out(-1), asr #31 => out = 1 |
| 3240 | // This is the same as 'neg out, dividend(0x80000000), asr #31'. |
| 3241 | final_dividend = dividend; |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3242 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3243 | if (abs_imm == 2) { |
| 3244 | int bits = DataType::Size(instruction->GetResultType()) * kBitsPerByte; |
| 3245 | __ Add(out, dividend, Operand(dividend, LSR, bits - 1)); |
| 3246 | } else { |
| 3247 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3248 | Register temp = temps.AcquireSameSizeAs(out); |
| 3249 | __ Add(temp, dividend, abs_imm - 1); |
| 3250 | __ Cmp(dividend, 0); |
| 3251 | __ Csel(out, temp, dividend, lt); |
| 3252 | } |
| 3253 | final_dividend = out; |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3254 | } |
| 3255 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3256 | int ctz_imm = CTZ(abs_imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3257 | if (imm > 0) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3258 | __ Asr(out, final_dividend, ctz_imm); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3259 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3260 | __ Neg(out, Operand(final_dividend, ASR, ctz_imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3261 | } |
| 3262 | } |
| 3263 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3264 | // Return true if the magic number was modified by subtracting 2^32(Int32 div) or 2^64(Int64 div). |
| 3265 | // So dividend needs to be added. |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3266 | static inline bool NeedToAddDividend(int64_t magic_number, int64_t divisor) { |
| 3267 | return divisor > 0 && magic_number < 0; |
| 3268 | } |
| 3269 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3270 | // Return true if the magic number was modified by adding 2^32(Int32 div) or 2^64(Int64 div). |
| 3271 | // So dividend needs to be subtracted. |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3272 | static inline bool NeedToSubDividend(int64_t magic_number, int64_t divisor) { |
| 3273 | return divisor < 0 && magic_number > 0; |
| 3274 | } |
| 3275 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3276 | // Generate code which increments the value in register 'in' by 1 if the value is negative. |
| 3277 | // It is done with 'add out, in, in, lsr #31 or #63'. |
| 3278 | // If the value is a result of an operation setting the N flag, CINC MI can be used |
| 3279 | // instead of ADD. 'use_cond_inc' controls this. |
| 3280 | void InstructionCodeGeneratorARM64::GenerateIncrementNegativeByOne( |
| 3281 | Register out, |
| 3282 | Register in, |
| 3283 | bool use_cond_inc) { |
| 3284 | if (use_cond_inc) { |
| 3285 | __ Cinc(out, in, mi); |
| 3286 | } else { |
| 3287 | __ Add(out, in, Operand(in, LSR, in.GetSizeInBits() - 1)); |
| 3288 | } |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3289 | } |
| 3290 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3291 | // Helper to generate code producing the result of HRem with a constant divisor. |
| 3292 | void InstructionCodeGeneratorARM64::GenerateResultRemWithAnyConstant( |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3293 | Register out, |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3294 | Register dividend, |
| 3295 | Register quotient, |
| 3296 | int64_t divisor, |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3297 | UseScratchRegisterScope* temps_scope) { |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3298 | Register temp_imm = temps_scope->AcquireSameSizeAs(out); |
| 3299 | __ Mov(temp_imm, divisor); |
| 3300 | __ Msub(out, quotient, temp_imm, dividend); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3301 | } |
| 3302 | |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3303 | // Helper to generate code for HDiv/HRem instructions when a dividend is non-negative and |
| 3304 | // a divisor is a positive constant, not power of 2. |
| 3305 | void InstructionCodeGeneratorARM64::GenerateInt64UnsignedDivRemWithAnyPositiveConstant( |
| 3306 | HBinaryOperation* instruction) { |
| 3307 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3308 | DCHECK(instruction->GetResultType() == DataType::Type::kInt64); |
| 3309 | |
| 3310 | LocationSummary* locations = instruction->GetLocations(); |
| 3311 | Location second = locations->InAt(1); |
| 3312 | DCHECK(second.IsConstant()); |
| 3313 | |
| 3314 | Register out = OutputRegister(instruction); |
| 3315 | Register dividend = InputRegisterAt(instruction, 0); |
| 3316 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3317 | DCHECK_GT(imm, 0); |
| 3318 | |
| 3319 | int64_t magic; |
| 3320 | int shift; |
| 3321 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ true, &magic, &shift); |
| 3322 | |
| 3323 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3324 | Register temp = temps.AcquireSameSizeAs(out); |
| 3325 | |
| 3326 | auto generate_unsigned_div_code = [this, magic, shift](Register out, |
| 3327 | Register dividend, |
| 3328 | Register temp) { |
| 3329 | // temp = get_high(dividend * magic) |
| 3330 | __ Mov(temp, magic); |
| 3331 | if (magic > 0 && shift == 0) { |
| 3332 | __ Smulh(out, dividend, temp); |
| 3333 | } else { |
| 3334 | __ Smulh(temp, dividend, temp); |
| 3335 | if (magic < 0) { |
| 3336 | // The negative magic means that the multiplier m is greater than INT64_MAX. |
| 3337 | // In such a case shift is never 0. See the proof in |
| 3338 | // InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant. |
| 3339 | __ Add(temp, temp, dividend); |
| 3340 | } |
| 3341 | DCHECK_NE(shift, 0); |
| 3342 | __ Lsr(out, temp, shift); |
| 3343 | } |
| 3344 | }; |
| 3345 | |
| 3346 | if (instruction->IsDiv()) { |
| 3347 | generate_unsigned_div_code(out, dividend, temp); |
| 3348 | } else { |
| 3349 | generate_unsigned_div_code(temp, dividend, temp); |
| 3350 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3351 | } |
| 3352 | } |
| 3353 | |
| 3354 | // Helper to generate code for HDiv/HRem instructions for any dividend and a constant divisor |
| 3355 | // (not power of 2). |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3356 | void InstructionCodeGeneratorARM64::GenerateInt64DivRemWithAnyConstant( |
| 3357 | HBinaryOperation* instruction) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3358 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3359 | DCHECK(instruction->GetResultType() == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3360 | |
| 3361 | LocationSummary* locations = instruction->GetLocations(); |
| 3362 | Location second = locations->InAt(1); |
| 3363 | DCHECK(second.IsConstant()); |
| 3364 | |
| 3365 | Register out = OutputRegister(instruction); |
| 3366 | Register dividend = InputRegisterAt(instruction, 0); |
| 3367 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3368 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3369 | int64_t magic; |
| 3370 | int shift; |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3371 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ true, &magic, &shift); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3372 | |
| 3373 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3374 | Register temp = temps.AcquireSameSizeAs(out); |
| 3375 | |
| 3376 | // temp = get_high(dividend * magic) |
| 3377 | __ Mov(temp, magic); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3378 | __ Smulh(temp, dividend, temp); |
| 3379 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3380 | // The multiplication result might need some corrections to be finalized. |
| 3381 | // The last correction is to increment by 1, if the result is negative. |
| 3382 | // Currently it is done with 'add result, temp_result, temp_result, lsr #31 or #63'. |
| 3383 | // Such ADD usually has latency 2, e.g. on Cortex-A55. |
| 3384 | // However if one of the corrections is ADD or SUB, the sign can be detected |
| 3385 | // with ADDS/SUBS. They set the N flag if the result is negative. |
| 3386 | // This allows to use CINC MI which has latency 1. |
| 3387 | bool use_cond_inc = false; |
| 3388 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3389 | // Some combinations of magic_number and the divisor require to correct the result. |
| 3390 | // Check whether the correction is needed. |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3391 | if (NeedToAddDividend(magic, imm)) { |
| 3392 | __ Adds(temp, temp, dividend); |
| 3393 | use_cond_inc = true; |
| 3394 | } else if (NeedToSubDividend(magic, imm)) { |
| 3395 | __ Subs(temp, temp, dividend); |
| 3396 | use_cond_inc = true; |
| 3397 | } |
| 3398 | |
| 3399 | if (shift != 0) { |
| 3400 | __ Asr(temp, temp, shift); |
| 3401 | } |
| 3402 | |
| 3403 | if (instruction->IsRem()) { |
| 3404 | GenerateIncrementNegativeByOne(temp, temp, use_cond_inc); |
| 3405 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3406 | } else { |
| 3407 | GenerateIncrementNegativeByOne(out, temp, use_cond_inc); |
| 3408 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3409 | } |
| 3410 | |
| 3411 | void InstructionCodeGeneratorARM64::GenerateInt32DivRemWithAnyConstant( |
| 3412 | HBinaryOperation* instruction) { |
| 3413 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3414 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 3415 | |
| 3416 | LocationSummary* locations = instruction->GetLocations(); |
| 3417 | Location second = locations->InAt(1); |
| 3418 | DCHECK(second.IsConstant()); |
| 3419 | |
| 3420 | Register out = OutputRegister(instruction); |
| 3421 | Register dividend = InputRegisterAt(instruction, 0); |
| 3422 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3423 | |
| 3424 | int64_t magic; |
| 3425 | int shift; |
| 3426 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| 3427 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3428 | Register temp = temps.AcquireSameSizeAs(out); |
| 3429 | |
| 3430 | // temp = get_high(dividend * magic) |
| 3431 | __ Mov(temp, magic); |
| 3432 | __ Smull(temp.X(), dividend, temp); |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3433 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3434 | // The multiplication result might need some corrections to be finalized. |
| 3435 | // The last correction is to increment by 1, if the result is negative. |
| 3436 | // Currently it is done with 'add result, temp_result, temp_result, lsr #31 or #63'. |
| 3437 | // Such ADD usually has latency 2, e.g. on Cortex-A55. |
| 3438 | // However if one of the corrections is ADD or SUB, the sign can be detected |
| 3439 | // with ADDS/SUBS. They set the N flag if the result is negative. |
| 3440 | // This allows to use CINC MI which has latency 1. |
| 3441 | bool use_cond_inc = false; |
| 3442 | |
| 3443 | // ADD/SUB correction is performed in the high 32 bits |
| 3444 | // as high 32 bits are ignored because type are kInt32. |
| 3445 | if (NeedToAddDividend(magic, imm)) { |
| 3446 | __ Adds(temp.X(), temp.X(), Operand(dividend.X(), LSL, 32)); |
| 3447 | use_cond_inc = true; |
| 3448 | } else if (NeedToSubDividend(magic, imm)) { |
| 3449 | __ Subs(temp.X(), temp.X(), Operand(dividend.X(), LSL, 32)); |
| 3450 | use_cond_inc = true; |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3451 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3452 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3453 | // Extract the result from the high 32 bits and apply the final right shift. |
| 3454 | DCHECK_LT(shift, 32); |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3455 | if (imm > 0 && HasNonNegativeInputAt(instruction, 0)) { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 3456 | // No need to adjust the result for a non-negative dividend and a positive divisor. |
| 3457 | if (instruction->IsDiv()) { |
| 3458 | __ Lsr(out.X(), temp.X(), 32 + shift); |
| 3459 | } else { |
| 3460 | __ Lsr(temp.X(), temp.X(), 32 + shift); |
| 3461 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3462 | } |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3463 | } else { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 3464 | __ Asr(temp.X(), temp.X(), 32 + shift); |
| 3465 | |
| 3466 | if (instruction->IsRem()) { |
| 3467 | GenerateIncrementNegativeByOne(temp, temp, use_cond_inc); |
| 3468 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3469 | } else { |
| 3470 | GenerateIncrementNegativeByOne(out, temp, use_cond_inc); |
| 3471 | } |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3472 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3473 | } |
| 3474 | |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3475 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction, |
| 3476 | int64_t divisor) { |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3477 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3478 | if (instruction->GetResultType() == DataType::Type::kInt64) { |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3479 | if (divisor > 0 && HasNonNegativeInputAt(instruction, 0)) { |
| 3480 | GenerateInt64UnsignedDivRemWithAnyPositiveConstant(instruction); |
| 3481 | } else { |
| 3482 | GenerateInt64DivRemWithAnyConstant(instruction); |
| 3483 | } |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3484 | } else { |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3485 | GenerateInt32DivRemWithAnyConstant(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3486 | } |
| 3487 | } |
| 3488 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3489 | void InstructionCodeGeneratorARM64::GenerateIntDivForConstDenom(HDiv *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3490 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3491 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3492 | if (imm == 0) { |
| 3493 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3494 | return; |
| 3495 | } |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3496 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3497 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3498 | GenerateIntDivForPower2Denom(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3499 | } else { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3500 | // Cases imm == -1 or imm == 1 are handled by InstructionSimplifier. |
| 3501 | DCHECK(imm < -2 || imm > 2) << imm; |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3502 | GenerateDivRemWithAnyConstant(instruction, imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3503 | } |
| 3504 | } |
| 3505 | |
| 3506 | void InstructionCodeGeneratorARM64::GenerateIntDiv(HDiv *instruction) { |
| 3507 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 3508 | << instruction->GetResultType(); |
| 3509 | |
| 3510 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 3511 | GenerateIntDivForConstDenom(instruction); |
| 3512 | } else { |
| 3513 | Register out = OutputRegister(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3514 | Register dividend = InputRegisterAt(instruction, 0); |
| 3515 | Register divisor = InputRegisterAt(instruction, 1); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3516 | __ Sdiv(out, dividend, divisor); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3517 | } |
| 3518 | } |
| 3519 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3520 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3521 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3522 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3523 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3524 | case DataType::Type::kInt32: |
| 3525 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3526 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3527 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3528 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3529 | break; |
| 3530 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3531 | case DataType::Type::kFloat32: |
| 3532 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3533 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3534 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3535 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3536 | break; |
| 3537 | |
| 3538 | default: |
| 3539 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3540 | } |
| 3541 | } |
| 3542 | |
| 3543 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3544 | DataType::Type type = div->GetResultType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3545 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3546 | case DataType::Type::kInt32: |
| 3547 | case DataType::Type::kInt64: |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3548 | GenerateIntDiv(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 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 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3554 | break; |
| 3555 | |
| 3556 | default: |
| 3557 | LOG(FATAL) << "Unexpected div type " << type; |
| 3558 | } |
| 3559 | } |
| 3560 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3561 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3562 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3563 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3567 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3568 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3569 | codegen_->AddSlowPath(slow_path); |
| 3570 | Location value = instruction->GetLocations()->InAt(0); |
| 3571 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3572 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3573 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3574 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3575 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3576 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3577 | } |
| 3578 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3579 | if (value.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3580 | int64_t divisor = Int64FromLocation(value); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3581 | if (divisor == 0) { |
| 3582 | __ B(slow_path->GetEntryLabel()); |
| 3583 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3584 | // A division by a non-null constant is valid. We don't need to perform |
| 3585 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3586 | } |
| 3587 | } else { |
| 3588 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3589 | } |
| 3590 | } |
| 3591 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3592 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3593 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3594 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3595 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3596 | } |
| 3597 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3598 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3599 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3600 | // Will be generated at use site. |
| 3601 | } |
| 3602 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3603 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3604 | exit->SetLocations(nullptr); |
| 3605 | } |
| 3606 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3607 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3608 | } |
| 3609 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3610 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3611 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3612 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3613 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3614 | } |
| 3615 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3616 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3617 | // Will be generated at use site. |
| 3618 | } |
| 3619 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3620 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3621 | if (successor->IsExitBlock()) { |
| 3622 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3623 | return; // no code needed |
| 3624 | } |
| 3625 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3626 | HBasicBlock* block = got->GetBlock(); |
| 3627 | HInstruction* previous = got->GetPrevious(); |
| 3628 | HLoopInformation* info = block->GetLoopInformation(); |
| 3629 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3630 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 3631 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3632 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
Vladimir Marko | e45883e | 2022-01-11 12:38:35 +0000 | [diff] [blame] | 3633 | return; // `GenerateSuspendCheck()` emitted the jump. |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3634 | } |
| 3635 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3636 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3637 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3638 | } |
| 3639 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3640 | __ B(codegen_->GetLabelOf(successor)); |
| 3641 | } |
| 3642 | } |
| 3643 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3644 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3645 | got->SetLocations(nullptr); |
| 3646 | } |
| 3647 | |
| 3648 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3649 | HandleGoto(got, got->GetSuccessor()); |
| 3650 | } |
| 3651 | |
| 3652 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3653 | try_boundary->SetLocations(nullptr); |
| 3654 | } |
| 3655 | |
| 3656 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3657 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3658 | if (!successor->IsExitBlock()) { |
| 3659 | HandleGoto(try_boundary, successor); |
| 3660 | } |
| 3661 | } |
| 3662 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3663 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3664 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3665 | vixl::aarch64::Label* true_target, |
| 3666 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3667 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3668 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3669 | if (true_target == nullptr && false_target == nullptr) { |
| 3670 | // Nothing to do. The code always falls through. |
| 3671 | return; |
| 3672 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3673 | // Constant condition, statically compared against "true" (integer value 1). |
| 3674 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3675 | if (true_target != nullptr) { |
| 3676 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3677 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3678 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3679 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3680 | if (false_target != nullptr) { |
| 3681 | __ B(false_target); |
| 3682 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3683 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3684 | return; |
| 3685 | } |
| 3686 | |
| 3687 | // The following code generates these patterns: |
| 3688 | // (1) true_target == nullptr && false_target != nullptr |
| 3689 | // - opposite condition true => branch to false_target |
| 3690 | // (2) true_target != nullptr && false_target == nullptr |
| 3691 | // - condition true => branch to true_target |
| 3692 | // (3) true_target != nullptr && false_target != nullptr |
| 3693 | // - condition true => branch to true_target |
| 3694 | // - branch to false_target |
| 3695 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3696 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3697 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3698 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3699 | if (true_target == nullptr) { |
| 3700 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3701 | } else { |
| 3702 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3703 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3704 | } else { |
| 3705 | // The condition instruction has not been materialized, use its inputs as |
| 3706 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3707 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3708 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3709 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3710 | if (DataType::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3711 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3712 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3713 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3714 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3715 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3716 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3717 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3718 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3719 | // Integer cases. |
| 3720 | Register lhs = InputRegisterAt(condition, 0); |
| 3721 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3722 | |
| 3723 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3724 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3725 | if (true_target == nullptr) { |
| 3726 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3727 | non_fallthrough_target = false_target; |
| 3728 | } else { |
| 3729 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3730 | non_fallthrough_target = true_target; |
| 3731 | } |
| 3732 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3733 | 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] | 3734 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3735 | switch (arm64_cond) { |
| 3736 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3737 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3738 | break; |
| 3739 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3740 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3741 | break; |
| 3742 | case lt: |
| 3743 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3744 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3745 | break; |
| 3746 | case ge: |
| 3747 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3748 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3749 | break; |
| 3750 | default: |
| 3751 | // Without the `static_cast` the compiler throws an error for |
| 3752 | // `-Werror=sign-promo`. |
| 3753 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3754 | } |
| 3755 | } else { |
| 3756 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3757 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3758 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3759 | } |
| 3760 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3761 | |
| 3762 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3763 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3764 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3765 | __ B(false_target); |
| 3766 | } |
| 3767 | } |
| 3768 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3769 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3770 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3771 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3772 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3773 | } |
| 3774 | } |
| 3775 | |
| 3776 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3777 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3778 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3779 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3780 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3781 | true_target = nullptr; |
| 3782 | } |
| 3783 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3784 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3785 | false_target = nullptr; |
| 3786 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3787 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3791 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3792 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3793 | InvokeRuntimeCallingConvention calling_convention; |
| 3794 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3795 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3796 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3797 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3798 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3799 | } |
| 3800 | } |
| 3801 | |
| 3802 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3803 | SlowPathCodeARM64* slow_path = |
| 3804 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3805 | GenerateTestAndBranch(deoptimize, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3806 | /* condition_input_index= */ 0, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3807 | slow_path->GetEntryLabel(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3808 | /* false_target= */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3809 | } |
| 3810 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3811 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3812 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3813 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3814 | locations->SetOut(Location::RequiresRegister()); |
| 3815 | } |
| 3816 | |
| 3817 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3818 | __ Ldr(OutputRegister(flag), |
| 3819 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3820 | } |
| 3821 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3822 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3823 | return condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3824 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3825 | } |
| 3826 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3827 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3828 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3829 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3830 | : ARM64Condition(cond); |
| 3831 | } |
| 3832 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3833 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3834 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3835 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3836 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3837 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3838 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3839 | } else { |
| 3840 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3841 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3842 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3843 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3844 | // Ask VIXL whether we should synthesize constants in registers. |
| 3845 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3846 | Operand true_op = is_true_value_constant ? |
| 3847 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3848 | Operand false_op = is_false_value_constant ? |
| 3849 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3850 | bool true_value_in_register = false; |
| 3851 | bool false_value_in_register = false; |
| 3852 | MacroAssembler::GetCselSynthesisInformation( |
| 3853 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3854 | true_value_in_register |= !is_true_value_constant; |
| 3855 | false_value_in_register |= !is_false_value_constant; |
| 3856 | |
| 3857 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3858 | : Location::ConstantLocation(cst_true_value)); |
| 3859 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3860 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3861 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3862 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3863 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3864 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3865 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3866 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3870 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3871 | Condition csel_cond; |
| 3872 | |
| 3873 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3874 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3875 | // Use the condition flags set by the previous instruction. |
| 3876 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3877 | } else { |
| 3878 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3879 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3880 | } |
| 3881 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3882 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3883 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3884 | } else { |
| 3885 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3886 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3887 | } |
| 3888 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3889 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3890 | __ Fcsel(OutputFPRegister(select), |
| 3891 | InputFPRegisterAt(select, 1), |
| 3892 | InputFPRegisterAt(select, 0), |
| 3893 | csel_cond); |
| 3894 | } else { |
| 3895 | __ Csel(OutputRegister(select), |
| 3896 | InputOperandAt(select, 1), |
| 3897 | InputOperandAt(select, 0), |
| 3898 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3899 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3900 | } |
| 3901 | |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 3902 | void LocationsBuilderARM64::VisitNop(HNop* nop) { |
| 3903 | new (GetGraph()->GetAllocator()) LocationSummary(nop); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3904 | } |
| 3905 | |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 3906 | void InstructionCodeGeneratorARM64::VisitNop(HNop*) { |
| 3907 | // The environment recording already happened in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3908 | } |
| 3909 | |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3910 | void CodeGeneratorARM64::IncreaseFrame(size_t adjustment) { |
| 3911 | __ Claim(adjustment); |
| 3912 | GetAssembler()->cfi().AdjustCFAOffset(adjustment); |
| 3913 | } |
| 3914 | |
| 3915 | void CodeGeneratorARM64::DecreaseFrame(size_t adjustment) { |
| 3916 | __ Drop(adjustment); |
| 3917 | GetAssembler()->cfi().AdjustCFAOffset(-adjustment); |
| 3918 | } |
| 3919 | |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3920 | void CodeGeneratorARM64::GenerateNop() { |
| 3921 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3922 | } |
| 3923 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 3924 | void LocationsBuilderARM64::VisitPredicatedInstanceFieldGet( |
| 3925 | HPredicatedInstanceFieldGet* instruction) { |
| 3926 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3927 | } |
| 3928 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3929 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3930 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3931 | } |
| 3932 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 3933 | void InstructionCodeGeneratorARM64::VisitPredicatedInstanceFieldGet( |
| 3934 | HPredicatedInstanceFieldGet* instruction) { |
| 3935 | vixl::aarch64::Label finish; |
| 3936 | __ Cbz(InputRegisterAt(instruction, 1), &finish); |
| 3937 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3938 | __ Bind(&finish); |
| 3939 | } |
| 3940 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3941 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3942 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3943 | } |
| 3944 | |
| 3945 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3946 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3947 | } |
| 3948 | |
| 3949 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3950 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3951 | } |
| 3952 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3953 | // Temp is used for read barrier. |
| 3954 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 3955 | if (gUseReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3956 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3957 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3958 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3959 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3960 | return 1; |
| 3961 | } |
| 3962 | return 0; |
| 3963 | } |
| 3964 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3965 | // 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] | 3966 | // interface pointer, one for loading the current interface. |
| 3967 | // The other checks have one temp for loading the object's class. |
| 3968 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3969 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3970 | return 3; |
| 3971 | } |
| 3972 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3973 | } |
| 3974 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3975 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3976 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3977 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3978 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3979 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3980 | case TypeCheckKind::kExactCheck: |
| 3981 | case TypeCheckKind::kAbstractClassCheck: |
| 3982 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3983 | case TypeCheckKind::kArrayObjectCheck: { |
| 3984 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 3985 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 3986 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3987 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3988 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3989 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3990 | case TypeCheckKind::kUnresolvedCheck: |
| 3991 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3992 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3993 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3994 | case TypeCheckKind::kBitstringCheck: |
| 3995 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3996 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3997 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3998 | LocationSummary* locations = |
| 3999 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4000 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4001 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4002 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4003 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4004 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 4005 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 4006 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 4007 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 4008 | } else { |
| 4009 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4010 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4011 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 4012 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 4013 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4014 | // Add temps if necessary for read barriers. |
| 4015 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4019 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4020 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4021 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4022 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4023 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 4024 | ? Register() |
| 4025 | : InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4026 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4027 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4028 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 4029 | DCHECK_LE(num_temps, 1u); |
| 4030 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4031 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4032 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4033 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4034 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4035 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4036 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4037 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4038 | |
| 4039 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4040 | // Avoid null check if we know `obj` is not null. |
| 4041 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4042 | __ Cbz(obj, &zero); |
| 4043 | } |
| 4044 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4045 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4046 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4047 | ReadBarrierOption read_barrier_option = |
| 4048 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4049 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4050 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4051 | out_loc, |
| 4052 | obj_loc, |
| 4053 | class_offset, |
| 4054 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4055 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4056 | __ Cmp(out, cls); |
| 4057 | __ Cset(out, eq); |
| 4058 | if (zero.IsLinked()) { |
| 4059 | __ B(&done); |
| 4060 | } |
| 4061 | break; |
| 4062 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4063 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4064 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4065 | ReadBarrierOption read_barrier_option = |
| 4066 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4067 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4068 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4069 | out_loc, |
| 4070 | obj_loc, |
| 4071 | class_offset, |
| 4072 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4073 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4074 | // If the class is abstract, we eagerly fetch the super class of the |
| 4075 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4076 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4077 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4078 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4079 | GenerateReferenceLoadOneRegister(instruction, |
| 4080 | out_loc, |
| 4081 | super_offset, |
| 4082 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4083 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4084 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4085 | __ Cbz(out, &done); |
| 4086 | __ Cmp(out, cls); |
| 4087 | __ B(ne, &loop); |
| 4088 | __ Mov(out, 1); |
| 4089 | if (zero.IsLinked()) { |
| 4090 | __ B(&done); |
| 4091 | } |
| 4092 | break; |
| 4093 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4094 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4095 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4096 | ReadBarrierOption read_barrier_option = |
| 4097 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4098 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4099 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4100 | out_loc, |
| 4101 | obj_loc, |
| 4102 | class_offset, |
| 4103 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4104 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4105 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4106 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4107 | __ Bind(&loop); |
| 4108 | __ Cmp(out, cls); |
| 4109 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4110 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4111 | GenerateReferenceLoadOneRegister(instruction, |
| 4112 | out_loc, |
| 4113 | super_offset, |
| 4114 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4115 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4116 | __ Cbnz(out, &loop); |
| 4117 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4118 | __ B(&done); |
| 4119 | __ Bind(&success); |
| 4120 | __ Mov(out, 1); |
| 4121 | if (zero.IsLinked()) { |
| 4122 | __ B(&done); |
| 4123 | } |
| 4124 | break; |
| 4125 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4126 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4127 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4128 | ReadBarrierOption read_barrier_option = |
| 4129 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4130 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4131 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4132 | out_loc, |
| 4133 | obj_loc, |
| 4134 | class_offset, |
| 4135 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4136 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4137 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4138 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4139 | __ Cmp(out, cls); |
| 4140 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4141 | // 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] | 4142 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4143 | GenerateReferenceLoadOneRegister(instruction, |
| 4144 | out_loc, |
| 4145 | component_offset, |
| 4146 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4147 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4148 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4149 | __ Cbz(out, &done); |
| 4150 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4151 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4152 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4153 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4154 | __ Mov(out, 1); |
| 4155 | __ B(&done); |
| 4156 | break; |
| 4157 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4158 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4159 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4160 | // No read barrier since the slow path will retry upon failure. |
| 4161 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4162 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4163 | out_loc, |
| 4164 | obj_loc, |
| 4165 | class_offset, |
| 4166 | maybe_temp_loc, |
| 4167 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4168 | __ Cmp(out, cls); |
| 4169 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4170 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4171 | instruction, /* is_fatal= */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4172 | codegen_->AddSlowPath(slow_path); |
| 4173 | __ B(ne, slow_path->GetEntryLabel()); |
| 4174 | __ Mov(out, 1); |
| 4175 | if (zero.IsLinked()) { |
| 4176 | __ B(&done); |
| 4177 | } |
| 4178 | break; |
| 4179 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4180 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4181 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4182 | case TypeCheckKind::kInterfaceCheck: { |
| 4183 | // Note that we indeed only call on slow path, but we always go |
| 4184 | // into the slow path for the unresolved and interface check |
| 4185 | // cases. |
| 4186 | // |
| 4187 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4188 | // entry point without resorting to a type checking slow path |
| 4189 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4190 | // require to assign fixed registers for the inputs of this |
| 4191 | // HInstanceOf instruction (following the runtime calling |
| 4192 | // convention), which might be cluttered by the potential first |
| 4193 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4194 | // |
| 4195 | // TODO: Introduce a new runtime entry point taking the object |
| 4196 | // to test (instead of its class) as argument, and let it deal |
| 4197 | // with the read barrier issues. This will let us refactor this |
| 4198 | // case of the `switch` code as it was previously (with a direct |
| 4199 | // call to the runtime not using a type checking slow path). |
| 4200 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4201 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4202 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4203 | instruction, /* is_fatal= */ false); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4204 | codegen_->AddSlowPath(slow_path); |
| 4205 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4206 | if (zero.IsLinked()) { |
| 4207 | __ B(&done); |
| 4208 | } |
| 4209 | break; |
| 4210 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4211 | |
| 4212 | case TypeCheckKind::kBitstringCheck: { |
| 4213 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4214 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4215 | out_loc, |
| 4216 | obj_loc, |
| 4217 | class_offset, |
| 4218 | maybe_temp_loc, |
| 4219 | kWithoutReadBarrier); |
| 4220 | |
| 4221 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 4222 | __ Cset(out, eq); |
| 4223 | if (zero.IsLinked()) { |
| 4224 | __ B(&done); |
| 4225 | } |
| 4226 | break; |
| 4227 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4228 | } |
| 4229 | |
| 4230 | if (zero.IsLinked()) { |
| 4231 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4232 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4233 | } |
| 4234 | |
| 4235 | if (done.IsLinked()) { |
| 4236 | __ Bind(&done); |
| 4237 | } |
| 4238 | |
| 4239 | if (slow_path != nullptr) { |
| 4240 | __ Bind(slow_path->GetExitLabel()); |
| 4241 | } |
| 4242 | } |
| 4243 | |
| 4244 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4245 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4246 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4247 | LocationSummary* locations = |
| 4248 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4249 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4250 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 4251 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 4252 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 4253 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 4254 | } else { |
| 4255 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4256 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4257 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4258 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4262 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4263 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4264 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4265 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4266 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 4267 | ? Register() |
| 4268 | : InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4269 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4270 | DCHECK_GE(num_temps, 1u); |
| 4271 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4272 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4273 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4274 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4275 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4276 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4277 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4278 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4279 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4280 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4281 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4282 | const uint32_t object_array_data_offset = |
| 4283 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4284 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4285 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4286 | SlowPathCodeARM64* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4287 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4288 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4289 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4290 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4291 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4292 | // Avoid null check if we know obj is not null. |
| 4293 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4294 | __ Cbz(obj, &done); |
| 4295 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4296 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4297 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4298 | case TypeCheckKind::kExactCheck: |
| 4299 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4300 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4301 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4302 | temp_loc, |
| 4303 | obj_loc, |
| 4304 | class_offset, |
| 4305 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4306 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4307 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4308 | __ Cmp(temp, cls); |
| 4309 | // Jump to slow path for throwing the exception or doing a |
| 4310 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4311 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4312 | break; |
| 4313 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4314 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4315 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4316 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4317 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4318 | temp_loc, |
| 4319 | obj_loc, |
| 4320 | class_offset, |
| 4321 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4322 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4323 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4324 | // If the class is abstract, we eagerly fetch the super class of the |
| 4325 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4326 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4327 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4328 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4329 | GenerateReferenceLoadOneRegister(instruction, |
| 4330 | temp_loc, |
| 4331 | super_offset, |
| 4332 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4333 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4334 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4335 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4336 | // exception. |
| 4337 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4338 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4339 | __ Cmp(temp, cls); |
| 4340 | __ B(ne, &loop); |
| 4341 | break; |
| 4342 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4343 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4344 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4345 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4346 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4347 | temp_loc, |
| 4348 | obj_loc, |
| 4349 | class_offset, |
| 4350 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4351 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4352 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4353 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4354 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4355 | __ Bind(&loop); |
| 4356 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4357 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4358 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4359 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4360 | GenerateReferenceLoadOneRegister(instruction, |
| 4361 | temp_loc, |
| 4362 | super_offset, |
| 4363 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4364 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4365 | |
| 4366 | // If the class reference currently in `temp` is not null, jump |
| 4367 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4368 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4369 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4370 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4371 | break; |
| 4372 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4373 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4374 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4375 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4376 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4377 | temp_loc, |
| 4378 | obj_loc, |
| 4379 | class_offset, |
| 4380 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4381 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4382 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4383 | // Do an exact check. |
| 4384 | __ Cmp(temp, cls); |
| 4385 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4386 | |
| 4387 | // 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] | 4388 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4389 | GenerateReferenceLoadOneRegister(instruction, |
| 4390 | temp_loc, |
| 4391 | component_offset, |
| 4392 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4393 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4394 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4395 | // If the component type is null, jump to the slow path to throw the exception. |
| 4396 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4397 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4398 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4399 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4400 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4401 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4402 | break; |
| 4403 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4404 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4405 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4406 | // 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] | 4407 | // |
| 4408 | // We cannot directly call the CheckCast runtime entry point |
| 4409 | // without resorting to a type checking slow path here (i.e. by |
| 4410 | // calling InvokeRuntime directly), as it would require to |
| 4411 | // assign fixed registers for the inputs of this HInstanceOf |
| 4412 | // instruction (following the runtime calling convention), which |
| 4413 | // might be cluttered by the potential first read barrier |
| 4414 | // emission at the beginning of this method. |
| 4415 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4416 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4417 | case TypeCheckKind::kInterfaceCheck: { |
| 4418 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4419 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4420 | temp_loc, |
| 4421 | obj_loc, |
| 4422 | class_offset, |
| 4423 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4424 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4425 | |
| 4426 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4427 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4428 | temp_loc, |
| 4429 | temp_loc, |
| 4430 | iftable_offset, |
| 4431 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4432 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4433 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4434 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4435 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4436 | vixl::aarch64::Label start_loop; |
| 4437 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4438 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4439 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4440 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4441 | // Go to next interface. |
| 4442 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4443 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4444 | // Compare the classes and continue the loop if they do not match. |
| 4445 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4446 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4447 | break; |
| 4448 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4449 | |
| 4450 | case TypeCheckKind::kBitstringCheck: { |
| 4451 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4452 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4453 | temp_loc, |
| 4454 | obj_loc, |
| 4455 | class_offset, |
| 4456 | maybe_temp2_loc, |
| 4457 | kWithoutReadBarrier); |
| 4458 | |
| 4459 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 4460 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 4461 | break; |
| 4462 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4463 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4464 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4465 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4466 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4467 | } |
| 4468 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4469 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4470 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4471 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4472 | } |
| 4473 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4474 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4475 | // Will be generated at use site. |
| 4476 | } |
| 4477 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4478 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4479 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4480 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4481 | } |
| 4482 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4483 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4484 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4485 | } |
| 4486 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4487 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4488 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4489 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4490 | // the method_idx. |
| 4491 | HandleInvoke(invoke); |
| 4492 | } |
| 4493 | |
| 4494 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4495 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4496 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4497 | } |
| 4498 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4499 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4500 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4501 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4502 | } |
| 4503 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4504 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4505 | HandleInvoke(invoke); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4506 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 4507 | // We cannot request ip1 as it's blocked by the register allocator. |
| 4508 | invoke->GetLocations()->SetInAt(invoke->GetNumberOfArguments() - 1, Location::Any()); |
| 4509 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4510 | } |
| 4511 | |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4512 | void CodeGeneratorARM64::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 4513 | Register klass) { |
| 4514 | DCHECK_EQ(klass.GetCode(), 0u); |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4515 | // We know the destination of an intrinsic, so no need to record inline |
| 4516 | // caches. |
| 4517 | if (!instruction->GetLocations()->Intrinsified() && |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 4518 | GetGraph()->IsCompilingBaseline() && |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4519 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4520 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 4521 | ProfilingInfo* info = GetGraph()->GetProfilingInfo(); |
| 4522 | DCHECK(info != nullptr); |
| 4523 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 4524 | uint64_t address = reinterpret_cast64<uint64_t>(cache); |
| 4525 | vixl::aarch64::Label done; |
| 4526 | __ Mov(x8, address); |
| 4527 | __ Ldr(x9, MemOperand(x8, InlineCache::ClassesOffset().Int32Value())); |
| 4528 | // Fast path for a monomorphic cache. |
| 4529 | __ Cmp(klass, x9); |
| 4530 | __ B(eq, &done); |
| 4531 | InvokeRuntime(kQuickUpdateInlineCache, instruction, instruction->GetDexPc()); |
| 4532 | __ Bind(&done); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4533 | } |
| 4534 | } |
| 4535 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4536 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4537 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4538 | LocationSummary* locations = invoke->GetLocations(); |
| 4539 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4540 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4541 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4542 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4543 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4544 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4545 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4546 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4547 | { |
| 4548 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4549 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4550 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4551 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4552 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4553 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4554 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4555 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4556 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4557 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4558 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4559 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4560 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4561 | // emit a read barrier for the previous class reference load. |
| 4562 | // However this is not required in practice, as this is an |
| 4563 | // intermediate/temporary reference and because the current |
| 4564 | // concurrent copying collector keeps the from-space memory |
| 4565 | // intact/accessible until the end of the marking phase (the |
| 4566 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4567 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4568 | |
| 4569 | // If we're compiling baseline, update the inline cache. |
| 4570 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4571 | |
| 4572 | // The register ip1 is required to be used for the hidden argument in |
| 4573 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
| 4574 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4575 | UseScratchRegisterScope scratch_scope(masm); |
| 4576 | scratch_scope.Exclude(ip1); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4577 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 4578 | Location interface_method = locations->InAt(invoke->GetNumberOfArguments() - 1); |
| 4579 | if (interface_method.IsStackSlot()) { |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 4580 | __ Ldr(ip1, StackOperandFrom(interface_method)); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4581 | } else { |
| 4582 | __ Mov(ip1, XRegisterFrom(interface_method)); |
| 4583 | } |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 4584 | // If the load kind is through a runtime call, we will pass the method we |
| 4585 | // fetch the IMT, which will either be a no-op if we don't hit the conflict |
| 4586 | // stub, or will make us always go through the trampoline when there is a |
| 4587 | // conflict. |
| 4588 | } else if (invoke->GetHiddenArgumentLoadKind() != MethodLoadKind::kRuntimeCall) { |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4589 | codegen_->LoadMethod( |
| 4590 | invoke->GetHiddenArgumentLoadKind(), Location::RegisterLocation(ip1.GetCode()), invoke); |
| 4591 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4592 | |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4593 | __ Ldr(temp, |
| 4594 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4595 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4596 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4597 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4598 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 4599 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRuntimeCall) { |
| 4600 | // We pass the method from the IMT in case of a conflict. This will ensure |
| 4601 | // we go into the runtime to resolve the actual method. |
| 4602 | __ Mov(ip1, temp); |
| 4603 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4604 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4605 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4606 | |
| 4607 | { |
| 4608 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4609 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4610 | |
| 4611 | // lr(); |
| 4612 | __ blr(lr); |
| 4613 | DCHECK(!codegen_->IsLeafMethod()); |
| 4614 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4615 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4616 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4617 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4618 | } |
| 4619 | |
| 4620 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4621 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4622 | if (intrinsic.TryDispatch(invoke)) { |
| 4623 | return; |
| 4624 | } |
| 4625 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4626 | HandleInvoke(invoke); |
| 4627 | } |
| 4628 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4629 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4630 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4631 | // art::PrepareForRegisterAllocation. |
| 4632 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4633 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4634 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4635 | if (intrinsic.TryDispatch(invoke)) { |
| 4636 | return; |
| 4637 | } |
| 4638 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4639 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4640 | CriticalNativeCallingConventionVisitorARM64 calling_convention_visitor( |
| 4641 | /*for_register_allocation=*/ true); |
| 4642 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 4643 | } else { |
| 4644 | HandleInvoke(invoke); |
| 4645 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4646 | } |
| 4647 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4648 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4649 | if (invoke->GetLocations()->Intrinsified()) { |
| 4650 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4651 | intrinsic.Dispatch(invoke); |
| 4652 | return true; |
| 4653 | } |
| 4654 | return false; |
| 4655 | } |
| 4656 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4657 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4658 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4659 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4660 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4661 | return desired_dispatch_info; |
| 4662 | } |
| 4663 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4664 | void CodeGeneratorARM64::LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke) { |
| 4665 | switch (load_kind) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4666 | case MethodLoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4667 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4668 | // Add ADRP with its PC-relative method patch. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4669 | vixl::aarch64::Label* adrp_label = |
| 4670 | NewBootImageMethodPatch(invoke->GetResolvedMethodReference()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4671 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4672 | // Add ADD with its PC-relative method patch. |
| 4673 | vixl::aarch64::Label* add_label = |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4674 | NewBootImageMethodPatch(invoke->GetResolvedMethodReference(), adrp_label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4675 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4676 | break; |
| 4677 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4678 | case MethodLoadKind::kBootImageRelRo: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4679 | // 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] | 4680 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
| 4681 | LoadBootImageRelRoEntry(WRegisterFrom(temp), boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4682 | break; |
| 4683 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4684 | case MethodLoadKind::kBssEntry: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4685 | // Add ADRP with its PC-relative .bss entry patch. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4686 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(invoke->GetMethodReference()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4687 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4688 | // Add LDR with its PC-relative .bss entry patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4689 | vixl::aarch64::Label* ldr_label = |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4690 | NewMethodBssEntryPatch(invoke->GetMethodReference(), adrp_label); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 4691 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4692 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4693 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4694 | } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4695 | case MethodLoadKind::kJitDirectAddress: { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4696 | // Load method address from literal pool. |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4697 | __ Ldr(XRegisterFrom(temp), |
| 4698 | DeduplicateUint64Literal(reinterpret_cast<uint64_t>(invoke->GetResolvedMethod()))); |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4699 | break; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4700 | } |
| 4701 | case MethodLoadKind::kRuntimeCall: { |
| 4702 | // Test situation, don't do anything. |
| 4703 | break; |
| 4704 | } |
| 4705 | default: { |
| 4706 | LOG(FATAL) << "Load kind should have already been handled " << load_kind; |
| 4707 | UNREACHABLE(); |
| 4708 | } |
| 4709 | } |
| 4710 | } |
| 4711 | |
| 4712 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4713 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| 4714 | // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention. |
| 4715 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4716 | switch (invoke->GetMethodLoadKind()) { |
| 4717 | case MethodLoadKind::kStringInit: { |
| 4718 | uint32_t offset = |
| 4719 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4720 | // temp = thread->string_init_entrypoint |
| 4721 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
| 4722 | break; |
| 4723 | } |
| 4724 | case MethodLoadKind::kRecursive: { |
| 4725 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
| 4726 | break; |
| 4727 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4728 | case MethodLoadKind::kRuntimeCall: { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4729 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4730 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4731 | } |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4732 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
| 4733 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| 4734 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
| 4735 | // Do not materialize the method pointer, load directly the entrypoint. |
| 4736 | // Add ADRP with its PC-relative JNI entrypoint patch. |
| 4737 | vixl::aarch64::Label* adrp_label = |
| 4738 | NewBootImageJniEntrypointPatch(invoke->GetResolvedMethodReference()); |
| 4739 | EmitAdrpPlaceholder(adrp_label, lr); |
| 4740 | // Add the LDR with its PC-relative method patch. |
| 4741 | vixl::aarch64::Label* add_label = |
| 4742 | NewBootImageJniEntrypointPatch(invoke->GetResolvedMethodReference(), adrp_label); |
| 4743 | EmitLdrOffsetPlaceholder(add_label, lr, lr); |
| 4744 | break; |
| 4745 | } |
| 4746 | FALLTHROUGH_INTENDED; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4747 | default: { |
| 4748 | LoadMethod(invoke->GetMethodLoadKind(), temp, invoke); |
| 4749 | break; |
| 4750 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4751 | } |
| 4752 | |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4753 | auto call_lr = [&]() { |
| 4754 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4755 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4756 | kInstructionSize, |
| 4757 | CodeBufferCheckScope::kExactSize); |
| 4758 | // lr() |
| 4759 | __ blr(lr); |
| 4760 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4761 | }; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4762 | switch (invoke->GetCodePtrLocation()) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4763 | case CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4764 | { |
Nicolas Geoffray | 282795c | 2021-09-24 18:16:41 +0100 | [diff] [blame] | 4765 | DCHECK(!GetGraph()->HasShouldDeoptimizeFlag()); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4766 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4767 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4768 | kInstructionSize, |
| 4769 | CodeBufferCheckScope::kExactSize); |
| 4770 | __ bl(&frame_entry_label_); |
| 4771 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4772 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4773 | break; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4774 | case CodePtrLocation::kCallCriticalNative: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4775 | size_t out_frame_size = |
| 4776 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorARM64, |
| 4777 | kAapcs64StackAlignment, |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 4778 | GetCriticalNativeDirectCallFrameSize>(invoke); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4779 | if (invoke->GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative) { |
| 4780 | call_lr(); |
| 4781 | } else { |
| 4782 | // LR = callee_method->ptr_sized_fields_.data_; // EntryPointFromJni |
| 4783 | MemberOffset offset = ArtMethod::EntryPointFromJniOffset(kArm64PointerSize); |
| 4784 | __ Ldr(lr, MemOperand(XRegisterFrom(callee_method), offset.Int32Value())); |
| 4785 | // lr() |
| 4786 | call_lr(); |
| 4787 | } |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4788 | // Zero-/sign-extend the result when needed due to native and managed ABI mismatch. |
| 4789 | switch (invoke->GetType()) { |
| 4790 | case DataType::Type::kBool: |
| 4791 | __ Ubfx(w0, w0, 0, 8); |
| 4792 | break; |
| 4793 | case DataType::Type::kInt8: |
| 4794 | __ Sbfx(w0, w0, 0, 8); |
| 4795 | break; |
| 4796 | case DataType::Type::kUint16: |
| 4797 | __ Ubfx(w0, w0, 0, 16); |
| 4798 | break; |
| 4799 | case DataType::Type::kInt16: |
| 4800 | __ Sbfx(w0, w0, 0, 16); |
| 4801 | break; |
| 4802 | case DataType::Type::kInt32: |
| 4803 | case DataType::Type::kInt64: |
| 4804 | case DataType::Type::kFloat32: |
| 4805 | case DataType::Type::kFloat64: |
| 4806 | case DataType::Type::kVoid: |
| 4807 | break; |
| 4808 | default: |
| 4809 | DCHECK(false) << invoke->GetType(); |
| 4810 | break; |
| 4811 | } |
| 4812 | if (out_frame_size != 0u) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 4813 | DecreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4814 | } |
| 4815 | break; |
| 4816 | } |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4817 | case CodePtrLocation::kCallArtMethod: { |
| 4818 | // LR = callee_method->ptr_sized_fields_.entry_point_from_quick_compiled_code_; |
| 4819 | MemberOffset offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
| 4820 | __ Ldr(lr, MemOperand(XRegisterFrom(callee_method), offset.Int32Value())); |
| 4821 | // lr() |
| 4822 | call_lr(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4823 | break; |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4824 | } |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4825 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4826 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4827 | DCHECK(!IsLeafMethod()); |
| 4828 | } |
| 4829 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4830 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4831 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4832 | // Use the calling convention instead of the location of the receiver, as |
| 4833 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4834 | // slow path, the arguments have been moved to the right place, so here we are |
| 4835 | // guaranteed that the receiver is the first register of the calling convention. |
| 4836 | InvokeDexCallingConvention calling_convention; |
| 4837 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4838 | Register temp = XRegisterFrom(temp_in); |
| 4839 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4840 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4841 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4842 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4843 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4844 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4845 | |
| 4846 | { |
| 4847 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4848 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4849 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4850 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4851 | MaybeRecordImplicitNullCheck(invoke); |
| 4852 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4853 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4854 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4855 | // intermediate/temporary reference and because the current |
| 4856 | // concurrent copying collector keeps the from-space memory |
| 4857 | // intact/accessible until the end of the marking phase (the |
| 4858 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4859 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4860 | |
| 4861 | // If we're compiling baseline, update the inline cache. |
| 4862 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4863 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4864 | // temp = temp->GetMethodAt(method_offset); |
| 4865 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4866 | // lr = temp->GetEntryPoint(); |
| 4867 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4868 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4869 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4870 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4871 | // lr(); |
| 4872 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4873 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4874 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4875 | } |
| 4876 | |
Vladimir Marko | 9922f00 | 2020-06-08 15:05:15 +0100 | [diff] [blame] | 4877 | void CodeGeneratorARM64::MoveFromReturnRegister(Location trg, DataType::Type type) { |
| 4878 | if (!trg.IsValid()) { |
| 4879 | DCHECK(type == DataType::Type::kVoid); |
| 4880 | return; |
| 4881 | } |
| 4882 | |
| 4883 | DCHECK_NE(type, DataType::Type::kVoid); |
| 4884 | |
| 4885 | if (DataType::IsIntegralType(type) || type == DataType::Type::kReference) { |
| 4886 | Register trg_reg = RegisterFrom(trg, type); |
| 4887 | Register res_reg = RegisterFrom(ARM64ReturnLocation(type), type); |
| 4888 | __ Mov(trg_reg, res_reg, kDiscardForSameWReg); |
| 4889 | } else { |
| 4890 | VRegister trg_reg = FPRegisterFrom(trg, type); |
| 4891 | VRegister res_reg = FPRegisterFrom(ARM64ReturnLocation(type), type); |
| 4892 | __ Fmov(trg_reg, res_reg); |
| 4893 | } |
| 4894 | } |
| 4895 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4896 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 4897 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
| 4898 | if (intrinsic.TryDispatch(invoke)) { |
| 4899 | return; |
| 4900 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4901 | HandleInvoke(invoke); |
| 4902 | } |
| 4903 | |
| 4904 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 4905 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4906 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| 4907 | return; |
| 4908 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4909 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4910 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4911 | } |
| 4912 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4913 | void LocationsBuilderARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4914 | HandleInvoke(invoke); |
| 4915 | } |
| 4916 | |
| 4917 | void InstructionCodeGeneratorARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4918 | codegen_->GenerateInvokeCustomCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4919 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4920 | } |
| 4921 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4922 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageIntrinsicPatch( |
| 4923 | uint32_t intrinsic_data, |
| 4924 | vixl::aarch64::Label* adrp_label) { |
| 4925 | return NewPcRelativePatch( |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4926 | /* dex_file= */ nullptr, intrinsic_data, adrp_label, &boot_image_other_patches_); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4927 | } |
| 4928 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4929 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageRelRoPatch( |
| 4930 | uint32_t boot_image_offset, |
| 4931 | vixl::aarch64::Label* adrp_label) { |
| 4932 | return NewPcRelativePatch( |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4933 | /* dex_file= */ nullptr, boot_image_offset, adrp_label, &boot_image_other_patches_); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4934 | } |
| 4935 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4936 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageMethodPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4937 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4938 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4939 | return NewPcRelativePatch( |
| 4940 | 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] | 4941 | } |
| 4942 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4943 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4944 | MethodReference target_method, |
| 4945 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4946 | return NewPcRelativePatch( |
| 4947 | 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] | 4948 | } |
| 4949 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4950 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageTypePatch( |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4951 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4952 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4953 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4954 | 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] | 4955 | } |
| 4956 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4957 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 4958 | HLoadClass* load_class, |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4959 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 4960 | const DexFile& dex_file = load_class->GetDexFile(); |
| 4961 | dex::TypeIndex type_index = load_class->GetTypeIndex(); |
| 4962 | ArenaDeque<PcRelativePatchInfo>* patches = nullptr; |
| 4963 | switch (load_class->GetLoadKind()) { |
| 4964 | case HLoadClass::LoadKind::kBssEntry: |
| 4965 | patches = &type_bss_entry_patches_; |
| 4966 | break; |
| 4967 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 4968 | patches = &public_type_bss_entry_patches_; |
| 4969 | break; |
| 4970 | case HLoadClass::LoadKind::kBssEntryPackage: |
| 4971 | patches = &package_type_bss_entry_patches_; |
| 4972 | break; |
| 4973 | default: |
| 4974 | LOG(FATAL) << "Unexpected load kind: " << load_class->GetLoadKind(); |
| 4975 | UNREACHABLE(); |
| 4976 | } |
| 4977 | return NewPcRelativePatch(&dex_file, type_index.index_, adrp_label, patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4978 | } |
| 4979 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4980 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageStringPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4981 | const DexFile& dex_file, |
| 4982 | dex::StringIndex string_index, |
| 4983 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4984 | return NewPcRelativePatch( |
| 4985 | &dex_file, string_index.index_, adrp_label, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4986 | } |
| 4987 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4988 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4989 | const DexFile& dex_file, |
| 4990 | dex::StringIndex string_index, |
| 4991 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4992 | 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] | 4993 | } |
| 4994 | |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4995 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageJniEntrypointPatch( |
| 4996 | MethodReference target_method, |
| 4997 | vixl::aarch64::Label* adrp_label) { |
| 4998 | return NewPcRelativePatch( |
| 4999 | target_method.dex_file, target_method.index, adrp_label, &boot_image_jni_entrypoint_patches_); |
| 5000 | } |
| 5001 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5002 | void CodeGeneratorARM64::EmitEntrypointThunkCall(ThreadOffset64 entrypoint_offset) { |
| 5003 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5004 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5005 | call_entrypoint_patches_.emplace_back(/*dex_file*/ nullptr, entrypoint_offset.Uint32Value()); |
| 5006 | vixl::aarch64::Label* bl_label = &call_entrypoint_patches_.back().label; |
| 5007 | __ bind(bl_label); |
| 5008 | __ bl(static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 5009 | } |
| 5010 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 5011 | void CodeGeneratorARM64::EmitBakerReadBarrierCbnz(uint32_t custom_data) { |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 5012 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5013 | if (GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 5014 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 5015 | vixl::aarch64::Label* slow_path_entry = &it->second.label; |
| 5016 | __ cbnz(mr, slow_path_entry); |
| 5017 | } else { |
| 5018 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 5019 | vixl::aarch64::Label* cbnz_label = &baker_read_barrier_patches_.back().label; |
| 5020 | __ bind(cbnz_label); |
| 5021 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 5022 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5023 | } |
| 5024 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5025 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5026 | const DexFile* dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5027 | uint32_t offset_or_index, |
| 5028 | vixl::aarch64::Label* adrp_label, |
| 5029 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5030 | // Add a patch entry and return the label. |
| 5031 | patches->emplace_back(dex_file, offset_or_index); |
| 5032 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5033 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5034 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 5035 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 5036 | return label; |
| 5037 | } |
| 5038 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5039 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 5040 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5041 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5042 | } |
| 5043 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5044 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5045 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5046 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5047 | return jit_string_patches_.GetOrCreate( |
| 5048 | StringReference(&dex_file, string_index), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5049 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5050 | } |
| 5051 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5052 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5053 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5054 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5055 | return jit_class_patches_.GetOrCreate( |
| 5056 | TypeReference(&dex_file, type_index), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5057 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5058 | } |
| 5059 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5060 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 5061 | vixl::aarch64::Register reg) { |
| 5062 | DCHECK(reg.IsX()); |
| 5063 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 5064 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5065 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5066 | } |
| 5067 | |
| 5068 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 5069 | vixl::aarch64::Register out, |
| 5070 | vixl::aarch64::Register base) { |
| 5071 | DCHECK(out.IsX()); |
| 5072 | DCHECK(base.IsX()); |
| 5073 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 5074 | __ Bind(fixup_label); |
| 5075 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 5076 | } |
| 5077 | |
| 5078 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 5079 | vixl::aarch64::Register out, |
| 5080 | vixl::aarch64::Register base) { |
| 5081 | DCHECK(base.IsX()); |
| 5082 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 5083 | __ Bind(fixup_label); |
| 5084 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 5085 | } |
| 5086 | |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5087 | void CodeGeneratorARM64::LoadBootImageRelRoEntry(vixl::aarch64::Register reg, |
| 5088 | uint32_t boot_image_offset) { |
| 5089 | DCHECK(reg.IsW()); |
| 5090 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5091 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_offset); |
| 5092 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 5093 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| 5094 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| 5095 | EmitLdrOffsetPlaceholder(ldr_label, reg.W(), reg.X()); |
| 5096 | } |
| 5097 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5098 | void CodeGeneratorARM64::LoadBootImageAddress(vixl::aarch64::Register reg, |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5099 | uint32_t boot_image_reference) { |
| 5100 | if (GetCompilerOptions().IsBootImage()) { |
| 5101 | // Add ADRP with its PC-relative type patch. |
| 5102 | vixl::aarch64::Label* adrp_label = NewBootImageIntrinsicPatch(boot_image_reference); |
| 5103 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 5104 | // Add ADD with its PC-relative type patch. |
| 5105 | vixl::aarch64::Label* add_label = NewBootImageIntrinsicPatch(boot_image_reference, adrp_label); |
| 5106 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 5107 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5108 | LoadBootImageRelRoEntry(reg, boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5109 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5110 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5111 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 5112 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5113 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5114 | __ Ldr(reg.W(), DeduplicateBootImageAddressLiteral(reinterpret_cast<uintptr_t>(address))); |
| 5115 | } |
| 5116 | } |
| 5117 | |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 5118 | void CodeGeneratorARM64::LoadTypeForBootImageIntrinsic(vixl::aarch64::Register reg, |
| 5119 | TypeReference target_type) { |
| 5120 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5121 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 5122 | // Add ADRP with its PC-relative type patch. |
| 5123 | vixl::aarch64::Label* adrp_label = |
| 5124 | NewBootImageTypePatch(*target_type.dex_file, target_type.TypeIndex()); |
| 5125 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 5126 | // Add ADD with its PC-relative type patch. |
| 5127 | vixl::aarch64::Label* add_label = |
| 5128 | NewBootImageTypePatch(*target_type.dex_file, target_type.TypeIndex(), adrp_label); |
| 5129 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
| 5130 | } |
| 5131 | |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5132 | void CodeGeneratorARM64::LoadIntrinsicDeclaringClass(vixl::aarch64::Register reg, HInvoke* invoke) { |
| 5133 | DCHECK_NE(invoke->GetIntrinsic(), Intrinsics::kNone); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5134 | if (GetCompilerOptions().IsBootImage()) { |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5135 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5136 | 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] | 5137 | LoadTypeForBootImageIntrinsic(reg, TypeReference(target_method.dex_file, type_idx)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5138 | } else { |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5139 | uint32_t boot_image_offset = GetBootImageOffsetOfIntrinsicDeclaringClass(invoke); |
| 5140 | LoadBootImageAddress(reg, boot_image_offset); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5141 | } |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5142 | } |
| 5143 | |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 5144 | void CodeGeneratorARM64::LoadClassRootForIntrinsic(vixl::aarch64::Register reg, |
| 5145 | ClassRoot class_root) { |
| 5146 | if (GetCompilerOptions().IsBootImage()) { |
| 5147 | ScopedObjectAccess soa(Thread::Current()); |
| 5148 | ObjPtr<mirror::Class> klass = GetClassRoot(class_root); |
| 5149 | TypeReference target_type(&klass->GetDexFile(), klass->GetDexTypeIndex()); |
| 5150 | LoadTypeForBootImageIntrinsic(reg, target_type); |
| 5151 | } else { |
| 5152 | uint32_t boot_image_offset = GetBootImageOffset(class_root); |
| 5153 | LoadBootImageAddress(reg, boot_image_offset); |
| 5154 | } |
| 5155 | } |
| 5156 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5157 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5158 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 5159 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5160 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5161 | for (const PcRelativePatchInfo& info : infos) { |
| 5162 | linker_patches->push_back(Factory(info.label.GetLocation(), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5163 | info.target_dex_file, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5164 | info.pc_insn_label->GetLocation(), |
| 5165 | info.offset_or_index)); |
| 5166 | } |
| 5167 | } |
| 5168 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5169 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 5170 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 5171 | const DexFile* target_dex_file, |
| 5172 | uint32_t pc_insn_offset, |
| 5173 | uint32_t boot_image_offset) { |
| 5174 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 5175 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5176 | } |
| 5177 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5178 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5179 | DCHECK(linker_patches->empty()); |
| 5180 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5181 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5182 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5183 | boot_image_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5184 | type_bss_entry_patches_.size() + |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5185 | public_type_bss_entry_patches_.size() + |
| 5186 | package_type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5187 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5188 | string_bss_entry_patches_.size() + |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5189 | boot_image_jni_entrypoint_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5190 | boot_image_other_patches_.size() + |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5191 | call_entrypoint_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5192 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5193 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5194 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5195 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5196 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5197 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5198 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5199 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5200 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5201 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5202 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5203 | DCHECK(boot_image_type_patches_.empty()); |
| 5204 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5205 | } |
| 5206 | if (GetCompilerOptions().IsBootImage()) { |
| 5207 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 5208 | boot_image_other_patches_, linker_patches); |
| 5209 | } else { |
| 5210 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 5211 | boot_image_other_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5212 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5213 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5214 | method_bss_entry_patches_, linker_patches); |
| 5215 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5216 | type_bss_entry_patches_, linker_patches); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5217 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PublicTypeBssEntryPatch>( |
| 5218 | public_type_bss_entry_patches_, linker_patches); |
| 5219 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PackageTypeBssEntryPatch>( |
| 5220 | package_type_bss_entry_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5221 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5222 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5223 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeJniEntrypointPatch>( |
| 5224 | boot_image_jni_entrypoint_patches_, linker_patches); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5225 | for (const PatchInfo<vixl::aarch64::Label>& info : call_entrypoint_patches_) { |
| 5226 | DCHECK(info.target_dex_file == nullptr); |
| 5227 | linker_patches->push_back(linker::LinkerPatch::CallEntrypointPatch( |
| 5228 | info.label.GetLocation(), info.offset_or_index)); |
| 5229 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5230 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5231 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 5232 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5233 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5234 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5235 | } |
| 5236 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5237 | bool CodeGeneratorARM64::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5238 | return patch.GetType() == linker::LinkerPatch::Type::kCallEntrypoint || |
| 5239 | patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5240 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 5241 | } |
| 5242 | |
| 5243 | void CodeGeneratorARM64::EmitThunkCode(const linker::LinkerPatch& patch, |
| 5244 | /*out*/ ArenaVector<uint8_t>* code, |
| 5245 | /*out*/ std::string* debug_name) { |
| 5246 | Arm64Assembler assembler(GetGraph()->GetAllocator()); |
| 5247 | switch (patch.GetType()) { |
| 5248 | case linker::LinkerPatch::Type::kCallRelative: { |
| 5249 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 5250 | // to the generic JNI and interpreter trampolines. |
| 5251 | Offset offset(ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 5252 | kArm64PointerSize).Int32Value()); |
| 5253 | assembler.JumpTo(ManagedRegister(arm64::X0), offset, ManagedRegister(arm64::IP0)); |
David Srbecky | 889da94 | 2021-04-30 13:03:14 +0100 | [diff] [blame] | 5254 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5255 | *debug_name = "MethodCallThunk"; |
| 5256 | } |
| 5257 | break; |
| 5258 | } |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5259 | case linker::LinkerPatch::Type::kCallEntrypoint: { |
| 5260 | Offset offset(patch.EntrypointOffset()); |
| 5261 | assembler.JumpTo(ManagedRegister(arm64::TR), offset, ManagedRegister(arm64::IP0)); |
David Srbecky | 889da94 | 2021-04-30 13:03:14 +0100 | [diff] [blame] | 5262 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5263 | *debug_name = "EntrypointCallThunk_" + std::to_string(offset.Uint32Value()); |
| 5264 | } |
| 5265 | break; |
| 5266 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5267 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| 5268 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 5269 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 5270 | break; |
| 5271 | } |
| 5272 | default: |
| 5273 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 5274 | UNREACHABLE(); |
| 5275 | } |
| 5276 | |
| 5277 | // Ensure we emit the literal pool if any. |
| 5278 | assembler.FinalizeCode(); |
| 5279 | code->resize(assembler.CodeSize()); |
| 5280 | MemoryRegion code_region(code->data(), code->size()); |
| 5281 | assembler.FinalizeInstructions(code_region); |
| 5282 | } |
| 5283 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5284 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 5285 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5286 | value, |
| 5287 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 5288 | } |
| 5289 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5290 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5291 | return uint64_literals_.GetOrCreate( |
| 5292 | value, |
| 5293 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5294 | } |
| 5295 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5296 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5297 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5298 | // art::PrepareForRegisterAllocation. |
| 5299 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5300 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5301 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5302 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5303 | return; |
| 5304 | } |
| 5305 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5306 | LocationSummary* locations = invoke->GetLocations(); |
| 5307 | codegen_->GenerateStaticOrDirectCall( |
| 5308 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5309 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5310 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5311 | } |
| 5312 | |
| 5313 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5314 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5315 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5316 | return; |
| 5317 | } |
| 5318 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5319 | { |
| 5320 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 5321 | // are no pools emitted. |
| 5322 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 5323 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 5324 | DCHECK(!codegen_->IsLeafMethod()); |
| 5325 | } |
| 5326 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5327 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5328 | } |
| 5329 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5330 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 5331 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5332 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5333 | case HLoadClass::LoadKind::kInvalid: |
| 5334 | LOG(FATAL) << "UNREACHABLE"; |
| 5335 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5336 | case HLoadClass::LoadKind::kReferrersClass: |
| 5337 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5338 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5339 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5340 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5341 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 5342 | case HLoadClass::LoadKind::kBssEntryPackage: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5343 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5344 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5345 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5346 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5347 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5348 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5349 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5350 | break; |
| 5351 | } |
| 5352 | return desired_class_load_kind; |
| 5353 | } |
| 5354 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5355 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5356 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5357 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5358 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5359 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5360 | cls, |
| 5361 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5362 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5363 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5364 | return; |
| 5365 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5366 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 5367 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 5368 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5369 | |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5370 | const bool requires_read_barrier = gUseReadBarrier && !cls->IsInBootImage(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5371 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5372 | ? LocationSummary::kCallOnSlowPath |
| 5373 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5374 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5375 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5376 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5377 | } |
| 5378 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5379 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5380 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5381 | } |
| 5382 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5383 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5384 | if (!gUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5385 | // 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] | 5386 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5387 | } else { |
| 5388 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5389 | } |
| 5390 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5391 | } |
| 5392 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5393 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5394 | // move. |
| 5395 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5396 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5397 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5398 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5399 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5400 | return; |
| 5401 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5402 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 5403 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 5404 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5405 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5406 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5407 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5408 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5409 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5410 | ? kWithoutReadBarrier |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5411 | : gCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5412 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5413 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5414 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5415 | DCHECK(!cls->CanCallRuntime()); |
| 5416 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5417 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5418 | Register current_method = InputRegisterAt(cls, 0); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5419 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5420 | out_loc, |
| 5421 | current_method, |
| 5422 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5423 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5424 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5425 | break; |
| 5426 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5427 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5428 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 5429 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5430 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5431 | // Add ADRP with its PC-relative type patch. |
| 5432 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5433 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5434 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5435 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5436 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5437 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5438 | codegen_->NewBootImageTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5439 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5440 | break; |
| 5441 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5442 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5443 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5444 | uint32_t boot_image_offset = CodeGenerator::GetBootImageOffset(cls); |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5445 | codegen_->LoadBootImageRelRoEntry(out.W(), boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5446 | break; |
| 5447 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5448 | case HLoadClass::LoadKind::kBssEntry: |
| 5449 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 5450 | case HLoadClass::LoadKind::kBssEntryPackage: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5451 | // Add ADRP with its PC-relative Class .bss entry patch. |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5452 | vixl::aarch64::Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5453 | vixl::aarch64::Label* adrp_label = codegen_->NewBssEntryTypePatch(cls); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5454 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5455 | // Add LDR with its PC-relative Class .bss entry patch. |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5456 | vixl::aarch64::Label* ldr_label = codegen_->NewBssEntryTypePatch(cls, adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5457 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5458 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5459 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5460 | out_loc, |
| 5461 | temp, |
| 5462 | /* offset placeholder */ 0u, |
| 5463 | ldr_label, |
| 5464 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5465 | generate_null_check = true; |
| 5466 | break; |
| 5467 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5468 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 5469 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 5470 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 5471 | DCHECK_NE(address, 0u); |
| 5472 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5473 | break; |
| 5474 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5475 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5476 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5477 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5478 | cls->GetClass())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5479 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5480 | out_loc, |
| 5481 | out.X(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5482 | /* offset= */ 0, |
| 5483 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5484 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5485 | break; |
| 5486 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5487 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5488 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5489 | LOG(FATAL) << "UNREACHABLE"; |
| 5490 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5491 | } |
| 5492 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5493 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5494 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5495 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 5496 | SlowPathCodeARM64* slow_path = |
| 5497 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5498 | codegen_->AddSlowPath(slow_path); |
| 5499 | if (generate_null_check) { |
| 5500 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5501 | } |
| 5502 | if (cls->MustGenerateClinitCheck()) { |
| 5503 | GenerateClassInitializationCheck(slow_path, out); |
| 5504 | } else { |
| 5505 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5506 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5507 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5508 | } |
| 5509 | } |
| 5510 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 5511 | void LocationsBuilderARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5512 | InvokeRuntimeCallingConvention calling_convention; |
| 5513 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5514 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 5515 | } |
| 5516 | |
| 5517 | void InstructionCodeGeneratorARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5518 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 5519 | } |
| 5520 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 5521 | void LocationsBuilderARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5522 | InvokeRuntimeCallingConvention calling_convention; |
| 5523 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5524 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 5525 | } |
| 5526 | |
| 5527 | void InstructionCodeGeneratorARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5528 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 5529 | } |
| 5530 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5531 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5532 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5533 | } |
| 5534 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5535 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5536 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5537 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5538 | locations->SetOut(Location::RequiresRegister()); |
| 5539 | } |
| 5540 | |
| 5541 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5542 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5543 | } |
| 5544 | |
| 5545 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5546 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5547 | } |
| 5548 | |
| 5549 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5550 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5551 | } |
| 5552 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5553 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5554 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5555 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5556 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5557 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5558 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5559 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5560 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5561 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5562 | case HLoadString::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5563 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5564 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5565 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5566 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5567 | } |
| 5568 | return desired_string_load_kind; |
| 5569 | } |
| 5570 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5571 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5572 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5573 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5574 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5575 | InvokeRuntimeCallingConvention calling_convention; |
| 5576 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5577 | } else { |
| 5578 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5579 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5580 | if (!gUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5581 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 5582 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5583 | } else { |
| 5584 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5585 | } |
| 5586 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5587 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5588 | } |
| 5589 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5590 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5591 | // move. |
| 5592 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5593 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5594 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5595 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5596 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5597 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5598 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 5599 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5600 | // Add ADRP with its PC-relative String patch. |
| 5601 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5602 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5603 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5604 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5605 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5606 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5607 | codegen_->NewBootImageStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5608 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5609 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5610 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5611 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5612 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5613 | uint32_t boot_image_offset = CodeGenerator::GetBootImageOffset(load); |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5614 | codegen_->LoadBootImageRelRoEntry(out.W(), boot_image_offset); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5615 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5616 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5617 | case HLoadString::LoadKind::kBssEntry: { |
| 5618 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5619 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5620 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5621 | Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5622 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5623 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5624 | // Add LDR with its PC-relative String .bss entry patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5625 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5626 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5627 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5628 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5629 | codegen_->GenerateGcRootFieldLoad(load, |
| 5630 | out_loc, |
| 5631 | temp, |
| 5632 | /* offset placeholder */ 0u, |
| 5633 | ldr_label, |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5634 | gCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5635 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5636 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5637 | codegen_->AddSlowPath(slow_path); |
| 5638 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5639 | __ Bind(slow_path->GetExitLabel()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5640 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5641 | return; |
| 5642 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5643 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 5644 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 5645 | DCHECK_NE(address, 0u); |
| 5646 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5647 | return; |
| 5648 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5649 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5650 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5651 | load->GetStringIndex(), |
| 5652 | load->GetString())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5653 | codegen_->GenerateGcRootFieldLoad(load, |
| 5654 | out_loc, |
| 5655 | out.X(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5656 | /* offset= */ 0, |
| 5657 | /* fixup_label= */ nullptr, |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5658 | gCompilerReadBarrierOption); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5659 | return; |
| 5660 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5661 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5662 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5663 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5664 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5665 | // 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] | 5666 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5667 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5668 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5669 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5670 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5671 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5672 | } |
| 5673 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5674 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5675 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5676 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5677 | } |
| 5678 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5679 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5680 | // Will be generated at use site. |
| 5681 | } |
| 5682 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5683 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5684 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5685 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5686 | InvokeRuntimeCallingConvention calling_convention; |
| 5687 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5688 | } |
| 5689 | |
| 5690 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5691 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5692 | instruction, |
| 5693 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5694 | if (instruction->IsEnter()) { |
| 5695 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5696 | } else { |
| 5697 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5698 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5699 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5700 | } |
| 5701 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5702 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5703 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5704 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5705 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5706 | case DataType::Type::kInt32: |
| 5707 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5708 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5709 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5710 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5711 | break; |
| 5712 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5713 | case DataType::Type::kFloat32: |
| 5714 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5715 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5716 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5717 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5718 | break; |
| 5719 | |
| 5720 | default: |
| 5721 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5722 | } |
| 5723 | } |
| 5724 | |
| 5725 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5726 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5727 | case DataType::Type::kInt32: |
| 5728 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5729 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5730 | break; |
| 5731 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5732 | case DataType::Type::kFloat32: |
| 5733 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5734 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5735 | break; |
| 5736 | |
| 5737 | default: |
| 5738 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5739 | } |
| 5740 | } |
| 5741 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5742 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5743 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5744 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5745 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5746 | case DataType::Type::kInt32: |
| 5747 | case DataType::Type::kInt64: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5748 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5749 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5750 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5751 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5752 | case DataType::Type::kFloat32: |
| 5753 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5754 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5755 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5756 | break; |
| 5757 | |
| 5758 | default: |
| 5759 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5760 | } |
| 5761 | } |
| 5762 | |
| 5763 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5764 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5765 | case DataType::Type::kInt32: |
| 5766 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5767 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5768 | break; |
| 5769 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5770 | case DataType::Type::kFloat32: |
| 5771 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5772 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5773 | break; |
| 5774 | |
| 5775 | default: |
| 5776 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5777 | } |
| 5778 | } |
| 5779 | |
| 5780 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5781 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5782 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5783 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5784 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5785 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5786 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5787 | } |
| 5788 | |
| 5789 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5790 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5791 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5792 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5793 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5794 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5795 | } |
| 5796 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5797 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5798 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5799 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5800 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5801 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5802 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5803 | } |
| 5804 | |
| 5805 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5806 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5807 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5808 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5809 | } |
| 5810 | |
| 5811 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5812 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5813 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5814 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5815 | } |
| 5816 | |
| 5817 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5818 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5819 | case DataType::Type::kInt32: |
| 5820 | case DataType::Type::kInt64: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5821 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5822 | break; |
| 5823 | |
| 5824 | default: |
| 5825 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5826 | } |
| 5827 | } |
| 5828 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5829 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5830 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5831 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5832 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5833 | } |
| 5834 | |
| 5835 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5836 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5837 | } |
| 5838 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5839 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5840 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5841 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5842 | } |
| 5843 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5844 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5845 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5846 | return; |
| 5847 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5848 | { |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 5849 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5850 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5851 | Location obj = instruction->GetLocations()->InAt(0); |
| 5852 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5853 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5854 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5855 | } |
| 5856 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5857 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5858 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5859 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5860 | |
| 5861 | LocationSummary* locations = instruction->GetLocations(); |
| 5862 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5863 | |
| 5864 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5865 | } |
| 5866 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5867 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5868 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5869 | } |
| 5870 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5871 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5872 | HandleBinaryOp(instruction); |
| 5873 | } |
| 5874 | |
| 5875 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5876 | HandleBinaryOp(instruction); |
| 5877 | } |
| 5878 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5879 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5880 | LOG(FATAL) << "Unreachable"; |
| 5881 | } |
| 5882 | |
| 5883 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5884 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5885 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5886 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5887 | // The back edge will generate the suspend check. |
| 5888 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5889 | } |
| 5890 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5891 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5892 | } |
| 5893 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5894 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5895 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5896 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5897 | if (location.IsStackSlot()) { |
| 5898 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5899 | } else if (location.IsDoubleStackSlot()) { |
| 5900 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5901 | } |
| 5902 | locations->SetOut(location); |
| 5903 | } |
| 5904 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5905 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5906 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5907 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5908 | } |
| 5909 | |
| 5910 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5911 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5912 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5913 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5914 | } |
| 5915 | |
| 5916 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5917 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5918 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5919 | } |
| 5920 | |
| 5921 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5922 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5923 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5924 | locations->SetInAt(i, Location::Any()); |
| 5925 | } |
| 5926 | locations->SetOut(Location::Any()); |
| 5927 | } |
| 5928 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5929 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5930 | LOG(FATAL) << "Unreachable"; |
| 5931 | } |
| 5932 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5933 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5934 | DataType::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5935 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5936 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5937 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5938 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5939 | |
| 5940 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5941 | case DataType::Type::kInt32: |
| 5942 | case DataType::Type::kInt64: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5943 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5944 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5945 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5946 | break; |
| 5947 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5948 | case DataType::Type::kFloat32: |
| 5949 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5950 | InvokeRuntimeCallingConvention calling_convention; |
| 5951 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5952 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5953 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5954 | |
| 5955 | break; |
| 5956 | } |
| 5957 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5958 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5959 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5960 | } |
| 5961 | } |
| 5962 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5963 | void InstructionCodeGeneratorARM64::GenerateIntRemForPower2Denom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5964 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5965 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 5966 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 5967 | |
| 5968 | Register out = OutputRegister(instruction); |
| 5969 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5970 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 5971 | if (HasNonNegativeOrMinIntInputAt(instruction, 0)) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 5972 | // No need to adjust the result for non-negative dividends or the INT32_MIN/INT64_MIN dividends. |
| 5973 | // NOTE: The generated code for HRem correctly works for the INT32_MIN/INT64_MIN dividends. |
| 5974 | // INT*_MIN % imm must be 0 for any imm of power 2. 'and' works only with bits |
| 5975 | // 0..30 (Int32 case)/0..62 (Int64 case) of a dividend. For INT32_MIN/INT64_MIN they are zeros. |
| 5976 | // So 'and' always produces zero. |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5977 | __ And(out, dividend, abs_imm - 1); |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 5978 | } else { |
| 5979 | if (abs_imm == 2) { |
| 5980 | __ Cmp(dividend, 0); |
| 5981 | __ And(out, dividend, 1); |
| 5982 | __ Csneg(out, out, out, ge); |
| 5983 | } else { |
| 5984 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5985 | Register temp = temps.AcquireSameSizeAs(out); |
| 5986 | |
| 5987 | __ Negs(temp, dividend); |
| 5988 | __ And(out, dividend, abs_imm - 1); |
| 5989 | __ And(temp, temp, abs_imm - 1); |
| 5990 | __ Csneg(out, out, temp, mi); |
| 5991 | } |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5992 | } |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5993 | } |
| 5994 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5995 | void InstructionCodeGeneratorARM64::GenerateIntRemForConstDenom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5996 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5997 | |
| 5998 | if (imm == 0) { |
| 5999 | // Do not generate anything. |
| 6000 | // DivZeroCheck would prevent any code to be executed. |
| 6001 | return; |
| 6002 | } |
| 6003 | |
Evgeny Astigeevich | f58dc65 | 2018-06-25 17:54:07 +0100 | [diff] [blame] | 6004 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 6005 | // Cases imm == -1 or imm == 1 are handled in constant folding by |
| 6006 | // InstructionWithAbsorbingInputSimplifier. |
| 6007 | // If the cases have survided till code generation they are handled in |
| 6008 | // GenerateIntRemForPower2Denom becauses -1 and 1 are the power of 2 (2^0). |
| 6009 | // The correct code is generated for them, just more instructions. |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 6010 | GenerateIntRemForPower2Denom(instruction); |
| 6011 | } else { |
| 6012 | DCHECK(imm < -2 || imm > 2) << imm; |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 6013 | GenerateDivRemWithAnyConstant(instruction, imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 6014 | } |
| 6015 | } |
| 6016 | |
| 6017 | void InstructionCodeGeneratorARM64::GenerateIntRem(HRem* instruction) { |
| 6018 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 6019 | << instruction->GetResultType(); |
| 6020 | |
| 6021 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 6022 | GenerateIntRemForConstDenom(instruction); |
| 6023 | } else { |
| 6024 | Register out = OutputRegister(instruction); |
| 6025 | Register dividend = InputRegisterAt(instruction, 0); |
| 6026 | Register divisor = InputRegisterAt(instruction, 1); |
| 6027 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6028 | Register temp = temps.AcquireSameSizeAs(out); |
| 6029 | __ Sdiv(temp, dividend, divisor); |
| 6030 | __ Msub(out, temp, divisor, dividend); |
| 6031 | } |
| 6032 | } |
| 6033 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6034 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6035 | DataType::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 6036 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6037 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6038 | case DataType::Type::kInt32: |
| 6039 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 6040 | GenerateIntRem(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6041 | break; |
| 6042 | } |
| 6043 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6044 | case DataType::Type::kFloat32: |
| 6045 | case DataType::Type::kFloat64: { |
| 6046 | QuickEntrypointEnum entrypoint = |
| 6047 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 6048 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6049 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6050 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 6051 | } else { |
| 6052 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 6053 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 6054 | break; |
| 6055 | } |
| 6056 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6057 | default: |
| 6058 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 6059 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6060 | } |
| 6061 | } |
| 6062 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6063 | void LocationsBuilderARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 6064 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6065 | } |
| 6066 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6067 | void InstructionCodeGeneratorARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 6068 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6069 | } |
| 6070 | |
| 6071 | void LocationsBuilderARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 6072 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6073 | } |
| 6074 | |
| 6075 | void InstructionCodeGeneratorARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 6076 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6077 | } |
| 6078 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 6079 | void LocationsBuilderARM64::VisitAbs(HAbs* abs) { |
| 6080 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 6081 | switch (abs->GetResultType()) { |
| 6082 | case DataType::Type::kInt32: |
| 6083 | case DataType::Type::kInt64: |
| 6084 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6085 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6086 | break; |
| 6087 | case DataType::Type::kFloat32: |
| 6088 | case DataType::Type::kFloat64: |
| 6089 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6090 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6091 | break; |
| 6092 | default: |
| 6093 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 6094 | } |
| 6095 | } |
| 6096 | |
| 6097 | void InstructionCodeGeneratorARM64::VisitAbs(HAbs* abs) { |
| 6098 | switch (abs->GetResultType()) { |
| 6099 | case DataType::Type::kInt32: |
| 6100 | case DataType::Type::kInt64: { |
| 6101 | Register in_reg = InputRegisterAt(abs, 0); |
| 6102 | Register out_reg = OutputRegister(abs); |
| 6103 | __ Cmp(in_reg, Operand(0)); |
| 6104 | __ Cneg(out_reg, in_reg, lt); |
| 6105 | break; |
| 6106 | } |
| 6107 | case DataType::Type::kFloat32: |
| 6108 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 6109 | VRegister in_reg = InputFPRegisterAt(abs, 0); |
| 6110 | VRegister out_reg = OutputFPRegister(abs); |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 6111 | __ Fabs(out_reg, in_reg); |
| 6112 | break; |
| 6113 | } |
| 6114 | default: |
| 6115 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 6116 | } |
| 6117 | } |
| 6118 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6119 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 6120 | constructor_fence->SetLocations(nullptr); |
| 6121 | } |
| 6122 | |
| 6123 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 6124 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 6125 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 6126 | } |
| 6127 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6128 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6129 | memory_barrier->SetLocations(nullptr); |
| 6130 | } |
| 6131 | |
| 6132 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6133 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6134 | } |
| 6135 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6136 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6137 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6138 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 6139 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6140 | } |
| 6141 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 6142 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* ret) { |
| 6143 | if (GetGraph()->IsCompilingOsr()) { |
| 6144 | // To simplify callers of an OSR method, we put the return value in both |
| 6145 | // floating point and core register. |
| 6146 | switch (ret->InputAt(0)->GetType()) { |
| 6147 | case DataType::Type::kFloat32: |
| 6148 | __ Fmov(w0, s0); |
| 6149 | break; |
| 6150 | case DataType::Type::kFloat64: |
| 6151 | __ Fmov(x0, d0); |
| 6152 | break; |
| 6153 | default: |
| 6154 | break; |
| 6155 | } |
| 6156 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6157 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6158 | } |
| 6159 | |
| 6160 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 6161 | instruction->SetLocations(nullptr); |
| 6162 | } |
| 6163 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6164 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6165 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6166 | } |
| 6167 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6168 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 6169 | HandleBinaryOp(ror); |
| 6170 | } |
| 6171 | |
| 6172 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 6173 | HandleBinaryOp(ror); |
| 6174 | } |
| 6175 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6176 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 6177 | HandleShift(shl); |
| 6178 | } |
| 6179 | |
| 6180 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 6181 | HandleShift(shl); |
| 6182 | } |
| 6183 | |
| 6184 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 6185 | HandleShift(shr); |
| 6186 | } |
| 6187 | |
| 6188 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 6189 | HandleShift(shr); |
| 6190 | } |
| 6191 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6192 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6193 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6194 | } |
| 6195 | |
| 6196 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6197 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6198 | } |
| 6199 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6200 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6201 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6202 | } |
| 6203 | |
| 6204 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 6205 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6206 | } |
| 6207 | |
| 6208 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 6209 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6210 | } |
| 6211 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6212 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6213 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6214 | } |
| 6215 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 6216 | void LocationsBuilderARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6217 | codegen_->CreateStringBuilderAppendLocations(instruction, LocationFrom(x0)); |
| 6218 | } |
| 6219 | |
| 6220 | void InstructionCodeGeneratorARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6221 | __ Mov(w0, instruction->GetFormat()->GetValue()); |
| 6222 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 6223 | } |
| 6224 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6225 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 6226 | HUnresolvedInstanceFieldGet* instruction) { |
| 6227 | FieldAccessCallingConventionARM64 calling_convention; |
| 6228 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6229 | instruction, instruction->GetFieldType(), calling_convention); |
| 6230 | } |
| 6231 | |
| 6232 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 6233 | HUnresolvedInstanceFieldGet* instruction) { |
| 6234 | FieldAccessCallingConventionARM64 calling_convention; |
| 6235 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6236 | instruction->GetFieldType(), |
| 6237 | instruction->GetFieldIndex(), |
| 6238 | instruction->GetDexPc(), |
| 6239 | calling_convention); |
| 6240 | } |
| 6241 | |
| 6242 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 6243 | HUnresolvedInstanceFieldSet* instruction) { |
| 6244 | FieldAccessCallingConventionARM64 calling_convention; |
| 6245 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6246 | instruction, instruction->GetFieldType(), calling_convention); |
| 6247 | } |
| 6248 | |
| 6249 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 6250 | HUnresolvedInstanceFieldSet* instruction) { |
| 6251 | FieldAccessCallingConventionARM64 calling_convention; |
| 6252 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6253 | instruction->GetFieldType(), |
| 6254 | instruction->GetFieldIndex(), |
| 6255 | instruction->GetDexPc(), |
| 6256 | calling_convention); |
| 6257 | } |
| 6258 | |
| 6259 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 6260 | HUnresolvedStaticFieldGet* instruction) { |
| 6261 | FieldAccessCallingConventionARM64 calling_convention; |
| 6262 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6263 | instruction, instruction->GetFieldType(), calling_convention); |
| 6264 | } |
| 6265 | |
| 6266 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 6267 | HUnresolvedStaticFieldGet* instruction) { |
| 6268 | FieldAccessCallingConventionARM64 calling_convention; |
| 6269 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6270 | instruction->GetFieldType(), |
| 6271 | instruction->GetFieldIndex(), |
| 6272 | instruction->GetDexPc(), |
| 6273 | calling_convention); |
| 6274 | } |
| 6275 | |
| 6276 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 6277 | HUnresolvedStaticFieldSet* instruction) { |
| 6278 | FieldAccessCallingConventionARM64 calling_convention; |
| 6279 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6280 | instruction, instruction->GetFieldType(), calling_convention); |
| 6281 | } |
| 6282 | |
| 6283 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 6284 | HUnresolvedStaticFieldSet* instruction) { |
| 6285 | FieldAccessCallingConventionARM64 calling_convention; |
| 6286 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6287 | instruction->GetFieldType(), |
| 6288 | instruction->GetFieldIndex(), |
| 6289 | instruction->GetDexPc(), |
| 6290 | calling_convention); |
| 6291 | } |
| 6292 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6293 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6294 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6295 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 6296 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6297 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6298 | // registers in full width (since the runtime only saves/restores lower part). |
| 6299 | locations->SetCustomSlowPathCallerSaves( |
| 6300 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6301 | } |
| 6302 | |
| 6303 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6304 | HBasicBlock* block = instruction->GetBlock(); |
| 6305 | if (block->GetLoopInformation() != nullptr) { |
| 6306 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6307 | // The back edge will generate the suspend check. |
| 6308 | return; |
| 6309 | } |
| 6310 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6311 | // The goto will generate the suspend check. |
| 6312 | return; |
| 6313 | } |
| 6314 | GenerateSuspendCheck(instruction, nullptr); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6315 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6316 | } |
| 6317 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6318 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6319 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6320 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6321 | InvokeRuntimeCallingConvention calling_convention; |
| 6322 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6323 | } |
| 6324 | |
| 6325 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 6326 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 6327 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6328 | } |
| 6329 | |
| 6330 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 6331 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6332 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6333 | DataType::Type input_type = conversion->GetInputType(); |
| 6334 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6335 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6336 | << input_type << " -> " << result_type; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6337 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 6338 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6339 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6340 | } |
| 6341 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6342 | if (DataType::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6343 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6344 | } else { |
| 6345 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6346 | } |
| 6347 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6348 | if (DataType::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6349 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6350 | } else { |
| 6351 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6352 | } |
| 6353 | } |
| 6354 | |
| 6355 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6356 | DataType::Type result_type = conversion->GetResultType(); |
| 6357 | DataType::Type input_type = conversion->GetInputType(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6358 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6359 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6360 | << input_type << " -> " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6361 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6362 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 6363 | int result_size = DataType::Size(result_type); |
| 6364 | int input_size = DataType::Size(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6365 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6366 | Register output = OutputRegister(conversion); |
| 6367 | Register source = InputRegisterAt(conversion, 0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6368 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 6369 | // 'int' values are used directly as W registers, discarding the top |
| 6370 | // bits, so we don't need to sign-extend and can just perform a move. |
| 6371 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 6372 | // top 32 bits of the target register. We theoretically could leave those |
| 6373 | // bits unchanged, but we would have to make sure that no code uses a |
| 6374 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 6375 | // zero. |
| 6376 | __ Mov(output.W(), source.W()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6377 | } else if (DataType::IsUnsignedType(result_type) || |
| 6378 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 6379 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6380 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6381 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6382 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6383 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6384 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6385 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 6386 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6387 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6388 | } else if (DataType::IsFloatingPointType(result_type) && |
| 6389 | DataType::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6390 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 6391 | } else { |
| 6392 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6393 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6394 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6395 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6396 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6397 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 6398 | HandleShift(ushr); |
| 6399 | } |
| 6400 | |
| 6401 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 6402 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6403 | } |
| 6404 | |
| 6405 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 6406 | HandleBinaryOp(instruction); |
| 6407 | } |
| 6408 | |
| 6409 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 6410 | HandleBinaryOp(instruction); |
| 6411 | } |
| 6412 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6413 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6414 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6415 | LOG(FATAL) << "Unreachable"; |
| 6416 | } |
| 6417 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6418 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6419 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6420 | LOG(FATAL) << "Unreachable"; |
| 6421 | } |
| 6422 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6423 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6424 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6425 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6426 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6427 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6428 | } |
| 6429 | |
| 6430 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6431 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6432 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6433 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 6434 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6435 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6436 | // 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] | 6437 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6438 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 6439 | // make sure we don't emit it if the target may run out of range. |
| 6440 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 6441 | // ranges and emit the tables only as required. |
| 6442 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6443 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6444 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6445 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 6446 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 6447 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6448 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6449 | Register temp = temps.AcquireW(); |
| 6450 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 6451 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6452 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6453 | // Jump to successors[0] if value == lower_bound. |
| 6454 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 6455 | int32_t last_index = 0; |
| 6456 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6457 | __ Subs(temp, temp, Operand(2)); |
| 6458 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6459 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6460 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6461 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6462 | } |
| 6463 | if (num_entries - last_index == 2) { |
| 6464 | // The last missing case_value. |
| 6465 | __ Cmp(temp, Operand(1)); |
| 6466 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6467 | } |
| 6468 | |
| 6469 | // And the default for any other value. |
| 6470 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6471 | __ B(codegen_->GetLabelOf(default_block)); |
| 6472 | } |
| 6473 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 6474 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6475 | |
| 6476 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6477 | |
| 6478 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 6479 | // registers, we are free to block one. |
| 6480 | Register temp_w = temps.AcquireW(); |
| 6481 | Register index; |
| 6482 | // Remove the bias. |
| 6483 | if (lower_bound != 0) { |
| 6484 | index = temp_w; |
| 6485 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 6486 | } else { |
| 6487 | index = value_reg; |
| 6488 | } |
| 6489 | |
| 6490 | // Jump to default block if index is out of the range. |
| 6491 | __ Cmp(index, Operand(num_entries)); |
| 6492 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 6493 | |
| 6494 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 6495 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 6496 | // register pressure. |
| 6497 | Register table_base = temps.AcquireX(); |
| 6498 | // Load jump offset from the table. |
| 6499 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 6500 | Register jump_offset = temp_w; |
| 6501 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 6502 | |
| 6503 | // Jump to target block by branching to table_base(pc related) + offset. |
| 6504 | Register target_address = table_base; |
| 6505 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 6506 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6507 | } |
| 6508 | } |
| 6509 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6510 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 6511 | HInstruction* instruction, |
| 6512 | Location out, |
| 6513 | uint32_t offset, |
| 6514 | Location maybe_temp, |
| 6515 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6516 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6517 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6518 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6519 | CHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6520 | if (kUseBakerReadBarrier) { |
| 6521 | // Load with fast path based Baker's read barrier. |
| 6522 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6523 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6524 | out, |
| 6525 | out_reg, |
| 6526 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6527 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6528 | /* needs_null_check= */ false, |
| 6529 | /* use_load_acquire= */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6530 | } else { |
| 6531 | // Load with slow path based read barrier. |
| 6532 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6533 | // in the following move operation, as we will need it for the |
| 6534 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6535 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6536 | __ Mov(temp_reg, out_reg); |
| 6537 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6538 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6539 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6540 | } |
| 6541 | } else { |
| 6542 | // Plain load with no read barrier. |
| 6543 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6544 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6545 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6546 | } |
| 6547 | } |
| 6548 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6549 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 6550 | HInstruction* instruction, |
| 6551 | Location out, |
| 6552 | Location obj, |
| 6553 | uint32_t offset, |
| 6554 | Location maybe_temp, |
| 6555 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6556 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6557 | Register out_reg = RegisterFrom(out, type); |
| 6558 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6559 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6560 | CHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6561 | if (kUseBakerReadBarrier) { |
| 6562 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6563 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6564 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6565 | out, |
| 6566 | obj_reg, |
| 6567 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6568 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6569 | /* needs_null_check= */ false, |
| 6570 | /* use_load_acquire= */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6571 | } else { |
| 6572 | // Load with slow path based read barrier. |
| 6573 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6574 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6575 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6576 | } |
| 6577 | } else { |
| 6578 | // Plain load with no read barrier. |
| 6579 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6580 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6581 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6582 | } |
| 6583 | } |
| 6584 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6585 | void CodeGeneratorARM64::GenerateGcRootFieldLoad( |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6586 | HInstruction* instruction, |
| 6587 | Location root, |
| 6588 | Register obj, |
| 6589 | uint32_t offset, |
| 6590 | vixl::aarch64::Label* fixup_label, |
| 6591 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6592 | DCHECK(fixup_label == nullptr || offset == 0u); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6593 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6594 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6595 | DCHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6596 | if (kUseBakerReadBarrier) { |
| 6597 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6598 | // Baker's read barrier are used. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6599 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6600 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6601 | // the Marking Register) to decide whether we need to enter |
| 6602 | // the slow path to mark the GC root. |
| 6603 | // |
| 6604 | // We use shared thunks for the slow path; shared within the method |
| 6605 | // for JIT, across methods for AOT. That thunk checks the reference |
| 6606 | // and jumps to the entrypoint if needed. |
| 6607 | // |
| 6608 | // lr = &return_address; |
| 6609 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6610 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6611 | // goto gc_root_thunk<root_reg>(lr) |
| 6612 | // } |
| 6613 | // return_address: |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6614 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6615 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6616 | DCHECK(temps.IsAvailable(ip0)); |
| 6617 | DCHECK(temps.IsAvailable(ip1)); |
| 6618 | temps.Exclude(ip0, ip1); |
| 6619 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6620 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6621 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6622 | vixl::aarch64::Label return_address; |
| 6623 | __ adr(lr, &return_address); |
| 6624 | if (fixup_label != nullptr) { |
| 6625 | __ bind(fixup_label); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6626 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6627 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6628 | "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] | 6629 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6630 | EmitBakerReadBarrierCbnz(custom_data); |
| 6631 | __ bind(&return_address); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6632 | } else { |
| 6633 | // GC root loaded through a slow path for read barriers other |
| 6634 | // than Baker's. |
| 6635 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6636 | if (fixup_label == nullptr) { |
| 6637 | __ Add(root_reg.X(), obj.X(), offset); |
| 6638 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6639 | EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6640 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6641 | // /* mirror::Object* */ root = root->Read() |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6642 | GenerateReadBarrierForRootSlow(instruction, root, root); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6643 | } |
| 6644 | } else { |
| 6645 | // Plain GC root load with no read barrier. |
| 6646 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6647 | if (fixup_label == nullptr) { |
| 6648 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6649 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6650 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6651 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6652 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6653 | // do not have to unpoison `root_reg` here. |
| 6654 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6655 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6656 | } |
| 6657 | |
Vladimir Marko | c8178f5 | 2020-11-24 10:38:16 +0000 | [diff] [blame] | 6658 | void CodeGeneratorARM64::GenerateIntrinsicCasMoveWithBakerReadBarrier( |
| 6659 | vixl::aarch64::Register marked_old_value, |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6660 | vixl::aarch64::Register old_value) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6661 | DCHECK(gUseReadBarrier); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6662 | DCHECK(kUseBakerReadBarrier); |
| 6663 | |
| 6664 | // 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] | 6665 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(marked_old_value.GetCode()); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6666 | |
| 6667 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6668 | vixl::aarch64::Label return_address; |
| 6669 | __ adr(lr, &return_address); |
| 6670 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6671 | "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] | 6672 | __ mov(marked_old_value, old_value); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6673 | EmitBakerReadBarrierCbnz(custom_data); |
| 6674 | __ bind(&return_address); |
| 6675 | } |
| 6676 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6677 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6678 | Location ref, |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6679 | vixl::aarch64::Register obj, |
| 6680 | const vixl::aarch64::MemOperand& src, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6681 | bool needs_null_check, |
| 6682 | bool use_load_acquire) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6683 | DCHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6684 | DCHECK(kUseBakerReadBarrier); |
| 6685 | |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6686 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6687 | // Marking Register) to decide whether we need to enter the slow |
| 6688 | // path to mark the reference. Then, in the slow path, check the |
| 6689 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6690 | // decide whether to mark `ref` or not. |
| 6691 | // |
| 6692 | // We use shared thunks for the slow path; shared within the method |
| 6693 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6694 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6695 | // it creates a fake dependency and returns to the LDR instruction. |
| 6696 | // |
| 6697 | // lr = &gray_return_address; |
| 6698 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6699 | // goto field_thunk<holder_reg, base_reg, use_load_acquire>(lr) |
| 6700 | // } |
| 6701 | // not_gray_return_address: |
| 6702 | // // Original reference load. If the offset is too large to fit |
| 6703 | // // into LDR, we use an adjusted base register here. |
| 6704 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 6705 | // gray_return_address: |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6706 | |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6707 | DCHECK(src.GetAddrMode() == vixl::aarch64::Offset); |
| 6708 | DCHECK_ALIGNED(src.GetOffset(), sizeof(mirror::HeapReference<mirror::Object>)); |
| 6709 | |
| 6710 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6711 | DCHECK(temps.IsAvailable(ip0)); |
| 6712 | DCHECK(temps.IsAvailable(ip1)); |
| 6713 | temps.Exclude(ip0, ip1); |
| 6714 | uint32_t custom_data = use_load_acquire |
| 6715 | ? EncodeBakerReadBarrierAcquireData(src.GetBaseRegister().GetCode(), obj.GetCode()) |
| 6716 | : EncodeBakerReadBarrierFieldData(src.GetBaseRegister().GetCode(), obj.GetCode()); |
| 6717 | |
| 6718 | { |
| 6719 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6720 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6721 | vixl::aarch64::Label return_address; |
| 6722 | __ adr(lr, &return_address); |
| 6723 | EmitBakerReadBarrierCbnz(custom_data); |
| 6724 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6725 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6726 | " 2 instructions (8B) for heap poisoning."); |
| 6727 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 6728 | if (use_load_acquire) { |
| 6729 | DCHECK_EQ(src.GetOffset(), 0); |
| 6730 | __ ldar(ref_reg, src); |
| 6731 | } else { |
| 6732 | __ ldr(ref_reg, src); |
| 6733 | } |
| 6734 | if (needs_null_check) { |
| 6735 | MaybeRecordImplicitNullCheck(instruction); |
| 6736 | } |
| 6737 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6738 | // macro instructions disallowed in ExactAssemblyScope. |
| 6739 | if (kPoisonHeapReferences) { |
| 6740 | __ neg(ref_reg, Operand(ref_reg)); |
| 6741 | } |
| 6742 | __ bind(&return_address); |
| 6743 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6744 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6745 | } |
| 6746 | |
| 6747 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6748 | Location ref, |
| 6749 | Register obj, |
| 6750 | uint32_t offset, |
| 6751 | Location maybe_temp, |
| 6752 | bool needs_null_check, |
| 6753 | bool use_load_acquire) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6754 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6755 | Register base = obj; |
| 6756 | if (use_load_acquire) { |
| 6757 | DCHECK(maybe_temp.IsRegister()); |
| 6758 | base = WRegisterFrom(maybe_temp); |
| 6759 | __ Add(base, obj, offset); |
| 6760 | offset = 0u; |
| 6761 | } else if (offset >= kReferenceLoadMinFarOffset) { |
| 6762 | DCHECK(maybe_temp.IsRegister()); |
| 6763 | base = WRegisterFrom(maybe_temp); |
| 6764 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6765 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6766 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6767 | } |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6768 | MemOperand src(base.X(), offset); |
| 6769 | GenerateFieldLoadWithBakerReadBarrier( |
| 6770 | instruction, ref, obj, src, needs_null_check, use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6771 | } |
| 6772 | |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6773 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HArrayGet* instruction, |
| 6774 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6775 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6776 | uint32_t data_offset, |
| 6777 | Location index, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6778 | bool needs_null_check) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6779 | DCHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6780 | DCHECK(kUseBakerReadBarrier); |
| 6781 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6782 | static_assert( |
| 6783 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6784 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6785 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6786 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6787 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6788 | // Marking Register) to decide whether we need to enter the slow |
| 6789 | // path to mark the reference. Then, in the slow path, check the |
| 6790 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6791 | // decide whether to mark `ref` or not. |
| 6792 | // |
| 6793 | // We use shared thunks for the slow path; shared within the method |
| 6794 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6795 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6796 | // it creates a fake dependency and returns to the LDR instruction. |
| 6797 | // |
| 6798 | // lr = &gray_return_address; |
| 6799 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6800 | // goto array_thunk<base_reg>(lr) |
| 6801 | // } |
| 6802 | // not_gray_return_address: |
| 6803 | // // Original reference load. If the offset is too large to fit |
| 6804 | // // into LDR, we use an adjusted base register here. |
| 6805 | // HeapReference<mirror::Object> reference = data[index]; |
| 6806 | // gray_return_address: |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6807 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6808 | DCHECK(index.IsValid()); |
| 6809 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 6810 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6811 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6812 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6813 | DCHECK(temps.IsAvailable(ip0)); |
| 6814 | DCHECK(temps.IsAvailable(ip1)); |
| 6815 | temps.Exclude(ip0, ip1); |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6816 | |
| 6817 | Register temp; |
| 6818 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 6819 | // We do not need to compute the intermediate address from the array: the |
| 6820 | // input instruction has done it already. See the comment in |
| 6821 | // `TryExtractArrayAccessAddress()`. |
| 6822 | if (kIsDebugBuild) { |
| 6823 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 6824 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 6825 | } |
| 6826 | temp = obj; |
| 6827 | } else { |
| 6828 | temp = WRegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 6829 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
| 6830 | } |
| 6831 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6832 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(temp.GetCode()); |
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 | { |
| 6835 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6836 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6837 | vixl::aarch64::Label return_address; |
| 6838 | __ adr(lr, &return_address); |
| 6839 | EmitBakerReadBarrierCbnz(custom_data); |
| 6840 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6841 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6842 | " 2 instructions (8B) for heap poisoning."); |
| 6843 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6844 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6845 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6846 | // macro instructions disallowed in ExactAssemblyScope. |
| 6847 | if (kPoisonHeapReferences) { |
| 6848 | __ neg(ref_reg, Operand(ref_reg)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6849 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6850 | __ bind(&return_address); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6851 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6852 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6853 | } |
| 6854 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6855 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6856 | // 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] | 6857 | if (kIsDebugBuild && gUseReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6858 | // The following condition is a run-time one; it is executed after the |
| 6859 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6860 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6861 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6862 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6863 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6864 | } |
| 6865 | } |
| 6866 | } |
| 6867 | |
Vladimir Marko | 1bff99f | 2020-11-02 15:07:33 +0000 | [diff] [blame] | 6868 | SlowPathCodeARM64* CodeGeneratorARM64::AddReadBarrierSlowPath(HInstruction* instruction, |
| 6869 | Location out, |
| 6870 | Location ref, |
| 6871 | Location obj, |
| 6872 | uint32_t offset, |
| 6873 | Location index) { |
| 6874 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
| 6875 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6876 | AddSlowPath(slow_path); |
| 6877 | return slow_path; |
| 6878 | } |
| 6879 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6880 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6881 | Location out, |
| 6882 | Location ref, |
| 6883 | Location obj, |
| 6884 | uint32_t offset, |
| 6885 | Location index) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6886 | DCHECK(gUseReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6887 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6888 | // Insert a slow path based read barrier *after* the reference load. |
| 6889 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6890 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6891 | // reference will be carried out by the runtime within the slow |
| 6892 | // path. |
| 6893 | // |
| 6894 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6895 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6896 | // not used by the artReadBarrierSlow entry point. |
| 6897 | // |
| 6898 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 1bff99f | 2020-11-02 15:07:33 +0000 | [diff] [blame] | 6899 | SlowPathCodeARM64* slow_path = AddReadBarrierSlowPath(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6900 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6901 | __ B(slow_path->GetEntryLabel()); |
| 6902 | __ Bind(slow_path->GetExitLabel()); |
| 6903 | } |
| 6904 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6905 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6906 | Location out, |
| 6907 | Location ref, |
| 6908 | Location obj, |
| 6909 | uint32_t offset, |
| 6910 | Location index) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6911 | if (gUseReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6912 | // Baker's read barriers shall be handled by the fast path |
| 6913 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6914 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6915 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6916 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6917 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6918 | } else if (kPoisonHeapReferences) { |
| 6919 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6920 | } |
| 6921 | } |
| 6922 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6923 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6924 | Location out, |
| 6925 | Location root) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6926 | DCHECK(gUseReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6927 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6928 | // Insert a slow path based read barrier *after* the GC root load. |
| 6929 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6930 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6931 | // not need to do anything special for this here. |
| 6932 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6933 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6934 | AddSlowPath(slow_path); |
| 6935 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6936 | __ B(slow_path->GetEntryLabel()); |
| 6937 | __ Bind(slow_path->GetExitLabel()); |
| 6938 | } |
| 6939 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6940 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6941 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6942 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6943 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6944 | locations->SetOut(Location::RequiresRegister()); |
| 6945 | } |
| 6946 | |
| 6947 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6948 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6949 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6950 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6951 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6952 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6953 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6954 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6955 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6956 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6957 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6958 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6959 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6960 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6961 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6962 | } |
| 6963 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6964 | static void PatchJitRootUse(uint8_t* code, |
| 6965 | const uint8_t* roots_data, |
| 6966 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6967 | uint64_t index_in_table) { |
| 6968 | uint32_t literal_offset = literal->GetOffset(); |
| 6969 | uintptr_t address = |
| 6970 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6971 | uint8_t* data = code + literal_offset; |
| 6972 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6973 | } |
| 6974 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6975 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6976 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6977 | const StringReference& string_reference = entry.first; |
| 6978 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6979 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6980 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6981 | } |
| 6982 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6983 | const TypeReference& type_reference = entry.first; |
| 6984 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6985 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6986 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6987 | } |
| 6988 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6989 | |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 6990 | MemOperand InstructionCodeGeneratorARM64::VecNEONAddress( |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 6991 | HVecMemoryOperation* instruction, |
| 6992 | UseScratchRegisterScope* temps_scope, |
| 6993 | size_t size, |
| 6994 | bool is_string_char_at, |
| 6995 | /*out*/ Register* scratch) { |
| 6996 | LocationSummary* locations = instruction->GetLocations(); |
| 6997 | Register base = InputRegisterAt(instruction, 0); |
| 6998 | |
| 6999 | if (instruction->InputAt(1)->IsIntermediateAddressIndex()) { |
| 7000 | DCHECK(!is_string_char_at); |
| 7001 | return MemOperand(base.X(), InputRegisterAt(instruction, 1).X()); |
| 7002 | } |
| 7003 | |
| 7004 | Location index = locations->InAt(1); |
| 7005 | uint32_t offset = is_string_char_at |
| 7006 | ? mirror::String::ValueOffset().Uint32Value() |
| 7007 | : mirror::Array::DataOffset(size).Uint32Value(); |
| 7008 | size_t shift = ComponentSizeShiftWidth(size); |
| 7009 | |
| 7010 | // HIntermediateAddress optimization is only applied for scalar ArrayGet and ArraySet. |
| 7011 | DCHECK(!instruction->InputAt(0)->IsIntermediateAddress()); |
| 7012 | |
| 7013 | if (index.IsConstant()) { |
| 7014 | offset += Int64FromLocation(index) << shift; |
| 7015 | return HeapOperand(base, offset); |
| 7016 | } else { |
| 7017 | *scratch = temps_scope->AcquireSameSizeAs(base); |
| 7018 | __ Add(*scratch, base, Operand(WRegisterFrom(index), LSL, shift)); |
| 7019 | return HeapOperand(*scratch, offset); |
| 7020 | } |
| 7021 | } |
| 7022 | |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 7023 | SVEMemOperand InstructionCodeGeneratorARM64::VecSVEAddress( |
| 7024 | HVecMemoryOperation* instruction, |
| 7025 | UseScratchRegisterScope* temps_scope, |
| 7026 | size_t size, |
| 7027 | bool is_string_char_at, |
| 7028 | /*out*/ Register* scratch) { |
| 7029 | LocationSummary* locations = instruction->GetLocations(); |
| 7030 | Register base = InputRegisterAt(instruction, 0); |
| 7031 | Location index = locations->InAt(1); |
| 7032 | |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 7033 | DCHECK(!instruction->InputAt(1)->IsIntermediateAddressIndex()); |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 7034 | DCHECK(!index.IsConstant()); |
| 7035 | |
| 7036 | uint32_t offset = is_string_char_at |
| 7037 | ? mirror::String::ValueOffset().Uint32Value() |
| 7038 | : mirror::Array::DataOffset(size).Uint32Value(); |
| 7039 | size_t shift = ComponentSizeShiftWidth(size); |
| 7040 | |
Raphael Gault | 0700b69 | 2020-09-30 08:33:10 +0000 | [diff] [blame] | 7041 | if (instruction->InputAt(0)->IsIntermediateAddress()) { |
| 7042 | return SVEMemOperand(base.X(), XRegisterFrom(index), LSL, shift); |
| 7043 | } |
| 7044 | |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 7045 | *scratch = temps_scope->AcquireSameSizeAs(base); |
| 7046 | __ Add(*scratch, base, offset); |
| 7047 | return SVEMemOperand(scratch->X(), XRegisterFrom(index), LSL, shift); |
| 7048 | } |
| 7049 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 7050 | #undef __ |
| 7051 | #undef QUICK_ENTRY_POINT |
| 7052 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7053 | #define __ assembler.GetVIXLAssembler()-> |
| 7054 | |
| 7055 | static void EmitGrayCheckAndFastPath(arm64::Arm64Assembler& assembler, |
| 7056 | vixl::aarch64::Register base_reg, |
| 7057 | vixl::aarch64::MemOperand& lock_word, |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7058 | vixl::aarch64::Label* slow_path, |
| 7059 | vixl::aarch64::Label* throw_npe = nullptr) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7060 | // Load the lock word containing the rb_state. |
| 7061 | __ Ldr(ip0.W(), lock_word); |
| 7062 | // 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] | 7063 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7064 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7065 | __ Tbnz(ip0.W(), LockWord::kReadBarrierStateShift, slow_path); |
| 7066 | static_assert( |
| 7067 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET, |
| 7068 | "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] | 7069 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 7070 | if (throw_npe != nullptr) { |
| 7071 | __ Bind(throw_npe); |
| 7072 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7073 | // Adjust the return address back to the LDR (1 instruction; 2 for heap poisoning). |
| 7074 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 7075 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 7076 | " 2 instructions (8B) for heap poisoning."); |
| 7077 | __ Add(lr, lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 7078 | // Introduce a dependency on the lock_word including rb_state, |
| 7079 | // to prevent load-load reordering, and without using |
| 7080 | // a memory barrier (which would be more expensive). |
| 7081 | __ Add(base_reg, base_reg, Operand(ip0, LSR, 32)); |
| 7082 | __ Br(lr); // And return back to the function. |
| 7083 | // Note: The fake dependency is unnecessary for the slow path. |
| 7084 | } |
| 7085 | |
| 7086 | // Load the read barrier introspection entrypoint in register `entrypoint`. |
| 7087 | static void LoadReadBarrierMarkIntrospectionEntrypoint(arm64::Arm64Assembler& assembler, |
| 7088 | vixl::aarch64::Register entrypoint) { |
| 7089 | // entrypoint = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 7090 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 7091 | const int32_t entry_point_offset = |
| 7092 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 7093 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| 7094 | } |
| 7095 | |
| 7096 | void CodeGeneratorARM64::CompileBakerReadBarrierThunk(Arm64Assembler& assembler, |
| 7097 | uint32_t encoded_data, |
| 7098 | /*out*/ std::string* debug_name) { |
| 7099 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 7100 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 7101 | case BakerReadBarrierKind::kField: |
| 7102 | case BakerReadBarrierKind::kAcquire: { |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 7103 | Register base_reg = |
| 7104 | vixl::aarch64::XRegister(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7105 | CheckValidReg(base_reg.GetCode()); |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 7106 | Register holder_reg = |
| 7107 | vixl::aarch64::XRegister(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7108 | CheckValidReg(holder_reg.GetCode()); |
| 7109 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 7110 | temps.Exclude(ip0, ip1); |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 7111 | // In the case of a field load (with relaxed semantic), if `base_reg` differs from |
| 7112 | // `holder_reg`, the offset was too large and we must have emitted (during the construction |
| 7113 | // of the HIR graph, see `art::HInstructionBuilder::BuildInstanceFieldAccess`) and preserved |
| 7114 | // (see `art::PrepareForRegisterAllocation::VisitNullCheck`) an explicit null check before |
| 7115 | // the load. Otherwise, for implicit null checks, we need to null-check the holder as we do |
| 7116 | // not necessarily do that check before going to the thunk. |
| 7117 | // |
| 7118 | // In the case of a field load with load-acquire semantics (where `base_reg` always differs |
| 7119 | // from `holder_reg`), we also need an explicit null check when implicit null checks are |
| 7120 | // allowed, as we do not emit one before going to the thunk. |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7121 | vixl::aarch64::Label throw_npe_label; |
| 7122 | vixl::aarch64::Label* throw_npe = nullptr; |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 7123 | if (GetCompilerOptions().GetImplicitNullChecks() && |
| 7124 | (holder_reg.Is(base_reg) || (kind == BakerReadBarrierKind::kAcquire))) { |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7125 | throw_npe = &throw_npe_label; |
| 7126 | __ Cbz(holder_reg.W(), throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7127 | } |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7128 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 7129 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 7130 | // to load the reference and call the entrypoint that performs further checks on the |
| 7131 | // reference and marks it if needed. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7132 | vixl::aarch64::Label slow_path; |
| 7133 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7134 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7135 | __ Bind(&slow_path); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 7136 | if (kind == BakerReadBarrierKind::kField) { |
| 7137 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 7138 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (immediate) unsigned offset. |
| 7139 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 7140 | __ Ubfx(ip0.W(), ip0.W(), 10, 12); // Extract the offset. |
| 7141 | __ Ldr(ip0.W(), MemOperand(base_reg, ip0, LSL, 2)); // Load the reference. |
| 7142 | } else { |
| 7143 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 7144 | DCHECK(!base_reg.Is(holder_reg)); |
| 7145 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 7146 | __ Ldar(ip0.W(), MemOperand(base_reg)); |
| 7147 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7148 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 7149 | __ Br(ip1); // Jump to the entrypoint. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7150 | break; |
| 7151 | } |
| 7152 | case BakerReadBarrierKind::kArray: { |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 7153 | Register base_reg = |
| 7154 | vixl::aarch64::XRegister(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7155 | CheckValidReg(base_reg.GetCode()); |
| 7156 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7157 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7158 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 7159 | temps.Exclude(ip0, ip1); |
| 7160 | vixl::aarch64::Label slow_path; |
| 7161 | int32_t data_offset = |
| 7162 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 7163 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 7164 | DCHECK_LT(lock_word.GetOffset(), 0); |
| 7165 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path); |
| 7166 | __ Bind(&slow_path); |
| 7167 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| 7168 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (register) unsigned offset. |
| 7169 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 7170 | __ Ubfx(ip0, ip0, 16, 6); // Extract the index register, plus 32 (bit 21 is set). |
| 7171 | __ Bfi(ip1, ip0, 3, 6); // Insert ip0 to the entrypoint address to create |
| 7172 | // a switch case target based on the index register. |
| 7173 | __ Mov(ip0, base_reg); // Move the base register to ip0. |
| 7174 | __ Br(ip1); // Jump to the entrypoint's array switch case. |
| 7175 | break; |
| 7176 | } |
| 7177 | case BakerReadBarrierKind::kGcRoot: { |
| 7178 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 7179 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 7180 | // otherwise return the reference (or the extracted forwarding address). |
| 7181 | // There is no gray bit check for GC roots. |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 7182 | Register root_reg = |
| 7183 | vixl::aarch64::WRegister(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7184 | CheckValidReg(root_reg.GetCode()); |
| 7185 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7186 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7187 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 7188 | temps.Exclude(ip0, ip1); |
| 7189 | vixl::aarch64::Label return_label, not_marked, forwarding_address; |
| 7190 | __ Cbz(root_reg, &return_label); |
| 7191 | MemOperand lock_word(root_reg.X(), mirror::Object::MonitorOffset().Int32Value()); |
| 7192 | __ Ldr(ip0.W(), lock_word); |
| 7193 | __ Tbz(ip0.W(), LockWord::kMarkBitStateShift, ¬_marked); |
| 7194 | __ Bind(&return_label); |
| 7195 | __ Br(lr); |
| 7196 | __ Bind(¬_marked); |
| 7197 | __ Tst(ip0.W(), Operand(ip0.W(), LSL, 1)); |
| 7198 | __ B(&forwarding_address, mi); |
| 7199 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 7200 | // Adjust the art_quick_read_barrier_mark_introspection address in IP1 to |
| 7201 | // art_quick_read_barrier_mark_introspection_gc_roots. |
| 7202 | __ Add(ip1, ip1, Operand(BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET)); |
| 7203 | __ Mov(ip0.W(), root_reg); |
| 7204 | __ Br(ip1); |
| 7205 | __ Bind(&forwarding_address); |
| 7206 | __ Lsl(root_reg, ip0.W(), LockWord::kForwardingAddressShift); |
| 7207 | __ Br(lr); |
| 7208 | break; |
| 7209 | } |
| 7210 | default: |
| 7211 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 7212 | UNREACHABLE(); |
| 7213 | } |
| 7214 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 7215 | // For JIT, the slow path is considered part of the compiled method, |
Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 7216 | // so JIT should pass null as `debug_name`. |
Santiago Aboy Solanes | 872ec72 | 2022-02-18 14:10:25 +0000 | [diff] [blame] | 7217 | DCHECK_IMPLIES(GetCompilerOptions().IsJitCompiler(), debug_name == nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 7218 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7219 | std::ostringstream oss; |
| 7220 | oss << "BakerReadBarrierThunk"; |
| 7221 | switch (kind) { |
| 7222 | case BakerReadBarrierKind::kField: |
| 7223 | oss << "Field_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 7224 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 7225 | break; |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 7226 | case BakerReadBarrierKind::kAcquire: |
| 7227 | oss << "Acquire_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 7228 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 7229 | break; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7230 | case BakerReadBarrierKind::kArray: |
| 7231 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 7232 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7233 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7234 | break; |
| 7235 | case BakerReadBarrierKind::kGcRoot: |
| 7236 | oss << "GcRoot_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 7237 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7238 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7239 | break; |
| 7240 | } |
| 7241 | *debug_name = oss.str(); |
| 7242 | } |
| 7243 | } |
| 7244 | |
| 7245 | #undef __ |
| 7246 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 7247 | } // namespace arm64 |
| 7248 | } // namespace art |