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 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 60 | namespace art { |
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); |
| 827 | arm64_codegen->InvokeRuntime(entry_point, instruction_, instruction_->GetDexPc(), this); |
| 828 | RestoreLiveRegisters(codegen, locations); |
| 829 | __ B(GetExitLabel()); |
| 830 | } |
| 831 | |
| 832 | const char* GetDescription() const override { |
| 833 | return "MethodEntryExitHooksSlowPath"; |
| 834 | } |
| 835 | |
| 836 | private: |
| 837 | DISALLOW_COPY_AND_ASSIGN(MethodEntryExitHooksSlowPathARM64); |
| 838 | }; |
| 839 | |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 840 | class CompileOptimizedSlowPathARM64 : public SlowPathCodeARM64 { |
| 841 | public: |
| 842 | CompileOptimizedSlowPathARM64() : SlowPathCodeARM64(/* instruction= */ nullptr) {} |
| 843 | |
| 844 | void EmitNativeCode(CodeGenerator* codegen) override { |
| 845 | uint32_t entrypoint_offset = |
| 846 | GetThreadOffset<kArm64PointerSize>(kQuickCompileOptimized).Int32Value(); |
| 847 | __ Bind(GetEntryLabel()); |
| 848 | __ Ldr(lr, MemOperand(tr, entrypoint_offset)); |
| 849 | // Note: we don't record the call here (and therefore don't generate a stack |
| 850 | // map), as the entrypoint should never be suspended. |
| 851 | __ Blr(lr); |
| 852 | __ B(GetExitLabel()); |
| 853 | } |
| 854 | |
| 855 | const char* GetDescription() const override { |
| 856 | return "CompileOptimizedSlowPath"; |
| 857 | } |
| 858 | |
| 859 | private: |
| 860 | DISALLOW_COPY_AND_ASSIGN(CompileOptimizedSlowPathARM64); |
| 861 | }; |
| 862 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 863 | #undef __ |
| 864 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 865 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 866 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 867 | if (type == DataType::Type::kVoid) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 868 | LOG(FATAL) << "Unreachable type " << type; |
| 869 | } |
| 870 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 871 | if (DataType::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 872 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 873 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 874 | } else if (!DataType::IsFloatingPointType(type) && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 875 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 876 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 877 | } else { |
| 878 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 879 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 880 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 881 | } |
| 882 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 883 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 884 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 885 | return next_location; |
| 886 | } |
| 887 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 888 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 889 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 890 | } |
| 891 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 892 | Location CriticalNativeCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
| 893 | DCHECK_NE(type, DataType::Type::kReference); |
| 894 | |
| 895 | Location location = Location::NoLocation(); |
| 896 | if (DataType::IsFloatingPointType(type)) { |
| 897 | if (fpr_index_ < kParameterFPRegistersLength) { |
| 898 | location = LocationFrom(kParameterFPRegisters[fpr_index_]); |
| 899 | ++fpr_index_; |
| 900 | } |
| 901 | } else { |
| 902 | // Native ABI uses the same registers as managed, except that the method register x0 |
| 903 | // is a normal argument. |
| 904 | if (gpr_index_ < 1u + kParameterCoreRegistersLength) { |
| 905 | location = LocationFrom(gpr_index_ == 0u ? x0 : kParameterCoreRegisters[gpr_index_ - 1u]); |
| 906 | ++gpr_index_; |
| 907 | } |
| 908 | } |
| 909 | if (location.IsInvalid()) { |
| 910 | if (DataType::Is64BitType(type)) { |
| 911 | location = Location::DoubleStackSlot(stack_offset_); |
| 912 | } else { |
| 913 | location = Location::StackSlot(stack_offset_); |
| 914 | } |
| 915 | stack_offset_ += kFramePointerSize; |
| 916 | |
| 917 | if (for_register_allocation_) { |
| 918 | location = Location::Any(); |
| 919 | } |
| 920 | } |
| 921 | return location; |
| 922 | } |
| 923 | |
| 924 | Location CriticalNativeCallingConventionVisitorARM64::GetReturnLocation(DataType::Type type) const { |
| 925 | // We perform conversion to the managed ABI return register after the call if needed. |
| 926 | InvokeDexCallingConventionVisitorARM64 dex_calling_convention; |
| 927 | return dex_calling_convention.GetReturnLocation(type); |
| 928 | } |
| 929 | |
| 930 | Location CriticalNativeCallingConventionVisitorARM64::GetMethodLocation() const { |
| 931 | // Pass the method in the hidden argument x15. |
| 932 | return Location::RegisterLocation(x15.GetCode()); |
| 933 | } |
| 934 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 935 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 936 | const CompilerOptions& compiler_options, |
| 937 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 938 | : CodeGenerator(graph, |
| 939 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 940 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 941 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 942 | callee_saved_core_registers.GetList(), |
| 943 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 944 | compiler_options, |
| 945 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 946 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 947 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 948 | location_builder_neon_(graph, this), |
| 949 | instruction_visitor_neon_(graph, this), |
| 950 | location_builder_sve_(graph, this), |
| 951 | instruction_visitor_sve_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 952 | move_resolver_(graph->GetAllocator(), this), |
Artem Serov | aa6f483 | 2018-11-21 18:57:54 +0000 | [diff] [blame] | 953 | assembler_(graph->GetAllocator(), |
| 954 | compiler_options.GetInstructionSetFeatures()->AsArm64InstructionSetFeatures()), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 955 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 956 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 957 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 958 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 959 | public_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 960 | package_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 961 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 962 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 963 | boot_image_jni_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 964 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 965 | call_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 966 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 967 | uint32_literals_(std::less<uint32_t>(), |
| 968 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 969 | uint64_literals_(std::less<uint64_t>(), |
| 970 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 971 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 972 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 973 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 974 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 975 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 976 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 977 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 978 | AddAllocatedRegister(LocationFrom(lr)); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 979 | |
| 980 | bool use_sve = ShouldUseSVE(); |
| 981 | if (use_sve) { |
| 982 | location_builder_ = &location_builder_sve_; |
| 983 | instruction_visitor_ = &instruction_visitor_sve_; |
| 984 | } else { |
| 985 | location_builder_ = &location_builder_neon_; |
| 986 | instruction_visitor_ = &instruction_visitor_neon_; |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | bool CodeGeneratorARM64::ShouldUseSVE() const { |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 991 | return GetInstructionSetFeatures().HasSVE(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 992 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 993 | |
Artem Serov | 55ab7e8 | 2020-04-27 21:02:28 +0100 | [diff] [blame] | 994 | size_t CodeGeneratorARM64::GetSIMDRegisterWidth() const { |
| 995 | return SupportsPredicatedSIMD() |
| 996 | ? GetInstructionSetFeatures().GetSVEVectorLength() / kBitsPerByte |
| 997 | : vixl::aarch64::kQRegSizeInBytes; |
| 998 | } |
| 999 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1000 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1001 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1002 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1003 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1004 | jump_table->EmitTable(this); |
| 1005 | } |
| 1006 | } |
| 1007 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1008 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1009 | EmitJumpTables(); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1010 | |
| 1011 | // Emit JIT baker read barrier slow paths. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 1012 | DCHECK(GetCompilerOptions().IsJitCompiler() || jit_baker_read_barrier_slow_paths_.empty()); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1013 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 1014 | uint32_t encoded_data = entry.first; |
| 1015 | vixl::aarch64::Label* slow_path_entry = &entry.second.label; |
| 1016 | __ Bind(slow_path_entry); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1017 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name= */ nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1020 | // Ensure we emit the literal pool. |
| 1021 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1022 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1023 | CodeGenerator::Finalize(allocator); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1024 | |
| 1025 | // Verify Baker read barrier linker patches. |
| 1026 | if (kIsDebugBuild) { |
| 1027 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 1028 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 1029 | DCHECK(info.label.IsBound()); |
| 1030 | uint32_t literal_offset = info.label.GetLocation(); |
| 1031 | DCHECK_ALIGNED(literal_offset, 4u); |
| 1032 | |
| 1033 | auto GetInsn = [&code](uint32_t offset) { |
| 1034 | DCHECK_ALIGNED(offset, 4u); |
| 1035 | return |
| 1036 | (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 1037 | (static_cast<uint32_t>(code[offset + 1]) << 8) + |
| 1038 | (static_cast<uint32_t>(code[offset + 2]) << 16)+ |
| 1039 | (static_cast<uint32_t>(code[offset + 3]) << 24); |
| 1040 | }; |
| 1041 | |
| 1042 | const uint32_t encoded_data = info.custom_data; |
| 1043 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 1044 | // Check that the next instruction matches the expected LDR. |
| 1045 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1046 | case BakerReadBarrierKind::kField: |
| 1047 | case BakerReadBarrierKind::kAcquire: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1048 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1049 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1050 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1051 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1052 | if (kind == BakerReadBarrierKind::kField) { |
| 1053 | // LDR (immediate) with correct base_reg. |
| 1054 | CHECK_EQ(next_insn & 0xffc003e0u, 0xb9400000u | (base_reg << 5)); |
| 1055 | } else { |
| 1056 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 1057 | // LDAR with correct base_reg. |
| 1058 | CHECK_EQ(next_insn & 0xffffffe0u, 0x88dffc00u | (base_reg << 5)); |
| 1059 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1060 | break; |
| 1061 | } |
| 1062 | case BakerReadBarrierKind::kArray: { |
| 1063 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1064 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 1065 | // LDR (register) with the correct base_reg, size=10 (32-bit), option=011 (extend = LSL), |
| 1066 | // and S=1 (shift amount = 2 for 32-bit version), i.e. LDR Wt, [Xn, Xm, LSL #2]. |
| 1067 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1068 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1069 | CHECK_EQ(next_insn & 0xffe0ffe0u, 0xb8607800u | (base_reg << 5)); |
| 1070 | CheckValidReg((next_insn >> 16) & 0x1f); // Check index register |
| 1071 | break; |
| 1072 | } |
| 1073 | case BakerReadBarrierKind::kGcRoot: { |
| 1074 | DCHECK_GE(literal_offset, 4u); |
| 1075 | uint32_t prev_insn = GetInsn(literal_offset - 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1076 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 1077 | // Usually LDR (immediate) with correct root_reg but |
Vladimir Marko | c8178f5 | 2020-11-24 10:38:16 +0000 | [diff] [blame] | 1078 | // we may have a "MOV marked, old_value" for intrinsic CAS. |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 1079 | if ((prev_insn & 0xffe0ffff) != (0x2a0003e0 | root_reg)) { // MOV? |
| 1080 | CHECK_EQ(prev_insn & 0xffc0001fu, 0xb9400000u | root_reg); // LDR? |
| 1081 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1082 | break; |
| 1083 | } |
| 1084 | default: |
| 1085 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 1086 | UNREACHABLE(); |
| 1087 | } |
| 1088 | } |
| 1089 | } |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1092 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1093 | // Note: There are 6 kinds of moves: |
| 1094 | // 1. constant -> GPR/FPR (non-cycle) |
| 1095 | // 2. constant -> stack (non-cycle) |
| 1096 | // 3. GPR/FPR -> GPR/FPR |
| 1097 | // 4. GPR/FPR -> stack |
| 1098 | // 5. stack -> GPR/FPR |
| 1099 | // 6. stack -> stack (non-cycle) |
| 1100 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1101 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1102 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1103 | // dependency. |
| 1104 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1105 | } |
| 1106 | |
| 1107 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1108 | vixl_temps_.Close(); |
| 1109 | } |
| 1110 | |
| 1111 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1112 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1113 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1114 | || kind == Location::kSIMDStackSlot); |
| 1115 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1116 | ? Location::kFpuRegister |
| 1117 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1118 | Location scratch = GetScratchLocation(kind); |
| 1119 | if (!scratch.Equals(Location::NoLocation())) { |
| 1120 | return scratch; |
| 1121 | } |
| 1122 | // Allocate from VIXL temp registers. |
| 1123 | if (kind == Location::kRegister) { |
| 1124 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1125 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1126 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1127 | scratch = codegen_->GetGraph()->HasSIMD() |
| 1128 | ? codegen_->GetInstructionCodeGeneratorArm64()->AllocateSIMDScratchLocation(&vixl_temps_) |
| 1129 | : LocationFrom(vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1130 | } |
| 1131 | AddScratchLocation(scratch); |
| 1132 | return scratch; |
| 1133 | } |
| 1134 | |
| 1135 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1136 | if (loc.IsRegister()) { |
| 1137 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1138 | } else { |
| 1139 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1140 | if (codegen_->GetGraph()->HasSIMD()) { |
| 1141 | codegen_->GetInstructionCodeGeneratorArm64()->FreeSIMDScratchLocation(loc, &vixl_temps_); |
| 1142 | } else { |
| 1143 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1144 | } |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1145 | } |
| 1146 | RemoveScratchLocation(loc); |
| 1147 | } |
| 1148 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1149 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1150 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1151 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 1154 | void LocationsBuilderARM64::VisitMethodExitHook(HMethodExitHook* method_hook) { |
| 1155 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| 1156 | LocationSummary(method_hook, LocationSummary::kCallOnSlowPath); |
| 1157 | DataType::Type return_type = method_hook->InputAt(0)->GetType(); |
| 1158 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
| 1159 | } |
| 1160 | |
| 1161 | void InstructionCodeGeneratorARM64::GenerateMethodEntryExitHook(HInstruction* instruction) { |
| 1162 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1163 | UseScratchRegisterScope temps(masm); |
| 1164 | Register temp = temps.AcquireX(); |
| 1165 | Register value = temps.AcquireW(); |
| 1166 | |
| 1167 | SlowPathCodeARM64* slow_path = |
| 1168 | new (codegen_->GetScopedAllocator()) MethodEntryExitHooksSlowPathARM64(instruction); |
| 1169 | codegen_->AddSlowPath(slow_path); |
| 1170 | |
| 1171 | uint64_t address = reinterpret_cast64<uint64_t>(Runtime::Current()->GetInstrumentation()); |
| 1172 | int offset = instrumentation::Instrumentation::NeedsEntryExitHooksOffset().Int32Value(); |
| 1173 | __ Mov(temp, address + offset); |
Mythri Alle | 9575c12 | 2021-11-12 12:04:41 +0000 | [diff] [blame] | 1174 | __ Ldrb(value, MemOperand(temp, 0)); |
Mythri Alle | 5097f83 | 2021-11-02 14:52:30 +0000 | [diff] [blame] | 1175 | __ Cbnz(value, slow_path->GetEntryLabel()); |
| 1176 | __ Bind(slow_path->GetExitLabel()); |
| 1177 | } |
| 1178 | |
| 1179 | void InstructionCodeGeneratorARM64::VisitMethodExitHook(HMethodExitHook* instruction) { |
| 1180 | DCHECK(codegen_->GetCompilerOptions().IsJitCompiler() && GetGraph()->IsDebuggable()); |
| 1181 | DCHECK(codegen_->RequiresCurrentMethod()); |
| 1182 | GenerateMethodEntryExitHook(instruction); |
| 1183 | } |
| 1184 | |
| 1185 | void LocationsBuilderARM64::VisitMethodEntryHook(HMethodEntryHook* method_hook) { |
| 1186 | new (GetGraph()->GetAllocator()) LocationSummary(method_hook, LocationSummary::kCallOnSlowPath); |
| 1187 | } |
| 1188 | |
| 1189 | void InstructionCodeGeneratorARM64::VisitMethodEntryHook(HMethodEntryHook* instruction) { |
| 1190 | DCHECK(codegen_->GetCompilerOptions().IsJitCompiler() && GetGraph()->IsDebuggable()); |
| 1191 | DCHECK(codegen_->RequiresCurrentMethod()); |
| 1192 | GenerateMethodEntryExitHook(instruction); |
| 1193 | } |
| 1194 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1195 | void CodeGeneratorARM64::MaybeIncrementHotness(bool is_frame_entry) { |
| 1196 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1197 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1198 | UseScratchRegisterScope temps(masm); |
| 1199 | Register counter = temps.AcquireX(); |
| 1200 | Register method = is_frame_entry ? kArtMethodRegister : temps.AcquireX(); |
| 1201 | if (!is_frame_entry) { |
| 1202 | __ Ldr(method, MemOperand(sp, 0)); |
| 1203 | } |
| 1204 | __ Ldrh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
Nicolas Geoffray | 61673dc | 2021-11-06 13:58:31 +0000 | [diff] [blame] | 1205 | vixl::aarch64::Label done; |
| 1206 | DCHECK_EQ(0u, interpreter::kNterpHotnessValue); |
| 1207 | __ Cbz(counter, &done); |
| 1208 | __ Add(counter, counter, -1); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1209 | __ Strh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
Nicolas Geoffray | 61673dc | 2021-11-06 13:58:31 +0000 | [diff] [blame] | 1210 | __ Bind(&done); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 1214 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) CompileOptimizedSlowPathARM64(); |
| 1215 | AddSlowPath(slow_path); |
| 1216 | ProfilingInfo* info = GetGraph()->GetProfilingInfo(); |
| 1217 | DCHECK(info != nullptr); |
| 1218 | DCHECK(!HasEmptyFrame()); |
| 1219 | uint64_t address = reinterpret_cast64<uint64_t>(info); |
| 1220 | vixl::aarch64::Label done; |
| 1221 | UseScratchRegisterScope temps(masm); |
| 1222 | Register temp = temps.AcquireX(); |
| 1223 | Register counter = temps.AcquireW(); |
| 1224 | __ Ldr(temp, DeduplicateUint64Literal(address)); |
| 1225 | __ Ldrh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 1226 | __ Cbz(counter, slow_path->GetEntryLabel()); |
| 1227 | __ Add(counter, counter, -1); |
| 1228 | __ Strh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 1229 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1230 | } |
| 1231 | } |
| 1232 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1233 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1234 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | ab3f8d2 | 2022-07-23 15:49:51 +0000 | [diff] [blame] | 1235 | |
| 1236 | // Check if we need to generate the clinit check. We will jump to the |
| 1237 | // resolution stub if the class is not initialized and the executing thread is |
| 1238 | // not the thread initializing it. |
| 1239 | // We do this before constructing the frame to get the correct stack trace if |
| 1240 | // an exception is thrown. |
| 1241 | if (GetCompilerOptions().ShouldCompileWithClinitCheck(GetGraph()->GetArtMethod())) { |
| 1242 | UseScratchRegisterScope temps(masm); |
| 1243 | vixl::aarch64::Label resolution; |
Nicolas Geoffray | f853790 | 2022-09-13 15:22:29 +0100 | [diff] [blame] | 1244 | vixl::aarch64::Label memory_barrier; |
Nicolas Geoffray | ab3f8d2 | 2022-07-23 15:49:51 +0000 | [diff] [blame] | 1245 | |
| 1246 | Register temp1 = temps.AcquireW(); |
| 1247 | Register temp2 = temps.AcquireW(); |
| 1248 | |
| 1249 | // Check if we're visibly initialized. |
| 1250 | |
| 1251 | // We don't emit a read barrier here to save on code size. We rely on the |
| 1252 | // resolution trampoline to do a suspend check before re-entering this code. |
| 1253 | __ Ldr(temp1, MemOperand(kArtMethodRegister, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 1254 | __ Ldrb(temp2, HeapOperand(temp1, status_byte_offset)); |
| 1255 | __ Cmp(temp2, shifted_visibly_initialized_value); |
| 1256 | __ B(hs, &frame_entry_label_); |
| 1257 | |
Nicolas Geoffray | f853790 | 2022-09-13 15:22:29 +0100 | [diff] [blame] | 1258 | // Check if we're initialized and jump to code that does a memory barrier if |
| 1259 | // so. |
| 1260 | __ Cmp(temp2, shifted_initialized_value); |
| 1261 | __ B(hs, &memory_barrier); |
| 1262 | |
Nicolas Geoffray | ab3f8d2 | 2022-07-23 15:49:51 +0000 | [diff] [blame] | 1263 | // Check if we're initializing and the thread initializing is the one |
| 1264 | // executing the code. |
| 1265 | __ Cmp(temp2, shifted_initializing_value); |
| 1266 | __ B(lo, &resolution); |
| 1267 | |
| 1268 | __ Ldr(temp1, HeapOperand(temp1, mirror::Class::ClinitThreadIdOffset().Int32Value())); |
| 1269 | __ Ldr(temp2, MemOperand(tr, Thread::TidOffset<kArm64PointerSize>().Int32Value())); |
| 1270 | __ Cmp(temp1, temp2); |
| 1271 | __ B(eq, &frame_entry_label_); |
| 1272 | __ Bind(&resolution); |
| 1273 | |
| 1274 | // Jump to the resolution stub. |
| 1275 | ThreadOffset64 entrypoint_offset = |
| 1276 | GetThreadOffset<kArm64PointerSize>(kQuickQuickResolutionTrampoline); |
| 1277 | __ Ldr(temp1.X(), MemOperand(tr, entrypoint_offset.Int32Value())); |
| 1278 | __ Br(temp1.X()); |
Nicolas Geoffray | f853790 | 2022-09-13 15:22:29 +0100 | [diff] [blame] | 1279 | |
| 1280 | __ Bind(&memory_barrier); |
| 1281 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Nicolas Geoffray | ab3f8d2 | 2022-07-23 15:49:51 +0000 | [diff] [blame] | 1282 | } |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1283 | __ Bind(&frame_entry_label_); |
| 1284 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1285 | bool do_overflow_check = |
| 1286 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1287 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1288 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1289 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1290 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1291 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1292 | { |
| 1293 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1294 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1295 | kInstructionSize, |
| 1296 | CodeBufferCheckScope::kExactSize); |
| 1297 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1298 | RecordPcInfo(nullptr, 0); |
| 1299 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1300 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1301 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1302 | if (!HasEmptyFrame()) { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1303 | // Stack layout: |
| 1304 | // sp[frame_size - 8] : lr. |
| 1305 | // ... : other preserved core registers. |
| 1306 | // ... : other preserved fp registers. |
| 1307 | // ... : reserved frame space. |
| 1308 | // sp[0] : current method. |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1309 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1310 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1311 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1312 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1313 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1314 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1315 | |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1316 | // Save the current method if we need it, or if using STP reduces code |
| 1317 | // size. Note that we do not do this in HCurrentMethod, as the |
| 1318 | // instruction might have been removed in the SSA graph. |
| 1319 | CPURegister lowest_spill; |
| 1320 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1321 | // If there is no gap between the method and the lowest core spill, use |
| 1322 | // aligned STP pre-index to store both. Max difference is 512. We do |
| 1323 | // that to reduce code size even if we do not have to save the method. |
| 1324 | DCHECK_LE(frame_size, 512); // 32 core registers are only 256 bytes. |
| 1325 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1326 | __ Stp(kArtMethodRegister, lowest_spill, MemOperand(sp, -frame_size, PreIndex)); |
| 1327 | } else if (RequiresCurrentMethod()) { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1328 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1329 | } else { |
| 1330 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1331 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1332 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1333 | if (lowest_spill.IsValid()) { |
| 1334 | GetAssembler()->cfi().RelOffset(DWARFReg(lowest_spill), core_spills_offset); |
| 1335 | core_spills_offset += kXRegSizeInBytes; |
| 1336 | } |
| 1337 | GetAssembler()->SpillRegisters(preserved_core_registers, core_spills_offset); |
| 1338 | GetAssembler()->SpillRegisters(preserved_fp_registers, fp_spills_offset); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1339 | |
| 1340 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1341 | // Initialize should_deoptimize flag to 0. |
| 1342 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1343 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1344 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1345 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1346 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1347 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1351 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1352 | if (!HasEmptyFrame()) { |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1353 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1354 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1355 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1356 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1357 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1358 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
| 1359 | |
| 1360 | CPURegister lowest_spill; |
| 1361 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1362 | // If there is no gap between the method and the lowest core spill, use |
| 1363 | // aligned LDP pre-index to pop both. Max difference is 504. We do |
| 1364 | // that to reduce code size even though the loaded method is unused. |
| 1365 | DCHECK_LE(frame_size, 504); // 32 core registers are only 256 bytes. |
| 1366 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1367 | core_spills_offset += kXRegSizeInBytes; |
| 1368 | } |
| 1369 | GetAssembler()->UnspillRegisters(preserved_fp_registers, fp_spills_offset); |
| 1370 | GetAssembler()->UnspillRegisters(preserved_core_registers, core_spills_offset); |
| 1371 | if (lowest_spill.IsValid()) { |
| 1372 | __ Ldp(xzr, lowest_spill, MemOperand(sp, frame_size, PostIndex)); |
| 1373 | GetAssembler()->cfi().Restore(DWARFReg(lowest_spill)); |
| 1374 | } else { |
| 1375 | __ Drop(frame_size); |
| 1376 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1377 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1378 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1379 | __ Ret(); |
| 1380 | GetAssembler()->cfi().RestoreState(); |
| 1381 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1382 | } |
| 1383 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1384 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1385 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1386 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1387 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1388 | } |
| 1389 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1390 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1391 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1392 | GetNumberOfFloatingPointRegisters())); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1393 | return CPURegList(CPURegister::kVRegister, kDRegSize, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1394 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1395 | } |
| 1396 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1397 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1398 | __ Bind(GetLabelOf(block)); |
| 1399 | } |
| 1400 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1401 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1402 | DCHECK(location.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1403 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1404 | } |
| 1405 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1406 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1407 | if (location.IsRegister()) { |
| 1408 | locations->AddTemp(location); |
| 1409 | } else { |
| 1410 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1411 | } |
| 1412 | } |
| 1413 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1414 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1415 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1416 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1417 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1418 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1419 | if (value_can_be_null) { |
| 1420 | __ Cbz(value, &done); |
| 1421 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1422 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1423 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1424 | // Calculate the offset (in the card table) of the card corresponding to |
| 1425 | // `object`. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1426 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1427 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 1428 | // `object`'s card. |
| 1429 | // |
| 1430 | // Register `card` contains the address of the card table. Note that the card |
| 1431 | // table's base is biased during its creation so that it always starts at an |
| 1432 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 1433 | // art::gc::accounting::CardTable::Create). Therefore the STRB instruction |
| 1434 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 1435 | // (located at `card + object >> kCardShift`). |
| 1436 | // |
| 1437 | // This dual use of the value in register `card` (1. to calculate the location |
| 1438 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 1439 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1440 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1441 | if (value_can_be_null) { |
| 1442 | __ Bind(&done); |
| 1443 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1444 | } |
| 1445 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1446 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1447 | // Blocked core registers: |
| 1448 | // lr : Runtime reserved. |
| 1449 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1450 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1451 | // ip1 : VIXL core temp. |
| 1452 | // ip0 : VIXL core temp. |
Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1453 | // x18 : Platform register. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1454 | // |
| 1455 | // Blocked fp registers: |
| 1456 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1457 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1458 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1459 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1460 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1461 | } |
Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1462 | blocked_core_registers_[X18] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1463 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1464 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1465 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1466 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1467 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1468 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1469 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1470 | // Stubs do not save callee-save floating point registers. If the graph |
| 1471 | // is debuggable, we need to deal with these registers differently. For |
| 1472 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1473 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1474 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1475 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1476 | } |
| 1477 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1478 | } |
| 1479 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1480 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1481 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1482 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1483 | return kArm64WordSize; |
| 1484 | } |
| 1485 | |
| 1486 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1487 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1488 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1489 | return kArm64WordSize; |
| 1490 | } |
| 1491 | |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1492 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1493 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1494 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1495 | << "use SaveRestoreLiveRegistersHelper"; |
| 1496 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1497 | } |
| 1498 | |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1499 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1500 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1501 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1502 | << "use SaveRestoreLiveRegistersHelper"; |
| 1503 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1506 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1507 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1511 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1512 | } |
| 1513 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1514 | const Arm64InstructionSetFeatures& CodeGeneratorARM64::GetInstructionSetFeatures() const { |
| 1515 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArm64InstructionSetFeatures(); |
| 1516 | } |
| 1517 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1518 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1519 | if (constant->IsIntConstant()) { |
| 1520 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1521 | } else if (constant->IsLongConstant()) { |
| 1522 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1523 | } else if (constant->IsNullConstant()) { |
| 1524 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1525 | } else if (constant->IsFloatConstant()) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1526 | __ Fmov(VRegister(destination), constant->AsFloatConstant()->GetValue()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1527 | } else { |
| 1528 | DCHECK(constant->IsDoubleConstant()); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1529 | __ Fmov(VRegister(destination), constant->AsDoubleConstant()->GetValue()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1530 | } |
| 1531 | } |
| 1532 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1533 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1534 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1535 | DCHECK(constant.IsConstant()); |
| 1536 | HConstant* cst = constant.GetConstant(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1537 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1538 | // 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] | 1539 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1540 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1541 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1542 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1545 | // Allocate a scratch register from the VIXL pool, querying first |
| 1546 | // the floating-point register pool, and then the core register |
| 1547 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1548 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1549 | // using a different allocation strategy. |
| 1550 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1551 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1552 | int size_in_bits) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1553 | return masm->GetScratchVRegisterList()->IsEmpty() |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1554 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1555 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1556 | } |
| 1557 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1558 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1559 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1560 | DataType::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1561 | if (source.Equals(destination)) { |
| 1562 | return; |
| 1563 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1564 | |
| 1565 | // A valid move can always be inferred from the destination and source |
| 1566 | // locations. When moving from and to a register, the argument type can be |
| 1567 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1568 | // checks the coherency of the locations and the type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1569 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1570 | |
| 1571 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1572 | if (unspecified_type) { |
| 1573 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1574 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1575 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1576 | || src_cst->IsFloatConstant() |
| 1577 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1578 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1579 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1580 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1581 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1582 | // type is appropriate. Else the source is a register, and since the |
| 1583 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1584 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1585 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1586 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1587 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1588 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1589 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1590 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1591 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1592 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1593 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1594 | } else if (source.IsSIMDStackSlot()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1595 | GetInstructionCodeGeneratorArm64()->LoadSIMDRegFromStack(destination, source); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1596 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1597 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1598 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1599 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1600 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1601 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1602 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1603 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1604 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1605 | ? DataType::Type::kInt64 |
| 1606 | : DataType::Type::kInt32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1607 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1608 | } |
| 1609 | } else { |
| 1610 | DCHECK(source.IsFpuRegister()); |
| 1611 | if (destination.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1612 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1613 | ? DataType::Type::kFloat64 |
| 1614 | : DataType::Type::kFloat32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1615 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1616 | } else { |
| 1617 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1618 | if (GetGraph()->HasSIMD()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1619 | GetInstructionCodeGeneratorArm64()->MoveSIMDRegToSIMDReg(destination, source); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1620 | } else { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1621 | __ Fmov(VRegister(dst), FPRegisterFrom(source, dst_type)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1622 | } |
| 1623 | } |
| 1624 | } |
| 1625 | } else if (destination.IsSIMDStackSlot()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1626 | GetInstructionCodeGeneratorArm64()->MoveToSIMDStackSlot(destination, source); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1627 | } else { // The destination is not a register. It must be a stack slot. |
| 1628 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1629 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1630 | if (unspecified_type) { |
| 1631 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1632 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1633 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1634 | dst_type = |
| 1635 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1636 | } |
| 1637 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1638 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1639 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1640 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1641 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1642 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1643 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1644 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1645 | HConstant* src_cst = source.GetConstant(); |
| 1646 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1647 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1648 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1649 | ? Register(xzr) |
| 1650 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1651 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1652 | if (src_cst->IsIntConstant()) { |
| 1653 | temp = temps.AcquireW(); |
| 1654 | } else if (src_cst->IsLongConstant()) { |
| 1655 | temp = temps.AcquireX(); |
| 1656 | } else if (src_cst->IsFloatConstant()) { |
| 1657 | temp = temps.AcquireS(); |
| 1658 | } else { |
| 1659 | DCHECK(src_cst->IsDoubleConstant()); |
| 1660 | temp = temps.AcquireD(); |
| 1661 | } |
| 1662 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1663 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1664 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1665 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1666 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1667 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1668 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1669 | // Use any scratch register (a core or a floating-point one) |
| 1670 | // from VIXL scratch register pools as a temporary. |
| 1671 | // |
| 1672 | // We used to only use the FP scratch register pool, but in some |
| 1673 | // rare cases the only register from this pool (D31) would |
| 1674 | // already be used (e.g. within a ParallelMove instruction, when |
| 1675 | // a move is blocked by a another move requiring a scratch FP |
| 1676 | // register, which would reserve D31). To prevent this issue, we |
| 1677 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1678 | // |
| 1679 | // 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] | 1680 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1681 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1682 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1683 | // allocates core scratch registers first. |
| 1684 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1685 | GetVIXLAssembler(), |
| 1686 | &temps, |
| 1687 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1688 | __ Ldr(temp, StackOperandFrom(source)); |
| 1689 | __ Str(temp, StackOperandFrom(destination)); |
| 1690 | } |
| 1691 | } |
| 1692 | } |
| 1693 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1694 | void CodeGeneratorARM64::Load(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1695 | CPURegister dst, |
| 1696 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1697 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1698 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1699 | case DataType::Type::kUint8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1700 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1701 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1702 | case DataType::Type::kInt8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1703 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1704 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1705 | case DataType::Type::kUint16: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1706 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1707 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1708 | case DataType::Type::kInt16: |
| 1709 | __ Ldrsh(Register(dst), src); |
| 1710 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1711 | case DataType::Type::kInt32: |
| 1712 | case DataType::Type::kReference: |
| 1713 | case DataType::Type::kInt64: |
| 1714 | case DataType::Type::kFloat32: |
| 1715 | case DataType::Type::kFloat64: |
| 1716 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1717 | __ Ldr(dst, src); |
| 1718 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1719 | case DataType::Type::kUint32: |
| 1720 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1721 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1722 | LOG(FATAL) << "Unreachable type " << type; |
| 1723 | } |
| 1724 | } |
| 1725 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1726 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 1727 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1728 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1729 | const MemOperand& src, |
| 1730 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1731 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1732 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1733 | Register temp_base = temps.AcquireX(); |
| 1734 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1735 | DCHECK(!src.IsPreIndex()); |
| 1736 | DCHECK(!src.IsPostIndex()); |
| 1737 | |
| 1738 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1739 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1740 | { |
| 1741 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1742 | MemOperand base = MemOperand(temp_base); |
| 1743 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1744 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1745 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1746 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1747 | { |
| 1748 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1749 | __ ldarb(Register(dst), base); |
| 1750 | if (needs_null_check) { |
| 1751 | MaybeRecordImplicitNullCheck(instruction); |
| 1752 | } |
| 1753 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1754 | if (type == DataType::Type::kInt8) { |
| 1755 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1756 | } |
| 1757 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1758 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1759 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1760 | { |
| 1761 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1762 | __ ldarh(Register(dst), base); |
| 1763 | if (needs_null_check) { |
| 1764 | MaybeRecordImplicitNullCheck(instruction); |
| 1765 | } |
| 1766 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1767 | if (type == DataType::Type::kInt16) { |
| 1768 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 1769 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1770 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1771 | case DataType::Type::kInt32: |
| 1772 | case DataType::Type::kReference: |
| 1773 | case DataType::Type::kInt64: |
| 1774 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1775 | { |
| 1776 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1777 | __ ldar(Register(dst), base); |
| 1778 | if (needs_null_check) { |
| 1779 | MaybeRecordImplicitNullCheck(instruction); |
| 1780 | } |
| 1781 | } |
| 1782 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1783 | case DataType::Type::kFloat32: |
| 1784 | case DataType::Type::kFloat64: { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1785 | DCHECK(dst.IsFPRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1786 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1787 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1788 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1789 | { |
| 1790 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1791 | __ ldar(temp, base); |
| 1792 | if (needs_null_check) { |
| 1793 | MaybeRecordImplicitNullCheck(instruction); |
| 1794 | } |
| 1795 | } |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1796 | __ Fmov(VRegister(dst), temp); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1797 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1798 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1799 | case DataType::Type::kUint32: |
| 1800 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1801 | case DataType::Type::kVoid: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1802 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1803 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1804 | } |
| 1805 | } |
| 1806 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1807 | void CodeGeneratorARM64::Store(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1808 | CPURegister src, |
| 1809 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1810 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1811 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1812 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1813 | case DataType::Type::kInt8: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1814 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1815 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1816 | case DataType::Type::kUint16: |
| 1817 | case DataType::Type::kInt16: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1818 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1819 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1820 | case DataType::Type::kInt32: |
| 1821 | case DataType::Type::kReference: |
| 1822 | case DataType::Type::kInt64: |
| 1823 | case DataType::Type::kFloat32: |
| 1824 | case DataType::Type::kFloat64: |
| 1825 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1826 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1827 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1828 | case DataType::Type::kUint32: |
| 1829 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1830 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1831 | LOG(FATAL) << "Unreachable type " << type; |
| 1832 | } |
| 1833 | } |
| 1834 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1835 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1836 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1837 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1838 | const MemOperand& dst, |
| 1839 | bool needs_null_check) { |
| 1840 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1841 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1842 | Register temp_base = temps.AcquireX(); |
| 1843 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1844 | DCHECK(!dst.IsPreIndex()); |
| 1845 | DCHECK(!dst.IsPostIndex()); |
| 1846 | |
| 1847 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1848 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1849 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1850 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1851 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1852 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1853 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1854 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1855 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1856 | { |
| 1857 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1858 | __ stlrb(Register(src), base); |
| 1859 | if (needs_null_check) { |
| 1860 | MaybeRecordImplicitNullCheck(instruction); |
| 1861 | } |
| 1862 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1863 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1864 | case DataType::Type::kUint16: |
| 1865 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1866 | { |
| 1867 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1868 | __ stlrh(Register(src), base); |
| 1869 | if (needs_null_check) { |
| 1870 | MaybeRecordImplicitNullCheck(instruction); |
| 1871 | } |
| 1872 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1873 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1874 | case DataType::Type::kInt32: |
| 1875 | case DataType::Type::kReference: |
| 1876 | case DataType::Type::kInt64: |
| 1877 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1878 | { |
| 1879 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1880 | __ stlr(Register(src), base); |
| 1881 | if (needs_null_check) { |
| 1882 | MaybeRecordImplicitNullCheck(instruction); |
| 1883 | } |
| 1884 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1885 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1886 | case DataType::Type::kFloat32: |
| 1887 | case DataType::Type::kFloat64: { |
| 1888 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1889 | Register temp_src; |
| 1890 | if (src.IsZero()) { |
| 1891 | // The zero register is used to avoid synthesizing zero constants. |
| 1892 | temp_src = Register(src); |
| 1893 | } else { |
| 1894 | DCHECK(src.IsFPRegister()); |
| 1895 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1896 | __ Fmov(temp_src, VRegister(src)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1897 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1898 | { |
| 1899 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1900 | __ stlr(temp_src, base); |
| 1901 | if (needs_null_check) { |
| 1902 | MaybeRecordImplicitNullCheck(instruction); |
| 1903 | } |
| 1904 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1905 | break; |
| 1906 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1907 | case DataType::Type::kUint32: |
| 1908 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1909 | case DataType::Type::kVoid: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1910 | LOG(FATAL) << "Unreachable type " << type; |
| 1911 | } |
| 1912 | } |
| 1913 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1914 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1915 | HInstruction* instruction, |
| 1916 | uint32_t dex_pc, |
| 1917 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1918 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1919 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1920 | ThreadOffset64 entrypoint_offset = GetThreadOffset<kArm64PointerSize>(entrypoint); |
| 1921 | // Reduce code size for AOT by using shared trampolines for slow path runtime calls across the |
| 1922 | // entire oat file. This adds an extra branch and we do not want to slow down the main path. |
| 1923 | // 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] | 1924 | if (slow_path == nullptr || GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1925 | __ Ldr(lr, MemOperand(tr, entrypoint_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1926 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 1927 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1928 | __ blr(lr); |
| 1929 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1930 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1931 | } |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1932 | } else { |
| 1933 | // Ensure the pc position is recorded immediately after the `bl` instruction. |
| 1934 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1935 | EmitEntrypointThunkCall(entrypoint_offset); |
| 1936 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1937 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1938 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1939 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1942 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1943 | HInstruction* instruction, |
| 1944 | SlowPathCode* slow_path) { |
| 1945 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1946 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1947 | __ Blr(lr); |
| 1948 | } |
| 1949 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1950 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1951 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1952 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1953 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1954 | |
Vladimir Marko | 2bb44fe | 2019-10-04 12:28:14 +0100 | [diff] [blame] | 1955 | // CMP (immediate) is limited to imm12 or imm12<<12, so we would need to materialize |
| 1956 | // the constant 0xf0000000 for comparison with the full 32-bit field. To reduce the code |
| 1957 | // size, load only the high byte of the field and compare with 0xf0. |
| 1958 | // Note: The same code size could be achieved with LDR+MNV(asr #24)+CBNZ but benchmarks |
| 1959 | // show that this pattern is slower (tested on little cores). |
| 1960 | __ Ldrb(temp, HeapOperand(class_reg, status_byte_offset)); |
| 1961 | __ Cmp(temp, shifted_visibly_initialized_value); |
| 1962 | __ B(lo, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1963 | __ Bind(slow_path->GetExitLabel()); |
| 1964 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1965 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 1966 | void InstructionCodeGeneratorARM64::GenerateBitstringTypeCheckCompare( |
| 1967 | HTypeCheckInstruction* check, vixl::aarch64::Register temp) { |
| 1968 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 1969 | uint32_t mask = check->GetBitstringMask(); |
| 1970 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 1971 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 1972 | |
| 1973 | if (mask_bits == 16u) { |
| 1974 | // Load only the bitstring part of the status word. |
| 1975 | __ Ldrh(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1976 | } else { |
| 1977 | // /* uint32_t */ temp = temp->status_ |
| 1978 | __ Ldr(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1979 | // Extract the bitstring bits. |
| 1980 | __ Ubfx(temp, temp, 0, mask_bits); |
| 1981 | } |
| 1982 | // Compare the bitstring bits to `path_to_root`. |
| 1983 | __ Cmp(temp, path_to_root); |
| 1984 | } |
| 1985 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1986 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1987 | BarrierType type = BarrierAll; |
| 1988 | |
| 1989 | switch (kind) { |
| 1990 | case MemBarrierKind::kAnyAny: |
| 1991 | case MemBarrierKind::kAnyStore: { |
| 1992 | type = BarrierAll; |
| 1993 | break; |
| 1994 | } |
| 1995 | case MemBarrierKind::kLoadAny: { |
| 1996 | type = BarrierReads; |
| 1997 | break; |
| 1998 | } |
| 1999 | case MemBarrierKind::kStoreStore: { |
| 2000 | type = BarrierWrites; |
| 2001 | break; |
| 2002 | } |
| 2003 | default: |
| 2004 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2005 | } |
| 2006 | __ Dmb(InnerShareable, type); |
| 2007 | } |
| 2008 | |
Vladimir Marko | 7039c11 | 2018-04-05 17:59:39 +0100 | [diff] [blame] | 2009 | bool CodeGeneratorARM64::CanUseImplicitSuspendCheck() const { |
| 2010 | // Use implicit suspend checks if requested in compiler options unless there are SIMD |
| 2011 | // instructions in the graph. The implicit suspend check saves all FP registers as |
| 2012 | // 64-bit (in line with the calling convention) but SIMD instructions can use 128-bit |
| 2013 | // registers, so they need to be saved in an explicit slow path. |
| 2014 | return GetCompilerOptions().GetImplicitSuspendChecks() && !GetGraph()->HasSIMD(); |
| 2015 | } |
| 2016 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2017 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2018 | HBasicBlock* successor) { |
Stelios Ioannou | c54cc7c | 2021-07-09 17:06:03 +0100 | [diff] [blame] | 2019 | if (instruction->IsNoOp()) { |
| 2020 | if (successor != nullptr) { |
| 2021 | __ B(codegen_->GetLabelOf(successor)); |
| 2022 | } |
| 2023 | return; |
| 2024 | } |
| 2025 | |
Vladimir Marko | 7039c11 | 2018-04-05 17:59:39 +0100 | [diff] [blame] | 2026 | if (codegen_->CanUseImplicitSuspendCheck()) { |
| 2027 | __ Ldr(kImplicitSuspendCheckRegister, MemOperand(kImplicitSuspendCheckRegister)); |
| 2028 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Vladimir Marko | e45883e | 2022-01-11 12:38:35 +0000 | [diff] [blame] | 2029 | if (successor != nullptr) { |
| 2030 | __ B(codegen_->GetLabelOf(successor)); |
| 2031 | } |
Vladimir Marko | 7039c11 | 2018-04-05 17:59:39 +0100 | [diff] [blame] | 2032 | return; |
| 2033 | } |
| 2034 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2035 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2036 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2037 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2038 | slow_path = |
| 2039 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2040 | instruction->SetSlowPath(slow_path); |
| 2041 | codegen_->AddSlowPath(slow_path); |
| 2042 | if (successor != nullptr) { |
| 2043 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2044 | } |
| 2045 | } else { |
| 2046 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2047 | } |
| 2048 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2049 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2050 | Register temp = temps.AcquireW(); |
| 2051 | |
Vladimir Marko | ddf4fd3 | 2021-11-22 16:31:57 +0000 | [diff] [blame] | 2052 | __ Ldr(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 2053 | __ Tst(temp, Thread::SuspendOrCheckpointRequestFlags()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2054 | if (successor == nullptr) { |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 2055 | __ B(ne, slow_path->GetEntryLabel()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2056 | __ Bind(slow_path->GetReturnLabel()); |
| 2057 | } else { |
Vladimir Marko | 254a858 | 2021-11-29 14:08:37 +0000 | [diff] [blame] | 2058 | __ B(eq, codegen_->GetLabelOf(successor)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2059 | __ B(slow_path->GetEntryLabel()); |
| 2060 | // slow_path will return to GetLabelOf(successor). |
| 2061 | } |
| 2062 | } |
| 2063 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2064 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2065 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2066 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2067 | assembler_(codegen->GetAssembler()), |
| 2068 | codegen_(codegen) {} |
| 2069 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2070 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2071 | DCHECK_EQ(instr->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2072 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2073 | DataType::Type type = instr->GetResultType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2074 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2075 | case DataType::Type::kInt32: |
| 2076 | case DataType::Type::kInt64: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2077 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2078 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2079 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2080 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2081 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2082 | case DataType::Type::kFloat32: |
| 2083 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2084 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2085 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2086 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2087 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2088 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2089 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2090 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2091 | } |
| 2092 | } |
| 2093 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2094 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2095 | const FieldInfo& field_info) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2096 | DCHECK(instruction->IsInstanceFieldGet() || |
| 2097 | instruction->IsStaticFieldGet() || |
| 2098 | instruction->IsPredicatedInstanceFieldGet()); |
| 2099 | |
| 2100 | bool is_predicated = instruction->IsPredicatedInstanceFieldGet(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2101 | |
| 2102 | bool object_field_get_with_read_barrier = |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2103 | gUseReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2104 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2105 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2106 | object_field_get_with_read_barrier |
| 2107 | ? LocationSummary::kCallOnSlowPath |
| 2108 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2109 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2110 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 2111 | // We need a temporary register for the read barrier load in |
| 2112 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2113 | // only if the field is volatile or the offset is too big. |
| 2114 | if (field_info.IsVolatile() || |
| 2115 | field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2116 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2117 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2118 | } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2119 | // Input for object receiver. |
| 2120 | locations->SetInAt(is_predicated ? 1 : 0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2121 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2122 | if (is_predicated) { |
| 2123 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2124 | locations->SetOut(Location::SameAsFirstInput()); |
| 2125 | } else { |
| 2126 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2127 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2128 | } else { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2129 | if (is_predicated) { |
| 2130 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2131 | locations->SetOut(Location::SameAsFirstInput()); |
| 2132 | } else { |
| 2133 | // The output overlaps for an object field get when read barriers |
| 2134 | // are enabled: we do not want the load to overwrite the object's |
| 2135 | // location, as we need it to emit the read barrier. |
| 2136 | locations->SetOut(Location::RequiresRegister(), |
| 2137 | object_field_get_with_read_barrier ? Location::kOutputOverlap |
| 2138 | : Location::kNoOutputOverlap); |
| 2139 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2140 | } |
| 2141 | } |
| 2142 | |
| 2143 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2144 | const FieldInfo& field_info) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2145 | DCHECK(instruction->IsInstanceFieldGet() || |
| 2146 | instruction->IsStaticFieldGet() || |
| 2147 | instruction->IsPredicatedInstanceFieldGet()); |
| 2148 | bool is_predicated = instruction->IsPredicatedInstanceFieldGet(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2149 | LocationSummary* locations = instruction->GetLocations(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2150 | uint32_t receiver_input = is_predicated ? 1 : 0; |
| 2151 | Location base_loc = locations->InAt(receiver_input); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2152 | Location out = locations->Out(); |
| 2153 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2154 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 2155 | DataType::Type load_type = instruction->GetType(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2156 | MemOperand field = |
| 2157 | HeapOperand(InputRegisterAt(instruction, receiver_input), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2158 | |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2159 | if (gUseReadBarrier && kUseBakerReadBarrier && |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2160 | load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2161 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2162 | // /* HeapReference<Object> */ out = *(base + offset) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2163 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2164 | Location maybe_temp = |
| 2165 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2166 | // Note that potential implicit null checks are handled in this |
| 2167 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2168 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2169 | instruction, |
| 2170 | out, |
| 2171 | base, |
| 2172 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2173 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2174 | /* needs_null_check= */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2175 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2176 | } else { |
| 2177 | // General case. |
| 2178 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2179 | // Note that a potential implicit null check is handled in this |
| 2180 | // CodeGeneratorARM64::LoadAcquire call. |
| 2181 | // NB: LoadAcquire will record the pc info if needed. |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 2182 | codegen_->LoadAcquire(instruction, |
| 2183 | load_type, |
| 2184 | OutputCPURegister(instruction), |
| 2185 | field, |
| 2186 | /* needs_null_check= */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2187 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2188 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2189 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2190 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2191 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2192 | } |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2193 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2194 | // If read barriers are enabled, emit read barriers other than |
| 2195 | // Baker's using a slow path (and also unpoison the loaded |
| 2196 | // reference, if heap poisoning is enabled). |
| 2197 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2198 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2199 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2203 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2204 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2205 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2206 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2207 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2208 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2209 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2210 | } else { |
| 2211 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2212 | } |
| 2213 | } |
| 2214 | |
| 2215 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2216 | const FieldInfo& field_info, |
| 2217 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2218 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2219 | bool is_predicated = |
| 2220 | instruction->IsInstanceFieldSet() && instruction->AsInstanceFieldSet()->GetIsPredicatedSet(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2221 | |
| 2222 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2223 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2224 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2225 | Offset offset = field_info.GetFieldOffset(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2226 | DataType::Type field_type = field_info.GetFieldType(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2227 | std::optional<vixl::aarch64::Label> pred_is_null; |
| 2228 | if (is_predicated) { |
| 2229 | pred_is_null.emplace(); |
| 2230 | __ Cbz(obj, &*pred_is_null); |
| 2231 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2232 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2233 | { |
| 2234 | // We use a block to end the scratch scope before the write barrier, thus |
| 2235 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2236 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2237 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2238 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2239 | DCHECK(value.IsW()); |
| 2240 | Register temp = temps.AcquireW(); |
| 2241 | __ Mov(temp, value.W()); |
| 2242 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2243 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2244 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2245 | |
| 2246 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2247 | codegen_->StoreRelease( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2248 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check= */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2249 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2250 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2251 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2252 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2253 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2254 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2258 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2259 | } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 2260 | |
| 2261 | if (is_predicated) { |
| 2262 | __ Bind(&*pred_is_null); |
| 2263 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2264 | } |
| 2265 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2266 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2267 | DataType::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2268 | |
| 2269 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2270 | case DataType::Type::kInt32: |
| 2271 | case DataType::Type::kInt64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2272 | Register dst = OutputRegister(instr); |
| 2273 | Register lhs = InputRegisterAt(instr, 0); |
| 2274 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2275 | if (instr->IsAdd()) { |
| 2276 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2277 | } else if (instr->IsAnd()) { |
| 2278 | __ And(dst, lhs, rhs); |
| 2279 | } else if (instr->IsOr()) { |
| 2280 | __ Orr(dst, lhs, rhs); |
| 2281 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2282 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2283 | } else if (instr->IsRor()) { |
| 2284 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2285 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2286 | __ Ror(dst, lhs, shift); |
| 2287 | } else { |
| 2288 | // Ensure shift distance is in the same size register as the result. If |
| 2289 | // we are rotating a long and the shift comes in a w register originally, |
| 2290 | // we don't need to sxtw for use as an x since the shift distances are |
| 2291 | // all & reg_bits - 1. |
| 2292 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2293 | } |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2294 | } else if (instr->IsMin() || instr->IsMax()) { |
| 2295 | __ Cmp(lhs, rhs); |
| 2296 | __ Csel(dst, lhs, rhs, instr->IsMin() ? lt : gt); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2297 | } else { |
| 2298 | DCHECK(instr->IsXor()); |
| 2299 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2300 | } |
| 2301 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2302 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2303 | case DataType::Type::kFloat32: |
| 2304 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 2305 | VRegister dst = OutputFPRegister(instr); |
| 2306 | VRegister lhs = InputFPRegisterAt(instr, 0); |
| 2307 | VRegister rhs = InputFPRegisterAt(instr, 1); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2308 | if (instr->IsAdd()) { |
| 2309 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2310 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2311 | __ Fsub(dst, lhs, rhs); |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2312 | } else if (instr->IsMin()) { |
| 2313 | __ Fmin(dst, lhs, rhs); |
| 2314 | } else if (instr->IsMax()) { |
| 2315 | __ Fmax(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2316 | } else { |
| 2317 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2318 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2319 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2320 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2321 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2322 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2323 | } |
| 2324 | } |
| 2325 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2326 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2327 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2328 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2329 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2330 | DataType::Type type = instr->GetResultType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2331 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2332 | case DataType::Type::kInt32: |
| 2333 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2334 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2335 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2336 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2337 | break; |
| 2338 | } |
| 2339 | default: |
| 2340 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2341 | } |
| 2342 | } |
| 2343 | |
| 2344 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2345 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2346 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2347 | DataType::Type type = instr->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2348 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2349 | case DataType::Type::kInt32: |
| 2350 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2351 | Register dst = OutputRegister(instr); |
| 2352 | Register lhs = InputRegisterAt(instr, 0); |
| 2353 | Operand rhs = InputOperandAt(instr, 1); |
| 2354 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2355 | uint32_t shift_value = rhs.GetImmediate() & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2356 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2357 | if (instr->IsShl()) { |
| 2358 | __ Lsl(dst, lhs, shift_value); |
| 2359 | } else if (instr->IsShr()) { |
| 2360 | __ Asr(dst, lhs, shift_value); |
| 2361 | } else { |
| 2362 | __ Lsr(dst, lhs, shift_value); |
| 2363 | } |
| 2364 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2365 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2366 | |
| 2367 | if (instr->IsShl()) { |
| 2368 | __ Lsl(dst, lhs, rhs_reg); |
| 2369 | } else if (instr->IsShr()) { |
| 2370 | __ Asr(dst, lhs, rhs_reg); |
| 2371 | } else { |
| 2372 | __ Lsr(dst, lhs, rhs_reg); |
| 2373 | } |
| 2374 | } |
| 2375 | break; |
| 2376 | } |
| 2377 | default: |
| 2378 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2379 | } |
| 2380 | } |
| 2381 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2382 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2383 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2387 | HandleBinaryOp(instruction); |
| 2388 | } |
| 2389 | |
| 2390 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2391 | HandleBinaryOp(instruction); |
| 2392 | } |
| 2393 | |
| 2394 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2395 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2396 | } |
| 2397 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2398 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2399 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2400 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2401 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2402 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2403 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2404 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2405 | } |
| 2406 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2407 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2408 | Register dst = OutputRegister(instr); |
| 2409 | Register lhs = InputRegisterAt(instr, 0); |
| 2410 | Register rhs = InputRegisterAt(instr, 1); |
| 2411 | |
| 2412 | switch (instr->GetOpKind()) { |
| 2413 | case HInstruction::kAnd: |
| 2414 | __ Bic(dst, lhs, rhs); |
| 2415 | break; |
| 2416 | case HInstruction::kOr: |
| 2417 | __ Orn(dst, lhs, rhs); |
| 2418 | break; |
| 2419 | case HInstruction::kXor: |
| 2420 | __ Eon(dst, lhs, rhs); |
| 2421 | break; |
| 2422 | default: |
| 2423 | LOG(FATAL) << "Unreachable"; |
| 2424 | } |
| 2425 | } |
| 2426 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2427 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2428 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2429 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2430 | instruction->GetType() == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2431 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2432 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2433 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2434 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2435 | } else { |
| 2436 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2437 | } |
| 2438 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2439 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2440 | } |
| 2441 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2442 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2443 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2444 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2445 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2446 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2447 | Register out = OutputRegister(instruction); |
| 2448 | Register left; |
| 2449 | if (kind != HInstruction::kNeg) { |
| 2450 | left = InputRegisterAt(instruction, 0); |
| 2451 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2452 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2453 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2454 | // conversion) can have a different type from the current instruction's type, |
| 2455 | // so we manually indicate the type. |
| 2456 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2457 | Operand right_operand(0); |
| 2458 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2459 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2460 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2461 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2462 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2463 | right_operand = Operand(right_reg, |
| 2464 | helpers::ShiftFromOpKind(op_kind), |
| 2465 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | // Logical binary operations do not support extension operations in the |
| 2469 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2470 | // the extension as a separate instruction. |
| 2471 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
Santiago Aboy Solanes | 872ec72 | 2022-02-18 14:10:25 +0000 | [diff] [blame] | 2472 | DCHECK_IMPLIES(right_operand.IsExtendedRegister(), |
| 2473 | kind != HInstruction::kAnd && kind != HInstruction::kOr && |
| 2474 | kind != HInstruction::kXor && kind != HInstruction::kNeg); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2475 | switch (kind) { |
| 2476 | case HInstruction::kAdd: |
| 2477 | __ Add(out, left, right_operand); |
| 2478 | break; |
| 2479 | case HInstruction::kAnd: |
| 2480 | __ And(out, left, right_operand); |
| 2481 | break; |
| 2482 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2483 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2484 | __ Neg(out, right_operand); |
| 2485 | break; |
| 2486 | case HInstruction::kOr: |
| 2487 | __ Orr(out, left, right_operand); |
| 2488 | break; |
| 2489 | case HInstruction::kSub: |
| 2490 | __ Sub(out, left, right_operand); |
| 2491 | break; |
| 2492 | case HInstruction::kXor: |
| 2493 | __ Eor(out, left, right_operand); |
| 2494 | break; |
| 2495 | default: |
| 2496 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2497 | UNREACHABLE(); |
| 2498 | } |
| 2499 | } |
| 2500 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2501 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2502 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2503 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2504 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2505 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2506 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2507 | } |
| 2508 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2509 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2510 | __ Add(OutputRegister(instruction), |
| 2511 | InputRegisterAt(instruction, 0), |
| 2512 | Operand(InputOperandAt(instruction, 1))); |
| 2513 | } |
| 2514 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2515 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2516 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2517 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2518 | |
| 2519 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2520 | |
| 2521 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2522 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2523 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2524 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2525 | // loop. |
| 2526 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2527 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2528 | : Location::RequiresRegister()); |
| 2529 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2530 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2531 | } |
| 2532 | |
| 2533 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2534 | HIntermediateAddressIndex* instruction) { |
| 2535 | Register index_reg = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2536 | uint32_t shift = Int64FromLocation(instruction->GetLocations()->InAt(2)); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2537 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2538 | |
| 2539 | if (shift == 0) { |
| 2540 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2541 | } else { |
| 2542 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2543 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2544 | } |
| 2545 | } |
| 2546 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2547 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2548 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2549 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2550 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2551 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2552 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2553 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2554 | // Don't allocate register for Mneg instruction. |
| 2555 | } else { |
| 2556 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2557 | Location::RequiresRegister()); |
| 2558 | } |
| 2559 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2560 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2561 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2562 | } |
| 2563 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2564 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2565 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2566 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2567 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2568 | |
| 2569 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2570 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2571 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2572 | if (instr->GetType() == DataType::Type::kInt64 && |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2573 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2574 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Florian Mayer | 6f572b7 | 2022-01-10 13:03:57 -0800 | [diff] [blame] | 2575 | ptrdiff_t off = masm->GetCursorOffset(); |
| 2576 | if (off >= static_cast<ptrdiff_t>(kInstructionSize) && |
| 2577 | masm->GetInstructionAt(off - static_cast<ptrdiff_t>(kInstructionSize))->IsLoadOrStore()) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2578 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2579 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2580 | __ nop(); |
| 2581 | } |
| 2582 | } |
| 2583 | |
| 2584 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2585 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2586 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2587 | } else { |
| 2588 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2589 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2590 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2591 | __ Mneg(res, mul_left, mul_right); |
| 2592 | } else { |
| 2593 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2594 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2595 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2596 | } |
| 2597 | } |
| 2598 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2599 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2600 | bool object_array_get_with_read_barrier = |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2601 | gUseReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2602 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2603 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2604 | object_array_get_with_read_barrier |
| 2605 | ? LocationSummary::kCallOnSlowPath |
| 2606 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2607 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2608 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2609 | if (instruction->GetIndex()->IsConstant()) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2610 | // Array loads with constant index are treated as field loads. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2611 | // We need a temporary register for the read barrier load in |
| 2612 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2613 | // only if the offset is too big. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2614 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2615 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2616 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2617 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2618 | locations->AddTemp(FixedTempLocation()); |
| 2619 | } |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2620 | } else if (!instruction->GetArray()->IsIntermediateAddress()) { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2621 | // We need a non-scratch temporary for the array data pointer in |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2622 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier() for the case with no |
| 2623 | // intermediate address. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2624 | locations->AddTemp(Location::RequiresRegister()); |
| 2625 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2626 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2627 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2628 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2629 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2630 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2631 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2632 | // The output overlaps in the case of an object array get with |
| 2633 | // read barriers enabled: we do not want the move to overwrite the |
| 2634 | // array's location, as we need it to emit the read barrier. |
| 2635 | locations->SetOut( |
| 2636 | Location::RequiresRegister(), |
| 2637 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2638 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2642 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2643 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2644 | LocationSummary* locations = instruction->GetLocations(); |
| 2645 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2646 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2647 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2648 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2649 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2650 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2651 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2652 | |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2653 | // The non-Baker read barrier instrumentation of object ArrayGet instructions |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2654 | // does not support the HIntermediateAddress instruction. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2655 | DCHECK(!((type == DataType::Type::kReference) && |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2656 | instruction->GetArray()->IsIntermediateAddress() && |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2657 | gUseReadBarrier && |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2658 | !kUseBakerReadBarrier)); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2659 | |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 2660 | if (type == DataType::Type::kReference && gUseReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2661 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2662 | // Note that a potential implicit null check is handled in the |
| 2663 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2664 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2665 | if (index.IsConstant()) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2666 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2667 | // 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] | 2668 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2669 | Location maybe_temp = |
| 2670 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2671 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2672 | out, |
| 2673 | obj.W(), |
| 2674 | offset, |
| 2675 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2676 | /* needs_null_check= */ false, |
| 2677 | /* use_load_acquire= */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2678 | } else { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2679 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2680 | instruction, out, obj.W(), offset, index, /* needs_null_check= */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2681 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2682 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2683 | // General case. |
| 2684 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2685 | Register length; |
| 2686 | if (maybe_compressed_char_at) { |
| 2687 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2688 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2689 | { |
| 2690 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2691 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2692 | |
| 2693 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2694 | DCHECK_LT(count_offset, offset); |
| 2695 | int64_t adjusted_offset = |
| 2696 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2697 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2698 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2699 | } else { |
| 2700 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2701 | } |
| 2702 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2703 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2704 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2705 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2706 | if (maybe_compressed_char_at) { |
| 2707 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2708 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2709 | "Expecting 0=compressed, 1=uncompressed"); |
| 2710 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2711 | __ Ldrb(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2712 | HeapOperand(obj, offset + Int64FromLocation(index))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2713 | __ B(&done); |
| 2714 | __ Bind(&uncompressed_load); |
| 2715 | __ Ldrh(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2716 | HeapOperand(obj, offset + (Int64FromLocation(index) << 1))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2717 | __ Bind(&done); |
| 2718 | } else { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2719 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2720 | source = HeapOperand(obj, offset); |
| 2721 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2722 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2723 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2724 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2725 | // We do not need to compute the intermediate address from the array: the |
| 2726 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2727 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2728 | if (kIsDebugBuild) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2729 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2730 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2731 | } |
| 2732 | temp = obj; |
| 2733 | } else { |
| 2734 | __ Add(temp, obj, offset); |
| 2735 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2736 | if (maybe_compressed_char_at) { |
| 2737 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2738 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2739 | "Expecting 0=compressed, 1=uncompressed"); |
| 2740 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2741 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2742 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2743 | __ B(&done); |
| 2744 | __ Bind(&uncompressed_load); |
| 2745 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2746 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2747 | __ Bind(&done); |
| 2748 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2749 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2750 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2751 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2752 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2753 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2754 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2755 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2756 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2757 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2758 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2759 | if (type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2760 | static_assert( |
| 2761 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2762 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2763 | Location obj_loc = locations->InAt(0); |
| 2764 | if (index.IsConstant()) { |
| 2765 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2766 | } else { |
| 2767 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2768 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2769 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2770 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2771 | } |
| 2772 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2773 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2774 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2775 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2776 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2780 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2781 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2782 | { |
| 2783 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2784 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2785 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2786 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2787 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2788 | // Mask out compression flag from String's array length. |
| 2789 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2790 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2791 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2792 | } |
| 2793 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2794 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2795 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2796 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2797 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2798 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2799 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2800 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2801 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2802 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2803 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2804 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2805 | } else if (DataType::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2806 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2807 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2808 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2809 | } |
| 2810 | } |
| 2811 | |
| 2812 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2813 | DataType::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2814 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2815 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2816 | bool needs_write_barrier = |
| 2817 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2818 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2819 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2820 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2821 | CPURegister source = value; |
| 2822 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2823 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2824 | MemOperand destination = HeapOperand(array); |
| 2825 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2826 | |
| 2827 | if (!needs_write_barrier) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2828 | DCHECK(!needs_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2829 | if (index.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2830 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2831 | destination = HeapOperand(array, offset); |
| 2832 | } else { |
| 2833 | UseScratchRegisterScope temps(masm); |
| 2834 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2835 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2836 | // We do not need to compute the intermediate address from the array: the |
| 2837 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2838 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2839 | if (kIsDebugBuild) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2840 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2841 | DCHECK(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2842 | } |
| 2843 | temp = array; |
| 2844 | } else { |
| 2845 | __ Add(temp, array, offset); |
| 2846 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2847 | destination = HeapOperand(temp, |
| 2848 | XRegisterFrom(index), |
| 2849 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2850 | DataType::SizeShift(value_type)); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2851 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2852 | { |
| 2853 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2854 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2855 | codegen_->Store(value_type, value, destination); |
| 2856 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2857 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2858 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2859 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2860 | |
| 2861 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 2862 | vixl::aarch64::Label do_store; |
| 2863 | if (can_value_be_null) { |
| 2864 | __ Cbz(Register(value), &do_store); |
| 2865 | } |
| 2866 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2867 | SlowPathCodeARM64* slow_path = nullptr; |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2868 | if (needs_type_check) { |
| 2869 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
| 2870 | codegen_->AddSlowPath(slow_path); |
| 2871 | |
| 2872 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2873 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2874 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2875 | |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2876 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2877 | Register temp = temps.AcquireSameSizeAs(array); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2878 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2879 | |
| 2880 | // Note that when Baker read barriers are enabled, the type |
| 2881 | // checks are performed without read barriers. This is fine, |
| 2882 | // even in the case where a class object is in the from-space |
| 2883 | // after the flip, as a comparison involving such a type would |
| 2884 | // not produce a false positive; it may of course produce a |
| 2885 | // false negative, in which case we would take the ArraySet |
| 2886 | // slow path. |
| 2887 | |
| 2888 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2889 | { |
| 2890 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2891 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2892 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2893 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2894 | } |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2895 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2896 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2897 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2898 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2899 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2900 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2901 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2902 | // nor `temp2`, as we are comparing two poisoned references. |
| 2903 | __ Cmp(temp, temp2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2904 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2905 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2906 | vixl::aarch64::Label do_put; |
| 2907 | __ B(eq, &do_put); |
| 2908 | // If heap poisoning is enabled, the `temp` reference has |
| 2909 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2910 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2911 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2912 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2913 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2914 | // If heap poisoning is enabled, no need to unpoison |
| 2915 | // `temp`, as we are comparing against null below. |
| 2916 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2917 | __ Bind(&do_put); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 2918 | } else { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2919 | __ B(ne, slow_path->GetEntryLabel()); |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2920 | } |
| 2921 | } |
| 2922 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2923 | codegen_->MarkGCCard(array, value.W(), /* value_can_be_null= */ false); |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2924 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2925 | if (can_value_be_null) { |
| 2926 | DCHECK(do_store.IsLinked()); |
| 2927 | __ Bind(&do_store); |
| 2928 | } |
| 2929 | |
| 2930 | UseScratchRegisterScope temps(masm); |
| 2931 | if (kPoisonHeapReferences) { |
| 2932 | Register temp_source = temps.AcquireSameSizeAs(array); |
| 2933 | DCHECK(value.IsW()); |
| 2934 | __ Mov(temp_source, value.W()); |
| 2935 | GetAssembler()->PoisonHeapReference(temp_source); |
| 2936 | source = temp_source; |
| 2937 | } |
| 2938 | |
| 2939 | if (index.IsConstant()) { |
| 2940 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
| 2941 | destination = HeapOperand(array, offset); |
| 2942 | } else { |
| 2943 | Register temp_base = temps.AcquireSameSizeAs(array); |
| 2944 | __ Add(temp_base, array, offset); |
| 2945 | destination = HeapOperand(temp_base, |
| 2946 | XRegisterFrom(index), |
| 2947 | LSL, |
| 2948 | DataType::SizeShift(value_type)); |
| 2949 | } |
| 2950 | |
| 2951 | { |
| 2952 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2953 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2954 | __ Str(source, destination); |
| 2955 | |
| 2956 | if (can_value_be_null || !needs_type_check) { |
| 2957 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2958 | } |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | if (slow_path != nullptr) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2962 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2963 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2964 | } |
| 2965 | } |
| 2966 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2967 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2968 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2969 | InvokeRuntimeCallingConvention calling_convention; |
| 2970 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 2971 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 2972 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2973 | |
| 2974 | // If both index and length are constant, we can check the bounds statically and |
| 2975 | // generate code accordingly. We want to make sure we generate constant locations |
| 2976 | // in that case, regardless of whether they are encodable in the comparison or not. |
| 2977 | HInstruction* index = instruction->InputAt(0); |
| 2978 | HInstruction* length = instruction->InputAt(1); |
| 2979 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 2980 | locations->SetInAt(0, both_const |
| 2981 | ? Location::ConstantLocation(index->AsConstant()) |
| 2982 | : ARM64EncodableConstantOrRegister(index, instruction)); |
| 2983 | locations->SetInAt(1, both_const |
| 2984 | ? Location::ConstantLocation(length->AsConstant()) |
| 2985 | : ARM64EncodableConstantOrRegister(length, instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2989 | LocationSummary* locations = instruction->GetLocations(); |
| 2990 | Location index_loc = locations->InAt(0); |
| 2991 | Location length_loc = locations->InAt(1); |
| 2992 | |
| 2993 | int cmp_first_input = 0; |
| 2994 | int cmp_second_input = 1; |
| 2995 | Condition cond = hs; |
| 2996 | |
| 2997 | if (index_loc.IsConstant()) { |
| 2998 | int64_t index = Int64FromLocation(index_loc); |
| 2999 | if (length_loc.IsConstant()) { |
| 3000 | int64_t length = Int64FromLocation(length_loc); |
| 3001 | if (index < 0 || index >= length) { |
| 3002 | BoundsCheckSlowPathARM64* slow_path = |
| 3003 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
| 3004 | codegen_->AddSlowPath(slow_path); |
| 3005 | __ B(slow_path->GetEntryLabel()); |
| 3006 | } else { |
| 3007 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 3008 | // However, some optimization after BCE may have generated this, and we should not |
| 3009 | // generate a bounds check if it is a valid range. |
| 3010 | } |
| 3011 | return; |
| 3012 | } |
| 3013 | // Only the index is constant: change the order of the operands and commute the condition |
| 3014 | // so we can use an immediate constant for the index (only the second input to a cmp |
| 3015 | // instruction can be an immediate). |
| 3016 | cmp_first_input = 1; |
| 3017 | cmp_second_input = 0; |
| 3018 | cond = ls; |
| 3019 | } |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3020 | BoundsCheckSlowPathARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3021 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 3022 | __ Cmp(InputRegisterAt(instruction, cmp_first_input), |
| 3023 | InputOperandAt(instruction, cmp_second_input)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3024 | codegen_->AddSlowPath(slow_path); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 3025 | __ B(slow_path->GetEntryLabel(), cond); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3026 | } |
| 3027 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3028 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3029 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3030 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3031 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3032 | if (check->HasUses()) { |
| 3033 | locations->SetOut(Location::SameAsFirstInput()); |
| 3034 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 3035 | // Rely on the type initialization to save everything we need. |
| 3036 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3040 | // We assume the class is not null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 3041 | SlowPathCodeARM64* slow_path = |
| 3042 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(check->GetLoadClass(), check); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3043 | codegen_->AddSlowPath(slow_path); |
| 3044 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3045 | } |
| 3046 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3047 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3048 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3049 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3050 | } |
| 3051 | |
| 3052 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 3053 | VRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3054 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3055 | if (rhs_loc.IsConstant()) { |
| 3056 | // 0.0 is the only immediate that can be encoded directly in |
| 3057 | // an FCMP instruction. |
| 3058 | // |
| 3059 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3060 | // specify that in a floating-point comparison, positive zero |
| 3061 | // and negative zero are considered equal, so we can use the |
| 3062 | // literal 0.0 for both cases here. |
| 3063 | // |
| 3064 | // Note however that some methods (Float.equal, Float.compare, |
| 3065 | // Float.compareTo, Double.equal, Double.compare, |
| 3066 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3067 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3068 | // -0.0. So if we ever translate calls to these methods into a |
| 3069 | // HCompare instruction, we must handle the -0.0 case with |
| 3070 | // care here. |
| 3071 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3072 | __ Fcmp(lhs_reg, 0.0); |
| 3073 | } else { |
| 3074 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3075 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3076 | } |
| 3077 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3078 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3079 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3080 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3081 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3082 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3083 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3084 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3085 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3086 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3087 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3088 | case DataType::Type::kInt32: |
| 3089 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3090 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3091 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3092 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3093 | break; |
| 3094 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3095 | case DataType::Type::kFloat32: |
| 3096 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3097 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3098 | locations->SetInAt(1, |
| 3099 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3100 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3101 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3102 | locations->SetOut(Location::RequiresRegister()); |
| 3103 | break; |
| 3104 | } |
| 3105 | default: |
| 3106 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3107 | } |
| 3108 | } |
| 3109 | |
| 3110 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3111 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3112 | |
| 3113 | // 0 if: left == right |
| 3114 | // 1 if: left > right |
| 3115 | // -1 if: left < right |
| 3116 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3117 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3118 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3119 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3120 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3121 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3122 | case DataType::Type::kInt32: |
| 3123 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3124 | Register result = OutputRegister(compare); |
| 3125 | Register left = InputRegisterAt(compare, 0); |
| 3126 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3127 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3128 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3129 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3130 | break; |
| 3131 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3132 | case DataType::Type::kFloat32: |
| 3133 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3134 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3135 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3136 | __ Cset(result, ne); |
| 3137 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3138 | break; |
| 3139 | } |
| 3140 | default: |
| 3141 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3142 | } |
| 3143 | } |
| 3144 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3145 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3146 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3147 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3148 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3149 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3150 | locations->SetInAt(1, |
| 3151 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3152 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3153 | : Location::RequiresFpuRegister()); |
| 3154 | } else { |
| 3155 | // Integer cases. |
| 3156 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3157 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3158 | } |
| 3159 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3160 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3161 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3162 | } |
| 3163 | } |
| 3164 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3165 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3166 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3167 | return; |
| 3168 | } |
| 3169 | |
| 3170 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3171 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3172 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3173 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3174 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3175 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3176 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3177 | } else { |
| 3178 | // Integer cases. |
| 3179 | Register lhs = InputRegisterAt(instruction, 0); |
| 3180 | Operand rhs = InputOperandAt(instruction, 1); |
| 3181 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3182 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3183 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3187 | M(Equal) \ |
| 3188 | M(NotEqual) \ |
| 3189 | M(LessThan) \ |
| 3190 | M(LessThanOrEqual) \ |
| 3191 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3192 | M(GreaterThanOrEqual) \ |
| 3193 | M(Below) \ |
| 3194 | M(BelowOrEqual) \ |
| 3195 | M(Above) \ |
| 3196 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3197 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3198 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3199 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3200 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3201 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3202 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3203 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3204 | void InstructionCodeGeneratorARM64::GenerateIntDivForPower2Denom(HDiv* instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3205 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3206 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3207 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 3208 | |
| 3209 | Register out = OutputRegister(instruction); |
| 3210 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3211 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3212 | Register final_dividend; |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3213 | if (HasNonNegativeOrMinIntInputAt(instruction, 0)) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3214 | // No need to adjust the result for non-negative dividends or the INT32_MIN/INT64_MIN dividends. |
| 3215 | // NOTE: The generated code for HDiv correctly works for the INT32_MIN/INT64_MIN dividends: |
| 3216 | // imm == 2 |
| 3217 | // add out, dividend(0x80000000), dividend(0x80000000), lsr #31 => out = 0x80000001 |
| 3218 | // asr out, out(0x80000001), #1 => out = 0xc0000000 |
| 3219 | // This is the same as 'asr out, 0x80000000, #1' |
| 3220 | // |
| 3221 | // imm > 2 |
| 3222 | // add temp, dividend(0x80000000), imm - 1 => temp = 0b10..01..1, where the number |
| 3223 | // of the rightmost 1s is ctz_imm. |
| 3224 | // cmp dividend(0x80000000), 0 => N = 1, V = 0 (lt is true) |
| 3225 | // csel out, temp(0b10..01..1), dividend(0x80000000), lt => out = 0b10..01..1 |
| 3226 | // asr out, out(0b10..01..1), #ctz_imm => out = 0b1..10..0, where the number of the |
| 3227 | // leftmost 1s is ctz_imm + 1. |
| 3228 | // This is the same as 'asr out, dividend(0x80000000), #ctz_imm'. |
| 3229 | // |
| 3230 | // imm == INT32_MIN |
| 3231 | // add tmp, dividend(0x80000000), #0x7fffffff => tmp = -1 |
| 3232 | // cmp dividend(0x80000000), 0 => N = 1, V = 0 (lt is true) |
| 3233 | // csel out, temp(-1), dividend(0x80000000), lt => out = -1 |
| 3234 | // neg out, out(-1), asr #31 => out = 1 |
| 3235 | // This is the same as 'neg out, dividend(0x80000000), asr #31'. |
| 3236 | final_dividend = dividend; |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3237 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3238 | if (abs_imm == 2) { |
| 3239 | int bits = DataType::Size(instruction->GetResultType()) * kBitsPerByte; |
| 3240 | __ Add(out, dividend, Operand(dividend, LSR, bits - 1)); |
| 3241 | } else { |
| 3242 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3243 | Register temp = temps.AcquireSameSizeAs(out); |
| 3244 | __ Add(temp, dividend, abs_imm - 1); |
| 3245 | __ Cmp(dividend, 0); |
| 3246 | __ Csel(out, temp, dividend, lt); |
| 3247 | } |
| 3248 | final_dividend = out; |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3249 | } |
| 3250 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3251 | int ctz_imm = CTZ(abs_imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3252 | if (imm > 0) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3253 | __ Asr(out, final_dividend, ctz_imm); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3254 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3255 | __ Neg(out, Operand(final_dividend, ASR, ctz_imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3256 | } |
| 3257 | } |
| 3258 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3259 | // Return true if the magic number was modified by subtracting 2^32(Int32 div) or 2^64(Int64 div). |
| 3260 | // So dividend needs to be added. |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3261 | static inline bool NeedToAddDividend(int64_t magic_number, int64_t divisor) { |
| 3262 | return divisor > 0 && magic_number < 0; |
| 3263 | } |
| 3264 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3265 | // Return true if the magic number was modified by adding 2^32(Int32 div) or 2^64(Int64 div). |
| 3266 | // So dividend needs to be subtracted. |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3267 | static inline bool NeedToSubDividend(int64_t magic_number, int64_t divisor) { |
| 3268 | return divisor < 0 && magic_number > 0; |
| 3269 | } |
| 3270 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3271 | // Generate code which increments the value in register 'in' by 1 if the value is negative. |
| 3272 | // It is done with 'add out, in, in, lsr #31 or #63'. |
| 3273 | // If the value is a result of an operation setting the N flag, CINC MI can be used |
| 3274 | // instead of ADD. 'use_cond_inc' controls this. |
| 3275 | void InstructionCodeGeneratorARM64::GenerateIncrementNegativeByOne( |
| 3276 | Register out, |
| 3277 | Register in, |
| 3278 | bool use_cond_inc) { |
| 3279 | if (use_cond_inc) { |
| 3280 | __ Cinc(out, in, mi); |
| 3281 | } else { |
| 3282 | __ Add(out, in, Operand(in, LSR, in.GetSizeInBits() - 1)); |
| 3283 | } |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3284 | } |
| 3285 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3286 | // Helper to generate code producing the result of HRem with a constant divisor. |
| 3287 | void InstructionCodeGeneratorARM64::GenerateResultRemWithAnyConstant( |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3288 | Register out, |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3289 | Register dividend, |
| 3290 | Register quotient, |
| 3291 | int64_t divisor, |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3292 | UseScratchRegisterScope* temps_scope) { |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3293 | Register temp_imm = temps_scope->AcquireSameSizeAs(out); |
| 3294 | __ Mov(temp_imm, divisor); |
| 3295 | __ Msub(out, quotient, temp_imm, dividend); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3296 | } |
| 3297 | |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3298 | // Helper to generate code for HDiv/HRem instructions when a dividend is non-negative and |
| 3299 | // a divisor is a positive constant, not power of 2. |
| 3300 | void InstructionCodeGeneratorARM64::GenerateInt64UnsignedDivRemWithAnyPositiveConstant( |
| 3301 | HBinaryOperation* instruction) { |
| 3302 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3303 | DCHECK(instruction->GetResultType() == DataType::Type::kInt64); |
| 3304 | |
| 3305 | LocationSummary* locations = instruction->GetLocations(); |
| 3306 | Location second = locations->InAt(1); |
| 3307 | DCHECK(second.IsConstant()); |
| 3308 | |
| 3309 | Register out = OutputRegister(instruction); |
| 3310 | Register dividend = InputRegisterAt(instruction, 0); |
| 3311 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3312 | DCHECK_GT(imm, 0); |
| 3313 | |
| 3314 | int64_t magic; |
| 3315 | int shift; |
| 3316 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ true, &magic, &shift); |
| 3317 | |
| 3318 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3319 | Register temp = temps.AcquireSameSizeAs(out); |
| 3320 | |
| 3321 | auto generate_unsigned_div_code = [this, magic, shift](Register out, |
| 3322 | Register dividend, |
| 3323 | Register temp) { |
| 3324 | // temp = get_high(dividend * magic) |
| 3325 | __ Mov(temp, magic); |
| 3326 | if (magic > 0 && shift == 0) { |
| 3327 | __ Smulh(out, dividend, temp); |
| 3328 | } else { |
| 3329 | __ Smulh(temp, dividend, temp); |
| 3330 | if (magic < 0) { |
| 3331 | // The negative magic means that the multiplier m is greater than INT64_MAX. |
| 3332 | // In such a case shift is never 0. See the proof in |
| 3333 | // InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant. |
| 3334 | __ Add(temp, temp, dividend); |
| 3335 | } |
| 3336 | DCHECK_NE(shift, 0); |
| 3337 | __ Lsr(out, temp, shift); |
| 3338 | } |
| 3339 | }; |
| 3340 | |
| 3341 | if (instruction->IsDiv()) { |
| 3342 | generate_unsigned_div_code(out, dividend, temp); |
| 3343 | } else { |
| 3344 | generate_unsigned_div_code(temp, dividend, temp); |
| 3345 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3346 | } |
| 3347 | } |
| 3348 | |
| 3349 | // Helper to generate code for HDiv/HRem instructions for any dividend and a constant divisor |
| 3350 | // (not power of 2). |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3351 | void InstructionCodeGeneratorARM64::GenerateInt64DivRemWithAnyConstant( |
| 3352 | HBinaryOperation* instruction) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3353 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3354 | DCHECK(instruction->GetResultType() == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3355 | |
| 3356 | LocationSummary* locations = instruction->GetLocations(); |
| 3357 | Location second = locations->InAt(1); |
| 3358 | DCHECK(second.IsConstant()); |
| 3359 | |
| 3360 | Register out = OutputRegister(instruction); |
| 3361 | Register dividend = InputRegisterAt(instruction, 0); |
| 3362 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3363 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3364 | int64_t magic; |
| 3365 | int shift; |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3366 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ true, &magic, &shift); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3367 | |
| 3368 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3369 | Register temp = temps.AcquireSameSizeAs(out); |
| 3370 | |
| 3371 | // temp = get_high(dividend * magic) |
| 3372 | __ Mov(temp, magic); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3373 | __ Smulh(temp, dividend, temp); |
| 3374 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3375 | // The multiplication result might need some corrections to be finalized. |
| 3376 | // The last correction is to increment by 1, if the result is negative. |
| 3377 | // Currently it is done with 'add result, temp_result, temp_result, lsr #31 or #63'. |
| 3378 | // Such ADD usually has latency 2, e.g. on Cortex-A55. |
| 3379 | // However if one of the corrections is ADD or SUB, the sign can be detected |
| 3380 | // with ADDS/SUBS. They set the N flag if the result is negative. |
| 3381 | // This allows to use CINC MI which has latency 1. |
| 3382 | bool use_cond_inc = false; |
| 3383 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3384 | // Some combinations of magic_number and the divisor require to correct the result. |
| 3385 | // Check whether the correction is needed. |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3386 | if (NeedToAddDividend(magic, imm)) { |
| 3387 | __ Adds(temp, temp, dividend); |
| 3388 | use_cond_inc = true; |
| 3389 | } else if (NeedToSubDividend(magic, imm)) { |
| 3390 | __ Subs(temp, temp, dividend); |
| 3391 | use_cond_inc = true; |
| 3392 | } |
| 3393 | |
| 3394 | if (shift != 0) { |
| 3395 | __ Asr(temp, temp, shift); |
| 3396 | } |
| 3397 | |
| 3398 | if (instruction->IsRem()) { |
| 3399 | GenerateIncrementNegativeByOne(temp, temp, use_cond_inc); |
| 3400 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3401 | } else { |
| 3402 | GenerateIncrementNegativeByOne(out, temp, use_cond_inc); |
| 3403 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3404 | } |
| 3405 | |
| 3406 | void InstructionCodeGeneratorARM64::GenerateInt32DivRemWithAnyConstant( |
| 3407 | HBinaryOperation* instruction) { |
| 3408 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3409 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 3410 | |
| 3411 | LocationSummary* locations = instruction->GetLocations(); |
| 3412 | Location second = locations->InAt(1); |
| 3413 | DCHECK(second.IsConstant()); |
| 3414 | |
| 3415 | Register out = OutputRegister(instruction); |
| 3416 | Register dividend = InputRegisterAt(instruction, 0); |
| 3417 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3418 | |
| 3419 | int64_t magic; |
| 3420 | int shift; |
| 3421 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| 3422 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3423 | Register temp = temps.AcquireSameSizeAs(out); |
| 3424 | |
| 3425 | // temp = get_high(dividend * magic) |
| 3426 | __ Mov(temp, magic); |
| 3427 | __ Smull(temp.X(), dividend, temp); |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3428 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3429 | // The multiplication result might need some corrections to be finalized. |
| 3430 | // The last correction is to increment by 1, if the result is negative. |
| 3431 | // Currently it is done with 'add result, temp_result, temp_result, lsr #31 or #63'. |
| 3432 | // Such ADD usually has latency 2, e.g. on Cortex-A55. |
| 3433 | // However if one of the corrections is ADD or SUB, the sign can be detected |
| 3434 | // with ADDS/SUBS. They set the N flag if the result is negative. |
| 3435 | // This allows to use CINC MI which has latency 1. |
| 3436 | bool use_cond_inc = false; |
| 3437 | |
| 3438 | // ADD/SUB correction is performed in the high 32 bits |
| 3439 | // as high 32 bits are ignored because type are kInt32. |
| 3440 | if (NeedToAddDividend(magic, imm)) { |
| 3441 | __ Adds(temp.X(), temp.X(), Operand(dividend.X(), LSL, 32)); |
| 3442 | use_cond_inc = true; |
| 3443 | } else if (NeedToSubDividend(magic, imm)) { |
| 3444 | __ Subs(temp.X(), temp.X(), Operand(dividend.X(), LSL, 32)); |
| 3445 | use_cond_inc = true; |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3446 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3447 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3448 | // Extract the result from the high 32 bits and apply the final right shift. |
| 3449 | DCHECK_LT(shift, 32); |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3450 | if (imm > 0 && HasNonNegativeInputAt(instruction, 0)) { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 3451 | // No need to adjust the result for a non-negative dividend and a positive divisor. |
| 3452 | if (instruction->IsDiv()) { |
| 3453 | __ Lsr(out.X(), temp.X(), 32 + shift); |
| 3454 | } else { |
| 3455 | __ Lsr(temp.X(), temp.X(), 32 + shift); |
| 3456 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3457 | } |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3458 | } else { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 3459 | __ Asr(temp.X(), temp.X(), 32 + shift); |
| 3460 | |
| 3461 | if (instruction->IsRem()) { |
| 3462 | GenerateIncrementNegativeByOne(temp, temp, use_cond_inc); |
| 3463 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3464 | } else { |
| 3465 | GenerateIncrementNegativeByOne(out, temp, use_cond_inc); |
| 3466 | } |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3467 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3468 | } |
| 3469 | |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3470 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction, |
| 3471 | int64_t divisor) { |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3472 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3473 | if (instruction->GetResultType() == DataType::Type::kInt64) { |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3474 | if (divisor > 0 && HasNonNegativeInputAt(instruction, 0)) { |
| 3475 | GenerateInt64UnsignedDivRemWithAnyPositiveConstant(instruction); |
| 3476 | } else { |
| 3477 | GenerateInt64DivRemWithAnyConstant(instruction); |
| 3478 | } |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3479 | } else { |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3480 | GenerateInt32DivRemWithAnyConstant(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3481 | } |
| 3482 | } |
| 3483 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3484 | void InstructionCodeGeneratorARM64::GenerateIntDivForConstDenom(HDiv *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3485 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3486 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3487 | if (imm == 0) { |
| 3488 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3489 | return; |
| 3490 | } |
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 (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3493 | GenerateIntDivForPower2Denom(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3494 | } else { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3495 | // Cases imm == -1 or imm == 1 are handled by InstructionSimplifier. |
| 3496 | DCHECK(imm < -2 || imm > 2) << imm; |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3497 | GenerateDivRemWithAnyConstant(instruction, imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3498 | } |
| 3499 | } |
| 3500 | |
| 3501 | void InstructionCodeGeneratorARM64::GenerateIntDiv(HDiv *instruction) { |
| 3502 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 3503 | << instruction->GetResultType(); |
| 3504 | |
| 3505 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 3506 | GenerateIntDivForConstDenom(instruction); |
| 3507 | } else { |
| 3508 | Register out = OutputRegister(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3509 | Register dividend = InputRegisterAt(instruction, 0); |
| 3510 | Register divisor = InputRegisterAt(instruction, 1); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3511 | __ Sdiv(out, dividend, divisor); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3512 | } |
| 3513 | } |
| 3514 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3515 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3516 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3517 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3518 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3519 | case DataType::Type::kInt32: |
| 3520 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3521 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3522 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3523 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3524 | break; |
| 3525 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3526 | case DataType::Type::kFloat32: |
| 3527 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3528 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3529 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3530 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3531 | break; |
| 3532 | |
| 3533 | default: |
| 3534 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3535 | } |
| 3536 | } |
| 3537 | |
| 3538 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3539 | DataType::Type type = div->GetResultType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3540 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3541 | case DataType::Type::kInt32: |
| 3542 | case DataType::Type::kInt64: |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3543 | GenerateIntDiv(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3544 | break; |
| 3545 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3546 | case DataType::Type::kFloat32: |
| 3547 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3548 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3549 | break; |
| 3550 | |
| 3551 | default: |
| 3552 | LOG(FATAL) << "Unexpected div type " << type; |
| 3553 | } |
| 3554 | } |
| 3555 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3556 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3557 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3558 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3559 | } |
| 3560 | |
| 3561 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3562 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3563 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3564 | codegen_->AddSlowPath(slow_path); |
| 3565 | Location value = instruction->GetLocations()->InAt(0); |
| 3566 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3567 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3568 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3569 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3570 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3571 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3572 | } |
| 3573 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3574 | if (value.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3575 | int64_t divisor = Int64FromLocation(value); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3576 | if (divisor == 0) { |
| 3577 | __ B(slow_path->GetEntryLabel()); |
| 3578 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3579 | // A division by a non-null constant is valid. We don't need to perform |
| 3580 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3581 | } |
| 3582 | } else { |
| 3583 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3584 | } |
| 3585 | } |
| 3586 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3587 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3588 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3589 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3590 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3591 | } |
| 3592 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3593 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3594 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3595 | // Will be generated at use site. |
| 3596 | } |
| 3597 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3598 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3599 | exit->SetLocations(nullptr); |
| 3600 | } |
| 3601 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3602 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3603 | } |
| 3604 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3605 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3606 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3607 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3608 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3609 | } |
| 3610 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3611 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3612 | // Will be generated at use site. |
| 3613 | } |
| 3614 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3615 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3616 | if (successor->IsExitBlock()) { |
| 3617 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3618 | return; // no code needed |
| 3619 | } |
| 3620 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3621 | HBasicBlock* block = got->GetBlock(); |
| 3622 | HInstruction* previous = got->GetPrevious(); |
| 3623 | HLoopInformation* info = block->GetLoopInformation(); |
| 3624 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3625 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 3626 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3627 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
Vladimir Marko | e45883e | 2022-01-11 12:38:35 +0000 | [diff] [blame] | 3628 | return; // `GenerateSuspendCheck()` emitted the jump. |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3629 | } |
| 3630 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3631 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3632 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3633 | } |
| 3634 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3635 | __ B(codegen_->GetLabelOf(successor)); |
| 3636 | } |
| 3637 | } |
| 3638 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3639 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3640 | got->SetLocations(nullptr); |
| 3641 | } |
| 3642 | |
| 3643 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3644 | HandleGoto(got, got->GetSuccessor()); |
| 3645 | } |
| 3646 | |
| 3647 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3648 | try_boundary->SetLocations(nullptr); |
| 3649 | } |
| 3650 | |
| 3651 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3652 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3653 | if (!successor->IsExitBlock()) { |
| 3654 | HandleGoto(try_boundary, successor); |
| 3655 | } |
| 3656 | } |
| 3657 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3658 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3659 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3660 | vixl::aarch64::Label* true_target, |
| 3661 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3662 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3663 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3664 | if (true_target == nullptr && false_target == nullptr) { |
| 3665 | // Nothing to do. The code always falls through. |
| 3666 | return; |
| 3667 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3668 | // Constant condition, statically compared against "true" (integer value 1). |
| 3669 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3670 | if (true_target != nullptr) { |
| 3671 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3672 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3673 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3674 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3675 | if (false_target != nullptr) { |
| 3676 | __ B(false_target); |
| 3677 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3678 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3679 | return; |
| 3680 | } |
| 3681 | |
| 3682 | // The following code generates these patterns: |
| 3683 | // (1) true_target == nullptr && false_target != nullptr |
| 3684 | // - opposite condition true => branch to false_target |
| 3685 | // (2) true_target != nullptr && false_target == nullptr |
| 3686 | // - condition true => branch to true_target |
| 3687 | // (3) true_target != nullptr && false_target != nullptr |
| 3688 | // - condition true => branch to true_target |
| 3689 | // - branch to false_target |
| 3690 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3691 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3692 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3693 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3694 | if (true_target == nullptr) { |
| 3695 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3696 | } else { |
| 3697 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3698 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3699 | } else { |
| 3700 | // The condition instruction has not been materialized, use its inputs as |
| 3701 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3702 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3703 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3704 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3705 | if (DataType::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3706 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3707 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3708 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3709 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3710 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3711 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3712 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3713 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3714 | // Integer cases. |
| 3715 | Register lhs = InputRegisterAt(condition, 0); |
| 3716 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3717 | |
| 3718 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3719 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3720 | if (true_target == nullptr) { |
| 3721 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3722 | non_fallthrough_target = false_target; |
| 3723 | } else { |
| 3724 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3725 | non_fallthrough_target = true_target; |
| 3726 | } |
| 3727 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3728 | 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] | 3729 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3730 | switch (arm64_cond) { |
| 3731 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3732 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3733 | break; |
| 3734 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3735 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3736 | break; |
| 3737 | case lt: |
| 3738 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3739 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3740 | break; |
| 3741 | case ge: |
| 3742 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3743 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3744 | break; |
| 3745 | default: |
| 3746 | // Without the `static_cast` the compiler throws an error for |
| 3747 | // `-Werror=sign-promo`. |
| 3748 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3749 | } |
| 3750 | } else { |
| 3751 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3752 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3753 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3754 | } |
| 3755 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3756 | |
| 3757 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3758 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3759 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3760 | __ B(false_target); |
| 3761 | } |
| 3762 | } |
| 3763 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3764 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3765 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3766 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3767 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3768 | } |
| 3769 | } |
| 3770 | |
| 3771 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3772 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3773 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3774 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3775 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3776 | true_target = nullptr; |
| 3777 | } |
| 3778 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3779 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3780 | false_target = nullptr; |
| 3781 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3782 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3783 | } |
| 3784 | |
| 3785 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3786 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3787 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3788 | InvokeRuntimeCallingConvention calling_convention; |
| 3789 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3790 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3791 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3792 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3793 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3794 | } |
| 3795 | } |
| 3796 | |
| 3797 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3798 | SlowPathCodeARM64* slow_path = |
| 3799 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3800 | GenerateTestAndBranch(deoptimize, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3801 | /* condition_input_index= */ 0, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3802 | slow_path->GetEntryLabel(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3803 | /* false_target= */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3804 | } |
| 3805 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3806 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3807 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3808 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3809 | locations->SetOut(Location::RequiresRegister()); |
| 3810 | } |
| 3811 | |
| 3812 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3813 | __ Ldr(OutputRegister(flag), |
| 3814 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3815 | } |
| 3816 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3817 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3818 | return condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3819 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3820 | } |
| 3821 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3822 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3823 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3824 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3825 | : ARM64Condition(cond); |
| 3826 | } |
| 3827 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3828 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3829 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3830 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3831 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3832 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3833 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3834 | } else { |
| 3835 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3836 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3837 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3838 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3839 | // Ask VIXL whether we should synthesize constants in registers. |
| 3840 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3841 | Operand true_op = is_true_value_constant ? |
| 3842 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3843 | Operand false_op = is_false_value_constant ? |
| 3844 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3845 | bool true_value_in_register = false; |
| 3846 | bool false_value_in_register = false; |
| 3847 | MacroAssembler::GetCselSynthesisInformation( |
| 3848 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3849 | true_value_in_register |= !is_true_value_constant; |
| 3850 | false_value_in_register |= !is_false_value_constant; |
| 3851 | |
| 3852 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3853 | : Location::ConstantLocation(cst_true_value)); |
| 3854 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3855 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3856 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3857 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3858 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3859 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3860 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3861 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3862 | } |
| 3863 | |
| 3864 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3865 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3866 | Condition csel_cond; |
| 3867 | |
| 3868 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3869 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3870 | // Use the condition flags set by the previous instruction. |
| 3871 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3872 | } else { |
| 3873 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3874 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3875 | } |
| 3876 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3877 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3878 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3879 | } else { |
| 3880 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3881 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3882 | } |
| 3883 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3884 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3885 | __ Fcsel(OutputFPRegister(select), |
| 3886 | InputFPRegisterAt(select, 1), |
| 3887 | InputFPRegisterAt(select, 0), |
| 3888 | csel_cond); |
| 3889 | } else { |
| 3890 | __ Csel(OutputRegister(select), |
| 3891 | InputOperandAt(select, 1), |
| 3892 | InputOperandAt(select, 0), |
| 3893 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3894 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3895 | } |
| 3896 | |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 3897 | void LocationsBuilderARM64::VisitNop(HNop* nop) { |
| 3898 | new (GetGraph()->GetAllocator()) LocationSummary(nop); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3899 | } |
| 3900 | |
Santiago Aboy Solanes | caf9b65 | 2022-06-24 10:03:30 +0100 | [diff] [blame] | 3901 | void InstructionCodeGeneratorARM64::VisitNop(HNop*) { |
| 3902 | // The environment recording already happened in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3903 | } |
| 3904 | |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3905 | void CodeGeneratorARM64::IncreaseFrame(size_t adjustment) { |
| 3906 | __ Claim(adjustment); |
| 3907 | GetAssembler()->cfi().AdjustCFAOffset(adjustment); |
| 3908 | } |
| 3909 | |
| 3910 | void CodeGeneratorARM64::DecreaseFrame(size_t adjustment) { |
| 3911 | __ Drop(adjustment); |
| 3912 | GetAssembler()->cfi().AdjustCFAOffset(-adjustment); |
| 3913 | } |
| 3914 | |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3915 | void CodeGeneratorARM64::GenerateNop() { |
| 3916 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3917 | } |
| 3918 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 3919 | void LocationsBuilderARM64::VisitPredicatedInstanceFieldGet( |
| 3920 | HPredicatedInstanceFieldGet* instruction) { |
| 3921 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3922 | } |
| 3923 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3924 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3925 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3926 | } |
| 3927 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 3928 | void InstructionCodeGeneratorARM64::VisitPredicatedInstanceFieldGet( |
| 3929 | HPredicatedInstanceFieldGet* instruction) { |
| 3930 | vixl::aarch64::Label finish; |
| 3931 | __ Cbz(InputRegisterAt(instruction, 1), &finish); |
| 3932 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3933 | __ Bind(&finish); |
| 3934 | } |
| 3935 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3936 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3937 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3938 | } |
| 3939 | |
| 3940 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3941 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3942 | } |
| 3943 | |
| 3944 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3945 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3946 | } |
| 3947 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3948 | // Temp is used for read barrier. |
| 3949 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 3950 | if (gUseReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3951 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3952 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3953 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3954 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3955 | return 1; |
| 3956 | } |
| 3957 | return 0; |
| 3958 | } |
| 3959 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3960 | // 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] | 3961 | // interface pointer, one for loading the current interface. |
| 3962 | // The other checks have one temp for loading the object's class. |
| 3963 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3964 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3965 | return 3; |
| 3966 | } |
| 3967 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3968 | } |
| 3969 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3970 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3971 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3972 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3973 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3974 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3975 | case TypeCheckKind::kExactCheck: |
| 3976 | case TypeCheckKind::kAbstractClassCheck: |
| 3977 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3978 | case TypeCheckKind::kArrayObjectCheck: { |
| 3979 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 3980 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 3981 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3982 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3983 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3984 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3985 | case TypeCheckKind::kUnresolvedCheck: |
| 3986 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3987 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3988 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3989 | case TypeCheckKind::kBitstringCheck: |
| 3990 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3991 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3992 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3993 | LocationSummary* locations = |
| 3994 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3995 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3996 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3997 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3998 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3999 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 4000 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 4001 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 4002 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 4003 | } else { |
| 4004 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4005 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4006 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 4007 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 4008 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4009 | // Add temps if necessary for read barriers. |
| 4010 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4011 | } |
| 4012 | |
| 4013 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4014 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4015 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4016 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4017 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4018 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 4019 | ? Register() |
| 4020 | : InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4021 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4022 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4023 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 4024 | DCHECK_LE(num_temps, 1u); |
| 4025 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4026 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4027 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4028 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4029 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4030 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4031 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4032 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4033 | |
| 4034 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4035 | // Avoid null check if we know `obj` is not null. |
| 4036 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4037 | __ Cbz(obj, &zero); |
| 4038 | } |
| 4039 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4040 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4041 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4042 | ReadBarrierOption read_barrier_option = |
| 4043 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4044 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4045 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4046 | out_loc, |
| 4047 | obj_loc, |
| 4048 | class_offset, |
| 4049 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4050 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4051 | __ Cmp(out, cls); |
| 4052 | __ Cset(out, eq); |
| 4053 | if (zero.IsLinked()) { |
| 4054 | __ B(&done); |
| 4055 | } |
| 4056 | break; |
| 4057 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4058 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4059 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4060 | ReadBarrierOption read_barrier_option = |
| 4061 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4062 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4063 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4064 | out_loc, |
| 4065 | obj_loc, |
| 4066 | class_offset, |
| 4067 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4068 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4069 | // If the class is abstract, we eagerly fetch the super class of the |
| 4070 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4071 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4072 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4073 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4074 | GenerateReferenceLoadOneRegister(instruction, |
| 4075 | out_loc, |
| 4076 | super_offset, |
| 4077 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4078 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4079 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4080 | __ Cbz(out, &done); |
| 4081 | __ Cmp(out, cls); |
| 4082 | __ B(ne, &loop); |
| 4083 | __ Mov(out, 1); |
| 4084 | if (zero.IsLinked()) { |
| 4085 | __ B(&done); |
| 4086 | } |
| 4087 | break; |
| 4088 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4089 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4090 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4091 | ReadBarrierOption read_barrier_option = |
| 4092 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4093 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4094 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4095 | out_loc, |
| 4096 | obj_loc, |
| 4097 | class_offset, |
| 4098 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4099 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4100 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4101 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4102 | __ Bind(&loop); |
| 4103 | __ Cmp(out, cls); |
| 4104 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4105 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4106 | GenerateReferenceLoadOneRegister(instruction, |
| 4107 | out_loc, |
| 4108 | super_offset, |
| 4109 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4110 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4111 | __ Cbnz(out, &loop); |
| 4112 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4113 | __ B(&done); |
| 4114 | __ Bind(&success); |
| 4115 | __ Mov(out, 1); |
| 4116 | if (zero.IsLinked()) { |
| 4117 | __ B(&done); |
| 4118 | } |
| 4119 | break; |
| 4120 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4121 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4122 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4123 | ReadBarrierOption read_barrier_option = |
| 4124 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4125 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4126 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4127 | out_loc, |
| 4128 | obj_loc, |
| 4129 | class_offset, |
| 4130 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4131 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4132 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4133 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4134 | __ Cmp(out, cls); |
| 4135 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4136 | // 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] | 4137 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4138 | GenerateReferenceLoadOneRegister(instruction, |
| 4139 | out_loc, |
| 4140 | component_offset, |
| 4141 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4142 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4143 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4144 | __ Cbz(out, &done); |
| 4145 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4146 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4147 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4148 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4149 | __ Mov(out, 1); |
| 4150 | __ B(&done); |
| 4151 | break; |
| 4152 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4153 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4154 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4155 | // No read barrier since the slow path will retry upon failure. |
| 4156 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4157 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4158 | out_loc, |
| 4159 | obj_loc, |
| 4160 | class_offset, |
| 4161 | maybe_temp_loc, |
| 4162 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4163 | __ Cmp(out, cls); |
| 4164 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4165 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4166 | instruction, /* is_fatal= */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4167 | codegen_->AddSlowPath(slow_path); |
| 4168 | __ B(ne, slow_path->GetEntryLabel()); |
| 4169 | __ Mov(out, 1); |
| 4170 | if (zero.IsLinked()) { |
| 4171 | __ B(&done); |
| 4172 | } |
| 4173 | break; |
| 4174 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4175 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4176 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4177 | case TypeCheckKind::kInterfaceCheck: { |
| 4178 | // Note that we indeed only call on slow path, but we always go |
| 4179 | // into the slow path for the unresolved and interface check |
| 4180 | // cases. |
| 4181 | // |
| 4182 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4183 | // entry point without resorting to a type checking slow path |
| 4184 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4185 | // require to assign fixed registers for the inputs of this |
| 4186 | // HInstanceOf instruction (following the runtime calling |
| 4187 | // convention), which might be cluttered by the potential first |
| 4188 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4189 | // |
| 4190 | // TODO: Introduce a new runtime entry point taking the object |
| 4191 | // to test (instead of its class) as argument, and let it deal |
| 4192 | // with the read barrier issues. This will let us refactor this |
| 4193 | // case of the `switch` code as it was previously (with a direct |
| 4194 | // call to the runtime not using a type checking slow path). |
| 4195 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4196 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4197 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4198 | instruction, /* is_fatal= */ false); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4199 | codegen_->AddSlowPath(slow_path); |
| 4200 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4201 | if (zero.IsLinked()) { |
| 4202 | __ B(&done); |
| 4203 | } |
| 4204 | break; |
| 4205 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4206 | |
| 4207 | case TypeCheckKind::kBitstringCheck: { |
| 4208 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4209 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4210 | out_loc, |
| 4211 | obj_loc, |
| 4212 | class_offset, |
| 4213 | maybe_temp_loc, |
| 4214 | kWithoutReadBarrier); |
| 4215 | |
| 4216 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 4217 | __ Cset(out, eq); |
| 4218 | if (zero.IsLinked()) { |
| 4219 | __ B(&done); |
| 4220 | } |
| 4221 | break; |
| 4222 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | if (zero.IsLinked()) { |
| 4226 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4227 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4228 | } |
| 4229 | |
| 4230 | if (done.IsLinked()) { |
| 4231 | __ Bind(&done); |
| 4232 | } |
| 4233 | |
| 4234 | if (slow_path != nullptr) { |
| 4235 | __ Bind(slow_path->GetExitLabel()); |
| 4236 | } |
| 4237 | } |
| 4238 | |
| 4239 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4240 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4241 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4242 | LocationSummary* locations = |
| 4243 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4244 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4245 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 4246 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 4247 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 4248 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 4249 | } else { |
| 4250 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4251 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4252 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4253 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4257 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4258 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4259 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4260 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4261 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 4262 | ? Register() |
| 4263 | : InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4264 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4265 | DCHECK_GE(num_temps, 1u); |
| 4266 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4267 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4268 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4269 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4270 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4271 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4272 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4273 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4274 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4275 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4276 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4277 | const uint32_t object_array_data_offset = |
| 4278 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4279 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4280 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4281 | SlowPathCodeARM64* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4282 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4283 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4284 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4285 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4286 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4287 | // Avoid null check if we know obj is not null. |
| 4288 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4289 | __ Cbz(obj, &done); |
| 4290 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4291 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4292 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4293 | case TypeCheckKind::kExactCheck: |
| 4294 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4295 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4296 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4297 | temp_loc, |
| 4298 | obj_loc, |
| 4299 | class_offset, |
| 4300 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4301 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4302 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4303 | __ Cmp(temp, cls); |
| 4304 | // Jump to slow path for throwing the exception or doing a |
| 4305 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4306 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4307 | break; |
| 4308 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4309 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4310 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4311 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4312 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4313 | temp_loc, |
| 4314 | obj_loc, |
| 4315 | class_offset, |
| 4316 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4317 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4318 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4319 | // If the class is abstract, we eagerly fetch the super class of the |
| 4320 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4321 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4322 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4323 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4324 | GenerateReferenceLoadOneRegister(instruction, |
| 4325 | temp_loc, |
| 4326 | super_offset, |
| 4327 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4328 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4329 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4330 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4331 | // exception. |
| 4332 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4333 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4334 | __ Cmp(temp, cls); |
| 4335 | __ B(ne, &loop); |
| 4336 | break; |
| 4337 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4338 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4339 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4340 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4341 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4342 | temp_loc, |
| 4343 | obj_loc, |
| 4344 | class_offset, |
| 4345 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4346 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4347 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4348 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4349 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4350 | __ Bind(&loop); |
| 4351 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4352 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4353 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4354 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4355 | GenerateReferenceLoadOneRegister(instruction, |
| 4356 | temp_loc, |
| 4357 | super_offset, |
| 4358 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4359 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4360 | |
| 4361 | // If the class reference currently in `temp` is not null, jump |
| 4362 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4363 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4364 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4365 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4366 | break; |
| 4367 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4368 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4369 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4370 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4371 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4372 | temp_loc, |
| 4373 | obj_loc, |
| 4374 | class_offset, |
| 4375 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4376 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4377 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4378 | // Do an exact check. |
| 4379 | __ Cmp(temp, cls); |
| 4380 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4381 | |
| 4382 | // 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] | 4383 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4384 | GenerateReferenceLoadOneRegister(instruction, |
| 4385 | temp_loc, |
| 4386 | component_offset, |
| 4387 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4388 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4389 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4390 | // If the component type is null, jump to the slow path to throw the exception. |
| 4391 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4392 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4393 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4394 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4395 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4396 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4397 | break; |
| 4398 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4399 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4400 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4401 | // 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] | 4402 | // |
| 4403 | // We cannot directly call the CheckCast runtime entry point |
| 4404 | // without resorting to a type checking slow path here (i.e. by |
| 4405 | // calling InvokeRuntime directly), as it would require to |
| 4406 | // assign fixed registers for the inputs of this HInstanceOf |
| 4407 | // instruction (following the runtime calling convention), which |
| 4408 | // might be cluttered by the potential first read barrier |
| 4409 | // emission at the beginning of this method. |
| 4410 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4411 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4412 | case TypeCheckKind::kInterfaceCheck: { |
| 4413 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4414 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4415 | temp_loc, |
| 4416 | obj_loc, |
| 4417 | class_offset, |
| 4418 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4419 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4420 | |
| 4421 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4422 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4423 | temp_loc, |
| 4424 | temp_loc, |
| 4425 | iftable_offset, |
| 4426 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4427 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4428 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4429 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4430 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4431 | vixl::aarch64::Label start_loop; |
| 4432 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4433 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4434 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4435 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4436 | // Go to next interface. |
| 4437 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4438 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4439 | // Compare the classes and continue the loop if they do not match. |
| 4440 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4441 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4442 | break; |
| 4443 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4444 | |
| 4445 | case TypeCheckKind::kBitstringCheck: { |
| 4446 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4447 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4448 | temp_loc, |
| 4449 | obj_loc, |
| 4450 | class_offset, |
| 4451 | maybe_temp2_loc, |
| 4452 | kWithoutReadBarrier); |
| 4453 | |
| 4454 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 4455 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 4456 | break; |
| 4457 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4458 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4459 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4460 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4461 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4464 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4465 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4466 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4467 | } |
| 4468 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4469 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4470 | // Will be generated at use site. |
| 4471 | } |
| 4472 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4473 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4474 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4475 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4476 | } |
| 4477 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4478 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4479 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4480 | } |
| 4481 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4482 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4483 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4484 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4485 | // the method_idx. |
| 4486 | HandleInvoke(invoke); |
| 4487 | } |
| 4488 | |
| 4489 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4490 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4491 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4492 | } |
| 4493 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4494 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4495 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4496 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4497 | } |
| 4498 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4499 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4500 | HandleInvoke(invoke); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4501 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 4502 | // We cannot request ip1 as it's blocked by the register allocator. |
| 4503 | invoke->GetLocations()->SetInAt(invoke->GetNumberOfArguments() - 1, Location::Any()); |
| 4504 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4505 | } |
| 4506 | |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4507 | void CodeGeneratorARM64::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 4508 | Register klass) { |
| 4509 | DCHECK_EQ(klass.GetCode(), 0u); |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4510 | // We know the destination of an intrinsic, so no need to record inline |
| 4511 | // caches. |
| 4512 | if (!instruction->GetLocations()->Intrinsified() && |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 4513 | GetGraph()->IsCompilingBaseline() && |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4514 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4515 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
Nicolas Geoffray | 9e59890 | 2021-11-19 14:53:07 +0000 | [diff] [blame] | 4516 | ProfilingInfo* info = GetGraph()->GetProfilingInfo(); |
| 4517 | DCHECK(info != nullptr); |
| 4518 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 4519 | uint64_t address = reinterpret_cast64<uint64_t>(cache); |
| 4520 | vixl::aarch64::Label done; |
| 4521 | __ Mov(x8, address); |
| 4522 | __ Ldr(x9, MemOperand(x8, InlineCache::ClassesOffset().Int32Value())); |
| 4523 | // Fast path for a monomorphic cache. |
| 4524 | __ Cmp(klass, x9); |
| 4525 | __ B(eq, &done); |
| 4526 | InvokeRuntime(kQuickUpdateInlineCache, instruction, instruction->GetDexPc()); |
| 4527 | __ Bind(&done); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4528 | } |
| 4529 | } |
| 4530 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4531 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4532 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4533 | LocationSummary* locations = invoke->GetLocations(); |
| 4534 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4535 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4536 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4537 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4538 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4539 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4540 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4541 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4542 | { |
| 4543 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4544 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4545 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4546 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4547 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4548 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4549 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4550 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4551 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4552 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4553 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4554 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4555 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4556 | // emit a read barrier for the previous class reference load. |
| 4557 | // However this is not required in practice, as this is an |
| 4558 | // intermediate/temporary reference and because the current |
| 4559 | // concurrent copying collector keeps the from-space memory |
| 4560 | // intact/accessible until the end of the marking phase (the |
| 4561 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4562 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4563 | |
| 4564 | // If we're compiling baseline, update the inline cache. |
| 4565 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4566 | |
| 4567 | // The register ip1 is required to be used for the hidden argument in |
| 4568 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
| 4569 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4570 | UseScratchRegisterScope scratch_scope(masm); |
| 4571 | scratch_scope.Exclude(ip1); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4572 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 4573 | Location interface_method = locations->InAt(invoke->GetNumberOfArguments() - 1); |
| 4574 | if (interface_method.IsStackSlot()) { |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 4575 | __ Ldr(ip1, StackOperandFrom(interface_method)); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4576 | } else { |
| 4577 | __ Mov(ip1, XRegisterFrom(interface_method)); |
| 4578 | } |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 4579 | // If the load kind is through a runtime call, we will pass the method we |
| 4580 | // fetch the IMT, which will either be a no-op if we don't hit the conflict |
| 4581 | // stub, or will make us always go through the trampoline when there is a |
| 4582 | // conflict. |
| 4583 | } else if (invoke->GetHiddenArgumentLoadKind() != MethodLoadKind::kRuntimeCall) { |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4584 | codegen_->LoadMethod( |
| 4585 | invoke->GetHiddenArgumentLoadKind(), Location::RegisterLocation(ip1.GetCode()), invoke); |
| 4586 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4587 | |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4588 | __ Ldr(temp, |
| 4589 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4590 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4591 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4592 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4593 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 4594 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRuntimeCall) { |
| 4595 | // We pass the method from the IMT in case of a conflict. This will ensure |
| 4596 | // we go into the runtime to resolve the actual method. |
| 4597 | __ Mov(ip1, temp); |
| 4598 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4599 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4600 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4601 | |
| 4602 | { |
| 4603 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4604 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4605 | |
| 4606 | // lr(); |
| 4607 | __ blr(lr); |
| 4608 | DCHECK(!codegen_->IsLeafMethod()); |
| 4609 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4610 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4611 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4612 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4613 | } |
| 4614 | |
| 4615 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4616 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4617 | if (intrinsic.TryDispatch(invoke)) { |
| 4618 | return; |
| 4619 | } |
| 4620 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4621 | HandleInvoke(invoke); |
| 4622 | } |
| 4623 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4624 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4625 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4626 | // art::PrepareForRegisterAllocation. |
| 4627 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4628 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4629 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4630 | if (intrinsic.TryDispatch(invoke)) { |
| 4631 | return; |
| 4632 | } |
| 4633 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4634 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4635 | CriticalNativeCallingConventionVisitorARM64 calling_convention_visitor( |
| 4636 | /*for_register_allocation=*/ true); |
| 4637 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 4638 | } else { |
| 4639 | HandleInvoke(invoke); |
| 4640 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4641 | } |
| 4642 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4643 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4644 | if (invoke->GetLocations()->Intrinsified()) { |
| 4645 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4646 | intrinsic.Dispatch(invoke); |
| 4647 | return true; |
| 4648 | } |
| 4649 | return false; |
| 4650 | } |
| 4651 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4652 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4653 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4654 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4655 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4656 | return desired_dispatch_info; |
| 4657 | } |
| 4658 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4659 | void CodeGeneratorARM64::LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke) { |
| 4660 | switch (load_kind) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4661 | case MethodLoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4662 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4663 | // Add ADRP with its PC-relative method patch. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4664 | vixl::aarch64::Label* adrp_label = |
| 4665 | NewBootImageMethodPatch(invoke->GetResolvedMethodReference()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4666 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4667 | // Add ADD with its PC-relative method patch. |
| 4668 | vixl::aarch64::Label* add_label = |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4669 | NewBootImageMethodPatch(invoke->GetResolvedMethodReference(), adrp_label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4670 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4671 | break; |
| 4672 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4673 | case MethodLoadKind::kBootImageRelRo: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4674 | // 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] | 4675 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
| 4676 | LoadBootImageRelRoEntry(WRegisterFrom(temp), boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4677 | break; |
| 4678 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4679 | case MethodLoadKind::kBssEntry: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4680 | // Add ADRP with its PC-relative .bss entry patch. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4681 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(invoke->GetMethodReference()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4682 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4683 | // Add LDR with its PC-relative .bss entry patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4684 | vixl::aarch64::Label* ldr_label = |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4685 | NewMethodBssEntryPatch(invoke->GetMethodReference(), adrp_label); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 4686 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4687 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4688 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4689 | } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4690 | case MethodLoadKind::kJitDirectAddress: { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4691 | // Load method address from literal pool. |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4692 | __ Ldr(XRegisterFrom(temp), |
| 4693 | DeduplicateUint64Literal(reinterpret_cast<uint64_t>(invoke->GetResolvedMethod()))); |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4694 | break; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4695 | } |
| 4696 | case MethodLoadKind::kRuntimeCall: { |
| 4697 | // Test situation, don't do anything. |
| 4698 | break; |
| 4699 | } |
| 4700 | default: { |
| 4701 | LOG(FATAL) << "Load kind should have already been handled " << load_kind; |
| 4702 | UNREACHABLE(); |
| 4703 | } |
| 4704 | } |
| 4705 | } |
| 4706 | |
| 4707 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4708 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| 4709 | // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention. |
| 4710 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4711 | switch (invoke->GetMethodLoadKind()) { |
| 4712 | case MethodLoadKind::kStringInit: { |
| 4713 | uint32_t offset = |
| 4714 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4715 | // temp = thread->string_init_entrypoint |
| 4716 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
| 4717 | break; |
| 4718 | } |
| 4719 | case MethodLoadKind::kRecursive: { |
| 4720 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
| 4721 | break; |
| 4722 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4723 | case MethodLoadKind::kRuntimeCall: { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4724 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4725 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4726 | } |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4727 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
| 4728 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| 4729 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
| 4730 | // Do not materialize the method pointer, load directly the entrypoint. |
| 4731 | // Add ADRP with its PC-relative JNI entrypoint patch. |
| 4732 | vixl::aarch64::Label* adrp_label = |
| 4733 | NewBootImageJniEntrypointPatch(invoke->GetResolvedMethodReference()); |
| 4734 | EmitAdrpPlaceholder(adrp_label, lr); |
| 4735 | // Add the LDR with its PC-relative method patch. |
| 4736 | vixl::aarch64::Label* add_label = |
| 4737 | NewBootImageJniEntrypointPatch(invoke->GetResolvedMethodReference(), adrp_label); |
| 4738 | EmitLdrOffsetPlaceholder(add_label, lr, lr); |
| 4739 | break; |
| 4740 | } |
| 4741 | FALLTHROUGH_INTENDED; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4742 | default: { |
| 4743 | LoadMethod(invoke->GetMethodLoadKind(), temp, invoke); |
| 4744 | break; |
| 4745 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4746 | } |
| 4747 | |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4748 | auto call_lr = [&]() { |
| 4749 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4750 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4751 | kInstructionSize, |
| 4752 | CodeBufferCheckScope::kExactSize); |
| 4753 | // lr() |
| 4754 | __ blr(lr); |
| 4755 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4756 | }; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4757 | switch (invoke->GetCodePtrLocation()) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4758 | case CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4759 | { |
Nicolas Geoffray | 282795c | 2021-09-24 18:16:41 +0100 | [diff] [blame] | 4760 | DCHECK(!GetGraph()->HasShouldDeoptimizeFlag()); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4761 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4762 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4763 | kInstructionSize, |
| 4764 | CodeBufferCheckScope::kExactSize); |
| 4765 | __ bl(&frame_entry_label_); |
| 4766 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4767 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4768 | break; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4769 | case CodePtrLocation::kCallCriticalNative: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4770 | size_t out_frame_size = |
| 4771 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorARM64, |
| 4772 | kAapcs64StackAlignment, |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 4773 | GetCriticalNativeDirectCallFrameSize>(invoke); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4774 | if (invoke->GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative) { |
| 4775 | call_lr(); |
| 4776 | } else { |
| 4777 | // LR = callee_method->ptr_sized_fields_.data_; // EntryPointFromJni |
| 4778 | MemberOffset offset = ArtMethod::EntryPointFromJniOffset(kArm64PointerSize); |
| 4779 | __ Ldr(lr, MemOperand(XRegisterFrom(callee_method), offset.Int32Value())); |
| 4780 | // lr() |
| 4781 | call_lr(); |
| 4782 | } |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4783 | // Zero-/sign-extend the result when needed due to native and managed ABI mismatch. |
| 4784 | switch (invoke->GetType()) { |
| 4785 | case DataType::Type::kBool: |
| 4786 | __ Ubfx(w0, w0, 0, 8); |
| 4787 | break; |
| 4788 | case DataType::Type::kInt8: |
| 4789 | __ Sbfx(w0, w0, 0, 8); |
| 4790 | break; |
| 4791 | case DataType::Type::kUint16: |
| 4792 | __ Ubfx(w0, w0, 0, 16); |
| 4793 | break; |
| 4794 | case DataType::Type::kInt16: |
| 4795 | __ Sbfx(w0, w0, 0, 16); |
| 4796 | break; |
| 4797 | case DataType::Type::kInt32: |
| 4798 | case DataType::Type::kInt64: |
| 4799 | case DataType::Type::kFloat32: |
| 4800 | case DataType::Type::kFloat64: |
| 4801 | case DataType::Type::kVoid: |
| 4802 | break; |
| 4803 | default: |
| 4804 | DCHECK(false) << invoke->GetType(); |
| 4805 | break; |
| 4806 | } |
| 4807 | if (out_frame_size != 0u) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 4808 | DecreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4809 | } |
| 4810 | break; |
| 4811 | } |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4812 | case CodePtrLocation::kCallArtMethod: { |
| 4813 | // LR = callee_method->ptr_sized_fields_.entry_point_from_quick_compiled_code_; |
| 4814 | MemberOffset offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
| 4815 | __ Ldr(lr, MemOperand(XRegisterFrom(callee_method), offset.Int32Value())); |
| 4816 | // lr() |
| 4817 | call_lr(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4818 | break; |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4819 | } |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4820 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4821 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4822 | DCHECK(!IsLeafMethod()); |
| 4823 | } |
| 4824 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4825 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4826 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4827 | // Use the calling convention instead of the location of the receiver, as |
| 4828 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4829 | // slow path, the arguments have been moved to the right place, so here we are |
| 4830 | // guaranteed that the receiver is the first register of the calling convention. |
| 4831 | InvokeDexCallingConvention calling_convention; |
| 4832 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4833 | Register temp = XRegisterFrom(temp_in); |
| 4834 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4835 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4836 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4837 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4838 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4839 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4840 | |
| 4841 | { |
| 4842 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4843 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4844 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4845 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4846 | MaybeRecordImplicitNullCheck(invoke); |
| 4847 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4848 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4849 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4850 | // intermediate/temporary reference and because the current |
| 4851 | // concurrent copying collector keeps the from-space memory |
| 4852 | // intact/accessible until the end of the marking phase (the |
| 4853 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4854 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4855 | |
| 4856 | // If we're compiling baseline, update the inline cache. |
| 4857 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4858 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4859 | // temp = temp->GetMethodAt(method_offset); |
| 4860 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4861 | // lr = temp->GetEntryPoint(); |
| 4862 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4863 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4864 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4865 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4866 | // lr(); |
| 4867 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4868 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4869 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4870 | } |
| 4871 | |
Vladimir Marko | 9922f00 | 2020-06-08 15:05:15 +0100 | [diff] [blame] | 4872 | void CodeGeneratorARM64::MoveFromReturnRegister(Location trg, DataType::Type type) { |
| 4873 | if (!trg.IsValid()) { |
| 4874 | DCHECK(type == DataType::Type::kVoid); |
| 4875 | return; |
| 4876 | } |
| 4877 | |
| 4878 | DCHECK_NE(type, DataType::Type::kVoid); |
| 4879 | |
| 4880 | if (DataType::IsIntegralType(type) || type == DataType::Type::kReference) { |
| 4881 | Register trg_reg = RegisterFrom(trg, type); |
| 4882 | Register res_reg = RegisterFrom(ARM64ReturnLocation(type), type); |
| 4883 | __ Mov(trg_reg, res_reg, kDiscardForSameWReg); |
| 4884 | } else { |
| 4885 | VRegister trg_reg = FPRegisterFrom(trg, type); |
| 4886 | VRegister res_reg = FPRegisterFrom(ARM64ReturnLocation(type), type); |
| 4887 | __ Fmov(trg_reg, res_reg); |
| 4888 | } |
| 4889 | } |
| 4890 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4891 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 4892 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
| 4893 | if (intrinsic.TryDispatch(invoke)) { |
| 4894 | return; |
| 4895 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4896 | HandleInvoke(invoke); |
| 4897 | } |
| 4898 | |
| 4899 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 4900 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4901 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| 4902 | return; |
| 4903 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4904 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4905 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4906 | } |
| 4907 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4908 | void LocationsBuilderARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4909 | HandleInvoke(invoke); |
| 4910 | } |
| 4911 | |
| 4912 | void InstructionCodeGeneratorARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4913 | codegen_->GenerateInvokeCustomCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4914 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4915 | } |
| 4916 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4917 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageIntrinsicPatch( |
| 4918 | uint32_t intrinsic_data, |
| 4919 | vixl::aarch64::Label* adrp_label) { |
| 4920 | return NewPcRelativePatch( |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4921 | /* dex_file= */ nullptr, intrinsic_data, adrp_label, &boot_image_other_patches_); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4922 | } |
| 4923 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4924 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageRelRoPatch( |
| 4925 | uint32_t boot_image_offset, |
| 4926 | vixl::aarch64::Label* adrp_label) { |
| 4927 | return NewPcRelativePatch( |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4928 | /* dex_file= */ nullptr, boot_image_offset, adrp_label, &boot_image_other_patches_); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4929 | } |
| 4930 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4931 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageMethodPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4932 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4933 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4934 | return NewPcRelativePatch( |
| 4935 | 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] | 4936 | } |
| 4937 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4938 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4939 | MethodReference target_method, |
| 4940 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4941 | return NewPcRelativePatch( |
| 4942 | 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] | 4943 | } |
| 4944 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4945 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageTypePatch( |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4946 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4947 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4948 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4949 | 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] | 4950 | } |
| 4951 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4952 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 4953 | HLoadClass* load_class, |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4954 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 4955 | const DexFile& dex_file = load_class->GetDexFile(); |
| 4956 | dex::TypeIndex type_index = load_class->GetTypeIndex(); |
| 4957 | ArenaDeque<PcRelativePatchInfo>* patches = nullptr; |
| 4958 | switch (load_class->GetLoadKind()) { |
| 4959 | case HLoadClass::LoadKind::kBssEntry: |
| 4960 | patches = &type_bss_entry_patches_; |
| 4961 | break; |
| 4962 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 4963 | patches = &public_type_bss_entry_patches_; |
| 4964 | break; |
| 4965 | case HLoadClass::LoadKind::kBssEntryPackage: |
| 4966 | patches = &package_type_bss_entry_patches_; |
| 4967 | break; |
| 4968 | default: |
| 4969 | LOG(FATAL) << "Unexpected load kind: " << load_class->GetLoadKind(); |
| 4970 | UNREACHABLE(); |
| 4971 | } |
| 4972 | return NewPcRelativePatch(&dex_file, type_index.index_, adrp_label, patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4973 | } |
| 4974 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4975 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageStringPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4976 | const DexFile& dex_file, |
| 4977 | dex::StringIndex string_index, |
| 4978 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4979 | return NewPcRelativePatch( |
| 4980 | &dex_file, string_index.index_, adrp_label, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4981 | } |
| 4982 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4983 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4984 | const DexFile& dex_file, |
| 4985 | dex::StringIndex string_index, |
| 4986 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4987 | 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] | 4988 | } |
| 4989 | |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4990 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageJniEntrypointPatch( |
| 4991 | MethodReference target_method, |
| 4992 | vixl::aarch64::Label* adrp_label) { |
| 4993 | return NewPcRelativePatch( |
| 4994 | target_method.dex_file, target_method.index, adrp_label, &boot_image_jni_entrypoint_patches_); |
| 4995 | } |
| 4996 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4997 | void CodeGeneratorARM64::EmitEntrypointThunkCall(ThreadOffset64 entrypoint_offset) { |
| 4998 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 4999 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5000 | call_entrypoint_patches_.emplace_back(/*dex_file*/ nullptr, entrypoint_offset.Uint32Value()); |
| 5001 | vixl::aarch64::Label* bl_label = &call_entrypoint_patches_.back().label; |
| 5002 | __ bind(bl_label); |
| 5003 | __ bl(static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 5004 | } |
| 5005 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 5006 | void CodeGeneratorARM64::EmitBakerReadBarrierCbnz(uint32_t custom_data) { |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 5007 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5008 | if (GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 5009 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 5010 | vixl::aarch64::Label* slow_path_entry = &it->second.label; |
| 5011 | __ cbnz(mr, slow_path_entry); |
| 5012 | } else { |
| 5013 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 5014 | vixl::aarch64::Label* cbnz_label = &baker_read_barrier_patches_.back().label; |
| 5015 | __ bind(cbnz_label); |
| 5016 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 5017 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5018 | } |
| 5019 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5020 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5021 | const DexFile* dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5022 | uint32_t offset_or_index, |
| 5023 | vixl::aarch64::Label* adrp_label, |
| 5024 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5025 | // Add a patch entry and return the label. |
| 5026 | patches->emplace_back(dex_file, offset_or_index); |
| 5027 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5028 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5029 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 5030 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 5031 | return label; |
| 5032 | } |
| 5033 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5034 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 5035 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5036 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5039 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5040 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5041 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5042 | return jit_string_patches_.GetOrCreate( |
| 5043 | StringReference(&dex_file, string_index), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5044 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5045 | } |
| 5046 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5047 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5048 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5049 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5050 | return jit_class_patches_.GetOrCreate( |
| 5051 | TypeReference(&dex_file, type_index), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5052 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5053 | } |
| 5054 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5055 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 5056 | vixl::aarch64::Register reg) { |
| 5057 | DCHECK(reg.IsX()); |
| 5058 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 5059 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5060 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5061 | } |
| 5062 | |
| 5063 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 5064 | vixl::aarch64::Register out, |
| 5065 | vixl::aarch64::Register base) { |
| 5066 | DCHECK(out.IsX()); |
| 5067 | DCHECK(base.IsX()); |
| 5068 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 5069 | __ Bind(fixup_label); |
| 5070 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 5071 | } |
| 5072 | |
| 5073 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 5074 | vixl::aarch64::Register out, |
| 5075 | vixl::aarch64::Register base) { |
| 5076 | DCHECK(base.IsX()); |
| 5077 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 5078 | __ Bind(fixup_label); |
| 5079 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 5080 | } |
| 5081 | |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5082 | void CodeGeneratorARM64::LoadBootImageRelRoEntry(vixl::aarch64::Register reg, |
| 5083 | uint32_t boot_image_offset) { |
| 5084 | DCHECK(reg.IsW()); |
| 5085 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5086 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_offset); |
| 5087 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 5088 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| 5089 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| 5090 | EmitLdrOffsetPlaceholder(ldr_label, reg.W(), reg.X()); |
| 5091 | } |
| 5092 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5093 | void CodeGeneratorARM64::LoadBootImageAddress(vixl::aarch64::Register reg, |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5094 | uint32_t boot_image_reference) { |
| 5095 | if (GetCompilerOptions().IsBootImage()) { |
| 5096 | // Add ADRP with its PC-relative type patch. |
| 5097 | vixl::aarch64::Label* adrp_label = NewBootImageIntrinsicPatch(boot_image_reference); |
| 5098 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 5099 | // Add ADD with its PC-relative type patch. |
| 5100 | vixl::aarch64::Label* add_label = NewBootImageIntrinsicPatch(boot_image_reference, adrp_label); |
| 5101 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 5102 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5103 | LoadBootImageRelRoEntry(reg, boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5104 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5105 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5106 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 5107 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5108 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5109 | __ Ldr(reg.W(), DeduplicateBootImageAddressLiteral(reinterpret_cast<uintptr_t>(address))); |
| 5110 | } |
| 5111 | } |
| 5112 | |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 5113 | void CodeGeneratorARM64::LoadTypeForBootImageIntrinsic(vixl::aarch64::Register reg, |
| 5114 | TypeReference target_type) { |
| 5115 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5116 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 5117 | // Add ADRP with its PC-relative type patch. |
| 5118 | vixl::aarch64::Label* adrp_label = |
| 5119 | NewBootImageTypePatch(*target_type.dex_file, target_type.TypeIndex()); |
| 5120 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 5121 | // Add ADD with its PC-relative type patch. |
| 5122 | vixl::aarch64::Label* add_label = |
| 5123 | NewBootImageTypePatch(*target_type.dex_file, target_type.TypeIndex(), adrp_label); |
| 5124 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
| 5125 | } |
| 5126 | |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5127 | void CodeGeneratorARM64::LoadIntrinsicDeclaringClass(vixl::aarch64::Register reg, HInvoke* invoke) { |
| 5128 | DCHECK_NE(invoke->GetIntrinsic(), Intrinsics::kNone); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5129 | if (GetCompilerOptions().IsBootImage()) { |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 5130 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5131 | 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] | 5132 | LoadTypeForBootImageIntrinsic(reg, TypeReference(target_method.dex_file, type_idx)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5133 | } else { |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5134 | uint32_t boot_image_offset = GetBootImageOffsetOfIntrinsicDeclaringClass(invoke); |
| 5135 | LoadBootImageAddress(reg, boot_image_offset); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5136 | } |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5137 | } |
| 5138 | |
Vladimir Marko | 98873af | 2020-12-16 12:10:03 +0000 | [diff] [blame] | 5139 | void CodeGeneratorARM64::LoadClassRootForIntrinsic(vixl::aarch64::Register reg, |
| 5140 | ClassRoot class_root) { |
| 5141 | if (GetCompilerOptions().IsBootImage()) { |
| 5142 | ScopedObjectAccess soa(Thread::Current()); |
| 5143 | ObjPtr<mirror::Class> klass = GetClassRoot(class_root); |
| 5144 | TypeReference target_type(&klass->GetDexFile(), klass->GetDexTypeIndex()); |
| 5145 | LoadTypeForBootImageIntrinsic(reg, target_type); |
| 5146 | } else { |
| 5147 | uint32_t boot_image_offset = GetBootImageOffset(class_root); |
| 5148 | LoadBootImageAddress(reg, boot_image_offset); |
| 5149 | } |
| 5150 | } |
| 5151 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5152 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5153 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 5154 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5155 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5156 | for (const PcRelativePatchInfo& info : infos) { |
| 5157 | linker_patches->push_back(Factory(info.label.GetLocation(), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5158 | info.target_dex_file, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5159 | info.pc_insn_label->GetLocation(), |
| 5160 | info.offset_or_index)); |
| 5161 | } |
| 5162 | } |
| 5163 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5164 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 5165 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 5166 | const DexFile* target_dex_file, |
| 5167 | uint32_t pc_insn_offset, |
| 5168 | uint32_t boot_image_offset) { |
| 5169 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 5170 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5171 | } |
| 5172 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5173 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5174 | DCHECK(linker_patches->empty()); |
| 5175 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5176 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5177 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5178 | boot_image_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5179 | type_bss_entry_patches_.size() + |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5180 | public_type_bss_entry_patches_.size() + |
| 5181 | package_type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5182 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5183 | string_bss_entry_patches_.size() + |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5184 | boot_image_jni_entrypoint_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5185 | boot_image_other_patches_.size() + |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5186 | call_entrypoint_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5187 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5188 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5189 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5190 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5191 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5192 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5193 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5194 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5195 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5196 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5197 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5198 | DCHECK(boot_image_type_patches_.empty()); |
| 5199 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5200 | } |
| 5201 | if (GetCompilerOptions().IsBootImage()) { |
| 5202 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 5203 | boot_image_other_patches_, linker_patches); |
| 5204 | } else { |
| 5205 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 5206 | boot_image_other_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5207 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5208 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5209 | method_bss_entry_patches_, linker_patches); |
| 5210 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5211 | type_bss_entry_patches_, linker_patches); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5212 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PublicTypeBssEntryPatch>( |
| 5213 | public_type_bss_entry_patches_, linker_patches); |
| 5214 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PackageTypeBssEntryPatch>( |
| 5215 | package_type_bss_entry_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5216 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5217 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5218 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeJniEntrypointPatch>( |
| 5219 | boot_image_jni_entrypoint_patches_, linker_patches); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5220 | for (const PatchInfo<vixl::aarch64::Label>& info : call_entrypoint_patches_) { |
| 5221 | DCHECK(info.target_dex_file == nullptr); |
| 5222 | linker_patches->push_back(linker::LinkerPatch::CallEntrypointPatch( |
| 5223 | info.label.GetLocation(), info.offset_or_index)); |
| 5224 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5225 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5226 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 5227 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5228 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5229 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5230 | } |
| 5231 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5232 | bool CodeGeneratorARM64::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5233 | return patch.GetType() == linker::LinkerPatch::Type::kCallEntrypoint || |
| 5234 | patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5235 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 5236 | } |
| 5237 | |
| 5238 | void CodeGeneratorARM64::EmitThunkCode(const linker::LinkerPatch& patch, |
| 5239 | /*out*/ ArenaVector<uint8_t>* code, |
| 5240 | /*out*/ std::string* debug_name) { |
| 5241 | Arm64Assembler assembler(GetGraph()->GetAllocator()); |
| 5242 | switch (patch.GetType()) { |
| 5243 | case linker::LinkerPatch::Type::kCallRelative: { |
| 5244 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 5245 | // to the generic JNI and interpreter trampolines. |
| 5246 | Offset offset(ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 5247 | kArm64PointerSize).Int32Value()); |
| 5248 | assembler.JumpTo(ManagedRegister(arm64::X0), offset, ManagedRegister(arm64::IP0)); |
David Srbecky | 889da94 | 2021-04-30 13:03:14 +0100 | [diff] [blame] | 5249 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5250 | *debug_name = "MethodCallThunk"; |
| 5251 | } |
| 5252 | break; |
| 5253 | } |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5254 | case linker::LinkerPatch::Type::kCallEntrypoint: { |
| 5255 | Offset offset(patch.EntrypointOffset()); |
| 5256 | assembler.JumpTo(ManagedRegister(arm64::TR), offset, ManagedRegister(arm64::IP0)); |
David Srbecky | 889da94 | 2021-04-30 13:03:14 +0100 | [diff] [blame] | 5257 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5258 | *debug_name = "EntrypointCallThunk_" + std::to_string(offset.Uint32Value()); |
| 5259 | } |
| 5260 | break; |
| 5261 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5262 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| 5263 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 5264 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 5265 | break; |
| 5266 | } |
| 5267 | default: |
| 5268 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 5269 | UNREACHABLE(); |
| 5270 | } |
| 5271 | |
| 5272 | // Ensure we emit the literal pool if any. |
| 5273 | assembler.FinalizeCode(); |
| 5274 | code->resize(assembler.CodeSize()); |
| 5275 | MemoryRegion code_region(code->data(), code->size()); |
| 5276 | assembler.FinalizeInstructions(code_region); |
| 5277 | } |
| 5278 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5279 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 5280 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5281 | value, |
| 5282 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 5283 | } |
| 5284 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5285 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5286 | return uint64_literals_.GetOrCreate( |
| 5287 | value, |
| 5288 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5289 | } |
| 5290 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5291 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5292 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5293 | // art::PrepareForRegisterAllocation. |
| 5294 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5295 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5296 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5297 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5298 | return; |
| 5299 | } |
| 5300 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5301 | LocationSummary* locations = invoke->GetLocations(); |
| 5302 | codegen_->GenerateStaticOrDirectCall( |
| 5303 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5304 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5305 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5306 | } |
| 5307 | |
| 5308 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5309 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5310 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5311 | return; |
| 5312 | } |
| 5313 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5314 | { |
| 5315 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 5316 | // are no pools emitted. |
| 5317 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 5318 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 5319 | DCHECK(!codegen_->IsLeafMethod()); |
| 5320 | } |
| 5321 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5322 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5323 | } |
| 5324 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5325 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 5326 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5327 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5328 | case HLoadClass::LoadKind::kInvalid: |
| 5329 | LOG(FATAL) << "UNREACHABLE"; |
| 5330 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5331 | case HLoadClass::LoadKind::kReferrersClass: |
| 5332 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5333 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5334 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5335 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5336 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 5337 | case HLoadClass::LoadKind::kBssEntryPackage: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5338 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5339 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5340 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5341 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5342 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5343 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5344 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5345 | break; |
| 5346 | } |
| 5347 | return desired_class_load_kind; |
| 5348 | } |
| 5349 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5350 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5351 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5352 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5353 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5354 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5355 | cls, |
| 5356 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5357 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5358 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5359 | return; |
| 5360 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5361 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 5362 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 5363 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5364 | |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5365 | const bool requires_read_barrier = gUseReadBarrier && !cls->IsInBootImage(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5366 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5367 | ? LocationSummary::kCallOnSlowPath |
| 5368 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5369 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5370 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5371 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5372 | } |
| 5373 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5374 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5375 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5376 | } |
| 5377 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5378 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5379 | if (!gUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5380 | // 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] | 5381 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5382 | } else { |
| 5383 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5384 | } |
| 5385 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5386 | } |
| 5387 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5388 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5389 | // move. |
| 5390 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5391 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5392 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5393 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5394 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5395 | return; |
| 5396 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5397 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 5398 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 5399 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5400 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5401 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5402 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5403 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5404 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5405 | ? kWithoutReadBarrier |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5406 | : gCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5407 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5408 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5409 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5410 | DCHECK(!cls->CanCallRuntime()); |
| 5411 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5412 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5413 | Register current_method = InputRegisterAt(cls, 0); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5414 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5415 | out_loc, |
| 5416 | current_method, |
| 5417 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5418 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5419 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5420 | break; |
| 5421 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5422 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5423 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 5424 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5425 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5426 | // Add ADRP with its PC-relative type patch. |
| 5427 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5428 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5429 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5430 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5431 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5432 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5433 | codegen_->NewBootImageTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5434 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5435 | break; |
| 5436 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5437 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5438 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5439 | uint32_t boot_image_offset = CodeGenerator::GetBootImageOffset(cls); |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5440 | codegen_->LoadBootImageRelRoEntry(out.W(), boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5441 | break; |
| 5442 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5443 | case HLoadClass::LoadKind::kBssEntry: |
| 5444 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 5445 | case HLoadClass::LoadKind::kBssEntryPackage: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5446 | // Add ADRP with its PC-relative Class .bss entry patch. |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5447 | vixl::aarch64::Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5448 | vixl::aarch64::Label* adrp_label = codegen_->NewBssEntryTypePatch(cls); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5449 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5450 | // Add LDR with its PC-relative Class .bss entry patch. |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5451 | vixl::aarch64::Label* ldr_label = codegen_->NewBssEntryTypePatch(cls, adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5452 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5453 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5454 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5455 | out_loc, |
| 5456 | temp, |
| 5457 | /* offset placeholder */ 0u, |
| 5458 | ldr_label, |
| 5459 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5460 | generate_null_check = true; |
| 5461 | break; |
| 5462 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5463 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 5464 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 5465 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 5466 | DCHECK_NE(address, 0u); |
| 5467 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5468 | break; |
| 5469 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5470 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5471 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5472 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5473 | cls->GetClass())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5474 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5475 | out_loc, |
| 5476 | out.X(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5477 | /* offset= */ 0, |
| 5478 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5479 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5480 | break; |
| 5481 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5482 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5483 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5484 | LOG(FATAL) << "UNREACHABLE"; |
| 5485 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5486 | } |
| 5487 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5488 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5489 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5490 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 5491 | SlowPathCodeARM64* slow_path = |
| 5492 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5493 | codegen_->AddSlowPath(slow_path); |
| 5494 | if (generate_null_check) { |
| 5495 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5496 | } |
| 5497 | if (cls->MustGenerateClinitCheck()) { |
| 5498 | GenerateClassInitializationCheck(slow_path, out); |
| 5499 | } else { |
| 5500 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5501 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5502 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5503 | } |
| 5504 | } |
| 5505 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 5506 | void LocationsBuilderARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5507 | InvokeRuntimeCallingConvention calling_convention; |
| 5508 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5509 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 5510 | } |
| 5511 | |
| 5512 | void InstructionCodeGeneratorARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5513 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 5514 | } |
| 5515 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 5516 | void LocationsBuilderARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5517 | InvokeRuntimeCallingConvention calling_convention; |
| 5518 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5519 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 5520 | } |
| 5521 | |
| 5522 | void InstructionCodeGeneratorARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5523 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 5524 | } |
| 5525 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5526 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5527 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5528 | } |
| 5529 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5530 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5531 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5532 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5533 | locations->SetOut(Location::RequiresRegister()); |
| 5534 | } |
| 5535 | |
| 5536 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5537 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5538 | } |
| 5539 | |
| 5540 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5541 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5545 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5546 | } |
| 5547 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5548 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5549 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5550 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5551 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5552 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5553 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5554 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5555 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5556 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5557 | case HLoadString::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5558 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5559 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5560 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5561 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5562 | } |
| 5563 | return desired_string_load_kind; |
| 5564 | } |
| 5565 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5566 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5567 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5568 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5569 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5570 | InvokeRuntimeCallingConvention calling_convention; |
| 5571 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5572 | } else { |
| 5573 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5574 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5575 | if (!gUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5576 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 5577 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5578 | } else { |
| 5579 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5580 | } |
| 5581 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5582 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5583 | } |
| 5584 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5585 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5586 | // move. |
| 5587 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5588 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5589 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5590 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5591 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5592 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5593 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 5594 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5595 | // Add ADRP with its PC-relative String patch. |
| 5596 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5597 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5598 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5599 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5600 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5601 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5602 | codegen_->NewBootImageStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5603 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5604 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5605 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5606 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5607 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5608 | uint32_t boot_image_offset = CodeGenerator::GetBootImageOffset(load); |
Vladimir Marko | 9d31daa | 2022-04-14 10:48:44 +0100 | [diff] [blame] | 5609 | codegen_->LoadBootImageRelRoEntry(out.W(), boot_image_offset); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5610 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5611 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5612 | case HLoadString::LoadKind::kBssEntry: { |
| 5613 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5614 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5615 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5616 | Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5617 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5618 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5619 | // Add LDR with its PC-relative String .bss entry patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5620 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5621 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5622 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5623 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5624 | codegen_->GenerateGcRootFieldLoad(load, |
| 5625 | out_loc, |
| 5626 | temp, |
| 5627 | /* offset placeholder */ 0u, |
| 5628 | ldr_label, |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5629 | gCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5630 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5631 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5632 | codegen_->AddSlowPath(slow_path); |
| 5633 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5634 | __ Bind(slow_path->GetExitLabel()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5635 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5636 | return; |
| 5637 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5638 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 5639 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 5640 | DCHECK_NE(address, 0u); |
| 5641 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5642 | return; |
| 5643 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5644 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5645 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5646 | load->GetStringIndex(), |
| 5647 | load->GetString())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5648 | codegen_->GenerateGcRootFieldLoad(load, |
| 5649 | out_loc, |
| 5650 | out.X(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5651 | /* offset= */ 0, |
| 5652 | /* fixup_label= */ nullptr, |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 5653 | gCompilerReadBarrierOption); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5654 | return; |
| 5655 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5656 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5657 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5658 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5659 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5660 | // 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] | 5661 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5662 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5663 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5664 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5665 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5666 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5667 | } |
| 5668 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5669 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5670 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5671 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5672 | } |
| 5673 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5674 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5675 | // Will be generated at use site. |
| 5676 | } |
| 5677 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5678 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5679 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5680 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5681 | InvokeRuntimeCallingConvention calling_convention; |
| 5682 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5683 | } |
| 5684 | |
| 5685 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5686 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5687 | instruction, |
| 5688 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5689 | if (instruction->IsEnter()) { |
| 5690 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5691 | } else { |
| 5692 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5693 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5694 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5695 | } |
| 5696 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5697 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5698 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5699 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5700 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5701 | case DataType::Type::kInt32: |
| 5702 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5703 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5704 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5705 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5706 | break; |
| 5707 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5708 | case DataType::Type::kFloat32: |
| 5709 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5710 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5711 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5712 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5713 | break; |
| 5714 | |
| 5715 | default: |
| 5716 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5717 | } |
| 5718 | } |
| 5719 | |
| 5720 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5721 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5722 | case DataType::Type::kInt32: |
| 5723 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5724 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5725 | break; |
| 5726 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5727 | case DataType::Type::kFloat32: |
| 5728 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5729 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5730 | break; |
| 5731 | |
| 5732 | default: |
| 5733 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5734 | } |
| 5735 | } |
| 5736 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5737 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5738 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5739 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5740 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5741 | case DataType::Type::kInt32: |
| 5742 | case DataType::Type::kInt64: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5743 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5744 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5745 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5746 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5747 | case DataType::Type::kFloat32: |
| 5748 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5749 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5750 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5751 | break; |
| 5752 | |
| 5753 | default: |
| 5754 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5755 | } |
| 5756 | } |
| 5757 | |
| 5758 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5759 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5760 | case DataType::Type::kInt32: |
| 5761 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5762 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5763 | break; |
| 5764 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5765 | case DataType::Type::kFloat32: |
| 5766 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5767 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5768 | break; |
| 5769 | |
| 5770 | default: |
| 5771 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5772 | } |
| 5773 | } |
| 5774 | |
| 5775 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5776 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5777 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5778 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5779 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5780 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5781 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5785 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5786 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5787 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5788 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5789 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5790 | } |
| 5791 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5792 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5793 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5794 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5795 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5796 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5797 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5801 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5802 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5803 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5804 | } |
| 5805 | |
| 5806 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5807 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5808 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5809 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5810 | } |
| 5811 | |
| 5812 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5813 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5814 | case DataType::Type::kInt32: |
| 5815 | case DataType::Type::kInt64: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5816 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5817 | break; |
| 5818 | |
| 5819 | default: |
| 5820 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5821 | } |
| 5822 | } |
| 5823 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5824 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5825 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5826 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5827 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5828 | } |
| 5829 | |
| 5830 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5831 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5832 | } |
| 5833 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5834 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5835 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5836 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5837 | } |
| 5838 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5839 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5840 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5841 | return; |
| 5842 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5843 | { |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 5844 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5845 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5846 | Location obj = instruction->GetLocations()->InAt(0); |
| 5847 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5848 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5849 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5850 | } |
| 5851 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5852 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5853 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5854 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5855 | |
| 5856 | LocationSummary* locations = instruction->GetLocations(); |
| 5857 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5858 | |
| 5859 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5860 | } |
| 5861 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5862 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5863 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5866 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5867 | HandleBinaryOp(instruction); |
| 5868 | } |
| 5869 | |
| 5870 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5871 | HandleBinaryOp(instruction); |
| 5872 | } |
| 5873 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5874 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5875 | LOG(FATAL) << "Unreachable"; |
| 5876 | } |
| 5877 | |
| 5878 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5879 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5880 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5881 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5882 | // The back edge will generate the suspend check. |
| 5883 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5884 | } |
| 5885 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5886 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5887 | } |
| 5888 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5889 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5890 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5891 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5892 | if (location.IsStackSlot()) { |
| 5893 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5894 | } else if (location.IsDoubleStackSlot()) { |
| 5895 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5896 | } |
| 5897 | locations->SetOut(location); |
| 5898 | } |
| 5899 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5900 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5901 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5902 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5906 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5907 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5908 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5909 | } |
| 5910 | |
| 5911 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5912 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5913 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5914 | } |
| 5915 | |
| 5916 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5917 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5918 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5919 | locations->SetInAt(i, Location::Any()); |
| 5920 | } |
| 5921 | locations->SetOut(Location::Any()); |
| 5922 | } |
| 5923 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5924 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5925 | LOG(FATAL) << "Unreachable"; |
| 5926 | } |
| 5927 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5928 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5929 | DataType::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5930 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5931 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5932 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5933 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5934 | |
| 5935 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5936 | case DataType::Type::kInt32: |
| 5937 | case DataType::Type::kInt64: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5938 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5939 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5940 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5941 | break; |
| 5942 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5943 | case DataType::Type::kFloat32: |
| 5944 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5945 | InvokeRuntimeCallingConvention calling_convention; |
| 5946 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5947 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5948 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5949 | |
| 5950 | break; |
| 5951 | } |
| 5952 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5953 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5954 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5955 | } |
| 5956 | } |
| 5957 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5958 | void InstructionCodeGeneratorARM64::GenerateIntRemForPower2Denom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5959 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5960 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 5961 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 5962 | |
| 5963 | Register out = OutputRegister(instruction); |
| 5964 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5965 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 5966 | if (HasNonNegativeOrMinIntInputAt(instruction, 0)) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 5967 | // No need to adjust the result for non-negative dividends or the INT32_MIN/INT64_MIN dividends. |
| 5968 | // NOTE: The generated code for HRem correctly works for the INT32_MIN/INT64_MIN dividends. |
| 5969 | // INT*_MIN % imm must be 0 for any imm of power 2. 'and' works only with bits |
| 5970 | // 0..30 (Int32 case)/0..62 (Int64 case) of a dividend. For INT32_MIN/INT64_MIN they are zeros. |
| 5971 | // So 'and' always produces zero. |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5972 | __ And(out, dividend, abs_imm - 1); |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 5973 | } else { |
| 5974 | if (abs_imm == 2) { |
| 5975 | __ Cmp(dividend, 0); |
| 5976 | __ And(out, dividend, 1); |
| 5977 | __ Csneg(out, out, out, ge); |
| 5978 | } else { |
| 5979 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5980 | Register temp = temps.AcquireSameSizeAs(out); |
| 5981 | |
| 5982 | __ Negs(temp, dividend); |
| 5983 | __ And(out, dividend, abs_imm - 1); |
| 5984 | __ And(temp, temp, abs_imm - 1); |
| 5985 | __ Csneg(out, out, temp, mi); |
| 5986 | } |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5987 | } |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5988 | } |
| 5989 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5990 | void InstructionCodeGeneratorARM64::GenerateIntRemForConstDenom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5991 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5992 | |
| 5993 | if (imm == 0) { |
| 5994 | // Do not generate anything. |
| 5995 | // DivZeroCheck would prevent any code to be executed. |
| 5996 | return; |
| 5997 | } |
| 5998 | |
Evgeny Astigeevich | f58dc65 | 2018-06-25 17:54:07 +0100 | [diff] [blame] | 5999 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 6000 | // Cases imm == -1 or imm == 1 are handled in constant folding by |
| 6001 | // InstructionWithAbsorbingInputSimplifier. |
| 6002 | // If the cases have survided till code generation they are handled in |
| 6003 | // GenerateIntRemForPower2Denom becauses -1 and 1 are the power of 2 (2^0). |
| 6004 | // The correct code is generated for them, just more instructions. |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 6005 | GenerateIntRemForPower2Denom(instruction); |
| 6006 | } else { |
| 6007 | DCHECK(imm < -2 || imm > 2) << imm; |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 6008 | GenerateDivRemWithAnyConstant(instruction, imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 6009 | } |
| 6010 | } |
| 6011 | |
| 6012 | void InstructionCodeGeneratorARM64::GenerateIntRem(HRem* instruction) { |
| 6013 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 6014 | << instruction->GetResultType(); |
| 6015 | |
| 6016 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 6017 | GenerateIntRemForConstDenom(instruction); |
| 6018 | } else { |
| 6019 | Register out = OutputRegister(instruction); |
| 6020 | Register dividend = InputRegisterAt(instruction, 0); |
| 6021 | Register divisor = InputRegisterAt(instruction, 1); |
| 6022 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6023 | Register temp = temps.AcquireSameSizeAs(out); |
| 6024 | __ Sdiv(temp, dividend, divisor); |
| 6025 | __ Msub(out, temp, divisor, dividend); |
| 6026 | } |
| 6027 | } |
| 6028 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6029 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6030 | DataType::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 6031 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6032 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6033 | case DataType::Type::kInt32: |
| 6034 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 6035 | GenerateIntRem(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6036 | break; |
| 6037 | } |
| 6038 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6039 | case DataType::Type::kFloat32: |
| 6040 | case DataType::Type::kFloat64: { |
| 6041 | QuickEntrypointEnum entrypoint = |
| 6042 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 6043 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6044 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6045 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 6046 | } else { |
| 6047 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 6048 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 6049 | break; |
| 6050 | } |
| 6051 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6052 | default: |
| 6053 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 6054 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6055 | } |
| 6056 | } |
| 6057 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6058 | void LocationsBuilderARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 6059 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6060 | } |
| 6061 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6062 | void InstructionCodeGeneratorARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 6063 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6064 | } |
| 6065 | |
| 6066 | void LocationsBuilderARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 6067 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6068 | } |
| 6069 | |
| 6070 | void InstructionCodeGeneratorARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 6071 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 6072 | } |
| 6073 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 6074 | void LocationsBuilderARM64::VisitAbs(HAbs* abs) { |
| 6075 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 6076 | switch (abs->GetResultType()) { |
| 6077 | case DataType::Type::kInt32: |
| 6078 | case DataType::Type::kInt64: |
| 6079 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6080 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6081 | break; |
| 6082 | case DataType::Type::kFloat32: |
| 6083 | case DataType::Type::kFloat64: |
| 6084 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6085 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6086 | break; |
| 6087 | default: |
| 6088 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 6089 | } |
| 6090 | } |
| 6091 | |
| 6092 | void InstructionCodeGeneratorARM64::VisitAbs(HAbs* abs) { |
| 6093 | switch (abs->GetResultType()) { |
| 6094 | case DataType::Type::kInt32: |
| 6095 | case DataType::Type::kInt64: { |
| 6096 | Register in_reg = InputRegisterAt(abs, 0); |
| 6097 | Register out_reg = OutputRegister(abs); |
| 6098 | __ Cmp(in_reg, Operand(0)); |
| 6099 | __ Cneg(out_reg, in_reg, lt); |
| 6100 | break; |
| 6101 | } |
| 6102 | case DataType::Type::kFloat32: |
| 6103 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 6104 | VRegister in_reg = InputFPRegisterAt(abs, 0); |
| 6105 | VRegister out_reg = OutputFPRegister(abs); |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 6106 | __ Fabs(out_reg, in_reg); |
| 6107 | break; |
| 6108 | } |
| 6109 | default: |
| 6110 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 6111 | } |
| 6112 | } |
| 6113 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 6114 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 6115 | constructor_fence->SetLocations(nullptr); |
| 6116 | } |
| 6117 | |
| 6118 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 6119 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 6120 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 6121 | } |
| 6122 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6123 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 6124 | memory_barrier->SetLocations(nullptr); |
| 6125 | } |
| 6126 | |
| 6127 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6128 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6129 | } |
| 6130 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6131 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6132 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6133 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 6134 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6135 | } |
| 6136 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 6137 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* ret) { |
| 6138 | if (GetGraph()->IsCompilingOsr()) { |
| 6139 | // To simplify callers of an OSR method, we put the return value in both |
| 6140 | // floating point and core register. |
| 6141 | switch (ret->InputAt(0)->GetType()) { |
| 6142 | case DataType::Type::kFloat32: |
| 6143 | __ Fmov(w0, s0); |
| 6144 | break; |
| 6145 | case DataType::Type::kFloat64: |
| 6146 | __ Fmov(x0, d0); |
| 6147 | break; |
| 6148 | default: |
| 6149 | break; |
| 6150 | } |
| 6151 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6152 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6153 | } |
| 6154 | |
| 6155 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 6156 | instruction->SetLocations(nullptr); |
| 6157 | } |
| 6158 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6159 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6160 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6161 | } |
| 6162 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6163 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 6164 | HandleBinaryOp(ror); |
| 6165 | } |
| 6166 | |
| 6167 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 6168 | HandleBinaryOp(ror); |
| 6169 | } |
| 6170 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6171 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 6172 | HandleShift(shl); |
| 6173 | } |
| 6174 | |
| 6175 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 6176 | HandleShift(shl); |
| 6177 | } |
| 6178 | |
| 6179 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 6180 | HandleShift(shr); |
| 6181 | } |
| 6182 | |
| 6183 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 6184 | HandleShift(shr); |
| 6185 | } |
| 6186 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6187 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6188 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6189 | } |
| 6190 | |
| 6191 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6192 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6193 | } |
| 6194 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6195 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6196 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 6200 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 6204 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6205 | } |
| 6206 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6207 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6208 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6209 | } |
| 6210 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 6211 | void LocationsBuilderARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6212 | codegen_->CreateStringBuilderAppendLocations(instruction, LocationFrom(x0)); |
| 6213 | } |
| 6214 | |
| 6215 | void InstructionCodeGeneratorARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6216 | __ Mov(w0, instruction->GetFormat()->GetValue()); |
| 6217 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 6218 | } |
| 6219 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6220 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 6221 | HUnresolvedInstanceFieldGet* instruction) { |
| 6222 | FieldAccessCallingConventionARM64 calling_convention; |
| 6223 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6224 | instruction, instruction->GetFieldType(), calling_convention); |
| 6225 | } |
| 6226 | |
| 6227 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 6228 | HUnresolvedInstanceFieldGet* instruction) { |
| 6229 | FieldAccessCallingConventionARM64 calling_convention; |
| 6230 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6231 | instruction->GetFieldType(), |
| 6232 | instruction->GetFieldIndex(), |
| 6233 | instruction->GetDexPc(), |
| 6234 | calling_convention); |
| 6235 | } |
| 6236 | |
| 6237 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 6238 | HUnresolvedInstanceFieldSet* instruction) { |
| 6239 | FieldAccessCallingConventionARM64 calling_convention; |
| 6240 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6241 | instruction, instruction->GetFieldType(), calling_convention); |
| 6242 | } |
| 6243 | |
| 6244 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 6245 | HUnresolvedInstanceFieldSet* instruction) { |
| 6246 | FieldAccessCallingConventionARM64 calling_convention; |
| 6247 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6248 | instruction->GetFieldType(), |
| 6249 | instruction->GetFieldIndex(), |
| 6250 | instruction->GetDexPc(), |
| 6251 | calling_convention); |
| 6252 | } |
| 6253 | |
| 6254 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 6255 | HUnresolvedStaticFieldGet* instruction) { |
| 6256 | FieldAccessCallingConventionARM64 calling_convention; |
| 6257 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6258 | instruction, instruction->GetFieldType(), calling_convention); |
| 6259 | } |
| 6260 | |
| 6261 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 6262 | HUnresolvedStaticFieldGet* instruction) { |
| 6263 | FieldAccessCallingConventionARM64 calling_convention; |
| 6264 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6265 | instruction->GetFieldType(), |
| 6266 | instruction->GetFieldIndex(), |
| 6267 | instruction->GetDexPc(), |
| 6268 | calling_convention); |
| 6269 | } |
| 6270 | |
| 6271 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 6272 | HUnresolvedStaticFieldSet* instruction) { |
| 6273 | FieldAccessCallingConventionARM64 calling_convention; |
| 6274 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6275 | instruction, instruction->GetFieldType(), calling_convention); |
| 6276 | } |
| 6277 | |
| 6278 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 6279 | HUnresolvedStaticFieldSet* instruction) { |
| 6280 | FieldAccessCallingConventionARM64 calling_convention; |
| 6281 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6282 | instruction->GetFieldType(), |
| 6283 | instruction->GetFieldIndex(), |
| 6284 | instruction->GetDexPc(), |
| 6285 | calling_convention); |
| 6286 | } |
| 6287 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6288 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6289 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6290 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 6291 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6292 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6293 | // registers in full width (since the runtime only saves/restores lower part). |
| 6294 | locations->SetCustomSlowPathCallerSaves( |
| 6295 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6296 | } |
| 6297 | |
| 6298 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6299 | HBasicBlock* block = instruction->GetBlock(); |
| 6300 | if (block->GetLoopInformation() != nullptr) { |
| 6301 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6302 | // The back edge will generate the suspend check. |
| 6303 | return; |
| 6304 | } |
| 6305 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6306 | // The goto will generate the suspend check. |
| 6307 | return; |
| 6308 | } |
| 6309 | GenerateSuspendCheck(instruction, nullptr); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6310 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6311 | } |
| 6312 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6313 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6314 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6315 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6316 | InvokeRuntimeCallingConvention calling_convention; |
| 6317 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6318 | } |
| 6319 | |
| 6320 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 6321 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 6322 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6323 | } |
| 6324 | |
| 6325 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 6326 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6327 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6328 | DataType::Type input_type = conversion->GetInputType(); |
| 6329 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6330 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6331 | << input_type << " -> " << result_type; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6332 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 6333 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6334 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6335 | } |
| 6336 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6337 | if (DataType::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6338 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6339 | } else { |
| 6340 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6341 | } |
| 6342 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6343 | if (DataType::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6344 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6345 | } else { |
| 6346 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6347 | } |
| 6348 | } |
| 6349 | |
| 6350 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6351 | DataType::Type result_type = conversion->GetResultType(); |
| 6352 | DataType::Type input_type = conversion->GetInputType(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6353 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6354 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6355 | << input_type << " -> " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6356 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6357 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 6358 | int result_size = DataType::Size(result_type); |
| 6359 | int input_size = DataType::Size(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6360 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6361 | Register output = OutputRegister(conversion); |
| 6362 | Register source = InputRegisterAt(conversion, 0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6363 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 6364 | // 'int' values are used directly as W registers, discarding the top |
| 6365 | // bits, so we don't need to sign-extend and can just perform a move. |
| 6366 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 6367 | // top 32 bits of the target register. We theoretically could leave those |
| 6368 | // bits unchanged, but we would have to make sure that no code uses a |
| 6369 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 6370 | // zero. |
| 6371 | __ Mov(output.W(), source.W()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6372 | } else if (DataType::IsUnsignedType(result_type) || |
| 6373 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 6374 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6375 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6376 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6377 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6378 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6379 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6380 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 6381 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6382 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6383 | } else if (DataType::IsFloatingPointType(result_type) && |
| 6384 | DataType::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6385 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 6386 | } else { |
| 6387 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6388 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6389 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6390 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6391 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6392 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 6393 | HandleShift(ushr); |
| 6394 | } |
| 6395 | |
| 6396 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 6397 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6398 | } |
| 6399 | |
| 6400 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 6401 | HandleBinaryOp(instruction); |
| 6402 | } |
| 6403 | |
| 6404 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 6405 | HandleBinaryOp(instruction); |
| 6406 | } |
| 6407 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6408 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6409 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6410 | LOG(FATAL) << "Unreachable"; |
| 6411 | } |
| 6412 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6413 | void InstructionCodeGeneratorARM64::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 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6418 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6419 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6420 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6421 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6422 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6423 | } |
| 6424 | |
| 6425 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6426 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6427 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6428 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 6429 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6430 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6431 | // 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] | 6432 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6433 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 6434 | // make sure we don't emit it if the target may run out of range. |
| 6435 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 6436 | // ranges and emit the tables only as required. |
| 6437 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6438 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6439 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6440 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 6441 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 6442 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6443 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6444 | Register temp = temps.AcquireW(); |
| 6445 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 6446 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6447 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6448 | // Jump to successors[0] if value == lower_bound. |
| 6449 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 6450 | int32_t last_index = 0; |
| 6451 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6452 | __ Subs(temp, temp, Operand(2)); |
| 6453 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6454 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6455 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6456 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6457 | } |
| 6458 | if (num_entries - last_index == 2) { |
| 6459 | // The last missing case_value. |
| 6460 | __ Cmp(temp, Operand(1)); |
| 6461 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6462 | } |
| 6463 | |
| 6464 | // And the default for any other value. |
| 6465 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6466 | __ B(codegen_->GetLabelOf(default_block)); |
| 6467 | } |
| 6468 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 6469 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6470 | |
| 6471 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6472 | |
| 6473 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 6474 | // registers, we are free to block one. |
| 6475 | Register temp_w = temps.AcquireW(); |
| 6476 | Register index; |
| 6477 | // Remove the bias. |
| 6478 | if (lower_bound != 0) { |
| 6479 | index = temp_w; |
| 6480 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 6481 | } else { |
| 6482 | index = value_reg; |
| 6483 | } |
| 6484 | |
| 6485 | // Jump to default block if index is out of the range. |
| 6486 | __ Cmp(index, Operand(num_entries)); |
| 6487 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 6488 | |
| 6489 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 6490 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 6491 | // register pressure. |
| 6492 | Register table_base = temps.AcquireX(); |
| 6493 | // Load jump offset from the table. |
| 6494 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 6495 | Register jump_offset = temp_w; |
| 6496 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 6497 | |
| 6498 | // Jump to target block by branching to table_base(pc related) + offset. |
| 6499 | Register target_address = table_base; |
| 6500 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 6501 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6502 | } |
| 6503 | } |
| 6504 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6505 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 6506 | HInstruction* instruction, |
| 6507 | Location out, |
| 6508 | uint32_t offset, |
| 6509 | Location maybe_temp, |
| 6510 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6511 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6512 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6513 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6514 | CHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6515 | if (kUseBakerReadBarrier) { |
| 6516 | // Load with fast path based Baker's read barrier. |
| 6517 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6518 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6519 | out, |
| 6520 | out_reg, |
| 6521 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6522 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6523 | /* needs_null_check= */ false, |
| 6524 | /* use_load_acquire= */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6525 | } else { |
| 6526 | // Load with slow path based read barrier. |
| 6527 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6528 | // in the following move operation, as we will need it for the |
| 6529 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6530 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6531 | __ Mov(temp_reg, out_reg); |
| 6532 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6533 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6534 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6535 | } |
| 6536 | } else { |
| 6537 | // Plain load with no read barrier. |
| 6538 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6539 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6540 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6541 | } |
| 6542 | } |
| 6543 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6544 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 6545 | HInstruction* instruction, |
| 6546 | Location out, |
| 6547 | Location obj, |
| 6548 | uint32_t offset, |
| 6549 | Location maybe_temp, |
| 6550 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6551 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6552 | Register out_reg = RegisterFrom(out, type); |
| 6553 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6554 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6555 | CHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6556 | if (kUseBakerReadBarrier) { |
| 6557 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6558 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6559 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6560 | out, |
| 6561 | obj_reg, |
| 6562 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6563 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6564 | /* needs_null_check= */ false, |
| 6565 | /* use_load_acquire= */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6566 | } else { |
| 6567 | // Load with slow path based read barrier. |
| 6568 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6569 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6570 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6571 | } |
| 6572 | } else { |
| 6573 | // Plain load with no read barrier. |
| 6574 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6575 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6576 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6577 | } |
| 6578 | } |
| 6579 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6580 | void CodeGeneratorARM64::GenerateGcRootFieldLoad( |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6581 | HInstruction* instruction, |
| 6582 | Location root, |
| 6583 | Register obj, |
| 6584 | uint32_t offset, |
| 6585 | vixl::aarch64::Label* fixup_label, |
| 6586 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6587 | DCHECK(fixup_label == nullptr || offset == 0u); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6588 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6589 | if (read_barrier_option == kWithReadBarrier) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6590 | DCHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6591 | if (kUseBakerReadBarrier) { |
| 6592 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6593 | // Baker's read barrier are used. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6594 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6595 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6596 | // the Marking Register) to decide whether we need to enter |
| 6597 | // the slow path to mark the GC root. |
| 6598 | // |
| 6599 | // We use shared thunks for the slow path; shared within the method |
| 6600 | // for JIT, across methods for AOT. That thunk checks the reference |
| 6601 | // and jumps to the entrypoint if needed. |
| 6602 | // |
| 6603 | // lr = &return_address; |
| 6604 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6605 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6606 | // goto gc_root_thunk<root_reg>(lr) |
| 6607 | // } |
| 6608 | // return_address: |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6609 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6610 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6611 | DCHECK(temps.IsAvailable(ip0)); |
| 6612 | DCHECK(temps.IsAvailable(ip1)); |
| 6613 | temps.Exclude(ip0, ip1); |
| 6614 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6615 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6616 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6617 | vixl::aarch64::Label return_address; |
| 6618 | __ adr(lr, &return_address); |
| 6619 | if (fixup_label != nullptr) { |
| 6620 | __ bind(fixup_label); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6621 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6622 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6623 | "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] | 6624 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6625 | EmitBakerReadBarrierCbnz(custom_data); |
| 6626 | __ bind(&return_address); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6627 | } else { |
| 6628 | // GC root loaded through a slow path for read barriers other |
| 6629 | // than Baker's. |
| 6630 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6631 | if (fixup_label == nullptr) { |
| 6632 | __ Add(root_reg.X(), obj.X(), offset); |
| 6633 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6634 | EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6635 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6636 | // /* mirror::Object* */ root = root->Read() |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6637 | GenerateReadBarrierForRootSlow(instruction, root, root); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6638 | } |
| 6639 | } else { |
| 6640 | // Plain GC root load with no read barrier. |
| 6641 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6642 | if (fixup_label == nullptr) { |
| 6643 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6644 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6645 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6646 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6647 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6648 | // do not have to unpoison `root_reg` here. |
| 6649 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6650 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6651 | } |
| 6652 | |
Vladimir Marko | c8178f5 | 2020-11-24 10:38:16 +0000 | [diff] [blame] | 6653 | void CodeGeneratorARM64::GenerateIntrinsicCasMoveWithBakerReadBarrier( |
| 6654 | vixl::aarch64::Register marked_old_value, |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6655 | vixl::aarch64::Register old_value) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6656 | DCHECK(gUseReadBarrier); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6657 | DCHECK(kUseBakerReadBarrier); |
| 6658 | |
| 6659 | // 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] | 6660 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(marked_old_value.GetCode()); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6661 | |
| 6662 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6663 | vixl::aarch64::Label return_address; |
| 6664 | __ adr(lr, &return_address); |
| 6665 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6666 | "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] | 6667 | __ mov(marked_old_value, old_value); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6668 | EmitBakerReadBarrierCbnz(custom_data); |
| 6669 | __ bind(&return_address); |
| 6670 | } |
| 6671 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6672 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6673 | Location ref, |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6674 | vixl::aarch64::Register obj, |
| 6675 | const vixl::aarch64::MemOperand& src, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6676 | bool needs_null_check, |
| 6677 | bool use_load_acquire) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6678 | DCHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6679 | DCHECK(kUseBakerReadBarrier); |
| 6680 | |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6681 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6682 | // Marking Register) to decide whether we need to enter the slow |
| 6683 | // path to mark the reference. Then, in the slow path, check the |
| 6684 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6685 | // decide whether to mark `ref` or not. |
| 6686 | // |
| 6687 | // We use shared thunks for the slow path; shared within the method |
| 6688 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6689 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6690 | // it creates a fake dependency and returns to the LDR instruction. |
| 6691 | // |
| 6692 | // lr = &gray_return_address; |
| 6693 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6694 | // goto field_thunk<holder_reg, base_reg, use_load_acquire>(lr) |
| 6695 | // } |
| 6696 | // not_gray_return_address: |
| 6697 | // // Original reference load. If the offset is too large to fit |
| 6698 | // // into LDR, we use an adjusted base register here. |
| 6699 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 6700 | // gray_return_address: |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6701 | |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6702 | DCHECK(src.GetAddrMode() == vixl::aarch64::Offset); |
| 6703 | DCHECK_ALIGNED(src.GetOffset(), sizeof(mirror::HeapReference<mirror::Object>)); |
| 6704 | |
| 6705 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6706 | DCHECK(temps.IsAvailable(ip0)); |
| 6707 | DCHECK(temps.IsAvailable(ip1)); |
| 6708 | temps.Exclude(ip0, ip1); |
| 6709 | uint32_t custom_data = use_load_acquire |
| 6710 | ? EncodeBakerReadBarrierAcquireData(src.GetBaseRegister().GetCode(), obj.GetCode()) |
| 6711 | : EncodeBakerReadBarrierFieldData(src.GetBaseRegister().GetCode(), obj.GetCode()); |
| 6712 | |
| 6713 | { |
| 6714 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6715 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6716 | vixl::aarch64::Label return_address; |
| 6717 | __ adr(lr, &return_address); |
| 6718 | EmitBakerReadBarrierCbnz(custom_data); |
| 6719 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6720 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6721 | " 2 instructions (8B) for heap poisoning."); |
| 6722 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 6723 | if (use_load_acquire) { |
| 6724 | DCHECK_EQ(src.GetOffset(), 0); |
| 6725 | __ ldar(ref_reg, src); |
| 6726 | } else { |
| 6727 | __ ldr(ref_reg, src); |
| 6728 | } |
| 6729 | if (needs_null_check) { |
| 6730 | MaybeRecordImplicitNullCheck(instruction); |
| 6731 | } |
| 6732 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6733 | // macro instructions disallowed in ExactAssemblyScope. |
| 6734 | if (kPoisonHeapReferences) { |
| 6735 | __ neg(ref_reg, Operand(ref_reg)); |
| 6736 | } |
| 6737 | __ bind(&return_address); |
| 6738 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6739 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6740 | } |
| 6741 | |
| 6742 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6743 | Location ref, |
| 6744 | Register obj, |
| 6745 | uint32_t offset, |
| 6746 | Location maybe_temp, |
| 6747 | bool needs_null_check, |
| 6748 | bool use_load_acquire) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6749 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6750 | Register base = obj; |
| 6751 | if (use_load_acquire) { |
| 6752 | DCHECK(maybe_temp.IsRegister()); |
| 6753 | base = WRegisterFrom(maybe_temp); |
| 6754 | __ Add(base, obj, offset); |
| 6755 | offset = 0u; |
| 6756 | } else if (offset >= kReferenceLoadMinFarOffset) { |
| 6757 | DCHECK(maybe_temp.IsRegister()); |
| 6758 | base = WRegisterFrom(maybe_temp); |
| 6759 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6760 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6761 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6762 | } |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6763 | MemOperand src(base.X(), offset); |
| 6764 | GenerateFieldLoadWithBakerReadBarrier( |
| 6765 | instruction, ref, obj, src, needs_null_check, use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6766 | } |
| 6767 | |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6768 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HArrayGet* instruction, |
| 6769 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6770 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6771 | uint32_t data_offset, |
| 6772 | Location index, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6773 | bool needs_null_check) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6774 | DCHECK(gUseReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6775 | DCHECK(kUseBakerReadBarrier); |
| 6776 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6777 | static_assert( |
| 6778 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6779 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6780 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6781 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6782 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6783 | // Marking Register) to decide whether we need to enter the slow |
| 6784 | // path to mark the reference. Then, in the slow path, check the |
| 6785 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6786 | // decide whether to mark `ref` or not. |
| 6787 | // |
| 6788 | // We use shared thunks for the slow path; shared within the method |
| 6789 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6790 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6791 | // it creates a fake dependency and returns to the LDR instruction. |
| 6792 | // |
| 6793 | // lr = &gray_return_address; |
| 6794 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6795 | // goto array_thunk<base_reg>(lr) |
| 6796 | // } |
| 6797 | // not_gray_return_address: |
| 6798 | // // Original reference load. If the offset is too large to fit |
| 6799 | // // into LDR, we use an adjusted base register here. |
| 6800 | // HeapReference<mirror::Object> reference = data[index]; |
| 6801 | // gray_return_address: |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6802 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6803 | DCHECK(index.IsValid()); |
| 6804 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 6805 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6806 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6807 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6808 | DCHECK(temps.IsAvailable(ip0)); |
| 6809 | DCHECK(temps.IsAvailable(ip1)); |
| 6810 | temps.Exclude(ip0, ip1); |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6811 | |
| 6812 | Register temp; |
| 6813 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 6814 | // We do not need to compute the intermediate address from the array: the |
| 6815 | // input instruction has done it already. See the comment in |
| 6816 | // `TryExtractArrayAccessAddress()`. |
| 6817 | if (kIsDebugBuild) { |
| 6818 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 6819 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 6820 | } |
| 6821 | temp = obj; |
| 6822 | } else { |
| 6823 | temp = WRegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 6824 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
| 6825 | } |
| 6826 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6827 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(temp.GetCode()); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6828 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6829 | { |
| 6830 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6831 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6832 | vixl::aarch64::Label return_address; |
| 6833 | __ adr(lr, &return_address); |
| 6834 | EmitBakerReadBarrierCbnz(custom_data); |
| 6835 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6836 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6837 | " 2 instructions (8B) for heap poisoning."); |
| 6838 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6839 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6840 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6841 | // macro instructions disallowed in ExactAssemblyScope. |
| 6842 | if (kPoisonHeapReferences) { |
| 6843 | __ neg(ref_reg, Operand(ref_reg)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6844 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6845 | __ bind(&return_address); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6846 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6847 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6848 | } |
| 6849 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6850 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6851 | // 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] | 6852 | if (kIsDebugBuild && gUseReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6853 | // The following condition is a run-time one; it is executed after the |
| 6854 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6855 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6856 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6857 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6858 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6859 | } |
| 6860 | } |
| 6861 | } |
| 6862 | |
Vladimir Marko | 1bff99f | 2020-11-02 15:07:33 +0000 | [diff] [blame] | 6863 | SlowPathCodeARM64* CodeGeneratorARM64::AddReadBarrierSlowPath(HInstruction* instruction, |
| 6864 | Location out, |
| 6865 | Location ref, |
| 6866 | Location obj, |
| 6867 | uint32_t offset, |
| 6868 | Location index) { |
| 6869 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
| 6870 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6871 | AddSlowPath(slow_path); |
| 6872 | return slow_path; |
| 6873 | } |
| 6874 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6875 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6876 | Location out, |
| 6877 | Location ref, |
| 6878 | Location obj, |
| 6879 | uint32_t offset, |
| 6880 | Location index) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6881 | DCHECK(gUseReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6882 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6883 | // Insert a slow path based read barrier *after* the reference load. |
| 6884 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6885 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6886 | // reference will be carried out by the runtime within the slow |
| 6887 | // path. |
| 6888 | // |
| 6889 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6890 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6891 | // not used by the artReadBarrierSlow entry point. |
| 6892 | // |
| 6893 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 1bff99f | 2020-11-02 15:07:33 +0000 | [diff] [blame] | 6894 | SlowPathCodeARM64* slow_path = AddReadBarrierSlowPath(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6895 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6896 | __ B(slow_path->GetEntryLabel()); |
| 6897 | __ Bind(slow_path->GetExitLabel()); |
| 6898 | } |
| 6899 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6900 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6901 | Location out, |
| 6902 | Location ref, |
| 6903 | Location obj, |
| 6904 | uint32_t offset, |
| 6905 | Location index) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6906 | if (gUseReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6907 | // Baker's read barriers shall be handled by the fast path |
| 6908 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6909 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6910 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6911 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6912 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6913 | } else if (kPoisonHeapReferences) { |
| 6914 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6915 | } |
| 6916 | } |
| 6917 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6918 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6919 | Location out, |
| 6920 | Location root) { |
Lokesh Gidra | ca5ed9f | 2022-04-20 01:39:28 +0000 | [diff] [blame] | 6921 | DCHECK(gUseReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6922 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6923 | // Insert a slow path based read barrier *after* the GC root load. |
| 6924 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6925 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6926 | // not need to do anything special for this here. |
| 6927 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6928 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6929 | AddSlowPath(slow_path); |
| 6930 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6931 | __ B(slow_path->GetEntryLabel()); |
| 6932 | __ Bind(slow_path->GetExitLabel()); |
| 6933 | } |
| 6934 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6935 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6936 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6937 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6938 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6939 | locations->SetOut(Location::RequiresRegister()); |
| 6940 | } |
| 6941 | |
| 6942 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6943 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6944 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6945 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6946 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6947 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6948 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6949 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6950 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6951 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6952 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6953 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6954 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6955 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6956 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6957 | } |
| 6958 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6959 | static void PatchJitRootUse(uint8_t* code, |
| 6960 | const uint8_t* roots_data, |
| 6961 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6962 | uint64_t index_in_table) { |
| 6963 | uint32_t literal_offset = literal->GetOffset(); |
| 6964 | uintptr_t address = |
| 6965 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6966 | uint8_t* data = code + literal_offset; |
| 6967 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6968 | } |
| 6969 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6970 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6971 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6972 | const StringReference& string_reference = entry.first; |
| 6973 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6974 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6975 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6976 | } |
| 6977 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6978 | const TypeReference& type_reference = entry.first; |
| 6979 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6980 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6981 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6982 | } |
| 6983 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6984 | |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 6985 | MemOperand InstructionCodeGeneratorARM64::VecNEONAddress( |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 6986 | HVecMemoryOperation* instruction, |
| 6987 | UseScratchRegisterScope* temps_scope, |
| 6988 | size_t size, |
| 6989 | bool is_string_char_at, |
| 6990 | /*out*/ Register* scratch) { |
| 6991 | LocationSummary* locations = instruction->GetLocations(); |
| 6992 | Register base = InputRegisterAt(instruction, 0); |
| 6993 | |
| 6994 | if (instruction->InputAt(1)->IsIntermediateAddressIndex()) { |
| 6995 | DCHECK(!is_string_char_at); |
| 6996 | return MemOperand(base.X(), InputRegisterAt(instruction, 1).X()); |
| 6997 | } |
| 6998 | |
| 6999 | Location index = locations->InAt(1); |
| 7000 | uint32_t offset = is_string_char_at |
| 7001 | ? mirror::String::ValueOffset().Uint32Value() |
| 7002 | : mirror::Array::DataOffset(size).Uint32Value(); |
| 7003 | size_t shift = ComponentSizeShiftWidth(size); |
| 7004 | |
| 7005 | // HIntermediateAddress optimization is only applied for scalar ArrayGet and ArraySet. |
| 7006 | DCHECK(!instruction->InputAt(0)->IsIntermediateAddress()); |
| 7007 | |
| 7008 | if (index.IsConstant()) { |
| 7009 | offset += Int64FromLocation(index) << shift; |
| 7010 | return HeapOperand(base, offset); |
| 7011 | } else { |
| 7012 | *scratch = temps_scope->AcquireSameSizeAs(base); |
| 7013 | __ Add(*scratch, base, Operand(WRegisterFrom(index), LSL, shift)); |
| 7014 | return HeapOperand(*scratch, offset); |
| 7015 | } |
| 7016 | } |
| 7017 | |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 7018 | SVEMemOperand InstructionCodeGeneratorARM64::VecSVEAddress( |
| 7019 | HVecMemoryOperation* instruction, |
| 7020 | UseScratchRegisterScope* temps_scope, |
| 7021 | size_t size, |
| 7022 | bool is_string_char_at, |
| 7023 | /*out*/ Register* scratch) { |
| 7024 | LocationSummary* locations = instruction->GetLocations(); |
| 7025 | Register base = InputRegisterAt(instruction, 0); |
| 7026 | Location index = locations->InAt(1); |
| 7027 | |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 7028 | DCHECK(!instruction->InputAt(1)->IsIntermediateAddressIndex()); |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 7029 | DCHECK(!index.IsConstant()); |
| 7030 | |
| 7031 | uint32_t offset = is_string_char_at |
| 7032 | ? mirror::String::ValueOffset().Uint32Value() |
| 7033 | : mirror::Array::DataOffset(size).Uint32Value(); |
| 7034 | size_t shift = ComponentSizeShiftWidth(size); |
| 7035 | |
Raphael Gault | 0700b69 | 2020-09-30 08:33:10 +0000 | [diff] [blame] | 7036 | if (instruction->InputAt(0)->IsIntermediateAddress()) { |
| 7037 | return SVEMemOperand(base.X(), XRegisterFrom(index), LSL, shift); |
| 7038 | } |
| 7039 | |
Artem Serov | 8ba4de1 | 2019-12-04 21:10:23 +0000 | [diff] [blame] | 7040 | *scratch = temps_scope->AcquireSameSizeAs(base); |
| 7041 | __ Add(*scratch, base, offset); |
| 7042 | return SVEMemOperand(scratch->X(), XRegisterFrom(index), LSL, shift); |
| 7043 | } |
| 7044 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 7045 | #undef __ |
| 7046 | #undef QUICK_ENTRY_POINT |
| 7047 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7048 | #define __ assembler.GetVIXLAssembler()-> |
| 7049 | |
| 7050 | static void EmitGrayCheckAndFastPath(arm64::Arm64Assembler& assembler, |
| 7051 | vixl::aarch64::Register base_reg, |
| 7052 | vixl::aarch64::MemOperand& lock_word, |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7053 | vixl::aarch64::Label* slow_path, |
| 7054 | vixl::aarch64::Label* throw_npe = nullptr) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7055 | // Load the lock word containing the rb_state. |
| 7056 | __ Ldr(ip0.W(), lock_word); |
| 7057 | // 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] | 7058 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7059 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 7060 | __ Tbnz(ip0.W(), LockWord::kReadBarrierStateShift, slow_path); |
| 7061 | static_assert( |
| 7062 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET, |
| 7063 | "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] | 7064 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 7065 | if (throw_npe != nullptr) { |
| 7066 | __ Bind(throw_npe); |
| 7067 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7068 | // Adjust the return address back to the LDR (1 instruction; 2 for heap poisoning). |
| 7069 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 7070 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 7071 | " 2 instructions (8B) for heap poisoning."); |
| 7072 | __ Add(lr, lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 7073 | // Introduce a dependency on the lock_word including rb_state, |
| 7074 | // to prevent load-load reordering, and without using |
| 7075 | // a memory barrier (which would be more expensive). |
| 7076 | __ Add(base_reg, base_reg, Operand(ip0, LSR, 32)); |
| 7077 | __ Br(lr); // And return back to the function. |
| 7078 | // Note: The fake dependency is unnecessary for the slow path. |
| 7079 | } |
| 7080 | |
| 7081 | // Load the read barrier introspection entrypoint in register `entrypoint`. |
| 7082 | static void LoadReadBarrierMarkIntrospectionEntrypoint(arm64::Arm64Assembler& assembler, |
| 7083 | vixl::aarch64::Register entrypoint) { |
| 7084 | // entrypoint = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 7085 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 7086 | const int32_t entry_point_offset = |
| 7087 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 7088 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| 7089 | } |
| 7090 | |
| 7091 | void CodeGeneratorARM64::CompileBakerReadBarrierThunk(Arm64Assembler& assembler, |
| 7092 | uint32_t encoded_data, |
| 7093 | /*out*/ std::string* debug_name) { |
| 7094 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 7095 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 7096 | case BakerReadBarrierKind::kField: |
| 7097 | case BakerReadBarrierKind::kAcquire: { |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 7098 | Register base_reg = |
| 7099 | vixl::aarch64::XRegister(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7100 | CheckValidReg(base_reg.GetCode()); |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 7101 | Register holder_reg = |
| 7102 | vixl::aarch64::XRegister(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7103 | CheckValidReg(holder_reg.GetCode()); |
| 7104 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 7105 | temps.Exclude(ip0, ip1); |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 7106 | // In the case of a field load (with relaxed semantic), if `base_reg` differs from |
| 7107 | // `holder_reg`, the offset was too large and we must have emitted (during the construction |
| 7108 | // of the HIR graph, see `art::HInstructionBuilder::BuildInstanceFieldAccess`) and preserved |
| 7109 | // (see `art::PrepareForRegisterAllocation::VisitNullCheck`) an explicit null check before |
| 7110 | // the load. Otherwise, for implicit null checks, we need to null-check the holder as we do |
| 7111 | // not necessarily do that check before going to the thunk. |
| 7112 | // |
| 7113 | // In the case of a field load with load-acquire semantics (where `base_reg` always differs |
| 7114 | // from `holder_reg`), we also need an explicit null check when implicit null checks are |
| 7115 | // allowed, as we do not emit one before going to the thunk. |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7116 | vixl::aarch64::Label throw_npe_label; |
| 7117 | vixl::aarch64::Label* throw_npe = nullptr; |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 7118 | if (GetCompilerOptions().GetImplicitNullChecks() && |
| 7119 | (holder_reg.Is(base_reg) || (kind == BakerReadBarrierKind::kAcquire))) { |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7120 | throw_npe = &throw_npe_label; |
| 7121 | __ Cbz(holder_reg.W(), throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7122 | } |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7123 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 7124 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 7125 | // to load the reference and call the entrypoint that performs further checks on the |
| 7126 | // reference and marks it if needed. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7127 | vixl::aarch64::Label slow_path; |
| 7128 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 7129 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7130 | __ Bind(&slow_path); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 7131 | if (kind == BakerReadBarrierKind::kField) { |
| 7132 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 7133 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (immediate) unsigned offset. |
| 7134 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 7135 | __ Ubfx(ip0.W(), ip0.W(), 10, 12); // Extract the offset. |
| 7136 | __ Ldr(ip0.W(), MemOperand(base_reg, ip0, LSL, 2)); // Load the reference. |
| 7137 | } else { |
| 7138 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 7139 | DCHECK(!base_reg.Is(holder_reg)); |
| 7140 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 7141 | __ Ldar(ip0.W(), MemOperand(base_reg)); |
| 7142 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7143 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 7144 | __ Br(ip1); // Jump to the entrypoint. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7145 | break; |
| 7146 | } |
| 7147 | case BakerReadBarrierKind::kArray: { |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 7148 | Register base_reg = |
| 7149 | vixl::aarch64::XRegister(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7150 | CheckValidReg(base_reg.GetCode()); |
| 7151 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7152 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7153 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 7154 | temps.Exclude(ip0, ip1); |
| 7155 | vixl::aarch64::Label slow_path; |
| 7156 | int32_t data_offset = |
| 7157 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 7158 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 7159 | DCHECK_LT(lock_word.GetOffset(), 0); |
| 7160 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path); |
| 7161 | __ Bind(&slow_path); |
| 7162 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| 7163 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (register) unsigned offset. |
| 7164 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 7165 | __ Ubfx(ip0, ip0, 16, 6); // Extract the index register, plus 32 (bit 21 is set). |
| 7166 | __ Bfi(ip1, ip0, 3, 6); // Insert ip0 to the entrypoint address to create |
| 7167 | // a switch case target based on the index register. |
| 7168 | __ Mov(ip0, base_reg); // Move the base register to ip0. |
| 7169 | __ Br(ip1); // Jump to the entrypoint's array switch case. |
| 7170 | break; |
| 7171 | } |
| 7172 | case BakerReadBarrierKind::kGcRoot: { |
| 7173 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 7174 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 7175 | // otherwise return the reference (or the extracted forwarding address). |
| 7176 | // There is no gray bit check for GC roots. |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 7177 | Register root_reg = |
| 7178 | vixl::aarch64::WRegister(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7179 | CheckValidReg(root_reg.GetCode()); |
| 7180 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7181 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7182 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 7183 | temps.Exclude(ip0, ip1); |
| 7184 | vixl::aarch64::Label return_label, not_marked, forwarding_address; |
| 7185 | __ Cbz(root_reg, &return_label); |
| 7186 | MemOperand lock_word(root_reg.X(), mirror::Object::MonitorOffset().Int32Value()); |
| 7187 | __ Ldr(ip0.W(), lock_word); |
| 7188 | __ Tbz(ip0.W(), LockWord::kMarkBitStateShift, ¬_marked); |
| 7189 | __ Bind(&return_label); |
| 7190 | __ Br(lr); |
| 7191 | __ Bind(¬_marked); |
| 7192 | __ Tst(ip0.W(), Operand(ip0.W(), LSL, 1)); |
| 7193 | __ B(&forwarding_address, mi); |
| 7194 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 7195 | // Adjust the art_quick_read_barrier_mark_introspection address in IP1 to |
| 7196 | // art_quick_read_barrier_mark_introspection_gc_roots. |
| 7197 | __ Add(ip1, ip1, Operand(BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET)); |
| 7198 | __ Mov(ip0.W(), root_reg); |
| 7199 | __ Br(ip1); |
| 7200 | __ Bind(&forwarding_address); |
| 7201 | __ Lsl(root_reg, ip0.W(), LockWord::kForwardingAddressShift); |
| 7202 | __ Br(lr); |
| 7203 | break; |
| 7204 | } |
| 7205 | default: |
| 7206 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 7207 | UNREACHABLE(); |
| 7208 | } |
| 7209 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 7210 | // For JIT, the slow path is considered part of the compiled method, |
Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 7211 | // so JIT should pass null as `debug_name`. |
Santiago Aboy Solanes | 872ec72 | 2022-02-18 14:10:25 +0000 | [diff] [blame] | 7212 | DCHECK_IMPLIES(GetCompilerOptions().IsJitCompiler(), debug_name == nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 7213 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7214 | std::ostringstream oss; |
| 7215 | oss << "BakerReadBarrierThunk"; |
| 7216 | switch (kind) { |
| 7217 | case BakerReadBarrierKind::kField: |
| 7218 | oss << "Field_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 7219 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 7220 | break; |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 7221 | case BakerReadBarrierKind::kAcquire: |
| 7222 | oss << "Acquire_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 7223 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 7224 | break; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7225 | case BakerReadBarrierKind::kArray: |
| 7226 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 7227 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7228 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7229 | break; |
| 7230 | case BakerReadBarrierKind::kGcRoot: |
| 7231 | oss << "GcRoot_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 7232 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7233 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7234 | break; |
| 7235 | } |
| 7236 | *debug_name = oss.str(); |
| 7237 | } |
| 7238 | } |
| 7239 | |
| 7240 | #undef __ |
| 7241 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 7242 | } // namespace arm64 |
| 7243 | } // namespace art |