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 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 19 | #include "arch/arm64/asm_support_arm64.h" |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 20 | #include "arch/arm64/instruction_set_features_arm64.h" |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 21 | #include "arch/arm64/jni_frame_arm64.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 22 | #include "art_method-inl.h" |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 23 | #include "base/bit_utils.h" |
| 24 | #include "base/bit_utils_iterator.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 25 | #include "class_table.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 26 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 27 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 28 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 29 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 30 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 31 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 32 | #include "heap_poisoning.h" |
Nicolas Geoffray | 4313ccb | 2020-08-26 17:01:15 +0100 | [diff] [blame] | 33 | #include "interpreter/mterp/nterp.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 34 | #include "intrinsics.h" |
| 35 | #include "intrinsics_arm64.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 36 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 37 | #include "lock_word.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 38 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 39 | #include "mirror/class-inl.h" |
Vladimir Marko | 2d98dc2 | 2020-10-01 11:21:37 +0000 | [diff] [blame] | 40 | #include "mirror/var_handle.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 41 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 42 | #include "thread.h" |
| 43 | #include "utils/arm64/assembler_arm64.h" |
| 44 | #include "utils/assembler.h" |
| 45 | #include "utils/stack_checks.h" |
| 46 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 47 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 48 | using vixl::ExactAssemblyScope; |
| 49 | using vixl::CodeBufferCheckScope; |
| 50 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 51 | |
| 52 | #ifdef __ |
| 53 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 54 | #endif |
| 55 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 56 | namespace art { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 57 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 58 | template<class MirrorType> |
| 59 | class GcRoot; |
| 60 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 61 | namespace arm64 { |
| 62 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 63 | using helpers::ARM64EncodableConstantOrRegister; |
| 64 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 65 | using helpers::CPURegisterFrom; |
| 66 | using helpers::DRegisterFrom; |
| 67 | using helpers::FPRegisterFrom; |
| 68 | using helpers::HeapOperand; |
| 69 | using helpers::HeapOperandFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 70 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 71 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 72 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 73 | using helpers::InputRegisterAt; |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 74 | using helpers::Int64FromLocation; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 75 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 76 | using helpers::LocationFrom; |
| 77 | using helpers::OperandFromMemOperand; |
| 78 | using helpers::OutputCPURegister; |
| 79 | using helpers::OutputFPRegister; |
| 80 | using helpers::OutputRegister; |
| 81 | using helpers::RegisterFrom; |
| 82 | using helpers::StackOperandFrom; |
| 83 | using helpers::VIXLRegCodeFromART; |
| 84 | using helpers::WRegisterFrom; |
| 85 | using helpers::XRegisterFrom; |
| 86 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 87 | // 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] | 88 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 89 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 90 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 91 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 92 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 93 | // 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] | 94 | // 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] | 95 | // the offset explicitly. |
| 96 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 97 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 98 | inline Condition ARM64Condition(IfCondition cond) { |
| 99 | switch (cond) { |
| 100 | case kCondEQ: return eq; |
| 101 | case kCondNE: return ne; |
| 102 | case kCondLT: return lt; |
| 103 | case kCondLE: return le; |
| 104 | case kCondGT: return gt; |
| 105 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 106 | case kCondB: return lo; |
| 107 | case kCondBE: return ls; |
| 108 | case kCondA: return hi; |
| 109 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 110 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 111 | LOG(FATAL) << "Unreachable"; |
| 112 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 115 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 116 | // The ARM64 condition codes can express all the necessary branches, see the |
| 117 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 118 | // There is no dex instruction or HIR that would need the missing conditions |
| 119 | // "equal or unordered" or "not equal". |
| 120 | switch (cond) { |
| 121 | case kCondEQ: return eq; |
| 122 | case kCondNE: return ne /* unordered */; |
| 123 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 124 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 125 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 126 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 127 | default: |
| 128 | LOG(FATAL) << "UNREACHABLE"; |
| 129 | UNREACHABLE(); |
| 130 | } |
| 131 | } |
| 132 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 133 | Location ARM64ReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 134 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 135 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 136 | // but we use the exact registers for clarity. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 137 | if (return_type == DataType::Type::kFloat32) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 138 | return LocationFrom(s0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 139 | } else if (return_type == DataType::Type::kFloat64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 140 | return LocationFrom(d0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 141 | } else if (return_type == DataType::Type::kInt64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 142 | return LocationFrom(x0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 143 | } else if (return_type == DataType::Type::kVoid) { |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 144 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 145 | } else { |
| 146 | return LocationFrom(w0); |
| 147 | } |
| 148 | } |
| 149 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 150 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 151 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 152 | } |
| 153 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 154 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 155 | InvokeRuntimeCallingConvention calling_convention; |
| 156 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 157 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 158 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 159 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 160 | DataType::Type::kReference).GetCode()); |
| 161 | return caller_saves; |
| 162 | } |
| 163 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 164 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 165 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 166 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 167 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 168 | // Calculate memory accessing operand for save/restore live registers. |
| 169 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 170 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 171 | int64_t spill_offset, |
| 172 | bool is_save) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 173 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
| 174 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 175 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 176 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 177 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 178 | codegen->GetNumberOfFloatingPointRegisters())); |
| 179 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 180 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 181 | const unsigned v_reg_size_in_bits = codegen->GetSlowPathFPWidth() * 8; |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 182 | DCHECK_LE(codegen->GetSIMDRegisterWidth(), kQRegSizeInBytes); |
Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 183 | CPURegList fp_list = CPURegList(CPURegister::kVRegister, v_reg_size_in_bits, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 184 | |
| 185 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 186 | UseScratchRegisterScope temps(masm); |
| 187 | |
| 188 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 189 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 190 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 191 | int64_t reg_size = kXRegSizeInBytes; |
| 192 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 193 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 194 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 195 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 196 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 197 | // to compute the base address(float point registers spill base address). |
| 198 | Register new_base = temps.AcquireSameSizeAs(base); |
| 199 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 200 | base = new_base; |
| 201 | spill_offset = -core_spill_size; |
| 202 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 203 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 204 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 205 | } |
| 206 | |
| 207 | if (is_save) { |
| 208 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 209 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 210 | } else { |
| 211 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 212 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 217 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 218 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 219 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 220 | // If the register holds an object, update the stack mask. |
| 221 | if (locations->RegisterContainsObject(i)) { |
| 222 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 223 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 224 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 225 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 226 | saved_core_stack_offsets_[i] = stack_offset; |
| 227 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 228 | } |
| 229 | |
Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 230 | const size_t fp_reg_size = codegen->GetSlowPathFPWidth(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 231 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 232 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 233 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 234 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 235 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 236 | stack_offset += fp_reg_size; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 237 | } |
| 238 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 239 | SaveRestoreLiveRegistersHelper(codegen, |
| 240 | locations, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 241 | codegen->GetFirstRegisterSlotInSlowPath(), /* is_save= */ true); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 245 | SaveRestoreLiveRegistersHelper(codegen, |
| 246 | locations, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 247 | codegen->GetFirstRegisterSlotInSlowPath(), /* is_save= */ false); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 248 | } |
| 249 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 250 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 251 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 252 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 253 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 254 | void EmitNativeCode(CodeGenerator* codegen) override { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 255 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 256 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 257 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 258 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 259 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 260 | // Live registers will be restored in the catch block if caught. |
| 261 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 262 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 263 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 264 | // move resolver. |
| 265 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 266 | codegen->EmitParallelMoves(locations->InAt(0), |
| 267 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 268 | DataType::Type::kInt32, |
| 269 | locations->InAt(1), |
| 270 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 271 | DataType::Type::kInt32); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 272 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 273 | ? kQuickThrowStringBounds |
| 274 | : kQuickThrowArrayBounds; |
| 275 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 276 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 277 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 278 | } |
| 279 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 280 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 281 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 282 | const char* GetDescription() const override { return "BoundsCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 283 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 284 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 285 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 286 | }; |
| 287 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 288 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 289 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 290 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 291 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 292 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 293 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 294 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 295 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 296 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 299 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 300 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 301 | const char* GetDescription() const override { return "DivZeroCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 302 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 303 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 304 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 305 | }; |
| 306 | |
| 307 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 308 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 309 | LoadClassSlowPathARM64(HLoadClass* cls, HInstruction* at) |
| 310 | : SlowPathCodeARM64(at), cls_(cls) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 311 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 312 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 315 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 316 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 317 | Location out = locations->Out(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 318 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 319 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 320 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 321 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 322 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 323 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 324 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 325 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 326 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 327 | if (must_resolve_type) { |
| 328 | DCHECK(IsSameDexFile(cls_->GetDexFile(), arm64_codegen->GetGraph()->GetDexFile())); |
| 329 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 330 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 331 | if (cls_->NeedsAccessCheck()) { |
| 332 | CheckEntrypointTypes<kQuickResolveTypeAndVerifyAccess, void*, uint32_t>(); |
| 333 | arm64_codegen->InvokeRuntime(kQuickResolveTypeAndVerifyAccess, instruction_, dex_pc, this); |
| 334 | } else { |
| 335 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| 336 | arm64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 337 | } |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 338 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 339 | } else { |
| 340 | DCHECK(must_do_clinit); |
| 341 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 342 | arm64_codegen->MoveLocation(LocationFrom(calling_convention.GetRegisterAt(0)), |
| 343 | source, |
| 344 | cls_->GetType()); |
| 345 | } |
| 346 | if (must_do_clinit) { |
| 347 | arm64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 348 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 349 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 350 | |
| 351 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 352 | if (out.IsValid()) { |
| 353 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 354 | DataType::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 355 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 356 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 357 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 358 | __ B(GetExitLabel()); |
| 359 | } |
| 360 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 361 | const char* GetDescription() const override { return "LoadClassSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 362 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 363 | private: |
| 364 | // The class this slow path will load. |
| 365 | HLoadClass* const cls_; |
| 366 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 367 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 368 | }; |
| 369 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 370 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 371 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 372 | explicit LoadStringSlowPathARM64(HLoadString* instruction) |
| 373 | : SlowPathCodeARM64(instruction) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 374 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 375 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 376 | LocationSummary* locations = instruction_->GetLocations(); |
| 377 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 378 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 379 | |
| 380 | __ Bind(GetEntryLabel()); |
| 381 | SaveLiveRegisters(codegen, locations); |
| 382 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 383 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 384 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 385 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 386 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 387 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 388 | DataType::Type type = instruction_->GetType(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 389 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 390 | |
| 391 | RestoreLiveRegisters(codegen, locations); |
| 392 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 393 | __ B(GetExitLabel()); |
| 394 | } |
| 395 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 396 | const char* GetDescription() const override { return "LoadStringSlowPathARM64"; } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 397 | |
| 398 | private: |
| 399 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 400 | }; |
| 401 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 402 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 403 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 404 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 405 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 406 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 407 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 408 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 409 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 410 | // Live registers will be restored in the catch block if caught. |
| 411 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 412 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 413 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 414 | instruction_, |
| 415 | instruction_->GetDexPc(), |
| 416 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 417 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 418 | } |
| 419 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 420 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 421 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 422 | const char* GetDescription() const override { return "NullCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 423 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 424 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 425 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 426 | }; |
| 427 | |
| 428 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 429 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 430 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 431 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 432 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 433 | void EmitNativeCode(CodeGenerator* codegen) override { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 434 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 435 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 436 | __ Bind(GetEntryLabel()); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 437 | SaveLiveRegisters(codegen, locations); // Only saves live vector regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 438 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 439 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 440 | RestoreLiveRegisters(codegen, locations); // Only restores live vector regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 441 | if (successor_ == nullptr) { |
| 442 | __ B(GetReturnLabel()); |
| 443 | } else { |
| 444 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 445 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 446 | } |
| 447 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 448 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 449 | DCHECK(successor_ == nullptr); |
| 450 | return &return_label_; |
| 451 | } |
| 452 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 453 | HBasicBlock* GetSuccessor() const { |
| 454 | return successor_; |
| 455 | } |
| 456 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 457 | const char* GetDescription() const override { return "SuspendCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 458 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 459 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 460 | // If not null, the block to branch to after the suspend check. |
| 461 | HBasicBlock* const successor_; |
| 462 | |
| 463 | // If `successor_` is null, the label to branch to after the suspend check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 464 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 465 | |
| 466 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 467 | }; |
| 468 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 469 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 470 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 471 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 472 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 473 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 474 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 475 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 476 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 477 | DCHECK(instruction_->IsCheckCast() |
| 478 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 479 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 480 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 481 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 482 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 483 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 484 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 485 | SaveLiveRegisters(codegen, locations); |
| 486 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 487 | |
| 488 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 489 | // move resolver. |
| 490 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 491 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 492 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 493 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 494 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 495 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 496 | DataType::Type::kReference); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 497 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 498 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 499 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 500 | DataType::Type ret_type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 501 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 502 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 503 | } else { |
| 504 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 505 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 506 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 509 | if (!is_fatal_) { |
| 510 | RestoreLiveRegisters(codegen, locations); |
| 511 | __ B(GetExitLabel()); |
| 512 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 515 | const char* GetDescription() const override { return "TypeCheckSlowPathARM64"; } |
| 516 | bool IsFatal() const override { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 517 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 518 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 519 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 520 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 521 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 522 | }; |
| 523 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 524 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 525 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 526 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 527 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 528 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 529 | void EmitNativeCode(CodeGenerator* codegen) override { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 530 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 531 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 532 | LocationSummary* locations = instruction_->GetLocations(); |
| 533 | SaveLiveRegisters(codegen, locations); |
| 534 | InvokeRuntimeCallingConvention calling_convention; |
| 535 | __ Mov(calling_convention.GetRegisterAt(0), |
| 536 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 537 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 538 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 541 | const char* GetDescription() const override { return "DeoptimizationSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 542 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 543 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 544 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 545 | }; |
| 546 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 547 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 548 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 549 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 550 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 551 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 552 | LocationSummary* locations = instruction_->GetLocations(); |
| 553 | __ Bind(GetEntryLabel()); |
| 554 | SaveLiveRegisters(codegen, locations); |
| 555 | |
| 556 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 557 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 558 | parallel_move.AddMove( |
| 559 | locations->InAt(0), |
| 560 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 561 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 562 | nullptr); |
| 563 | parallel_move.AddMove( |
| 564 | locations->InAt(1), |
| 565 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 566 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 567 | nullptr); |
| 568 | parallel_move.AddMove( |
| 569 | locations->InAt(2), |
| 570 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 571 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 572 | nullptr); |
| 573 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 574 | |
| 575 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 576 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 577 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 578 | RestoreLiveRegisters(codegen, locations); |
| 579 | __ B(GetExitLabel()); |
| 580 | } |
| 581 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 582 | const char* GetDescription() const override { return "ArraySetSlowPathARM64"; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 583 | |
| 584 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 585 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 586 | }; |
| 587 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 588 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 589 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 590 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 591 | |
| 592 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 593 | // 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] | 594 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 595 | num_entries * sizeof(int32_t), |
| 596 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 597 | |
| 598 | __ Bind(&table_start_); |
| 599 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 600 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 601 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 602 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 603 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 604 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 605 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 606 | Literal<int32_t> literal(jump_offset); |
| 607 | __ place(&literal); |
| 608 | } |
| 609 | } |
| 610 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 611 | // Slow path generating a read barrier for a heap reference. |
| 612 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 613 | public: |
| 614 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 615 | Location out, |
| 616 | Location ref, |
| 617 | Location obj, |
| 618 | uint32_t offset, |
| 619 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 620 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 621 | out_(out), |
| 622 | ref_(ref), |
| 623 | obj_(obj), |
| 624 | offset_(offset), |
| 625 | index_(index) { |
| 626 | DCHECK(kEmitCompilerReadBarrier); |
| 627 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 628 | // has been overwritten by (or after) the heap object reference load |
| 629 | // to be instrumented, e.g.: |
| 630 | // |
| 631 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 632 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 633 | // |
| 634 | // In that case, we have lost the information about the original |
| 635 | // object, and the emitted read barrier cannot work properly. |
| 636 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 637 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 638 | } |
| 639 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 640 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 641 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 642 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 643 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 644 | DCHECK(locations->CanCall()); |
| 645 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 646 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 647 | instruction_->IsStaticFieldGet() || |
| 648 | instruction_->IsArrayGet() || |
| 649 | instruction_->IsInstanceOf() || |
| 650 | instruction_->IsCheckCast() || |
Vladimir Marko | a41ea27 | 2020-09-07 15:24:36 +0000 | [diff] [blame] | 651 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 652 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 653 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 654 | // The read barrier instrumentation of object ArrayGet |
| 655 | // instructions does not support the HIntermediateAddress |
| 656 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 657 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 658 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 659 | |
| 660 | __ Bind(GetEntryLabel()); |
| 661 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 662 | SaveLiveRegisters(codegen, locations); |
| 663 | |
| 664 | // We may have to change the index's value, but as `index_` is a |
| 665 | // constant member (like other "inputs" of this slow path), |
| 666 | // introduce a copy of it, `index`. |
| 667 | Location index = index_; |
| 668 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 669 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 670 | if (instruction_->IsArrayGet()) { |
| 671 | // Compute the actual memory offset and store it in `index`. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 672 | Register index_reg = RegisterFrom(index_, DataType::Type::kInt32); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 673 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 674 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 675 | // We are about to change the value of `index_reg` (see the |
| 676 | // calls to vixl::MacroAssembler::Lsl and |
| 677 | // vixl::MacroAssembler::Mov below), but it has |
| 678 | // not been saved by the previous call to |
| 679 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 680 | // callee-save register -- |
| 681 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 682 | // callee-save registers, as it has been designed with the |
| 683 | // assumption that callee-save registers are supposed to be |
| 684 | // handled by the called function. So, as a callee-save |
| 685 | // register, `index_reg` _would_ eventually be saved onto |
| 686 | // the stack, but it would be too late: we would have |
| 687 | // changed its value earlier. Therefore, we manually save |
| 688 | // it here into another freely available register, |
| 689 | // `free_reg`, chosen of course among the caller-save |
| 690 | // registers (as a callee-save `free_reg` register would |
| 691 | // exhibit the same problem). |
| 692 | // |
| 693 | // Note we could have requested a temporary register from |
| 694 | // the register allocator instead; but we prefer not to, as |
| 695 | // this is a slow path, and we know we can find a |
| 696 | // caller-save register that is available. |
| 697 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 698 | __ Mov(free_reg.W(), index_reg); |
| 699 | index_reg = free_reg; |
| 700 | index = LocationFrom(index_reg); |
| 701 | } else { |
| 702 | // The initial register stored in `index_` has already been |
| 703 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 704 | // (as it is not a callee-save register), so we can freely |
| 705 | // use it. |
| 706 | } |
| 707 | // Shifting the index value contained in `index_reg` by the scale |
| 708 | // factor (2) cannot overflow in practice, as the runtime is |
| 709 | // unable to allocate object arrays with a size larger than |
| 710 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 711 | __ Lsl(index_reg, index_reg, DataType::SizeShift(type)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 712 | static_assert( |
| 713 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 714 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 715 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 716 | } else { |
Vladimir Marko | a41ea27 | 2020-09-07 15:24:36 +0000 | [diff] [blame] | 717 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile/VarHandleGet |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 718 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 719 | // (as in the case of ArrayGet), as it is actually an offset |
| 720 | // to an object field within an object. |
| 721 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 722 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
Vladimir Marko | 2d98dc2 | 2020-10-01 11:21:37 +0000 | [diff] [blame] | 723 | Intrinsics intrinsic = instruction_->AsInvoke()->GetIntrinsic(); |
| 724 | DCHECK(intrinsic == Intrinsics::kUnsafeGetObject || |
| 725 | intrinsic == Intrinsics::kUnsafeGetObjectVolatile || |
Vladimir Marko | e17530a | 2020-11-11 17:02:26 +0000 | [diff] [blame] | 726 | intrinsic == Intrinsics::kUnsafeCASObject || |
Vladimir Marko | 2d98dc2 | 2020-10-01 11:21:37 +0000 | [diff] [blame] | 727 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == |
Vladimir Marko | 1bff99f | 2020-11-02 15:07:33 +0000 | [diff] [blame] | 728 | mirror::VarHandle::AccessModeTemplate::kGet || |
| 729 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == |
| 730 | mirror::VarHandle::AccessModeTemplate::kCompareAndSet || |
| 731 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == |
Vladimir Marko | 32c2eb8 | 2020-11-10 16:58:47 +0000 | [diff] [blame] | 732 | mirror::VarHandle::AccessModeTemplate::kCompareAndExchange || |
| 733 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == |
| 734 | mirror::VarHandle::AccessModeTemplate::kGetAndUpdate) |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 735 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 736 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 737 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | |
| 741 | // We're moving two or three locations to locations that could |
| 742 | // overlap, so we need a parallel move resolver. |
| 743 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 744 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 745 | parallel_move.AddMove(ref_, |
| 746 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 747 | type, |
| 748 | nullptr); |
| 749 | parallel_move.AddMove(obj_, |
| 750 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 751 | type, |
| 752 | nullptr); |
| 753 | if (index.IsValid()) { |
| 754 | parallel_move.AddMove(index, |
| 755 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 756 | DataType::Type::kInt32, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 757 | nullptr); |
| 758 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 759 | } else { |
| 760 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 761 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 762 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 763 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 764 | instruction_, |
| 765 | instruction_->GetDexPc(), |
| 766 | this); |
| 767 | CheckEntrypointTypes< |
| 768 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 769 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 770 | |
| 771 | RestoreLiveRegisters(codegen, locations); |
| 772 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 773 | __ B(GetExitLabel()); |
| 774 | } |
| 775 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 776 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 777 | |
| 778 | private: |
| 779 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 780 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 781 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 782 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 783 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 784 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 785 | } |
| 786 | } |
| 787 | // We shall never fail to find a free caller-save register, as |
| 788 | // there are more than two core caller-save registers on ARM64 |
| 789 | // (meaning it is possible to find one which is different from |
| 790 | // `ref` and `obj`). |
| 791 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 792 | LOG(FATAL) << "Could not find a free register"; |
| 793 | UNREACHABLE(); |
| 794 | } |
| 795 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 796 | const Location out_; |
| 797 | const Location ref_; |
| 798 | const Location obj_; |
| 799 | const uint32_t offset_; |
| 800 | // An additional location containing an index to an array. |
| 801 | // Only used for HArrayGet and the UnsafeGetObject & |
| 802 | // UnsafeGetObjectVolatile intrinsics. |
| 803 | const Location index_; |
| 804 | |
| 805 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 806 | }; |
| 807 | |
| 808 | // Slow path generating a read barrier for a GC root. |
| 809 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 810 | public: |
| 811 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 812 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 813 | DCHECK(kEmitCompilerReadBarrier); |
| 814 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 815 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 816 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 817 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 818 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 819 | DCHECK(locations->CanCall()); |
| 820 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Vladimir Marko | a41ea27 | 2020-09-07 15:24:36 +0000 | [diff] [blame] | 821 | DCHECK(instruction_->IsLoadClass() || |
| 822 | instruction_->IsLoadString() || |
| 823 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 824 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 825 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 826 | |
| 827 | __ Bind(GetEntryLabel()); |
| 828 | SaveLiveRegisters(codegen, locations); |
| 829 | |
| 830 | InvokeRuntimeCallingConvention calling_convention; |
| 831 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 832 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 833 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 834 | // thus we need a 64-bit move here, and we cannot use |
| 835 | // |
| 836 | // arm64_codegen->MoveLocation( |
| 837 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 838 | // root_, |
| 839 | // type); |
| 840 | // |
| 841 | // 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] | 842 | // reference type (`DataType::Type::kReference`). |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 843 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 844 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 845 | instruction_, |
| 846 | instruction_->GetDexPc(), |
| 847 | this); |
| 848 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 849 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 850 | |
| 851 | RestoreLiveRegisters(codegen, locations); |
| 852 | __ B(GetExitLabel()); |
| 853 | } |
| 854 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 855 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathARM64"; } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 856 | |
| 857 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 858 | const Location out_; |
| 859 | const Location root_; |
| 860 | |
| 861 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 862 | }; |
| 863 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 864 | #undef __ |
| 865 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 866 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 867 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 868 | if (type == DataType::Type::kVoid) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 869 | LOG(FATAL) << "Unreachable type " << type; |
| 870 | } |
| 871 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 872 | if (DataType::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 873 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 874 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 875 | } else if (!DataType::IsFloatingPointType(type) && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 876 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 877 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 878 | } else { |
| 879 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 880 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 881 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 882 | } |
| 883 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 884 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 885 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 886 | return next_location; |
| 887 | } |
| 888 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 889 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 890 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 891 | } |
| 892 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 893 | Location CriticalNativeCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
| 894 | DCHECK_NE(type, DataType::Type::kReference); |
| 895 | |
| 896 | Location location = Location::NoLocation(); |
| 897 | if (DataType::IsFloatingPointType(type)) { |
| 898 | if (fpr_index_ < kParameterFPRegistersLength) { |
| 899 | location = LocationFrom(kParameterFPRegisters[fpr_index_]); |
| 900 | ++fpr_index_; |
| 901 | } |
| 902 | } else { |
| 903 | // Native ABI uses the same registers as managed, except that the method register x0 |
| 904 | // is a normal argument. |
| 905 | if (gpr_index_ < 1u + kParameterCoreRegistersLength) { |
| 906 | location = LocationFrom(gpr_index_ == 0u ? x0 : kParameterCoreRegisters[gpr_index_ - 1u]); |
| 907 | ++gpr_index_; |
| 908 | } |
| 909 | } |
| 910 | if (location.IsInvalid()) { |
| 911 | if (DataType::Is64BitType(type)) { |
| 912 | location = Location::DoubleStackSlot(stack_offset_); |
| 913 | } else { |
| 914 | location = Location::StackSlot(stack_offset_); |
| 915 | } |
| 916 | stack_offset_ += kFramePointerSize; |
| 917 | |
| 918 | if (for_register_allocation_) { |
| 919 | location = Location::Any(); |
| 920 | } |
| 921 | } |
| 922 | return location; |
| 923 | } |
| 924 | |
| 925 | Location CriticalNativeCallingConventionVisitorARM64::GetReturnLocation(DataType::Type type) const { |
| 926 | // We perform conversion to the managed ABI return register after the call if needed. |
| 927 | InvokeDexCallingConventionVisitorARM64 dex_calling_convention; |
| 928 | return dex_calling_convention.GetReturnLocation(type); |
| 929 | } |
| 930 | |
| 931 | Location CriticalNativeCallingConventionVisitorARM64::GetMethodLocation() const { |
| 932 | // Pass the method in the hidden argument x15. |
| 933 | return Location::RegisterLocation(x15.GetCode()); |
| 934 | } |
| 935 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 936 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 937 | const CompilerOptions& compiler_options, |
| 938 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 939 | : CodeGenerator(graph, |
| 940 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 941 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 942 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 943 | callee_saved_core_registers.GetList(), |
| 944 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 945 | compiler_options, |
| 946 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 947 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 948 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 949 | location_builder_neon_(graph, this), |
| 950 | instruction_visitor_neon_(graph, this), |
| 951 | location_builder_sve_(graph, this), |
| 952 | instruction_visitor_sve_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 953 | move_resolver_(graph->GetAllocator(), this), |
Artem Serov | aa6f483 | 2018-11-21 18:57:54 +0000 | [diff] [blame] | 954 | assembler_(graph->GetAllocator(), |
| 955 | compiler_options.GetInstructionSetFeatures()->AsArm64InstructionSetFeatures()), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 956 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 957 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 958 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 959 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 960 | public_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 961 | package_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 962 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 963 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 964 | boot_image_jni_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 965 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 966 | call_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 967 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 968 | uint32_literals_(std::less<uint32_t>(), |
| 969 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 970 | uint64_literals_(std::less<uint64_t>(), |
| 971 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 972 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 973 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 974 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 975 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 976 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 977 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 978 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 979 | AddAllocatedRegister(LocationFrom(lr)); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 980 | |
| 981 | bool use_sve = ShouldUseSVE(); |
| 982 | if (use_sve) { |
| 983 | location_builder_ = &location_builder_sve_; |
| 984 | instruction_visitor_ = &instruction_visitor_sve_; |
| 985 | } else { |
| 986 | location_builder_ = &location_builder_neon_; |
| 987 | instruction_visitor_ = &instruction_visitor_neon_; |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | bool CodeGeneratorARM64::ShouldUseSVE() const { |
| 992 | return kArm64AllowSVE && GetInstructionSetFeatures().HasSVE(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 993 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 994 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 995 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 996 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 997 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 998 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 999 | jump_table->EmitTable(this); |
| 1000 | } |
| 1001 | } |
| 1002 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1003 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1004 | EmitJumpTables(); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1005 | |
| 1006 | // Emit JIT baker read barrier slow paths. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 1007 | DCHECK(GetCompilerOptions().IsJitCompiler() || jit_baker_read_barrier_slow_paths_.empty()); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1008 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 1009 | uint32_t encoded_data = entry.first; |
| 1010 | vixl::aarch64::Label* slow_path_entry = &entry.second.label; |
| 1011 | __ Bind(slow_path_entry); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1012 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name= */ nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1015 | // Ensure we emit the literal pool. |
| 1016 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1017 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1018 | CodeGenerator::Finalize(allocator); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1019 | |
| 1020 | // Verify Baker read barrier linker patches. |
| 1021 | if (kIsDebugBuild) { |
| 1022 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 1023 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 1024 | DCHECK(info.label.IsBound()); |
| 1025 | uint32_t literal_offset = info.label.GetLocation(); |
| 1026 | DCHECK_ALIGNED(literal_offset, 4u); |
| 1027 | |
| 1028 | auto GetInsn = [&code](uint32_t offset) { |
| 1029 | DCHECK_ALIGNED(offset, 4u); |
| 1030 | return |
| 1031 | (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 1032 | (static_cast<uint32_t>(code[offset + 1]) << 8) + |
| 1033 | (static_cast<uint32_t>(code[offset + 2]) << 16)+ |
| 1034 | (static_cast<uint32_t>(code[offset + 3]) << 24); |
| 1035 | }; |
| 1036 | |
| 1037 | const uint32_t encoded_data = info.custom_data; |
| 1038 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 1039 | // Check that the next instruction matches the expected LDR. |
| 1040 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1041 | case BakerReadBarrierKind::kField: |
| 1042 | case BakerReadBarrierKind::kAcquire: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1043 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1044 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1045 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1046 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1047 | if (kind == BakerReadBarrierKind::kField) { |
| 1048 | // LDR (immediate) with correct base_reg. |
| 1049 | CHECK_EQ(next_insn & 0xffc003e0u, 0xb9400000u | (base_reg << 5)); |
| 1050 | } else { |
| 1051 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 1052 | // LDAR with correct base_reg. |
| 1053 | CHECK_EQ(next_insn & 0xffffffe0u, 0x88dffc00u | (base_reg << 5)); |
| 1054 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1055 | break; |
| 1056 | } |
| 1057 | case BakerReadBarrierKind::kArray: { |
| 1058 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1059 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 1060 | // LDR (register) with the correct base_reg, size=10 (32-bit), option=011 (extend = LSL), |
| 1061 | // and S=1 (shift amount = 2 for 32-bit version), i.e. LDR Wt, [Xn, Xm, LSL #2]. |
| 1062 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1063 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1064 | CHECK_EQ(next_insn & 0xffe0ffe0u, 0xb8607800u | (base_reg << 5)); |
| 1065 | CheckValidReg((next_insn >> 16) & 0x1f); // Check index register |
| 1066 | break; |
| 1067 | } |
| 1068 | case BakerReadBarrierKind::kGcRoot: { |
| 1069 | DCHECK_GE(literal_offset, 4u); |
| 1070 | uint32_t prev_insn = GetInsn(literal_offset - 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1071 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 1072 | // Usually LDR (immediate) with correct root_reg but |
Vladimir Marko | c8178f5 | 2020-11-24 10:38:16 +0000 | [diff] [blame^] | 1073 | // we may have a "MOV marked, old_value" for intrinsic CAS. |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 1074 | if ((prev_insn & 0xffe0ffff) != (0x2a0003e0 | root_reg)) { // MOV? |
| 1075 | CHECK_EQ(prev_insn & 0xffc0001fu, 0xb9400000u | root_reg); // LDR? |
| 1076 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1077 | break; |
| 1078 | } |
| 1079 | default: |
| 1080 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 1081 | UNREACHABLE(); |
| 1082 | } |
| 1083 | } |
| 1084 | } |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1087 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1088 | // Note: There are 6 kinds of moves: |
| 1089 | // 1. constant -> GPR/FPR (non-cycle) |
| 1090 | // 2. constant -> stack (non-cycle) |
| 1091 | // 3. GPR/FPR -> GPR/FPR |
| 1092 | // 4. GPR/FPR -> stack |
| 1093 | // 5. stack -> GPR/FPR |
| 1094 | // 6. stack -> stack (non-cycle) |
| 1095 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1096 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1097 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1098 | // dependency. |
| 1099 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1100 | } |
| 1101 | |
| 1102 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1103 | vixl_temps_.Close(); |
| 1104 | } |
| 1105 | |
| 1106 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1107 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1108 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1109 | || kind == Location::kSIMDStackSlot); |
| 1110 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1111 | ? Location::kFpuRegister |
| 1112 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1113 | Location scratch = GetScratchLocation(kind); |
| 1114 | if (!scratch.Equals(Location::NoLocation())) { |
| 1115 | return scratch; |
| 1116 | } |
| 1117 | // Allocate from VIXL temp registers. |
| 1118 | if (kind == Location::kRegister) { |
| 1119 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1120 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1121 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1122 | scratch = codegen_->GetGraph()->HasSIMD() |
| 1123 | ? codegen_->GetInstructionCodeGeneratorArm64()->AllocateSIMDScratchLocation(&vixl_temps_) |
| 1124 | : LocationFrom(vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1125 | } |
| 1126 | AddScratchLocation(scratch); |
| 1127 | return scratch; |
| 1128 | } |
| 1129 | |
| 1130 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1131 | if (loc.IsRegister()) { |
| 1132 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1133 | } else { |
| 1134 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1135 | if (codegen_->GetGraph()->HasSIMD()) { |
| 1136 | codegen_->GetInstructionCodeGeneratorArm64()->FreeSIMDScratchLocation(loc, &vixl_temps_); |
| 1137 | } else { |
| 1138 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1139 | } |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1140 | } |
| 1141 | RemoveScratchLocation(loc); |
| 1142 | } |
| 1143 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1144 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1145 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1146 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1149 | void CodeGeneratorARM64::MaybeIncrementHotness(bool is_frame_entry) { |
| 1150 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1151 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1152 | UseScratchRegisterScope temps(masm); |
| 1153 | Register counter = temps.AcquireX(); |
| 1154 | Register method = is_frame_entry ? kArtMethodRegister : temps.AcquireX(); |
| 1155 | if (!is_frame_entry) { |
| 1156 | __ Ldr(method, MemOperand(sp, 0)); |
| 1157 | } |
| 1158 | __ Ldrh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1159 | __ Add(counter, counter, 1); |
| 1160 | // Subtract one if the counter would overflow. |
| 1161 | __ Sub(counter, counter, Operand(counter, LSR, 16)); |
| 1162 | __ Strh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1163 | } |
| 1164 | |
| 1165 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 1166 | ScopedProfilingInfoUse spiu( |
| 1167 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 1168 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1169 | if (info != nullptr) { |
Nicolas Geoffray | c1cd133 | 2020-01-25 13:08:24 +0000 | [diff] [blame] | 1170 | uint64_t address = reinterpret_cast64<uint64_t>(info); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1171 | vixl::aarch64::Label done; |
| 1172 | UseScratchRegisterScope temps(masm); |
| 1173 | Register temp = temps.AcquireX(); |
| 1174 | Register counter = temps.AcquireW(); |
| 1175 | __ Mov(temp, address); |
| 1176 | __ Ldrh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 1177 | __ Add(counter, counter, 1); |
Nicolas Geoffray | 4313ccb | 2020-08-26 17:01:15 +0100 | [diff] [blame] | 1178 | __ And(counter, counter, interpreter::kTieredHotnessMask); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1179 | __ Strh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
Nicolas Geoffray | 4313ccb | 2020-08-26 17:01:15 +0100 | [diff] [blame] | 1180 | __ Cbnz(counter, &done); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1181 | if (is_frame_entry) { |
| 1182 | if (HasEmptyFrame()) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1183 | // The entrypoint expects the method at the bottom of the stack. We |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1184 | // claim stack space necessary for alignment. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1185 | IncreaseFrame(kStackAlignment); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1186 | __ Stp(kArtMethodRegister, lr, MemOperand(sp, 0)); |
| 1187 | } else if (!RequiresCurrentMethod()) { |
| 1188 | __ Str(kArtMethodRegister, MemOperand(sp, 0)); |
| 1189 | } |
| 1190 | } else { |
| 1191 | CHECK(RequiresCurrentMethod()); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1192 | } |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1193 | uint32_t entrypoint_offset = |
| 1194 | GetThreadOffset<kArm64PointerSize>(kQuickCompileOptimized).Int32Value(); |
| 1195 | __ Ldr(lr, MemOperand(tr, entrypoint_offset)); |
| 1196 | // Note: we don't record the call here (and therefore don't generate a stack |
| 1197 | // map), as the entrypoint should never be suspended. |
| 1198 | __ Blr(lr); |
| 1199 | if (HasEmptyFrame()) { |
| 1200 | CHECK(is_frame_entry); |
| 1201 | __ Ldr(lr, MemOperand(sp, 8)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1202 | DecreaseFrame(kStackAlignment); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1203 | } |
| 1204 | __ Bind(&done); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1205 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1209 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1210 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1211 | __ Bind(&frame_entry_label_); |
| 1212 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1213 | bool do_overflow_check = |
| 1214 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1215 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1216 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1217 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1218 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1219 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1220 | { |
| 1221 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1222 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1223 | kInstructionSize, |
| 1224 | CodeBufferCheckScope::kExactSize); |
| 1225 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1226 | RecordPcInfo(nullptr, 0); |
| 1227 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1228 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1229 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1230 | if (!HasEmptyFrame()) { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1231 | // Stack layout: |
| 1232 | // sp[frame_size - 8] : lr. |
| 1233 | // ... : other preserved core registers. |
| 1234 | // ... : other preserved fp registers. |
| 1235 | // ... : reserved frame space. |
| 1236 | // sp[0] : current method. |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1237 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1238 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1239 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1240 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1241 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1242 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1243 | |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1244 | // Save the current method if we need it, or if using STP reduces code |
| 1245 | // size. Note that we do not do this in HCurrentMethod, as the |
| 1246 | // instruction might have been removed in the SSA graph. |
| 1247 | CPURegister lowest_spill; |
| 1248 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1249 | // If there is no gap between the method and the lowest core spill, use |
| 1250 | // aligned STP pre-index to store both. Max difference is 512. We do |
| 1251 | // that to reduce code size even if we do not have to save the method. |
| 1252 | DCHECK_LE(frame_size, 512); // 32 core registers are only 256 bytes. |
| 1253 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1254 | __ Stp(kArtMethodRegister, lowest_spill, MemOperand(sp, -frame_size, PreIndex)); |
| 1255 | } else if (RequiresCurrentMethod()) { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1256 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1257 | } else { |
| 1258 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1259 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1260 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1261 | if (lowest_spill.IsValid()) { |
| 1262 | GetAssembler()->cfi().RelOffset(DWARFReg(lowest_spill), core_spills_offset); |
| 1263 | core_spills_offset += kXRegSizeInBytes; |
| 1264 | } |
| 1265 | GetAssembler()->SpillRegisters(preserved_core_registers, core_spills_offset); |
| 1266 | GetAssembler()->SpillRegisters(preserved_fp_registers, fp_spills_offset); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1267 | |
| 1268 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1269 | // Initialize should_deoptimize flag to 0. |
| 1270 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1271 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1272 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1273 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1274 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1275 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1279 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1280 | if (!HasEmptyFrame()) { |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1281 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1282 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1283 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1284 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1285 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1286 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
| 1287 | |
| 1288 | CPURegister lowest_spill; |
| 1289 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1290 | // If there is no gap between the method and the lowest core spill, use |
| 1291 | // aligned LDP pre-index to pop both. Max difference is 504. We do |
| 1292 | // that to reduce code size even though the loaded method is unused. |
| 1293 | DCHECK_LE(frame_size, 504); // 32 core registers are only 256 bytes. |
| 1294 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1295 | core_spills_offset += kXRegSizeInBytes; |
| 1296 | } |
| 1297 | GetAssembler()->UnspillRegisters(preserved_fp_registers, fp_spills_offset); |
| 1298 | GetAssembler()->UnspillRegisters(preserved_core_registers, core_spills_offset); |
| 1299 | if (lowest_spill.IsValid()) { |
| 1300 | __ Ldp(xzr, lowest_spill, MemOperand(sp, frame_size, PostIndex)); |
| 1301 | GetAssembler()->cfi().Restore(DWARFReg(lowest_spill)); |
| 1302 | } else { |
| 1303 | __ Drop(frame_size); |
| 1304 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1305 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1306 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1307 | __ Ret(); |
| 1308 | GetAssembler()->cfi().RestoreState(); |
| 1309 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1310 | } |
| 1311 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1312 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1313 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1314 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1315 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1316 | } |
| 1317 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1318 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1319 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1320 | GetNumberOfFloatingPointRegisters())); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1321 | return CPURegList(CPURegister::kVRegister, kDRegSize, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1322 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1323 | } |
| 1324 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1325 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1326 | __ Bind(GetLabelOf(block)); |
| 1327 | } |
| 1328 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1329 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1330 | DCHECK(location.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1331 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1332 | } |
| 1333 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1334 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1335 | if (location.IsRegister()) { |
| 1336 | locations->AddTemp(location); |
| 1337 | } else { |
| 1338 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1339 | } |
| 1340 | } |
| 1341 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1342 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1343 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1344 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1345 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1346 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1347 | if (value_can_be_null) { |
| 1348 | __ Cbz(value, &done); |
| 1349 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1350 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1351 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1352 | // Calculate the offset (in the card table) of the card corresponding to |
| 1353 | // `object`. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1354 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1355 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 1356 | // `object`'s card. |
| 1357 | // |
| 1358 | // Register `card` contains the address of the card table. Note that the card |
| 1359 | // table's base is biased during its creation so that it always starts at an |
| 1360 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 1361 | // art::gc::accounting::CardTable::Create). Therefore the STRB instruction |
| 1362 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 1363 | // (located at `card + object >> kCardShift`). |
| 1364 | // |
| 1365 | // This dual use of the value in register `card` (1. to calculate the location |
| 1366 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 1367 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1368 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1369 | if (value_can_be_null) { |
| 1370 | __ Bind(&done); |
| 1371 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1372 | } |
| 1373 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1374 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1375 | // Blocked core registers: |
| 1376 | // lr : Runtime reserved. |
| 1377 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1378 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1379 | // ip1 : VIXL core temp. |
| 1380 | // ip0 : VIXL core temp. |
Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1381 | // x18 : Platform register. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1382 | // |
| 1383 | // Blocked fp registers: |
| 1384 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1385 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1386 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1387 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1388 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1389 | } |
Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1390 | blocked_core_registers_[X18] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1391 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1392 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1393 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1394 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1395 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1396 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1397 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1398 | // Stubs do not save callee-save floating point registers. If the graph |
| 1399 | // is debuggable, we need to deal with these registers differently. For |
| 1400 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1401 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1402 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1403 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1404 | } |
| 1405 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1406 | } |
| 1407 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1408 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1409 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1410 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1411 | return kArm64WordSize; |
| 1412 | } |
| 1413 | |
| 1414 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1415 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1416 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1417 | return kArm64WordSize; |
| 1418 | } |
| 1419 | |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1420 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1421 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1422 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1423 | << "use SaveRestoreLiveRegistersHelper"; |
| 1424 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1427 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1428 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1429 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1430 | << "use SaveRestoreLiveRegistersHelper"; |
| 1431 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1434 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1435 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1439 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1440 | } |
| 1441 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1442 | const Arm64InstructionSetFeatures& CodeGeneratorARM64::GetInstructionSetFeatures() const { |
| 1443 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArm64InstructionSetFeatures(); |
| 1444 | } |
| 1445 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1446 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1447 | if (constant->IsIntConstant()) { |
| 1448 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1449 | } else if (constant->IsLongConstant()) { |
| 1450 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1451 | } else if (constant->IsNullConstant()) { |
| 1452 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1453 | } else if (constant->IsFloatConstant()) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1454 | __ Fmov(VRegister(destination), constant->AsFloatConstant()->GetValue()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1455 | } else { |
| 1456 | DCHECK(constant->IsDoubleConstant()); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1457 | __ Fmov(VRegister(destination), constant->AsDoubleConstant()->GetValue()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1458 | } |
| 1459 | } |
| 1460 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1461 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1462 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1463 | DCHECK(constant.IsConstant()); |
| 1464 | HConstant* cst = constant.GetConstant(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1465 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1466 | // 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] | 1467 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1468 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1469 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1470 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1473 | // Allocate a scratch register from the VIXL pool, querying first |
| 1474 | // the floating-point register pool, and then the core register |
| 1475 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1476 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1477 | // using a different allocation strategy. |
| 1478 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1479 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1480 | int size_in_bits) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1481 | return masm->GetScratchVRegisterList()->IsEmpty() |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1482 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1483 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1484 | } |
| 1485 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1486 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1487 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1488 | DataType::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1489 | if (source.Equals(destination)) { |
| 1490 | return; |
| 1491 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1492 | |
| 1493 | // A valid move can always be inferred from the destination and source |
| 1494 | // locations. When moving from and to a register, the argument type can be |
| 1495 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1496 | // checks the coherency of the locations and the type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1497 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1498 | |
| 1499 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1500 | if (unspecified_type) { |
| 1501 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1502 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1503 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1504 | || src_cst->IsFloatConstant() |
| 1505 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1506 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1507 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1508 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1509 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1510 | // type is appropriate. Else the source is a register, and since the |
| 1511 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1512 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1513 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1514 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1515 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1516 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1517 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1518 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1519 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1520 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1521 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1522 | } else if (source.IsSIMDStackSlot()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1523 | GetInstructionCodeGeneratorArm64()->LoadSIMDRegFromStack(destination, source); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1524 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1525 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1526 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1527 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1528 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1529 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1530 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1531 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1532 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1533 | ? DataType::Type::kInt64 |
| 1534 | : DataType::Type::kInt32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1535 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1536 | } |
| 1537 | } else { |
| 1538 | DCHECK(source.IsFpuRegister()); |
| 1539 | if (destination.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1540 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1541 | ? DataType::Type::kFloat64 |
| 1542 | : DataType::Type::kFloat32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1543 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1544 | } else { |
| 1545 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1546 | if (GetGraph()->HasSIMD()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1547 | GetInstructionCodeGeneratorArm64()->MoveSIMDRegToSIMDReg(destination, source); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1548 | } else { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1549 | __ Fmov(VRegister(dst), FPRegisterFrom(source, dst_type)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1550 | } |
| 1551 | } |
| 1552 | } |
| 1553 | } else if (destination.IsSIMDStackSlot()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1554 | GetInstructionCodeGeneratorArm64()->MoveToSIMDStackSlot(destination, source); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1555 | } else { // The destination is not a register. It must be a stack slot. |
| 1556 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1557 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1558 | if (unspecified_type) { |
| 1559 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1560 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1561 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1562 | dst_type = |
| 1563 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1564 | } |
| 1565 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1566 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1567 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1568 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1569 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1570 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1571 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1572 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1573 | HConstant* src_cst = source.GetConstant(); |
| 1574 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1575 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1576 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1577 | ? Register(xzr) |
| 1578 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1579 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1580 | if (src_cst->IsIntConstant()) { |
| 1581 | temp = temps.AcquireW(); |
| 1582 | } else if (src_cst->IsLongConstant()) { |
| 1583 | temp = temps.AcquireX(); |
| 1584 | } else if (src_cst->IsFloatConstant()) { |
| 1585 | temp = temps.AcquireS(); |
| 1586 | } else { |
| 1587 | DCHECK(src_cst->IsDoubleConstant()); |
| 1588 | temp = temps.AcquireD(); |
| 1589 | } |
| 1590 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1591 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1592 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1593 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1594 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1595 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1596 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1597 | // Use any scratch register (a core or a floating-point one) |
| 1598 | // from VIXL scratch register pools as a temporary. |
| 1599 | // |
| 1600 | // We used to only use the FP scratch register pool, but in some |
| 1601 | // rare cases the only register from this pool (D31) would |
| 1602 | // already be used (e.g. within a ParallelMove instruction, when |
| 1603 | // a move is blocked by a another move requiring a scratch FP |
| 1604 | // register, which would reserve D31). To prevent this issue, we |
| 1605 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1606 | // |
| 1607 | // 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] | 1608 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1609 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1610 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1611 | // allocates core scratch registers first. |
| 1612 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1613 | GetVIXLAssembler(), |
| 1614 | &temps, |
| 1615 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1616 | __ Ldr(temp, StackOperandFrom(source)); |
| 1617 | __ Str(temp, StackOperandFrom(destination)); |
| 1618 | } |
| 1619 | } |
| 1620 | } |
| 1621 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1622 | void CodeGeneratorARM64::Load(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1623 | CPURegister dst, |
| 1624 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1625 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1626 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1627 | case DataType::Type::kUint8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1628 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1629 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1630 | case DataType::Type::kInt8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1631 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1632 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1633 | case DataType::Type::kUint16: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1634 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1635 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1636 | case DataType::Type::kInt16: |
| 1637 | __ Ldrsh(Register(dst), src); |
| 1638 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1639 | case DataType::Type::kInt32: |
| 1640 | case DataType::Type::kReference: |
| 1641 | case DataType::Type::kInt64: |
| 1642 | case DataType::Type::kFloat32: |
| 1643 | case DataType::Type::kFloat64: |
| 1644 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1645 | __ Ldr(dst, src); |
| 1646 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1647 | case DataType::Type::kUint32: |
| 1648 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1649 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1650 | LOG(FATAL) << "Unreachable type " << type; |
| 1651 | } |
| 1652 | } |
| 1653 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1654 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1655 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1656 | const MemOperand& src, |
| 1657 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1658 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1659 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1660 | Register temp_base = temps.AcquireX(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1661 | DataType::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1662 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1663 | DCHECK(!src.IsPreIndex()); |
| 1664 | DCHECK(!src.IsPostIndex()); |
| 1665 | |
| 1666 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1667 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1668 | { |
| 1669 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1670 | MemOperand base = MemOperand(temp_base); |
| 1671 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1672 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1673 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1674 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1675 | { |
| 1676 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1677 | __ ldarb(Register(dst), base); |
| 1678 | if (needs_null_check) { |
| 1679 | MaybeRecordImplicitNullCheck(instruction); |
| 1680 | } |
| 1681 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1682 | if (type == DataType::Type::kInt8) { |
| 1683 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1684 | } |
| 1685 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1686 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1687 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1688 | { |
| 1689 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1690 | __ ldarh(Register(dst), base); |
| 1691 | if (needs_null_check) { |
| 1692 | MaybeRecordImplicitNullCheck(instruction); |
| 1693 | } |
| 1694 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1695 | if (type == DataType::Type::kInt16) { |
| 1696 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 1697 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1698 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1699 | case DataType::Type::kInt32: |
| 1700 | case DataType::Type::kReference: |
| 1701 | case DataType::Type::kInt64: |
| 1702 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1703 | { |
| 1704 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1705 | __ ldar(Register(dst), base); |
| 1706 | if (needs_null_check) { |
| 1707 | MaybeRecordImplicitNullCheck(instruction); |
| 1708 | } |
| 1709 | } |
| 1710 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1711 | case DataType::Type::kFloat32: |
| 1712 | case DataType::Type::kFloat64: { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1713 | DCHECK(dst.IsFPRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1714 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1715 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1716 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1717 | { |
| 1718 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1719 | __ ldar(temp, base); |
| 1720 | if (needs_null_check) { |
| 1721 | MaybeRecordImplicitNullCheck(instruction); |
| 1722 | } |
| 1723 | } |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1724 | __ Fmov(VRegister(dst), temp); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1725 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1726 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1727 | case DataType::Type::kUint32: |
| 1728 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1729 | case DataType::Type::kVoid: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1730 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1731 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1732 | } |
| 1733 | } |
| 1734 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1735 | void CodeGeneratorARM64::Store(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1736 | CPURegister src, |
| 1737 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1738 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1739 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1740 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1741 | case DataType::Type::kInt8: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1742 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1743 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1744 | case DataType::Type::kUint16: |
| 1745 | case DataType::Type::kInt16: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1746 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1747 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1748 | case DataType::Type::kInt32: |
| 1749 | case DataType::Type::kReference: |
| 1750 | case DataType::Type::kInt64: |
| 1751 | case DataType::Type::kFloat32: |
| 1752 | case DataType::Type::kFloat64: |
| 1753 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1754 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1755 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1756 | case DataType::Type::kUint32: |
| 1757 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1758 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1759 | LOG(FATAL) << "Unreachable type " << type; |
| 1760 | } |
| 1761 | } |
| 1762 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1763 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1764 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1765 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1766 | const MemOperand& dst, |
| 1767 | bool needs_null_check) { |
| 1768 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1769 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1770 | Register temp_base = temps.AcquireX(); |
| 1771 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1772 | DCHECK(!dst.IsPreIndex()); |
| 1773 | DCHECK(!dst.IsPostIndex()); |
| 1774 | |
| 1775 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1776 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1777 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1778 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1779 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1780 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1781 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1782 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1783 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1784 | { |
| 1785 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1786 | __ stlrb(Register(src), base); |
| 1787 | if (needs_null_check) { |
| 1788 | MaybeRecordImplicitNullCheck(instruction); |
| 1789 | } |
| 1790 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1791 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1792 | case DataType::Type::kUint16: |
| 1793 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1794 | { |
| 1795 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1796 | __ stlrh(Register(src), base); |
| 1797 | if (needs_null_check) { |
| 1798 | MaybeRecordImplicitNullCheck(instruction); |
| 1799 | } |
| 1800 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1801 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1802 | case DataType::Type::kInt32: |
| 1803 | case DataType::Type::kReference: |
| 1804 | case DataType::Type::kInt64: |
| 1805 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1806 | { |
| 1807 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1808 | __ stlr(Register(src), base); |
| 1809 | if (needs_null_check) { |
| 1810 | MaybeRecordImplicitNullCheck(instruction); |
| 1811 | } |
| 1812 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1813 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1814 | case DataType::Type::kFloat32: |
| 1815 | case DataType::Type::kFloat64: { |
| 1816 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1817 | Register temp_src; |
| 1818 | if (src.IsZero()) { |
| 1819 | // The zero register is used to avoid synthesizing zero constants. |
| 1820 | temp_src = Register(src); |
| 1821 | } else { |
| 1822 | DCHECK(src.IsFPRegister()); |
| 1823 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1824 | __ Fmov(temp_src, VRegister(src)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1825 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1826 | { |
| 1827 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1828 | __ stlr(temp_src, base); |
| 1829 | if (needs_null_check) { |
| 1830 | MaybeRecordImplicitNullCheck(instruction); |
| 1831 | } |
| 1832 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1833 | break; |
| 1834 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1835 | case DataType::Type::kUint32: |
| 1836 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1837 | case DataType::Type::kVoid: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1838 | LOG(FATAL) << "Unreachable type " << type; |
| 1839 | } |
| 1840 | } |
| 1841 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1842 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1843 | HInstruction* instruction, |
| 1844 | uint32_t dex_pc, |
| 1845 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1846 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1847 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1848 | ThreadOffset64 entrypoint_offset = GetThreadOffset<kArm64PointerSize>(entrypoint); |
| 1849 | // Reduce code size for AOT by using shared trampolines for slow path runtime calls across the |
| 1850 | // entire oat file. This adds an extra branch and we do not want to slow down the main path. |
| 1851 | // 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] | 1852 | if (slow_path == nullptr || GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1853 | __ Ldr(lr, MemOperand(tr, entrypoint_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1854 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 1855 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1856 | __ blr(lr); |
| 1857 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1858 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1859 | } |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1860 | } else { |
| 1861 | // Ensure the pc position is recorded immediately after the `bl` instruction. |
| 1862 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1863 | EmitEntrypointThunkCall(entrypoint_offset); |
| 1864 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1865 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1866 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1867 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1868 | } |
| 1869 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1870 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1871 | HInstruction* instruction, |
| 1872 | SlowPathCode* slow_path) { |
| 1873 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1874 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1875 | __ Blr(lr); |
| 1876 | } |
| 1877 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1878 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1879 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1880 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1881 | Register temp = temps.AcquireW(); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1882 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
Vladimir Marko | 2bb44fe | 2019-10-04 12:28:14 +0100 | [diff] [blame] | 1883 | const size_t status_byte_offset = |
| 1884 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 1885 | constexpr uint32_t shifted_visibly_initialized_value = |
| 1886 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1887 | |
Vladimir Marko | 2bb44fe | 2019-10-04 12:28:14 +0100 | [diff] [blame] | 1888 | // CMP (immediate) is limited to imm12 or imm12<<12, so we would need to materialize |
| 1889 | // the constant 0xf0000000 for comparison with the full 32-bit field. To reduce the code |
| 1890 | // size, load only the high byte of the field and compare with 0xf0. |
| 1891 | // Note: The same code size could be achieved with LDR+MNV(asr #24)+CBNZ but benchmarks |
| 1892 | // show that this pattern is slower (tested on little cores). |
| 1893 | __ Ldrb(temp, HeapOperand(class_reg, status_byte_offset)); |
| 1894 | __ Cmp(temp, shifted_visibly_initialized_value); |
| 1895 | __ B(lo, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1896 | __ Bind(slow_path->GetExitLabel()); |
| 1897 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1898 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 1899 | void InstructionCodeGeneratorARM64::GenerateBitstringTypeCheckCompare( |
| 1900 | HTypeCheckInstruction* check, vixl::aarch64::Register temp) { |
| 1901 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 1902 | uint32_t mask = check->GetBitstringMask(); |
| 1903 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 1904 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 1905 | |
| 1906 | if (mask_bits == 16u) { |
| 1907 | // Load only the bitstring part of the status word. |
| 1908 | __ Ldrh(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1909 | } else { |
| 1910 | // /* uint32_t */ temp = temp->status_ |
| 1911 | __ Ldr(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1912 | // Extract the bitstring bits. |
| 1913 | __ Ubfx(temp, temp, 0, mask_bits); |
| 1914 | } |
| 1915 | // Compare the bitstring bits to `path_to_root`. |
| 1916 | __ Cmp(temp, path_to_root); |
| 1917 | } |
| 1918 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1919 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1920 | BarrierType type = BarrierAll; |
| 1921 | |
| 1922 | switch (kind) { |
| 1923 | case MemBarrierKind::kAnyAny: |
| 1924 | case MemBarrierKind::kAnyStore: { |
| 1925 | type = BarrierAll; |
| 1926 | break; |
| 1927 | } |
| 1928 | case MemBarrierKind::kLoadAny: { |
| 1929 | type = BarrierReads; |
| 1930 | break; |
| 1931 | } |
| 1932 | case MemBarrierKind::kStoreStore: { |
| 1933 | type = BarrierWrites; |
| 1934 | break; |
| 1935 | } |
| 1936 | default: |
| 1937 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1938 | } |
| 1939 | __ Dmb(InnerShareable, type); |
| 1940 | } |
| 1941 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1942 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1943 | HBasicBlock* successor) { |
| 1944 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1945 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1946 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1947 | slow_path = |
| 1948 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1949 | instruction->SetSlowPath(slow_path); |
| 1950 | codegen_->AddSlowPath(slow_path); |
| 1951 | if (successor != nullptr) { |
| 1952 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1953 | } |
| 1954 | } else { |
| 1955 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1956 | } |
| 1957 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1958 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1959 | Register temp = temps.AcquireW(); |
| 1960 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1961 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1962 | if (successor == nullptr) { |
| 1963 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1964 | __ Bind(slow_path->GetReturnLabel()); |
| 1965 | } else { |
| 1966 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1967 | __ B(slow_path->GetEntryLabel()); |
| 1968 | // slow_path will return to GetLabelOf(successor). |
| 1969 | } |
| 1970 | } |
| 1971 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1972 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1973 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1974 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1975 | assembler_(codegen->GetAssembler()), |
| 1976 | codegen_(codegen) {} |
| 1977 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1978 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1979 | DCHECK_EQ(instr->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1980 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1981 | DataType::Type type = instr->GetResultType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1982 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1983 | case DataType::Type::kInt32: |
| 1984 | case DataType::Type::kInt64: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1985 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1986 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1987 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1988 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1989 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1990 | case DataType::Type::kFloat32: |
| 1991 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1992 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1993 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1994 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1995 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1996 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1997 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1998 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1999 | } |
| 2000 | } |
| 2001 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2002 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2003 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2004 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2005 | |
| 2006 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2007 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2008 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2009 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2010 | object_field_get_with_read_barrier |
| 2011 | ? LocationSummary::kCallOnSlowPath |
| 2012 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2013 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2014 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 2015 | // We need a temporary register for the read barrier load in |
| 2016 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2017 | // only if the field is volatile or the offset is too big. |
| 2018 | if (field_info.IsVolatile() || |
| 2019 | field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2020 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2021 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2022 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2023 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2024 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2025 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2026 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2027 | // The output overlaps for an object field get when read barriers |
| 2028 | // are enabled: we do not want the load to overwrite the object's |
| 2029 | // location, as we need it to emit the read barrier. |
| 2030 | locations->SetOut( |
| 2031 | Location::RequiresRegister(), |
| 2032 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2037 | const FieldInfo& field_info) { |
| 2038 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2039 | LocationSummary* locations = instruction->GetLocations(); |
| 2040 | Location base_loc = locations->InAt(0); |
| 2041 | Location out = locations->Out(); |
| 2042 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2043 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 2044 | DataType::Type load_type = instruction->GetType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2045 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2046 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2047 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2048 | load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2049 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2050 | // /* HeapReference<Object> */ out = *(base + offset) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2051 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2052 | Location maybe_temp = |
| 2053 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2054 | // Note that potential implicit null checks are handled in this |
| 2055 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2056 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2057 | instruction, |
| 2058 | out, |
| 2059 | base, |
| 2060 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2061 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2062 | /* needs_null_check= */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2063 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2064 | } else { |
| 2065 | // General case. |
| 2066 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2067 | // Note that a potential implicit null check is handled in this |
| 2068 | // CodeGeneratorARM64::LoadAcquire call. |
| 2069 | // NB: LoadAcquire will record the pc info if needed. |
| 2070 | codegen_->LoadAcquire( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2071 | instruction, OutputCPURegister(instruction), field, /* needs_null_check= */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2072 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2073 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2074 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2075 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2076 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2077 | } |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2078 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2079 | // If read barriers are enabled, emit read barriers other than |
| 2080 | // Baker's using a slow path (and also unpoison the loaded |
| 2081 | // reference, if heap poisoning is enabled). |
| 2082 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2083 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2084 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2088 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2089 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2090 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2091 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2092 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2093 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2094 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2095 | } else { |
| 2096 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2097 | } |
| 2098 | } |
| 2099 | |
| 2100 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2101 | const FieldInfo& field_info, |
| 2102 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2103 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2104 | |
| 2105 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2106 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2107 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2108 | Offset offset = field_info.GetFieldOffset(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2109 | DataType::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2110 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2111 | { |
| 2112 | // We use a block to end the scratch scope before the write barrier, thus |
| 2113 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2114 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2115 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2116 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2117 | DCHECK(value.IsW()); |
| 2118 | Register temp = temps.AcquireW(); |
| 2119 | __ Mov(temp, value.W()); |
| 2120 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2121 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2122 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2123 | |
| 2124 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2125 | codegen_->StoreRelease( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2126 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check= */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2127 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2128 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2129 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2130 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2131 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2132 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2136 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2137 | } |
| 2138 | } |
| 2139 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2140 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2141 | DataType::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2142 | |
| 2143 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2144 | case DataType::Type::kInt32: |
| 2145 | case DataType::Type::kInt64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2146 | Register dst = OutputRegister(instr); |
| 2147 | Register lhs = InputRegisterAt(instr, 0); |
| 2148 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2149 | if (instr->IsAdd()) { |
| 2150 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2151 | } else if (instr->IsAnd()) { |
| 2152 | __ And(dst, lhs, rhs); |
| 2153 | } else if (instr->IsOr()) { |
| 2154 | __ Orr(dst, lhs, rhs); |
| 2155 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2156 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2157 | } else if (instr->IsRor()) { |
| 2158 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2159 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2160 | __ Ror(dst, lhs, shift); |
| 2161 | } else { |
| 2162 | // Ensure shift distance is in the same size register as the result. If |
| 2163 | // we are rotating a long and the shift comes in a w register originally, |
| 2164 | // we don't need to sxtw for use as an x since the shift distances are |
| 2165 | // all & reg_bits - 1. |
| 2166 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2167 | } |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2168 | } else if (instr->IsMin() || instr->IsMax()) { |
| 2169 | __ Cmp(lhs, rhs); |
| 2170 | __ Csel(dst, lhs, rhs, instr->IsMin() ? lt : gt); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2171 | } else { |
| 2172 | DCHECK(instr->IsXor()); |
| 2173 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2174 | } |
| 2175 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2176 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2177 | case DataType::Type::kFloat32: |
| 2178 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 2179 | VRegister dst = OutputFPRegister(instr); |
| 2180 | VRegister lhs = InputFPRegisterAt(instr, 0); |
| 2181 | VRegister rhs = InputFPRegisterAt(instr, 1); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2182 | if (instr->IsAdd()) { |
| 2183 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2184 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2185 | __ Fsub(dst, lhs, rhs); |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2186 | } else if (instr->IsMin()) { |
| 2187 | __ Fmin(dst, lhs, rhs); |
| 2188 | } else if (instr->IsMax()) { |
| 2189 | __ Fmax(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2190 | } else { |
| 2191 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2192 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2193 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2194 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2195 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2196 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2197 | } |
| 2198 | } |
| 2199 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2200 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2201 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2202 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2203 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2204 | DataType::Type type = instr->GetResultType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2205 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2206 | case DataType::Type::kInt32: |
| 2207 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2208 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2209 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2210 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2211 | break; |
| 2212 | } |
| 2213 | default: |
| 2214 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2219 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2220 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2221 | DataType::Type type = instr->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2222 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2223 | case DataType::Type::kInt32: |
| 2224 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2225 | Register dst = OutputRegister(instr); |
| 2226 | Register lhs = InputRegisterAt(instr, 0); |
| 2227 | Operand rhs = InputOperandAt(instr, 1); |
| 2228 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2229 | uint32_t shift_value = rhs.GetImmediate() & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2230 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2231 | if (instr->IsShl()) { |
| 2232 | __ Lsl(dst, lhs, shift_value); |
| 2233 | } else if (instr->IsShr()) { |
| 2234 | __ Asr(dst, lhs, shift_value); |
| 2235 | } else { |
| 2236 | __ Lsr(dst, lhs, shift_value); |
| 2237 | } |
| 2238 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2239 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2240 | |
| 2241 | if (instr->IsShl()) { |
| 2242 | __ Lsl(dst, lhs, rhs_reg); |
| 2243 | } else if (instr->IsShr()) { |
| 2244 | __ Asr(dst, lhs, rhs_reg); |
| 2245 | } else { |
| 2246 | __ Lsr(dst, lhs, rhs_reg); |
| 2247 | } |
| 2248 | } |
| 2249 | break; |
| 2250 | } |
| 2251 | default: |
| 2252 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2253 | } |
| 2254 | } |
| 2255 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2256 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2257 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2261 | HandleBinaryOp(instruction); |
| 2262 | } |
| 2263 | |
| 2264 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2265 | HandleBinaryOp(instruction); |
| 2266 | } |
| 2267 | |
| 2268 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2269 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2270 | } |
| 2271 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2272 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2273 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2274 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2275 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2276 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2277 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2278 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2279 | } |
| 2280 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2281 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2282 | Register dst = OutputRegister(instr); |
| 2283 | Register lhs = InputRegisterAt(instr, 0); |
| 2284 | Register rhs = InputRegisterAt(instr, 1); |
| 2285 | |
| 2286 | switch (instr->GetOpKind()) { |
| 2287 | case HInstruction::kAnd: |
| 2288 | __ Bic(dst, lhs, rhs); |
| 2289 | break; |
| 2290 | case HInstruction::kOr: |
| 2291 | __ Orn(dst, lhs, rhs); |
| 2292 | break; |
| 2293 | case HInstruction::kXor: |
| 2294 | __ Eon(dst, lhs, rhs); |
| 2295 | break; |
| 2296 | default: |
| 2297 | LOG(FATAL) << "Unreachable"; |
| 2298 | } |
| 2299 | } |
| 2300 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2301 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2302 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2303 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2304 | instruction->GetType() == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2305 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2306 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2307 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2308 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2309 | } else { |
| 2310 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2311 | } |
| 2312 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2313 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2314 | } |
| 2315 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2316 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2317 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2318 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2319 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2320 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2321 | Register out = OutputRegister(instruction); |
| 2322 | Register left; |
| 2323 | if (kind != HInstruction::kNeg) { |
| 2324 | left = InputRegisterAt(instruction, 0); |
| 2325 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2326 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2327 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2328 | // conversion) can have a different type from the current instruction's type, |
| 2329 | // so we manually indicate the type. |
| 2330 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2331 | Operand right_operand(0); |
| 2332 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2333 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2334 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2335 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2336 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2337 | right_operand = Operand(right_reg, |
| 2338 | helpers::ShiftFromOpKind(op_kind), |
| 2339 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | // Logical binary operations do not support extension operations in the |
| 2343 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2344 | // the extension as a separate instruction. |
| 2345 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2346 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2347 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2348 | kind != HInstruction::kNeg)); |
| 2349 | switch (kind) { |
| 2350 | case HInstruction::kAdd: |
| 2351 | __ Add(out, left, right_operand); |
| 2352 | break; |
| 2353 | case HInstruction::kAnd: |
| 2354 | __ And(out, left, right_operand); |
| 2355 | break; |
| 2356 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2357 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2358 | __ Neg(out, right_operand); |
| 2359 | break; |
| 2360 | case HInstruction::kOr: |
| 2361 | __ Orr(out, left, right_operand); |
| 2362 | break; |
| 2363 | case HInstruction::kSub: |
| 2364 | __ Sub(out, left, right_operand); |
| 2365 | break; |
| 2366 | case HInstruction::kXor: |
| 2367 | __ Eor(out, left, right_operand); |
| 2368 | break; |
| 2369 | default: |
| 2370 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2371 | UNREACHABLE(); |
| 2372 | } |
| 2373 | } |
| 2374 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2375 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2376 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2377 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2378 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2379 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2380 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2381 | } |
| 2382 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2383 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2384 | __ Add(OutputRegister(instruction), |
| 2385 | InputRegisterAt(instruction, 0), |
| 2386 | Operand(InputOperandAt(instruction, 1))); |
| 2387 | } |
| 2388 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2389 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2390 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2391 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2392 | |
| 2393 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2394 | |
| 2395 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2396 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2397 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2398 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2399 | // loop. |
| 2400 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2401 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2402 | : Location::RequiresRegister()); |
| 2403 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2404 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2405 | } |
| 2406 | |
| 2407 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2408 | HIntermediateAddressIndex* instruction) { |
| 2409 | Register index_reg = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2410 | uint32_t shift = Int64FromLocation(instruction->GetLocations()->InAt(2)); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2411 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2412 | |
| 2413 | if (shift == 0) { |
| 2414 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2415 | } else { |
| 2416 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2417 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2418 | } |
| 2419 | } |
| 2420 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2421 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2422 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2423 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2424 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2425 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2426 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2427 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2428 | // Don't allocate register for Mneg instruction. |
| 2429 | } else { |
| 2430 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2431 | Location::RequiresRegister()); |
| 2432 | } |
| 2433 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2434 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2435 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2436 | } |
| 2437 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2438 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2439 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2440 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2441 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2442 | |
| 2443 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2444 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2445 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2446 | if (instr->GetType() == DataType::Type::kInt64 && |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2447 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2448 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2449 | vixl::aarch64::Instruction* prev = |
| 2450 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2451 | if (prev->IsLoadOrStore()) { |
| 2452 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2453 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2454 | __ nop(); |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2459 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2460 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2461 | } else { |
| 2462 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2463 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2464 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2465 | __ Mneg(res, mul_left, mul_right); |
| 2466 | } else { |
| 2467 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2468 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2469 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2470 | } |
| 2471 | } |
| 2472 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2473 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2474 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2475 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2476 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2477 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2478 | object_array_get_with_read_barrier |
| 2479 | ? LocationSummary::kCallOnSlowPath |
| 2480 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2481 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2482 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2483 | if (instruction->GetIndex()->IsConstant()) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2484 | // Array loads with constant index are treated as field loads. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2485 | // We need a temporary register for the read barrier load in |
| 2486 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2487 | // only if the offset is too big. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2488 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2489 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2490 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2491 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2492 | locations->AddTemp(FixedTempLocation()); |
| 2493 | } |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2494 | } else if (!instruction->GetArray()->IsIntermediateAddress()) { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2495 | // We need a non-scratch temporary for the array data pointer in |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2496 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier() for the case with no |
| 2497 | // intermediate address. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2498 | locations->AddTemp(Location::RequiresRegister()); |
| 2499 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2500 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2501 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2502 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2503 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2504 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2505 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2506 | // The output overlaps in the case of an object array get with |
| 2507 | // read barriers enabled: we do not want the move to overwrite the |
| 2508 | // array's location, as we need it to emit the read barrier. |
| 2509 | locations->SetOut( |
| 2510 | Location::RequiresRegister(), |
| 2511 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2512 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2516 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2517 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2518 | LocationSummary* locations = instruction->GetLocations(); |
| 2519 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2520 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2521 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2522 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2523 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2524 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2525 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2526 | |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2527 | // The non-Baker read barrier instrumentation of object ArrayGet instructions |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2528 | // does not support the HIntermediateAddress instruction. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2529 | DCHECK(!((type == DataType::Type::kReference) && |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2530 | instruction->GetArray()->IsIntermediateAddress() && |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2531 | kEmitCompilerReadBarrier && |
| 2532 | !kUseBakerReadBarrier)); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2533 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2534 | if (type == DataType::Type::kReference && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2535 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2536 | // Note that a potential implicit null check is handled in the |
| 2537 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2538 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2539 | if (index.IsConstant()) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2540 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2541 | // 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] | 2542 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2543 | Location maybe_temp = |
| 2544 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2545 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2546 | out, |
| 2547 | obj.W(), |
| 2548 | offset, |
| 2549 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2550 | /* needs_null_check= */ false, |
| 2551 | /* use_load_acquire= */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2552 | } else { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2553 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2554 | instruction, out, obj.W(), offset, index, /* needs_null_check= */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2555 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2556 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2557 | // General case. |
| 2558 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2559 | Register length; |
| 2560 | if (maybe_compressed_char_at) { |
| 2561 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2562 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2563 | { |
| 2564 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2565 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2566 | |
| 2567 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2568 | DCHECK_LT(count_offset, offset); |
| 2569 | int64_t adjusted_offset = |
| 2570 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2571 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2572 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2573 | } else { |
| 2574 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2575 | } |
| 2576 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2577 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2578 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2579 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2580 | if (maybe_compressed_char_at) { |
| 2581 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2582 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2583 | "Expecting 0=compressed, 1=uncompressed"); |
| 2584 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2585 | __ Ldrb(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2586 | HeapOperand(obj, offset + Int64FromLocation(index))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2587 | __ B(&done); |
| 2588 | __ Bind(&uncompressed_load); |
| 2589 | __ Ldrh(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2590 | HeapOperand(obj, offset + (Int64FromLocation(index) << 1))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2591 | __ Bind(&done); |
| 2592 | } else { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2593 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2594 | source = HeapOperand(obj, offset); |
| 2595 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2596 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2597 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2598 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2599 | // We do not need to compute the intermediate address from the array: the |
| 2600 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2601 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2602 | if (kIsDebugBuild) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2603 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2604 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2605 | } |
| 2606 | temp = obj; |
| 2607 | } else { |
| 2608 | __ Add(temp, obj, offset); |
| 2609 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2610 | if (maybe_compressed_char_at) { |
| 2611 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2612 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2613 | "Expecting 0=compressed, 1=uncompressed"); |
| 2614 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2615 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2616 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2617 | __ B(&done); |
| 2618 | __ Bind(&uncompressed_load); |
| 2619 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2620 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2621 | __ Bind(&done); |
| 2622 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2623 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2624 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2625 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2626 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2627 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2628 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2629 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2630 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2631 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2632 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2633 | if (type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2634 | static_assert( |
| 2635 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2636 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2637 | Location obj_loc = locations->InAt(0); |
| 2638 | if (index.IsConstant()) { |
| 2639 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2640 | } else { |
| 2641 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2642 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2643 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2644 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2645 | } |
| 2646 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2647 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2648 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2649 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2650 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2654 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2655 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2656 | { |
| 2657 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2658 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2659 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2660 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2661 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2662 | // Mask out compression flag from String's array length. |
| 2663 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2664 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2665 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2666 | } |
| 2667 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2668 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2669 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2670 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2671 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2672 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2673 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2674 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2675 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2676 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2677 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2678 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2679 | } else if (DataType::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2680 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2681 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2682 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2687 | DataType::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2688 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2689 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2690 | bool needs_write_barrier = |
| 2691 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2692 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2693 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2694 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2695 | CPURegister source = value; |
| 2696 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2697 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2698 | MemOperand destination = HeapOperand(array); |
| 2699 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2700 | |
| 2701 | if (!needs_write_barrier) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2702 | DCHECK(!needs_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2703 | if (index.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2704 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2705 | destination = HeapOperand(array, offset); |
| 2706 | } else { |
| 2707 | UseScratchRegisterScope temps(masm); |
| 2708 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2709 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2710 | // We do not need to compute the intermediate address from the array: the |
| 2711 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2712 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2713 | if (kIsDebugBuild) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2714 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2715 | DCHECK(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2716 | } |
| 2717 | temp = array; |
| 2718 | } else { |
| 2719 | __ Add(temp, array, offset); |
| 2720 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2721 | destination = HeapOperand(temp, |
| 2722 | XRegisterFrom(index), |
| 2723 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2724 | DataType::SizeShift(value_type)); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2725 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2726 | { |
| 2727 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2728 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2729 | codegen_->Store(value_type, value, destination); |
| 2730 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2731 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2732 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2733 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2734 | |
| 2735 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 2736 | vixl::aarch64::Label do_store; |
| 2737 | if (can_value_be_null) { |
| 2738 | __ Cbz(Register(value), &do_store); |
| 2739 | } |
| 2740 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2741 | SlowPathCodeARM64* slow_path = nullptr; |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2742 | if (needs_type_check) { |
| 2743 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
| 2744 | codegen_->AddSlowPath(slow_path); |
| 2745 | |
| 2746 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2747 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2748 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2749 | |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2750 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2751 | Register temp = temps.AcquireSameSizeAs(array); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2752 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2753 | |
| 2754 | // Note that when Baker read barriers are enabled, the type |
| 2755 | // checks are performed without read barriers. This is fine, |
| 2756 | // even in the case where a class object is in the from-space |
| 2757 | // after the flip, as a comparison involving such a type would |
| 2758 | // not produce a false positive; it may of course produce a |
| 2759 | // false negative, in which case we would take the ArraySet |
| 2760 | // slow path. |
| 2761 | |
| 2762 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2763 | { |
| 2764 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2765 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2766 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2767 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2768 | } |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2769 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2770 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2771 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2772 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2773 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2774 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2775 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2776 | // nor `temp2`, as we are comparing two poisoned references. |
| 2777 | __ Cmp(temp, temp2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2778 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2779 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2780 | vixl::aarch64::Label do_put; |
| 2781 | __ B(eq, &do_put); |
| 2782 | // If heap poisoning is enabled, the `temp` reference has |
| 2783 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2784 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2785 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2786 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2787 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2788 | // If heap poisoning is enabled, no need to unpoison |
| 2789 | // `temp`, as we are comparing against null below. |
| 2790 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2791 | __ Bind(&do_put); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 2792 | } else { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2793 | __ B(ne, slow_path->GetEntryLabel()); |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2794 | } |
| 2795 | } |
| 2796 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2797 | codegen_->MarkGCCard(array, value.W(), /* value_can_be_null= */ false); |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2798 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2799 | if (can_value_be_null) { |
| 2800 | DCHECK(do_store.IsLinked()); |
| 2801 | __ Bind(&do_store); |
| 2802 | } |
| 2803 | |
| 2804 | UseScratchRegisterScope temps(masm); |
| 2805 | if (kPoisonHeapReferences) { |
| 2806 | Register temp_source = temps.AcquireSameSizeAs(array); |
| 2807 | DCHECK(value.IsW()); |
| 2808 | __ Mov(temp_source, value.W()); |
| 2809 | GetAssembler()->PoisonHeapReference(temp_source); |
| 2810 | source = temp_source; |
| 2811 | } |
| 2812 | |
| 2813 | if (index.IsConstant()) { |
| 2814 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
| 2815 | destination = HeapOperand(array, offset); |
| 2816 | } else { |
| 2817 | Register temp_base = temps.AcquireSameSizeAs(array); |
| 2818 | __ Add(temp_base, array, offset); |
| 2819 | destination = HeapOperand(temp_base, |
| 2820 | XRegisterFrom(index), |
| 2821 | LSL, |
| 2822 | DataType::SizeShift(value_type)); |
| 2823 | } |
| 2824 | |
| 2825 | { |
| 2826 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2827 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2828 | __ Str(source, destination); |
| 2829 | |
| 2830 | if (can_value_be_null || !needs_type_check) { |
| 2831 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2832 | } |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | if (slow_path != nullptr) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2836 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2837 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2838 | } |
| 2839 | } |
| 2840 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2841 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2842 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2843 | InvokeRuntimeCallingConvention calling_convention; |
| 2844 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 2845 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 2846 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2847 | |
| 2848 | // If both index and length are constant, we can check the bounds statically and |
| 2849 | // generate code accordingly. We want to make sure we generate constant locations |
| 2850 | // in that case, regardless of whether they are encodable in the comparison or not. |
| 2851 | HInstruction* index = instruction->InputAt(0); |
| 2852 | HInstruction* length = instruction->InputAt(1); |
| 2853 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 2854 | locations->SetInAt(0, both_const |
| 2855 | ? Location::ConstantLocation(index->AsConstant()) |
| 2856 | : ARM64EncodableConstantOrRegister(index, instruction)); |
| 2857 | locations->SetInAt(1, both_const |
| 2858 | ? Location::ConstantLocation(length->AsConstant()) |
| 2859 | : ARM64EncodableConstantOrRegister(length, instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2863 | LocationSummary* locations = instruction->GetLocations(); |
| 2864 | Location index_loc = locations->InAt(0); |
| 2865 | Location length_loc = locations->InAt(1); |
| 2866 | |
| 2867 | int cmp_first_input = 0; |
| 2868 | int cmp_second_input = 1; |
| 2869 | Condition cond = hs; |
| 2870 | |
| 2871 | if (index_loc.IsConstant()) { |
| 2872 | int64_t index = Int64FromLocation(index_loc); |
| 2873 | if (length_loc.IsConstant()) { |
| 2874 | int64_t length = Int64FromLocation(length_loc); |
| 2875 | if (index < 0 || index >= length) { |
| 2876 | BoundsCheckSlowPathARM64* slow_path = |
| 2877 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
| 2878 | codegen_->AddSlowPath(slow_path); |
| 2879 | __ B(slow_path->GetEntryLabel()); |
| 2880 | } else { |
| 2881 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 2882 | // However, some optimization after BCE may have generated this, and we should not |
| 2883 | // generate a bounds check if it is a valid range. |
| 2884 | } |
| 2885 | return; |
| 2886 | } |
| 2887 | // Only the index is constant: change the order of the operands and commute the condition |
| 2888 | // so we can use an immediate constant for the index (only the second input to a cmp |
| 2889 | // instruction can be an immediate). |
| 2890 | cmp_first_input = 1; |
| 2891 | cmp_second_input = 0; |
| 2892 | cond = ls; |
| 2893 | } |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2894 | BoundsCheckSlowPathARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2895 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2896 | __ Cmp(InputRegisterAt(instruction, cmp_first_input), |
| 2897 | InputOperandAt(instruction, cmp_second_input)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2898 | codegen_->AddSlowPath(slow_path); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2899 | __ B(slow_path->GetEntryLabel(), cond); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2900 | } |
| 2901 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2902 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2903 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2904 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2905 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2906 | if (check->HasUses()) { |
| 2907 | locations->SetOut(Location::SameAsFirstInput()); |
| 2908 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 2909 | // Rely on the type initialization to save everything we need. |
| 2910 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2914 | // We assume the class is not null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 2915 | SlowPathCodeARM64* slow_path = |
| 2916 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(check->GetLoadClass(), check); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2917 | codegen_->AddSlowPath(slow_path); |
| 2918 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2919 | } |
| 2920 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2921 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2922 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2923 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2924 | } |
| 2925 | |
| 2926 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 2927 | VRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2928 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2929 | if (rhs_loc.IsConstant()) { |
| 2930 | // 0.0 is the only immediate that can be encoded directly in |
| 2931 | // an FCMP instruction. |
| 2932 | // |
| 2933 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2934 | // specify that in a floating-point comparison, positive zero |
| 2935 | // and negative zero are considered equal, so we can use the |
| 2936 | // literal 0.0 for both cases here. |
| 2937 | // |
| 2938 | // Note however that some methods (Float.equal, Float.compare, |
| 2939 | // Float.compareTo, Double.equal, Double.compare, |
| 2940 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2941 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2942 | // -0.0. So if we ever translate calls to these methods into a |
| 2943 | // HCompare instruction, we must handle the -0.0 case with |
| 2944 | // care here. |
| 2945 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2946 | __ Fcmp(lhs_reg, 0.0); |
| 2947 | } else { |
| 2948 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2949 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2950 | } |
| 2951 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2952 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2953 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2954 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2955 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2956 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2957 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2958 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2959 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2960 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2961 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2962 | case DataType::Type::kInt32: |
| 2963 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2964 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2965 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2966 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2967 | break; |
| 2968 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2969 | case DataType::Type::kFloat32: |
| 2970 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2971 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2972 | locations->SetInAt(1, |
| 2973 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2974 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2975 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2976 | locations->SetOut(Location::RequiresRegister()); |
| 2977 | break; |
| 2978 | } |
| 2979 | default: |
| 2980 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2985 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2986 | |
| 2987 | // 0 if: left == right |
| 2988 | // 1 if: left > right |
| 2989 | // -1 if: left < right |
| 2990 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2991 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2992 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2993 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2994 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2995 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2996 | case DataType::Type::kInt32: |
| 2997 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2998 | Register result = OutputRegister(compare); |
| 2999 | Register left = InputRegisterAt(compare, 0); |
| 3000 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3001 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3002 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3003 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3004 | break; |
| 3005 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3006 | case DataType::Type::kFloat32: |
| 3007 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3008 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3009 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3010 | __ Cset(result, ne); |
| 3011 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3012 | break; |
| 3013 | } |
| 3014 | default: |
| 3015 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3016 | } |
| 3017 | } |
| 3018 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3019 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3020 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3021 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3022 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3023 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3024 | locations->SetInAt(1, |
| 3025 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3026 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3027 | : Location::RequiresFpuRegister()); |
| 3028 | } else { |
| 3029 | // Integer cases. |
| 3030 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3031 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3032 | } |
| 3033 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3034 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3035 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3036 | } |
| 3037 | } |
| 3038 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3039 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3040 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3041 | return; |
| 3042 | } |
| 3043 | |
| 3044 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3045 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3046 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3047 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3048 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3049 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3050 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3051 | } else { |
| 3052 | // Integer cases. |
| 3053 | Register lhs = InputRegisterAt(instruction, 0); |
| 3054 | Operand rhs = InputOperandAt(instruction, 1); |
| 3055 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3056 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3057 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3061 | M(Equal) \ |
| 3062 | M(NotEqual) \ |
| 3063 | M(LessThan) \ |
| 3064 | M(LessThanOrEqual) \ |
| 3065 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3066 | M(GreaterThanOrEqual) \ |
| 3067 | M(Below) \ |
| 3068 | M(BelowOrEqual) \ |
| 3069 | M(Above) \ |
| 3070 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3071 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3072 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3073 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3074 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3075 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3076 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3077 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3078 | void InstructionCodeGeneratorARM64::GenerateIntDivForPower2Denom(HDiv* instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3079 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3080 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3081 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 3082 | |
| 3083 | Register out = OutputRegister(instruction); |
| 3084 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3085 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3086 | Register final_dividend; |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3087 | if (HasNonNegativeOrMinIntInputAt(instruction, 0)) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3088 | // No need to adjust the result for non-negative dividends or the INT32_MIN/INT64_MIN dividends. |
| 3089 | // NOTE: The generated code for HDiv correctly works for the INT32_MIN/INT64_MIN dividends: |
| 3090 | // imm == 2 |
| 3091 | // add out, dividend(0x80000000), dividend(0x80000000), lsr #31 => out = 0x80000001 |
| 3092 | // asr out, out(0x80000001), #1 => out = 0xc0000000 |
| 3093 | // This is the same as 'asr out, 0x80000000, #1' |
| 3094 | // |
| 3095 | // imm > 2 |
| 3096 | // add temp, dividend(0x80000000), imm - 1 => temp = 0b10..01..1, where the number |
| 3097 | // of the rightmost 1s is ctz_imm. |
| 3098 | // cmp dividend(0x80000000), 0 => N = 1, V = 0 (lt is true) |
| 3099 | // csel out, temp(0b10..01..1), dividend(0x80000000), lt => out = 0b10..01..1 |
| 3100 | // asr out, out(0b10..01..1), #ctz_imm => out = 0b1..10..0, where the number of the |
| 3101 | // leftmost 1s is ctz_imm + 1. |
| 3102 | // This is the same as 'asr out, dividend(0x80000000), #ctz_imm'. |
| 3103 | // |
| 3104 | // imm == INT32_MIN |
| 3105 | // add tmp, dividend(0x80000000), #0x7fffffff => tmp = -1 |
| 3106 | // cmp dividend(0x80000000), 0 => N = 1, V = 0 (lt is true) |
| 3107 | // csel out, temp(-1), dividend(0x80000000), lt => out = -1 |
| 3108 | // neg out, out(-1), asr #31 => out = 1 |
| 3109 | // This is the same as 'neg out, dividend(0x80000000), asr #31'. |
| 3110 | final_dividend = dividend; |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3111 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3112 | if (abs_imm == 2) { |
| 3113 | int bits = DataType::Size(instruction->GetResultType()) * kBitsPerByte; |
| 3114 | __ Add(out, dividend, Operand(dividend, LSR, bits - 1)); |
| 3115 | } else { |
| 3116 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3117 | Register temp = temps.AcquireSameSizeAs(out); |
| 3118 | __ Add(temp, dividend, abs_imm - 1); |
| 3119 | __ Cmp(dividend, 0); |
| 3120 | __ Csel(out, temp, dividend, lt); |
| 3121 | } |
| 3122 | final_dividend = out; |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3123 | } |
| 3124 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3125 | int ctz_imm = CTZ(abs_imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3126 | if (imm > 0) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3127 | __ Asr(out, final_dividend, ctz_imm); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3128 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3129 | __ Neg(out, Operand(final_dividend, ASR, ctz_imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3130 | } |
| 3131 | } |
| 3132 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3133 | // Return true if the magic number was modified by subtracting 2^32(Int32 div) or 2^64(Int64 div). |
| 3134 | // So dividend needs to be added. |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3135 | static inline bool NeedToAddDividend(int64_t magic_number, int64_t divisor) { |
| 3136 | return divisor > 0 && magic_number < 0; |
| 3137 | } |
| 3138 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3139 | // Return true if the magic number was modified by adding 2^32(Int32 div) or 2^64(Int64 div). |
| 3140 | // So dividend needs to be subtracted. |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3141 | static inline bool NeedToSubDividend(int64_t magic_number, int64_t divisor) { |
| 3142 | return divisor < 0 && magic_number > 0; |
| 3143 | } |
| 3144 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3145 | // Generate code which increments the value in register 'in' by 1 if the value is negative. |
| 3146 | // It is done with 'add out, in, in, lsr #31 or #63'. |
| 3147 | // If the value is a result of an operation setting the N flag, CINC MI can be used |
| 3148 | // instead of ADD. 'use_cond_inc' controls this. |
| 3149 | void InstructionCodeGeneratorARM64::GenerateIncrementNegativeByOne( |
| 3150 | Register out, |
| 3151 | Register in, |
| 3152 | bool use_cond_inc) { |
| 3153 | if (use_cond_inc) { |
| 3154 | __ Cinc(out, in, mi); |
| 3155 | } else { |
| 3156 | __ Add(out, in, Operand(in, LSR, in.GetSizeInBits() - 1)); |
| 3157 | } |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3158 | } |
| 3159 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3160 | // Helper to generate code producing the result of HRem with a constant divisor. |
| 3161 | void InstructionCodeGeneratorARM64::GenerateResultRemWithAnyConstant( |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3162 | Register out, |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3163 | Register dividend, |
| 3164 | Register quotient, |
| 3165 | int64_t divisor, |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3166 | UseScratchRegisterScope* temps_scope) { |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3167 | Register temp_imm = temps_scope->AcquireSameSizeAs(out); |
| 3168 | __ Mov(temp_imm, divisor); |
| 3169 | __ Msub(out, quotient, temp_imm, dividend); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3170 | } |
| 3171 | |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3172 | // Helper to generate code for HDiv/HRem instructions when a dividend is non-negative and |
| 3173 | // a divisor is a positive constant, not power of 2. |
| 3174 | void InstructionCodeGeneratorARM64::GenerateInt64UnsignedDivRemWithAnyPositiveConstant( |
| 3175 | HBinaryOperation* instruction) { |
| 3176 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3177 | DCHECK(instruction->GetResultType() == DataType::Type::kInt64); |
| 3178 | |
| 3179 | LocationSummary* locations = instruction->GetLocations(); |
| 3180 | Location second = locations->InAt(1); |
| 3181 | DCHECK(second.IsConstant()); |
| 3182 | |
| 3183 | Register out = OutputRegister(instruction); |
| 3184 | Register dividend = InputRegisterAt(instruction, 0); |
| 3185 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3186 | DCHECK_GT(imm, 0); |
| 3187 | |
| 3188 | int64_t magic; |
| 3189 | int shift; |
| 3190 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ true, &magic, &shift); |
| 3191 | |
| 3192 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3193 | Register temp = temps.AcquireSameSizeAs(out); |
| 3194 | |
| 3195 | auto generate_unsigned_div_code = [this, magic, shift](Register out, |
| 3196 | Register dividend, |
| 3197 | Register temp) { |
| 3198 | // temp = get_high(dividend * magic) |
| 3199 | __ Mov(temp, magic); |
| 3200 | if (magic > 0 && shift == 0) { |
| 3201 | __ Smulh(out, dividend, temp); |
| 3202 | } else { |
| 3203 | __ Smulh(temp, dividend, temp); |
| 3204 | if (magic < 0) { |
| 3205 | // The negative magic means that the multiplier m is greater than INT64_MAX. |
| 3206 | // In such a case shift is never 0. See the proof in |
| 3207 | // InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant. |
| 3208 | __ Add(temp, temp, dividend); |
| 3209 | } |
| 3210 | DCHECK_NE(shift, 0); |
| 3211 | __ Lsr(out, temp, shift); |
| 3212 | } |
| 3213 | }; |
| 3214 | |
| 3215 | if (instruction->IsDiv()) { |
| 3216 | generate_unsigned_div_code(out, dividend, temp); |
| 3217 | } else { |
| 3218 | generate_unsigned_div_code(temp, dividend, temp); |
| 3219 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3220 | } |
| 3221 | } |
| 3222 | |
| 3223 | // Helper to generate code for HDiv/HRem instructions for any dividend and a constant divisor |
| 3224 | // (not power of 2). |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3225 | void InstructionCodeGeneratorARM64::GenerateInt64DivRemWithAnyConstant( |
| 3226 | HBinaryOperation* instruction) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3227 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3228 | DCHECK(instruction->GetResultType() == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3229 | |
| 3230 | LocationSummary* locations = instruction->GetLocations(); |
| 3231 | Location second = locations->InAt(1); |
| 3232 | DCHECK(second.IsConstant()); |
| 3233 | |
| 3234 | Register out = OutputRegister(instruction); |
| 3235 | Register dividend = InputRegisterAt(instruction, 0); |
| 3236 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3237 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3238 | int64_t magic; |
| 3239 | int shift; |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3240 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ true, &magic, &shift); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3241 | |
| 3242 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3243 | Register temp = temps.AcquireSameSizeAs(out); |
| 3244 | |
| 3245 | // temp = get_high(dividend * magic) |
| 3246 | __ Mov(temp, magic); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3247 | __ Smulh(temp, dividend, temp); |
| 3248 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3249 | // The multiplication result might need some corrections to be finalized. |
| 3250 | // The last correction is to increment by 1, if the result is negative. |
| 3251 | // Currently it is done with 'add result, temp_result, temp_result, lsr #31 or #63'. |
| 3252 | // Such ADD usually has latency 2, e.g. on Cortex-A55. |
| 3253 | // However if one of the corrections is ADD or SUB, the sign can be detected |
| 3254 | // with ADDS/SUBS. They set the N flag if the result is negative. |
| 3255 | // This allows to use CINC MI which has latency 1. |
| 3256 | bool use_cond_inc = false; |
| 3257 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3258 | // Some combinations of magic_number and the divisor require to correct the result. |
| 3259 | // Check whether the correction is needed. |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3260 | if (NeedToAddDividend(magic, imm)) { |
| 3261 | __ Adds(temp, temp, dividend); |
| 3262 | use_cond_inc = true; |
| 3263 | } else if (NeedToSubDividend(magic, imm)) { |
| 3264 | __ Subs(temp, temp, dividend); |
| 3265 | use_cond_inc = true; |
| 3266 | } |
| 3267 | |
| 3268 | if (shift != 0) { |
| 3269 | __ Asr(temp, temp, shift); |
| 3270 | } |
| 3271 | |
| 3272 | if (instruction->IsRem()) { |
| 3273 | GenerateIncrementNegativeByOne(temp, temp, use_cond_inc); |
| 3274 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3275 | } else { |
| 3276 | GenerateIncrementNegativeByOne(out, temp, use_cond_inc); |
| 3277 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | void InstructionCodeGeneratorARM64::GenerateInt32DivRemWithAnyConstant( |
| 3281 | HBinaryOperation* instruction) { |
| 3282 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3283 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 3284 | |
| 3285 | LocationSummary* locations = instruction->GetLocations(); |
| 3286 | Location second = locations->InAt(1); |
| 3287 | DCHECK(second.IsConstant()); |
| 3288 | |
| 3289 | Register out = OutputRegister(instruction); |
| 3290 | Register dividend = InputRegisterAt(instruction, 0); |
| 3291 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3292 | |
| 3293 | int64_t magic; |
| 3294 | int shift; |
| 3295 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| 3296 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3297 | Register temp = temps.AcquireSameSizeAs(out); |
| 3298 | |
| 3299 | // temp = get_high(dividend * magic) |
| 3300 | __ Mov(temp, magic); |
| 3301 | __ Smull(temp.X(), dividend, temp); |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3302 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3303 | // The multiplication result might need some corrections to be finalized. |
| 3304 | // The last correction is to increment by 1, if the result is negative. |
| 3305 | // Currently it is done with 'add result, temp_result, temp_result, lsr #31 or #63'. |
| 3306 | // Such ADD usually has latency 2, e.g. on Cortex-A55. |
| 3307 | // However if one of the corrections is ADD or SUB, the sign can be detected |
| 3308 | // with ADDS/SUBS. They set the N flag if the result is negative. |
| 3309 | // This allows to use CINC MI which has latency 1. |
| 3310 | bool use_cond_inc = false; |
| 3311 | |
| 3312 | // ADD/SUB correction is performed in the high 32 bits |
| 3313 | // as high 32 bits are ignored because type are kInt32. |
| 3314 | if (NeedToAddDividend(magic, imm)) { |
| 3315 | __ Adds(temp.X(), temp.X(), Operand(dividend.X(), LSL, 32)); |
| 3316 | use_cond_inc = true; |
| 3317 | } else if (NeedToSubDividend(magic, imm)) { |
| 3318 | __ Subs(temp.X(), temp.X(), Operand(dividend.X(), LSL, 32)); |
| 3319 | use_cond_inc = true; |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3320 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3321 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3322 | // Extract the result from the high 32 bits and apply the final right shift. |
| 3323 | DCHECK_LT(shift, 32); |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3324 | if (imm > 0 && HasNonNegativeInputAt(instruction, 0)) { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 3325 | // No need to adjust the result for a non-negative dividend and a positive divisor. |
| 3326 | if (instruction->IsDiv()) { |
| 3327 | __ Lsr(out.X(), temp.X(), 32 + shift); |
| 3328 | } else { |
| 3329 | __ Lsr(temp.X(), temp.X(), 32 + shift); |
| 3330 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3331 | } |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3332 | } else { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 3333 | __ Asr(temp.X(), temp.X(), 32 + shift); |
| 3334 | |
| 3335 | if (instruction->IsRem()) { |
| 3336 | GenerateIncrementNegativeByOne(temp, temp, use_cond_inc); |
| 3337 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3338 | } else { |
| 3339 | GenerateIncrementNegativeByOne(out, temp, use_cond_inc); |
| 3340 | } |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3341 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3342 | } |
| 3343 | |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3344 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction, |
| 3345 | int64_t divisor) { |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3346 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3347 | if (instruction->GetResultType() == DataType::Type::kInt64) { |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3348 | if (divisor > 0 && HasNonNegativeInputAt(instruction, 0)) { |
| 3349 | GenerateInt64UnsignedDivRemWithAnyPositiveConstant(instruction); |
| 3350 | } else { |
| 3351 | GenerateInt64DivRemWithAnyConstant(instruction); |
| 3352 | } |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3353 | } else { |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3354 | GenerateInt32DivRemWithAnyConstant(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3355 | } |
| 3356 | } |
| 3357 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3358 | void InstructionCodeGeneratorARM64::GenerateIntDivForConstDenom(HDiv *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3359 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3360 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3361 | if (imm == 0) { |
| 3362 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3363 | return; |
| 3364 | } |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3365 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3366 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3367 | GenerateIntDivForPower2Denom(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3368 | } else { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3369 | // Cases imm == -1 or imm == 1 are handled by InstructionSimplifier. |
| 3370 | DCHECK(imm < -2 || imm > 2) << imm; |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 3371 | GenerateDivRemWithAnyConstant(instruction, imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3372 | } |
| 3373 | } |
| 3374 | |
| 3375 | void InstructionCodeGeneratorARM64::GenerateIntDiv(HDiv *instruction) { |
| 3376 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 3377 | << instruction->GetResultType(); |
| 3378 | |
| 3379 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 3380 | GenerateIntDivForConstDenom(instruction); |
| 3381 | } else { |
| 3382 | Register out = OutputRegister(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3383 | Register dividend = InputRegisterAt(instruction, 0); |
| 3384 | Register divisor = InputRegisterAt(instruction, 1); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3385 | __ Sdiv(out, dividend, divisor); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3386 | } |
| 3387 | } |
| 3388 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3389 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3390 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3391 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3392 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3393 | case DataType::Type::kInt32: |
| 3394 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3395 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3396 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3397 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3398 | break; |
| 3399 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3400 | case DataType::Type::kFloat32: |
| 3401 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3402 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3403 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3404 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3405 | break; |
| 3406 | |
| 3407 | default: |
| 3408 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3409 | } |
| 3410 | } |
| 3411 | |
| 3412 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3413 | DataType::Type type = div->GetResultType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3414 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3415 | case DataType::Type::kInt32: |
| 3416 | case DataType::Type::kInt64: |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3417 | GenerateIntDiv(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3418 | break; |
| 3419 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3420 | case DataType::Type::kFloat32: |
| 3421 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3422 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3423 | break; |
| 3424 | |
| 3425 | default: |
| 3426 | LOG(FATAL) << "Unexpected div type " << type; |
| 3427 | } |
| 3428 | } |
| 3429 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3430 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3431 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3432 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3433 | } |
| 3434 | |
| 3435 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3436 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3437 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3438 | codegen_->AddSlowPath(slow_path); |
| 3439 | Location value = instruction->GetLocations()->InAt(0); |
| 3440 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3441 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3442 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3443 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3444 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3445 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3446 | } |
| 3447 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3448 | if (value.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3449 | int64_t divisor = Int64FromLocation(value); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3450 | if (divisor == 0) { |
| 3451 | __ B(slow_path->GetEntryLabel()); |
| 3452 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3453 | // A division by a non-null constant is valid. We don't need to perform |
| 3454 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3455 | } |
| 3456 | } else { |
| 3457 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3458 | } |
| 3459 | } |
| 3460 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3461 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3462 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3463 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3464 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3465 | } |
| 3466 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3467 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3468 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3469 | // Will be generated at use site. |
| 3470 | } |
| 3471 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3472 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3473 | exit->SetLocations(nullptr); |
| 3474 | } |
| 3475 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3476 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3477 | } |
| 3478 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3479 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3480 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3481 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3482 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3483 | } |
| 3484 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3485 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3486 | // Will be generated at use site. |
| 3487 | } |
| 3488 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3489 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3490 | if (successor->IsExitBlock()) { |
| 3491 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3492 | return; // no code needed |
| 3493 | } |
| 3494 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3495 | HBasicBlock* block = got->GetBlock(); |
| 3496 | HInstruction* previous = got->GetPrevious(); |
| 3497 | HLoopInformation* info = block->GetLoopInformation(); |
| 3498 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3499 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 3500 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3501 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3502 | return; |
| 3503 | } |
| 3504 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3505 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3506 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3507 | } |
| 3508 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3509 | __ B(codegen_->GetLabelOf(successor)); |
| 3510 | } |
| 3511 | } |
| 3512 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3513 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3514 | got->SetLocations(nullptr); |
| 3515 | } |
| 3516 | |
| 3517 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3518 | HandleGoto(got, got->GetSuccessor()); |
| 3519 | } |
| 3520 | |
| 3521 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3522 | try_boundary->SetLocations(nullptr); |
| 3523 | } |
| 3524 | |
| 3525 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3526 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3527 | if (!successor->IsExitBlock()) { |
| 3528 | HandleGoto(try_boundary, successor); |
| 3529 | } |
| 3530 | } |
| 3531 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3532 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3533 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3534 | vixl::aarch64::Label* true_target, |
| 3535 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3536 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3537 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3538 | if (true_target == nullptr && false_target == nullptr) { |
| 3539 | // Nothing to do. The code always falls through. |
| 3540 | return; |
| 3541 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3542 | // Constant condition, statically compared against "true" (integer value 1). |
| 3543 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3544 | if (true_target != nullptr) { |
| 3545 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3546 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3547 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3548 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3549 | if (false_target != nullptr) { |
| 3550 | __ B(false_target); |
| 3551 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3552 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3553 | return; |
| 3554 | } |
| 3555 | |
| 3556 | // The following code generates these patterns: |
| 3557 | // (1) true_target == nullptr && false_target != nullptr |
| 3558 | // - opposite condition true => branch to false_target |
| 3559 | // (2) true_target != nullptr && false_target == nullptr |
| 3560 | // - condition true => branch to true_target |
| 3561 | // (3) true_target != nullptr && false_target != nullptr |
| 3562 | // - condition true => branch to true_target |
| 3563 | // - branch to false_target |
| 3564 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3565 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3566 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3567 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3568 | if (true_target == nullptr) { |
| 3569 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3570 | } else { |
| 3571 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3572 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3573 | } else { |
| 3574 | // The condition instruction has not been materialized, use its inputs as |
| 3575 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3576 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3577 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3578 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3579 | if (DataType::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3580 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3581 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3582 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3583 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3584 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3585 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3586 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3587 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3588 | // Integer cases. |
| 3589 | Register lhs = InputRegisterAt(condition, 0); |
| 3590 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3591 | |
| 3592 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3593 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3594 | if (true_target == nullptr) { |
| 3595 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3596 | non_fallthrough_target = false_target; |
| 3597 | } else { |
| 3598 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3599 | non_fallthrough_target = true_target; |
| 3600 | } |
| 3601 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3602 | 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] | 3603 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3604 | switch (arm64_cond) { |
| 3605 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3606 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3607 | break; |
| 3608 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3609 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3610 | break; |
| 3611 | case lt: |
| 3612 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3613 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3614 | break; |
| 3615 | case ge: |
| 3616 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3617 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3618 | break; |
| 3619 | default: |
| 3620 | // Without the `static_cast` the compiler throws an error for |
| 3621 | // `-Werror=sign-promo`. |
| 3622 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3623 | } |
| 3624 | } else { |
| 3625 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3626 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3627 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3628 | } |
| 3629 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3630 | |
| 3631 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3632 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3633 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3634 | __ B(false_target); |
| 3635 | } |
| 3636 | } |
| 3637 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3638 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3639 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3640 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3641 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3642 | } |
| 3643 | } |
| 3644 | |
| 3645 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3646 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3647 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3648 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3649 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3650 | true_target = nullptr; |
| 3651 | } |
| 3652 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3653 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3654 | false_target = nullptr; |
| 3655 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3656 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3660 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3661 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3662 | InvokeRuntimeCallingConvention calling_convention; |
| 3663 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3664 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3665 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3666 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3667 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3668 | } |
| 3669 | } |
| 3670 | |
| 3671 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3672 | SlowPathCodeARM64* slow_path = |
| 3673 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3674 | GenerateTestAndBranch(deoptimize, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3675 | /* condition_input_index= */ 0, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3676 | slow_path->GetEntryLabel(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3677 | /* false_target= */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3678 | } |
| 3679 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3680 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3681 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3682 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3683 | locations->SetOut(Location::RequiresRegister()); |
| 3684 | } |
| 3685 | |
| 3686 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3687 | __ Ldr(OutputRegister(flag), |
| 3688 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3689 | } |
| 3690 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3691 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3692 | return condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3693 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3694 | } |
| 3695 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3696 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3697 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3698 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3699 | : ARM64Condition(cond); |
| 3700 | } |
| 3701 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3702 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3703 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3704 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3705 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3706 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3707 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3708 | } else { |
| 3709 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3710 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3711 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3712 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3713 | // Ask VIXL whether we should synthesize constants in registers. |
| 3714 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3715 | Operand true_op = is_true_value_constant ? |
| 3716 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3717 | Operand false_op = is_false_value_constant ? |
| 3718 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3719 | bool true_value_in_register = false; |
| 3720 | bool false_value_in_register = false; |
| 3721 | MacroAssembler::GetCselSynthesisInformation( |
| 3722 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3723 | true_value_in_register |= !is_true_value_constant; |
| 3724 | false_value_in_register |= !is_false_value_constant; |
| 3725 | |
| 3726 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3727 | : Location::ConstantLocation(cst_true_value)); |
| 3728 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3729 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3730 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3731 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3732 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3733 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3734 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3735 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3739 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3740 | Condition csel_cond; |
| 3741 | |
| 3742 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3743 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3744 | // Use the condition flags set by the previous instruction. |
| 3745 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3746 | } else { |
| 3747 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3748 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3749 | } |
| 3750 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3751 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3752 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3753 | } else { |
| 3754 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3755 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3756 | } |
| 3757 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3758 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3759 | __ Fcsel(OutputFPRegister(select), |
| 3760 | InputFPRegisterAt(select, 1), |
| 3761 | InputFPRegisterAt(select, 0), |
| 3762 | csel_cond); |
| 3763 | } else { |
| 3764 | __ Csel(OutputRegister(select), |
| 3765 | InputOperandAt(select, 1), |
| 3766 | InputOperandAt(select, 0), |
| 3767 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3768 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3769 | } |
| 3770 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3771 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3772 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3773 | } |
| 3774 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3775 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3776 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3777 | } |
| 3778 | |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3779 | void CodeGeneratorARM64::IncreaseFrame(size_t adjustment) { |
| 3780 | __ Claim(adjustment); |
| 3781 | GetAssembler()->cfi().AdjustCFAOffset(adjustment); |
| 3782 | } |
| 3783 | |
| 3784 | void CodeGeneratorARM64::DecreaseFrame(size_t adjustment) { |
| 3785 | __ Drop(adjustment); |
| 3786 | GetAssembler()->cfi().AdjustCFAOffset(-adjustment); |
| 3787 | } |
| 3788 | |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3789 | void CodeGeneratorARM64::GenerateNop() { |
| 3790 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3791 | } |
| 3792 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3793 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3794 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3795 | } |
| 3796 | |
| 3797 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3798 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3802 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3806 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3807 | } |
| 3808 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3809 | // Temp is used for read barrier. |
| 3810 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3811 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3812 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3813 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3814 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3815 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3816 | return 1; |
| 3817 | } |
| 3818 | return 0; |
| 3819 | } |
| 3820 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3821 | // 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] | 3822 | // interface pointer, one for loading the current interface. |
| 3823 | // The other checks have one temp for loading the object's class. |
| 3824 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3825 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3826 | return 3; |
| 3827 | } |
| 3828 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3829 | } |
| 3830 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3831 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3832 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3833 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3834 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3835 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3836 | case TypeCheckKind::kExactCheck: |
| 3837 | case TypeCheckKind::kAbstractClassCheck: |
| 3838 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3839 | case TypeCheckKind::kArrayObjectCheck: { |
| 3840 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 3841 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 3842 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3843 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3844 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3845 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3846 | case TypeCheckKind::kUnresolvedCheck: |
| 3847 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3848 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3849 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3850 | case TypeCheckKind::kBitstringCheck: |
| 3851 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3852 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3853 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3854 | LocationSummary* locations = |
| 3855 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3856 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3857 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3858 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3859 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3860 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3861 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3862 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3863 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3864 | } else { |
| 3865 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3866 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3867 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3868 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3869 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3870 | // Add temps if necessary for read barriers. |
| 3871 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3875 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3876 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3877 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3878 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3879 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 3880 | ? Register() |
| 3881 | : InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3882 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3883 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3884 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3885 | DCHECK_LE(num_temps, 1u); |
| 3886 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3887 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3888 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3889 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3890 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3891 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3892 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3893 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3894 | |
| 3895 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3896 | // Avoid null check if we know `obj` is not null. |
| 3897 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3898 | __ Cbz(obj, &zero); |
| 3899 | } |
| 3900 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3901 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3902 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3903 | ReadBarrierOption read_barrier_option = |
| 3904 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3905 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3906 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3907 | out_loc, |
| 3908 | obj_loc, |
| 3909 | class_offset, |
| 3910 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3911 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3912 | __ Cmp(out, cls); |
| 3913 | __ Cset(out, eq); |
| 3914 | if (zero.IsLinked()) { |
| 3915 | __ B(&done); |
| 3916 | } |
| 3917 | break; |
| 3918 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3919 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3920 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3921 | ReadBarrierOption read_barrier_option = |
| 3922 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3923 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3924 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3925 | out_loc, |
| 3926 | obj_loc, |
| 3927 | class_offset, |
| 3928 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3929 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3930 | // If the class is abstract, we eagerly fetch the super class of the |
| 3931 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3932 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3933 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3934 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3935 | GenerateReferenceLoadOneRegister(instruction, |
| 3936 | out_loc, |
| 3937 | super_offset, |
| 3938 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3939 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3940 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3941 | __ Cbz(out, &done); |
| 3942 | __ Cmp(out, cls); |
| 3943 | __ B(ne, &loop); |
| 3944 | __ Mov(out, 1); |
| 3945 | if (zero.IsLinked()) { |
| 3946 | __ B(&done); |
| 3947 | } |
| 3948 | break; |
| 3949 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3950 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3951 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3952 | ReadBarrierOption read_barrier_option = |
| 3953 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3954 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3955 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3956 | out_loc, |
| 3957 | obj_loc, |
| 3958 | class_offset, |
| 3959 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3960 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3961 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3962 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3963 | __ Bind(&loop); |
| 3964 | __ Cmp(out, cls); |
| 3965 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3966 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3967 | GenerateReferenceLoadOneRegister(instruction, |
| 3968 | out_loc, |
| 3969 | super_offset, |
| 3970 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3971 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3972 | __ Cbnz(out, &loop); |
| 3973 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3974 | __ B(&done); |
| 3975 | __ Bind(&success); |
| 3976 | __ Mov(out, 1); |
| 3977 | if (zero.IsLinked()) { |
| 3978 | __ B(&done); |
| 3979 | } |
| 3980 | break; |
| 3981 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3982 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3983 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3984 | ReadBarrierOption read_barrier_option = |
| 3985 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3986 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3987 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3988 | out_loc, |
| 3989 | obj_loc, |
| 3990 | class_offset, |
| 3991 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3992 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3993 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3994 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3995 | __ Cmp(out, cls); |
| 3996 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3997 | // 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] | 3998 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3999 | GenerateReferenceLoadOneRegister(instruction, |
| 4000 | out_loc, |
| 4001 | component_offset, |
| 4002 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4003 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4004 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4005 | __ Cbz(out, &done); |
| 4006 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4007 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4008 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4009 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4010 | __ Mov(out, 1); |
| 4011 | __ B(&done); |
| 4012 | break; |
| 4013 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4014 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4015 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4016 | // No read barrier since the slow path will retry upon failure. |
| 4017 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4018 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4019 | out_loc, |
| 4020 | obj_loc, |
| 4021 | class_offset, |
| 4022 | maybe_temp_loc, |
| 4023 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4024 | __ Cmp(out, cls); |
| 4025 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4026 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4027 | instruction, /* is_fatal= */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4028 | codegen_->AddSlowPath(slow_path); |
| 4029 | __ B(ne, slow_path->GetEntryLabel()); |
| 4030 | __ Mov(out, 1); |
| 4031 | if (zero.IsLinked()) { |
| 4032 | __ B(&done); |
| 4033 | } |
| 4034 | break; |
| 4035 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4036 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4037 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4038 | case TypeCheckKind::kInterfaceCheck: { |
| 4039 | // Note that we indeed only call on slow path, but we always go |
| 4040 | // into the slow path for the unresolved and interface check |
| 4041 | // cases. |
| 4042 | // |
| 4043 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4044 | // entry point without resorting to a type checking slow path |
| 4045 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4046 | // require to assign fixed registers for the inputs of this |
| 4047 | // HInstanceOf instruction (following the runtime calling |
| 4048 | // convention), which might be cluttered by the potential first |
| 4049 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4050 | // |
| 4051 | // TODO: Introduce a new runtime entry point taking the object |
| 4052 | // to test (instead of its class) as argument, and let it deal |
| 4053 | // with the read barrier issues. This will let us refactor this |
| 4054 | // case of the `switch` code as it was previously (with a direct |
| 4055 | // call to the runtime not using a type checking slow path). |
| 4056 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4057 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4058 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4059 | instruction, /* is_fatal= */ false); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4060 | codegen_->AddSlowPath(slow_path); |
| 4061 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4062 | if (zero.IsLinked()) { |
| 4063 | __ B(&done); |
| 4064 | } |
| 4065 | break; |
| 4066 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4067 | |
| 4068 | case TypeCheckKind::kBitstringCheck: { |
| 4069 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4070 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4071 | out_loc, |
| 4072 | obj_loc, |
| 4073 | class_offset, |
| 4074 | maybe_temp_loc, |
| 4075 | kWithoutReadBarrier); |
| 4076 | |
| 4077 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 4078 | __ Cset(out, eq); |
| 4079 | if (zero.IsLinked()) { |
| 4080 | __ B(&done); |
| 4081 | } |
| 4082 | break; |
| 4083 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | if (zero.IsLinked()) { |
| 4087 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4088 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4089 | } |
| 4090 | |
| 4091 | if (done.IsLinked()) { |
| 4092 | __ Bind(&done); |
| 4093 | } |
| 4094 | |
| 4095 | if (slow_path != nullptr) { |
| 4096 | __ Bind(slow_path->GetExitLabel()); |
| 4097 | } |
| 4098 | } |
| 4099 | |
| 4100 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4101 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4102 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4103 | LocationSummary* locations = |
| 4104 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4105 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4106 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 4107 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 4108 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 4109 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 4110 | } else { |
| 4111 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4112 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4113 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4114 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4115 | } |
| 4116 | |
| 4117 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4118 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4119 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4120 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4121 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4122 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 4123 | ? Register() |
| 4124 | : InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4125 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4126 | DCHECK_GE(num_temps, 1u); |
| 4127 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4128 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4129 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4130 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4131 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4132 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4133 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4134 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4135 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4136 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4137 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4138 | const uint32_t object_array_data_offset = |
| 4139 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4140 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4141 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4142 | SlowPathCodeARM64* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4143 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4144 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4145 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4146 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4147 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4148 | // Avoid null check if we know obj is not null. |
| 4149 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4150 | __ Cbz(obj, &done); |
| 4151 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4152 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4153 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4154 | case TypeCheckKind::kExactCheck: |
| 4155 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4156 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4157 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4158 | temp_loc, |
| 4159 | obj_loc, |
| 4160 | class_offset, |
| 4161 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4162 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4163 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4164 | __ Cmp(temp, cls); |
| 4165 | // Jump to slow path for throwing the exception or doing a |
| 4166 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4167 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4168 | break; |
| 4169 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4170 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4171 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4172 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4173 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4174 | temp_loc, |
| 4175 | obj_loc, |
| 4176 | class_offset, |
| 4177 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4178 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4179 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4180 | // If the class is abstract, we eagerly fetch the super class of the |
| 4181 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4182 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4183 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4184 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4185 | GenerateReferenceLoadOneRegister(instruction, |
| 4186 | temp_loc, |
| 4187 | super_offset, |
| 4188 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4189 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4190 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4191 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4192 | // exception. |
| 4193 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4194 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4195 | __ Cmp(temp, cls); |
| 4196 | __ B(ne, &loop); |
| 4197 | break; |
| 4198 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4199 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4200 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4201 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4202 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4203 | temp_loc, |
| 4204 | obj_loc, |
| 4205 | class_offset, |
| 4206 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4207 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4208 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4209 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4210 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4211 | __ Bind(&loop); |
| 4212 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4213 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4214 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4215 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4216 | GenerateReferenceLoadOneRegister(instruction, |
| 4217 | temp_loc, |
| 4218 | super_offset, |
| 4219 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4220 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4221 | |
| 4222 | // If the class reference currently in `temp` is not null, jump |
| 4223 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4224 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4225 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4226 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4227 | break; |
| 4228 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4229 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4230 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4231 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4232 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4233 | temp_loc, |
| 4234 | obj_loc, |
| 4235 | class_offset, |
| 4236 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4237 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4238 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4239 | // Do an exact check. |
| 4240 | __ Cmp(temp, cls); |
| 4241 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4242 | |
| 4243 | // 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] | 4244 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4245 | GenerateReferenceLoadOneRegister(instruction, |
| 4246 | temp_loc, |
| 4247 | component_offset, |
| 4248 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4249 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4250 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4251 | // If the component type is null, jump to the slow path to throw the exception. |
| 4252 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4253 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4254 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4255 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4256 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4257 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4258 | break; |
| 4259 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4260 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4261 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4262 | // 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] | 4263 | // |
| 4264 | // We cannot directly call the CheckCast runtime entry point |
| 4265 | // without resorting to a type checking slow path here (i.e. by |
| 4266 | // calling InvokeRuntime directly), as it would require to |
| 4267 | // assign fixed registers for the inputs of this HInstanceOf |
| 4268 | // instruction (following the runtime calling convention), which |
| 4269 | // might be cluttered by the potential first read barrier |
| 4270 | // emission at the beginning of this method. |
| 4271 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4272 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4273 | case TypeCheckKind::kInterfaceCheck: { |
| 4274 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4275 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4276 | temp_loc, |
| 4277 | obj_loc, |
| 4278 | class_offset, |
| 4279 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4280 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4281 | |
| 4282 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4283 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4284 | temp_loc, |
| 4285 | temp_loc, |
| 4286 | iftable_offset, |
| 4287 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4288 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4289 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4290 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4291 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4292 | vixl::aarch64::Label start_loop; |
| 4293 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4294 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4295 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4296 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4297 | // Go to next interface. |
| 4298 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4299 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4300 | // Compare the classes and continue the loop if they do not match. |
| 4301 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4302 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4303 | break; |
| 4304 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4305 | |
| 4306 | case TypeCheckKind::kBitstringCheck: { |
| 4307 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4308 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4309 | temp_loc, |
| 4310 | obj_loc, |
| 4311 | class_offset, |
| 4312 | maybe_temp2_loc, |
| 4313 | kWithoutReadBarrier); |
| 4314 | |
| 4315 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 4316 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 4317 | break; |
| 4318 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4319 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4320 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4321 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4322 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4323 | } |
| 4324 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4325 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4326 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4327 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4328 | } |
| 4329 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4330 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4331 | // Will be generated at use site. |
| 4332 | } |
| 4333 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4334 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4335 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4336 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4337 | } |
| 4338 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4339 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4340 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4341 | } |
| 4342 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4343 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4344 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4345 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4346 | // the method_idx. |
| 4347 | HandleInvoke(invoke); |
| 4348 | } |
| 4349 | |
| 4350 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4351 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4352 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4353 | } |
| 4354 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4355 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4356 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4357 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4358 | } |
| 4359 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4360 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4361 | HandleInvoke(invoke); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4362 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 4363 | // We cannot request ip1 as it's blocked by the register allocator. |
| 4364 | invoke->GetLocations()->SetInAt(invoke->GetNumberOfArguments() - 1, Location::Any()); |
| 4365 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4366 | } |
| 4367 | |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4368 | void CodeGeneratorARM64::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 4369 | Register klass) { |
| 4370 | DCHECK_EQ(klass.GetCode(), 0u); |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4371 | // We know the destination of an intrinsic, so no need to record inline |
| 4372 | // caches. |
| 4373 | if (!instruction->GetLocations()->Intrinsified() && |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 4374 | GetGraph()->IsCompilingBaseline() && |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4375 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4376 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 4377 | ScopedProfilingInfoUse spiu( |
| 4378 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 4379 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 4380 | if (info != nullptr) { |
| 4381 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 4382 | uint64_t address = reinterpret_cast64<uint64_t>(cache); |
| 4383 | vixl::aarch64::Label done; |
| 4384 | __ Mov(x8, address); |
| 4385 | __ Ldr(x9, MemOperand(x8, InlineCache::ClassesOffset().Int32Value())); |
| 4386 | // Fast path for a monomorphic cache. |
| 4387 | __ Cmp(klass, x9); |
| 4388 | __ B(eq, &done); |
| 4389 | InvokeRuntime(kQuickUpdateInlineCache, instruction, instruction->GetDexPc()); |
| 4390 | __ Bind(&done); |
| 4391 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4392 | } |
| 4393 | } |
| 4394 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4395 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4396 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4397 | LocationSummary* locations = invoke->GetLocations(); |
| 4398 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4399 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4400 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4401 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4402 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4403 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4404 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4405 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4406 | { |
| 4407 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4408 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4409 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4410 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4411 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4412 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4413 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4414 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4415 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4416 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4417 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4418 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4419 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4420 | // emit a read barrier for the previous class reference load. |
| 4421 | // However this is not required in practice, as this is an |
| 4422 | // intermediate/temporary reference and because the current |
| 4423 | // concurrent copying collector keeps the from-space memory |
| 4424 | // intact/accessible until the end of the marking phase (the |
| 4425 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4426 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4427 | |
| 4428 | // If we're compiling baseline, update the inline cache. |
| 4429 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4430 | |
| 4431 | // The register ip1 is required to be used for the hidden argument in |
| 4432 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
| 4433 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4434 | UseScratchRegisterScope scratch_scope(masm); |
| 4435 | scratch_scope.Exclude(ip1); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4436 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 4437 | Location interface_method = locations->InAt(invoke->GetNumberOfArguments() - 1); |
| 4438 | if (interface_method.IsStackSlot()) { |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 4439 | __ Ldr(ip1, StackOperandFrom(interface_method)); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4440 | } else { |
| 4441 | __ Mov(ip1, XRegisterFrom(interface_method)); |
| 4442 | } |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 4443 | // If the load kind is through a runtime call, we will pass the method we |
| 4444 | // fetch the IMT, which will either be a no-op if we don't hit the conflict |
| 4445 | // stub, or will make us always go through the trampoline when there is a |
| 4446 | // conflict. |
| 4447 | } else if (invoke->GetHiddenArgumentLoadKind() != MethodLoadKind::kRuntimeCall) { |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4448 | codegen_->LoadMethod( |
| 4449 | invoke->GetHiddenArgumentLoadKind(), Location::RegisterLocation(ip1.GetCode()), invoke); |
| 4450 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4451 | |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4452 | __ Ldr(temp, |
| 4453 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4454 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4455 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4456 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4457 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 4458 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRuntimeCall) { |
| 4459 | // We pass the method from the IMT in case of a conflict. This will ensure |
| 4460 | // we go into the runtime to resolve the actual method. |
| 4461 | __ Mov(ip1, temp); |
| 4462 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4463 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4464 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4465 | |
| 4466 | { |
| 4467 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4468 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4469 | |
| 4470 | // lr(); |
| 4471 | __ blr(lr); |
| 4472 | DCHECK(!codegen_->IsLeafMethod()); |
| 4473 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4474 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4475 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4476 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4477 | } |
| 4478 | |
| 4479 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4480 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4481 | if (intrinsic.TryDispatch(invoke)) { |
| 4482 | return; |
| 4483 | } |
| 4484 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4485 | HandleInvoke(invoke); |
| 4486 | } |
| 4487 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4488 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4489 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4490 | // art::PrepareForRegisterAllocation. |
| 4491 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4492 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4493 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4494 | if (intrinsic.TryDispatch(invoke)) { |
| 4495 | return; |
| 4496 | } |
| 4497 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4498 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4499 | CriticalNativeCallingConventionVisitorARM64 calling_convention_visitor( |
| 4500 | /*for_register_allocation=*/ true); |
| 4501 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 4502 | } else { |
| 4503 | HandleInvoke(invoke); |
| 4504 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4505 | } |
| 4506 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4507 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4508 | if (invoke->GetLocations()->Intrinsified()) { |
| 4509 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4510 | intrinsic.Dispatch(invoke); |
| 4511 | return true; |
| 4512 | } |
| 4513 | return false; |
| 4514 | } |
| 4515 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4516 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4517 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4518 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4519 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4520 | return desired_dispatch_info; |
| 4521 | } |
| 4522 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4523 | void CodeGeneratorARM64::LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke) { |
| 4524 | switch (load_kind) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4525 | case MethodLoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4526 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4527 | // Add ADRP with its PC-relative method patch. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4528 | vixl::aarch64::Label* adrp_label = |
| 4529 | NewBootImageMethodPatch(invoke->GetResolvedMethodReference()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4530 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4531 | // Add ADD with its PC-relative method patch. |
| 4532 | vixl::aarch64::Label* add_label = |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4533 | NewBootImageMethodPatch(invoke->GetResolvedMethodReference(), adrp_label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4534 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4535 | break; |
| 4536 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4537 | case MethodLoadKind::kBootImageRelRo: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4538 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4539 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4540 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_offset); |
| 4541 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4542 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| 4543 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| 4544 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 4545 | EmitLdrOffsetPlaceholder(ldr_label, WRegisterFrom(temp), XRegisterFrom(temp)); |
| 4546 | break; |
| 4547 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4548 | case MethodLoadKind::kBssEntry: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4549 | // Add ADRP with its PC-relative .bss entry patch. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4550 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(invoke->GetMethodReference()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4551 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4552 | // Add LDR with its PC-relative .bss entry patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4553 | vixl::aarch64::Label* ldr_label = |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4554 | NewMethodBssEntryPatch(invoke->GetMethodReference(), adrp_label); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 4555 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4556 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4557 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4558 | } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4559 | case MethodLoadKind::kJitDirectAddress: { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4560 | // Load method address from literal pool. |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4561 | __ Ldr(XRegisterFrom(temp), |
| 4562 | DeduplicateUint64Literal(reinterpret_cast<uint64_t>(invoke->GetResolvedMethod()))); |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4563 | break; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4564 | } |
| 4565 | case MethodLoadKind::kRuntimeCall: { |
| 4566 | // Test situation, don't do anything. |
| 4567 | break; |
| 4568 | } |
| 4569 | default: { |
| 4570 | LOG(FATAL) << "Load kind should have already been handled " << load_kind; |
| 4571 | UNREACHABLE(); |
| 4572 | } |
| 4573 | } |
| 4574 | } |
| 4575 | |
| 4576 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4577 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| 4578 | // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention. |
| 4579 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4580 | switch (invoke->GetMethodLoadKind()) { |
| 4581 | case MethodLoadKind::kStringInit: { |
| 4582 | uint32_t offset = |
| 4583 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4584 | // temp = thread->string_init_entrypoint |
| 4585 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
| 4586 | break; |
| 4587 | } |
| 4588 | case MethodLoadKind::kRecursive: { |
| 4589 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
| 4590 | break; |
| 4591 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4592 | case MethodLoadKind::kRuntimeCall: { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4593 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4594 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4595 | } |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4596 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
| 4597 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| 4598 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
| 4599 | // Do not materialize the method pointer, load directly the entrypoint. |
| 4600 | // Add ADRP with its PC-relative JNI entrypoint patch. |
| 4601 | vixl::aarch64::Label* adrp_label = |
| 4602 | NewBootImageJniEntrypointPatch(invoke->GetResolvedMethodReference()); |
| 4603 | EmitAdrpPlaceholder(adrp_label, lr); |
| 4604 | // Add the LDR with its PC-relative method patch. |
| 4605 | vixl::aarch64::Label* add_label = |
| 4606 | NewBootImageJniEntrypointPatch(invoke->GetResolvedMethodReference(), adrp_label); |
| 4607 | EmitLdrOffsetPlaceholder(add_label, lr, lr); |
| 4608 | break; |
| 4609 | } |
| 4610 | FALLTHROUGH_INTENDED; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 4611 | default: { |
| 4612 | LoadMethod(invoke->GetMethodLoadKind(), temp, invoke); |
| 4613 | break; |
| 4614 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4615 | } |
| 4616 | |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4617 | auto call_lr = [&]() { |
| 4618 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4619 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4620 | kInstructionSize, |
| 4621 | CodeBufferCheckScope::kExactSize); |
| 4622 | // lr() |
| 4623 | __ blr(lr); |
| 4624 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4625 | }; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4626 | switch (invoke->GetCodePtrLocation()) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4627 | case CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4628 | { |
| 4629 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4630 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4631 | kInstructionSize, |
| 4632 | CodeBufferCheckScope::kExactSize); |
| 4633 | __ bl(&frame_entry_label_); |
| 4634 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4635 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4636 | break; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 4637 | case CodePtrLocation::kCallCriticalNative: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4638 | size_t out_frame_size = |
| 4639 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorARM64, |
| 4640 | kAapcs64StackAlignment, |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 4641 | GetCriticalNativeDirectCallFrameSize>(invoke); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4642 | if (invoke->GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative) { |
| 4643 | call_lr(); |
| 4644 | } else { |
| 4645 | // LR = callee_method->ptr_sized_fields_.data_; // EntryPointFromJni |
| 4646 | MemberOffset offset = ArtMethod::EntryPointFromJniOffset(kArm64PointerSize); |
| 4647 | __ Ldr(lr, MemOperand(XRegisterFrom(callee_method), offset.Int32Value())); |
| 4648 | // lr() |
| 4649 | call_lr(); |
| 4650 | } |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4651 | // Zero-/sign-extend the result when needed due to native and managed ABI mismatch. |
| 4652 | switch (invoke->GetType()) { |
| 4653 | case DataType::Type::kBool: |
| 4654 | __ Ubfx(w0, w0, 0, 8); |
| 4655 | break; |
| 4656 | case DataType::Type::kInt8: |
| 4657 | __ Sbfx(w0, w0, 0, 8); |
| 4658 | break; |
| 4659 | case DataType::Type::kUint16: |
| 4660 | __ Ubfx(w0, w0, 0, 16); |
| 4661 | break; |
| 4662 | case DataType::Type::kInt16: |
| 4663 | __ Sbfx(w0, w0, 0, 16); |
| 4664 | break; |
| 4665 | case DataType::Type::kInt32: |
| 4666 | case DataType::Type::kInt64: |
| 4667 | case DataType::Type::kFloat32: |
| 4668 | case DataType::Type::kFloat64: |
| 4669 | case DataType::Type::kVoid: |
| 4670 | break; |
| 4671 | default: |
| 4672 | DCHECK(false) << invoke->GetType(); |
| 4673 | break; |
| 4674 | } |
| 4675 | if (out_frame_size != 0u) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 4676 | DecreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4677 | } |
| 4678 | break; |
| 4679 | } |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4680 | case CodePtrLocation::kCallArtMethod: { |
| 4681 | // LR = callee_method->ptr_sized_fields_.entry_point_from_quick_compiled_code_; |
| 4682 | MemberOffset offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
| 4683 | __ Ldr(lr, MemOperand(XRegisterFrom(callee_method), offset.Int32Value())); |
| 4684 | // lr() |
| 4685 | call_lr(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4686 | break; |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4687 | } |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4688 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4689 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4690 | DCHECK(!IsLeafMethod()); |
| 4691 | } |
| 4692 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4693 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4694 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4695 | // Use the calling convention instead of the location of the receiver, as |
| 4696 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4697 | // slow path, the arguments have been moved to the right place, so here we are |
| 4698 | // guaranteed that the receiver is the first register of the calling convention. |
| 4699 | InvokeDexCallingConvention calling_convention; |
| 4700 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4701 | Register temp = XRegisterFrom(temp_in); |
| 4702 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4703 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4704 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4705 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4706 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4707 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4708 | |
| 4709 | { |
| 4710 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4711 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4712 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4713 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4714 | MaybeRecordImplicitNullCheck(invoke); |
| 4715 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4716 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4717 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4718 | // intermediate/temporary reference and because the current |
| 4719 | // concurrent copying collector keeps the from-space memory |
| 4720 | // intact/accessible until the end of the marking phase (the |
| 4721 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4722 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4723 | |
| 4724 | // If we're compiling baseline, update the inline cache. |
| 4725 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4726 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4727 | // temp = temp->GetMethodAt(method_offset); |
| 4728 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4729 | // lr = temp->GetEntryPoint(); |
| 4730 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4731 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4732 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4733 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4734 | // lr(); |
| 4735 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4736 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4737 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4738 | } |
| 4739 | |
Vladimir Marko | 9922f00 | 2020-06-08 15:05:15 +0100 | [diff] [blame] | 4740 | void CodeGeneratorARM64::MoveFromReturnRegister(Location trg, DataType::Type type) { |
| 4741 | if (!trg.IsValid()) { |
| 4742 | DCHECK(type == DataType::Type::kVoid); |
| 4743 | return; |
| 4744 | } |
| 4745 | |
| 4746 | DCHECK_NE(type, DataType::Type::kVoid); |
| 4747 | |
| 4748 | if (DataType::IsIntegralType(type) || type == DataType::Type::kReference) { |
| 4749 | Register trg_reg = RegisterFrom(trg, type); |
| 4750 | Register res_reg = RegisterFrom(ARM64ReturnLocation(type), type); |
| 4751 | __ Mov(trg_reg, res_reg, kDiscardForSameWReg); |
| 4752 | } else { |
| 4753 | VRegister trg_reg = FPRegisterFrom(trg, type); |
| 4754 | VRegister res_reg = FPRegisterFrom(ARM64ReturnLocation(type), type); |
| 4755 | __ Fmov(trg_reg, res_reg); |
| 4756 | } |
| 4757 | } |
| 4758 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4759 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 4760 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
| 4761 | if (intrinsic.TryDispatch(invoke)) { |
| 4762 | return; |
| 4763 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4764 | HandleInvoke(invoke); |
| 4765 | } |
| 4766 | |
| 4767 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 4768 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4769 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| 4770 | return; |
| 4771 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4772 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4773 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4774 | } |
| 4775 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4776 | void LocationsBuilderARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4777 | HandleInvoke(invoke); |
| 4778 | } |
| 4779 | |
| 4780 | void InstructionCodeGeneratorARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4781 | codegen_->GenerateInvokeCustomCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4782 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4783 | } |
| 4784 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4785 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageIntrinsicPatch( |
| 4786 | uint32_t intrinsic_data, |
| 4787 | vixl::aarch64::Label* adrp_label) { |
| 4788 | return NewPcRelativePatch( |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4789 | /* dex_file= */ nullptr, intrinsic_data, adrp_label, &boot_image_other_patches_); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4790 | } |
| 4791 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4792 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageRelRoPatch( |
| 4793 | uint32_t boot_image_offset, |
| 4794 | vixl::aarch64::Label* adrp_label) { |
| 4795 | return NewPcRelativePatch( |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4796 | /* dex_file= */ nullptr, boot_image_offset, adrp_label, &boot_image_other_patches_); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4797 | } |
| 4798 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4799 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageMethodPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4800 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4801 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4802 | return NewPcRelativePatch( |
| 4803 | 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] | 4804 | } |
| 4805 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4806 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4807 | MethodReference target_method, |
| 4808 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4809 | return NewPcRelativePatch( |
| 4810 | 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] | 4811 | } |
| 4812 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4813 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageTypePatch( |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4814 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4815 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4816 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4817 | 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] | 4818 | } |
| 4819 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4820 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 4821 | HLoadClass* load_class, |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4822 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 4823 | const DexFile& dex_file = load_class->GetDexFile(); |
| 4824 | dex::TypeIndex type_index = load_class->GetTypeIndex(); |
| 4825 | ArenaDeque<PcRelativePatchInfo>* patches = nullptr; |
| 4826 | switch (load_class->GetLoadKind()) { |
| 4827 | case HLoadClass::LoadKind::kBssEntry: |
| 4828 | patches = &type_bss_entry_patches_; |
| 4829 | break; |
| 4830 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 4831 | patches = &public_type_bss_entry_patches_; |
| 4832 | break; |
| 4833 | case HLoadClass::LoadKind::kBssEntryPackage: |
| 4834 | patches = &package_type_bss_entry_patches_; |
| 4835 | break; |
| 4836 | default: |
| 4837 | LOG(FATAL) << "Unexpected load kind: " << load_class->GetLoadKind(); |
| 4838 | UNREACHABLE(); |
| 4839 | } |
| 4840 | return NewPcRelativePatch(&dex_file, type_index.index_, adrp_label, patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4841 | } |
| 4842 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4843 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageStringPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4844 | const DexFile& dex_file, |
| 4845 | dex::StringIndex string_index, |
| 4846 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4847 | return NewPcRelativePatch( |
| 4848 | &dex_file, string_index.index_, adrp_label, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4849 | } |
| 4850 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4851 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4852 | const DexFile& dex_file, |
| 4853 | dex::StringIndex string_index, |
| 4854 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4855 | 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] | 4856 | } |
| 4857 | |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 4858 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageJniEntrypointPatch( |
| 4859 | MethodReference target_method, |
| 4860 | vixl::aarch64::Label* adrp_label) { |
| 4861 | return NewPcRelativePatch( |
| 4862 | target_method.dex_file, target_method.index, adrp_label, &boot_image_jni_entrypoint_patches_); |
| 4863 | } |
| 4864 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4865 | void CodeGeneratorARM64::EmitEntrypointThunkCall(ThreadOffset64 entrypoint_offset) { |
| 4866 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 4867 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4868 | call_entrypoint_patches_.emplace_back(/*dex_file*/ nullptr, entrypoint_offset.Uint32Value()); |
| 4869 | vixl::aarch64::Label* bl_label = &call_entrypoint_patches_.back().label; |
| 4870 | __ bind(bl_label); |
| 4871 | __ bl(static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 4872 | } |
| 4873 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 4874 | void CodeGeneratorARM64::EmitBakerReadBarrierCbnz(uint32_t custom_data) { |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 4875 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 4876 | if (GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 4877 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 4878 | vixl::aarch64::Label* slow_path_entry = &it->second.label; |
| 4879 | __ cbnz(mr, slow_path_entry); |
| 4880 | } else { |
| 4881 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4882 | vixl::aarch64::Label* cbnz_label = &baker_read_barrier_patches_.back().label; |
| 4883 | __ bind(cbnz_label); |
| 4884 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 4885 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4886 | } |
| 4887 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4888 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4889 | const DexFile* dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4890 | uint32_t offset_or_index, |
| 4891 | vixl::aarch64::Label* adrp_label, |
| 4892 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4893 | // Add a patch entry and return the label. |
| 4894 | patches->emplace_back(dex_file, offset_or_index); |
| 4895 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4896 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4897 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4898 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4899 | return label; |
| 4900 | } |
| 4901 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4902 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4903 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4904 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4905 | } |
| 4906 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4907 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4908 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4909 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4910 | return jit_string_patches_.GetOrCreate( |
| 4911 | StringReference(&dex_file, string_index), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4912 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4913 | } |
| 4914 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4915 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4916 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4917 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4918 | return jit_class_patches_.GetOrCreate( |
| 4919 | TypeReference(&dex_file, type_index), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4920 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4921 | } |
| 4922 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4923 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4924 | vixl::aarch64::Register reg) { |
| 4925 | DCHECK(reg.IsX()); |
| 4926 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4927 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4928 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4929 | } |
| 4930 | |
| 4931 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4932 | vixl::aarch64::Register out, |
| 4933 | vixl::aarch64::Register base) { |
| 4934 | DCHECK(out.IsX()); |
| 4935 | DCHECK(base.IsX()); |
| 4936 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4937 | __ Bind(fixup_label); |
| 4938 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4939 | } |
| 4940 | |
| 4941 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4942 | vixl::aarch64::Register out, |
| 4943 | vixl::aarch64::Register base) { |
| 4944 | DCHECK(base.IsX()); |
| 4945 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4946 | __ Bind(fixup_label); |
| 4947 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4948 | } |
| 4949 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4950 | void CodeGeneratorARM64::LoadBootImageAddress(vixl::aarch64::Register reg, |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4951 | uint32_t boot_image_reference) { |
| 4952 | if (GetCompilerOptions().IsBootImage()) { |
| 4953 | // Add ADRP with its PC-relative type patch. |
| 4954 | vixl::aarch64::Label* adrp_label = NewBootImageIntrinsicPatch(boot_image_reference); |
| 4955 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4956 | // Add ADD with its PC-relative type patch. |
| 4957 | vixl::aarch64::Label* add_label = NewBootImageIntrinsicPatch(boot_image_reference, adrp_label); |
| 4958 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 4959 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4960 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4961 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4962 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4963 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4964 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_reference, adrp_label); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4965 | EmitLdrOffsetPlaceholder(ldr_label, reg.W(), reg.X()); |
| 4966 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 4967 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4968 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 4969 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4970 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4971 | __ Ldr(reg.W(), DeduplicateBootImageAddressLiteral(reinterpret_cast<uintptr_t>(address))); |
| 4972 | } |
| 4973 | } |
| 4974 | |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 4975 | void CodeGeneratorARM64::LoadIntrinsicDeclaringClass(vixl::aarch64::Register reg, HInvoke* invoke) { |
| 4976 | DCHECK_NE(invoke->GetIntrinsic(), Intrinsics::kNone); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4977 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4978 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 4979 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4980 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 4981 | // Add ADRP with its PC-relative type patch. |
| 4982 | vixl::aarch64::Label* adrp_label = NewBootImageTypePatch(*target_method.dex_file, type_idx); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 4983 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4984 | // Add ADD with its PC-relative type patch. |
| 4985 | vixl::aarch64::Label* add_label = |
| 4986 | NewBootImageTypePatch(*target_method.dex_file, type_idx, adrp_label); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 4987 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4988 | } else { |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 4989 | uint32_t boot_image_offset = GetBootImageOffsetOfIntrinsicDeclaringClass(invoke); |
| 4990 | LoadBootImageAddress(reg, boot_image_offset); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4991 | } |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4992 | } |
| 4993 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4994 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4995 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4996 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4997 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4998 | for (const PcRelativePatchInfo& info : infos) { |
| 4999 | linker_patches->push_back(Factory(info.label.GetLocation(), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5000 | info.target_dex_file, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5001 | info.pc_insn_label->GetLocation(), |
| 5002 | info.offset_or_index)); |
| 5003 | } |
| 5004 | } |
| 5005 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5006 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 5007 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 5008 | const DexFile* target_dex_file, |
| 5009 | uint32_t pc_insn_offset, |
| 5010 | uint32_t boot_image_offset) { |
| 5011 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 5012 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5013 | } |
| 5014 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5015 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5016 | DCHECK(linker_patches->empty()); |
| 5017 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5018 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5019 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5020 | boot_image_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5021 | type_bss_entry_patches_.size() + |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5022 | public_type_bss_entry_patches_.size() + |
| 5023 | package_type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5024 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5025 | string_bss_entry_patches_.size() + |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5026 | boot_image_jni_entrypoint_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5027 | boot_image_other_patches_.size() + |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5028 | call_entrypoint_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5029 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5030 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5031 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5032 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5033 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5034 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5035 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5036 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5037 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5038 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5039 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5040 | DCHECK(boot_image_type_patches_.empty()); |
| 5041 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 5042 | } |
| 5043 | if (GetCompilerOptions().IsBootImage()) { |
| 5044 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 5045 | boot_image_other_patches_, linker_patches); |
| 5046 | } else { |
| 5047 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 5048 | boot_image_other_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5049 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5050 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 5051 | method_bss_entry_patches_, linker_patches); |
| 5052 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 5053 | type_bss_entry_patches_, linker_patches); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5054 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PublicTypeBssEntryPatch>( |
| 5055 | public_type_bss_entry_patches_, linker_patches); |
| 5056 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PackageTypeBssEntryPatch>( |
| 5057 | package_type_bss_entry_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5058 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 5059 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 5060 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeJniEntrypointPatch>( |
| 5061 | boot_image_jni_entrypoint_patches_, linker_patches); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5062 | for (const PatchInfo<vixl::aarch64::Label>& info : call_entrypoint_patches_) { |
| 5063 | DCHECK(info.target_dex_file == nullptr); |
| 5064 | linker_patches->push_back(linker::LinkerPatch::CallEntrypointPatch( |
| 5065 | info.label.GetLocation(), info.offset_or_index)); |
| 5066 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5067 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5068 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 5069 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5070 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5071 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5072 | } |
| 5073 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5074 | bool CodeGeneratorARM64::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5075 | return patch.GetType() == linker::LinkerPatch::Type::kCallEntrypoint || |
| 5076 | patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5077 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 5078 | } |
| 5079 | |
| 5080 | void CodeGeneratorARM64::EmitThunkCode(const linker::LinkerPatch& patch, |
| 5081 | /*out*/ ArenaVector<uint8_t>* code, |
| 5082 | /*out*/ std::string* debug_name) { |
| 5083 | Arm64Assembler assembler(GetGraph()->GetAllocator()); |
| 5084 | switch (patch.GetType()) { |
| 5085 | case linker::LinkerPatch::Type::kCallRelative: { |
| 5086 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 5087 | // to the generic JNI and interpreter trampolines. |
| 5088 | Offset offset(ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 5089 | kArm64PointerSize).Int32Value()); |
| 5090 | assembler.JumpTo(ManagedRegister(arm64::X0), offset, ManagedRegister(arm64::IP0)); |
| 5091 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 5092 | *debug_name = "MethodCallThunk"; |
| 5093 | } |
| 5094 | break; |
| 5095 | } |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 5096 | case linker::LinkerPatch::Type::kCallEntrypoint: { |
| 5097 | Offset offset(patch.EntrypointOffset()); |
| 5098 | assembler.JumpTo(ManagedRegister(arm64::TR), offset, ManagedRegister(arm64::IP0)); |
| 5099 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 5100 | *debug_name = "EntrypointCallThunk_" + std::to_string(offset.Uint32Value()); |
| 5101 | } |
| 5102 | break; |
| 5103 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5104 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| 5105 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 5106 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 5107 | break; |
| 5108 | } |
| 5109 | default: |
| 5110 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 5111 | UNREACHABLE(); |
| 5112 | } |
| 5113 | |
| 5114 | // Ensure we emit the literal pool if any. |
| 5115 | assembler.FinalizeCode(); |
| 5116 | code->resize(assembler.CodeSize()); |
| 5117 | MemoryRegion code_region(code->data(), code->size()); |
| 5118 | assembler.FinalizeInstructions(code_region); |
| 5119 | } |
| 5120 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5121 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 5122 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5123 | value, |
| 5124 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 5125 | } |
| 5126 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5127 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5128 | return uint64_literals_.GetOrCreate( |
| 5129 | value, |
| 5130 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5131 | } |
| 5132 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5133 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 5134 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 5135 | // art::PrepareForRegisterAllocation. |
| 5136 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 5137 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5138 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5139 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5140 | return; |
| 5141 | } |
| 5142 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 5143 | LocationSummary* locations = invoke->GetLocations(); |
| 5144 | codegen_->GenerateStaticOrDirectCall( |
| 5145 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5146 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5147 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5148 | } |
| 5149 | |
| 5150 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5151 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5152 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 5153 | return; |
| 5154 | } |
| 5155 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5156 | { |
| 5157 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 5158 | // are no pools emitted. |
| 5159 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 5160 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 5161 | DCHECK(!codegen_->IsLeafMethod()); |
| 5162 | } |
| 5163 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5164 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5165 | } |
| 5166 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5167 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 5168 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5169 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5170 | case HLoadClass::LoadKind::kInvalid: |
| 5171 | LOG(FATAL) << "UNREACHABLE"; |
| 5172 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5173 | case HLoadClass::LoadKind::kReferrersClass: |
| 5174 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5175 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5176 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5177 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5178 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 5179 | case HLoadClass::LoadKind::kBssEntryPackage: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5180 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5181 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5182 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5183 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5184 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5185 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5186 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5187 | break; |
| 5188 | } |
| 5189 | return desired_class_load_kind; |
| 5190 | } |
| 5191 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5192 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5193 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5194 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5195 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5196 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5197 | cls, |
| 5198 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5199 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5200 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5201 | return; |
| 5202 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5203 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 5204 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 5205 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5206 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5207 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5208 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5209 | ? LocationSummary::kCallOnSlowPath |
| 5210 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5211 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5212 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5213 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5214 | } |
| 5215 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5216 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5217 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5218 | } |
| 5219 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5220 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 5221 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5222 | // 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] | 5223 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5224 | } else { |
| 5225 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5226 | } |
| 5227 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5228 | } |
| 5229 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5230 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5231 | // move. |
| 5232 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5233 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5234 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5235 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5236 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5237 | return; |
| 5238 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5239 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 5240 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 5241 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5242 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5243 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5244 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5245 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5246 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5247 | ? kWithoutReadBarrier |
| 5248 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5249 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5250 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5251 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5252 | DCHECK(!cls->CanCallRuntime()); |
| 5253 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5254 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5255 | Register current_method = InputRegisterAt(cls, 0); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5256 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5257 | out_loc, |
| 5258 | current_method, |
| 5259 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5260 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5261 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5262 | break; |
| 5263 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5264 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5265 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 5266 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5267 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5268 | // Add ADRP with its PC-relative type patch. |
| 5269 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5270 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5271 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5272 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5273 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5274 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5275 | codegen_->NewBootImageTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5276 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5277 | break; |
| 5278 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5279 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5280 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5281 | uint32_t boot_image_offset = CodeGenerator::GetBootImageOffset(cls); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5282 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5283 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5284 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5285 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5286 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5287 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5288 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5289 | break; |
| 5290 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5291 | case HLoadClass::LoadKind::kBssEntry: |
| 5292 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 5293 | case HLoadClass::LoadKind::kBssEntryPackage: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5294 | // Add ADRP with its PC-relative Class .bss entry patch. |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5295 | vixl::aarch64::Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5296 | vixl::aarch64::Label* adrp_label = codegen_->NewBssEntryTypePatch(cls); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5297 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5298 | // Add LDR with its PC-relative Class .bss entry patch. |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 5299 | vixl::aarch64::Label* ldr_label = codegen_->NewBssEntryTypePatch(cls, adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5300 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5301 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5302 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5303 | out_loc, |
| 5304 | temp, |
| 5305 | /* offset placeholder */ 0u, |
| 5306 | ldr_label, |
| 5307 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5308 | generate_null_check = true; |
| 5309 | break; |
| 5310 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5311 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 5312 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 5313 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 5314 | DCHECK_NE(address, 0u); |
| 5315 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5316 | break; |
| 5317 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5318 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5319 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5320 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5321 | cls->GetClass())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5322 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5323 | out_loc, |
| 5324 | out.X(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5325 | /* offset= */ 0, |
| 5326 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5327 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5328 | break; |
| 5329 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5330 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5331 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5332 | LOG(FATAL) << "UNREACHABLE"; |
| 5333 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5334 | } |
| 5335 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5336 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5337 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5338 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 5339 | SlowPathCodeARM64* slow_path = |
| 5340 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5341 | codegen_->AddSlowPath(slow_path); |
| 5342 | if (generate_null_check) { |
| 5343 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5344 | } |
| 5345 | if (cls->MustGenerateClinitCheck()) { |
| 5346 | GenerateClassInitializationCheck(slow_path, out); |
| 5347 | } else { |
| 5348 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5349 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5350 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5351 | } |
| 5352 | } |
| 5353 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 5354 | void LocationsBuilderARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5355 | InvokeRuntimeCallingConvention calling_convention; |
| 5356 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5357 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 5358 | } |
| 5359 | |
| 5360 | void InstructionCodeGeneratorARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5361 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 5362 | } |
| 5363 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 5364 | void LocationsBuilderARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5365 | InvokeRuntimeCallingConvention calling_convention; |
| 5366 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5367 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 5368 | } |
| 5369 | |
| 5370 | void InstructionCodeGeneratorARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5371 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 5372 | } |
| 5373 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5374 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5375 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5376 | } |
| 5377 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5378 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5379 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5380 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5381 | locations->SetOut(Location::RequiresRegister()); |
| 5382 | } |
| 5383 | |
| 5384 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5385 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5386 | } |
| 5387 | |
| 5388 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5389 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5390 | } |
| 5391 | |
| 5392 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5393 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5394 | } |
| 5395 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5396 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5397 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5398 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5399 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5400 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5401 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5402 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5403 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5404 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5405 | case HLoadString::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5406 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5407 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5408 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5409 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5410 | } |
| 5411 | return desired_string_load_kind; |
| 5412 | } |
| 5413 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5414 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5415 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5416 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5417 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5418 | InvokeRuntimeCallingConvention calling_convention; |
| 5419 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5420 | } else { |
| 5421 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5422 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5423 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5424 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 5425 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5426 | } else { |
| 5427 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5428 | } |
| 5429 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5430 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5431 | } |
| 5432 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5433 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5434 | // move. |
| 5435 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5436 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5437 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5438 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5439 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5440 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5441 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 5442 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5443 | // Add ADRP with its PC-relative String patch. |
| 5444 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5445 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5446 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5447 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5448 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5449 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5450 | codegen_->NewBootImageStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5451 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5452 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5453 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5454 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5455 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5456 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 5457 | uint32_t boot_image_offset = CodeGenerator::GetBootImageOffset(load); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5458 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5459 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5460 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5461 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5462 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5463 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 5464 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5465 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5466 | case HLoadString::LoadKind::kBssEntry: { |
| 5467 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5468 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5469 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5470 | Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5471 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5472 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5473 | // Add LDR with its PC-relative String .bss entry patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5474 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5475 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5476 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5477 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5478 | codegen_->GenerateGcRootFieldLoad(load, |
| 5479 | out_loc, |
| 5480 | temp, |
| 5481 | /* offset placeholder */ 0u, |
| 5482 | ldr_label, |
| 5483 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5484 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5485 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5486 | codegen_->AddSlowPath(slow_path); |
| 5487 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5488 | __ Bind(slow_path->GetExitLabel()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5489 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5490 | return; |
| 5491 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5492 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 5493 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 5494 | DCHECK_NE(address, 0u); |
| 5495 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5496 | return; |
| 5497 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5498 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5499 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5500 | load->GetStringIndex(), |
| 5501 | load->GetString())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5502 | codegen_->GenerateGcRootFieldLoad(load, |
| 5503 | out_loc, |
| 5504 | out.X(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5505 | /* offset= */ 0, |
| 5506 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5507 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5508 | return; |
| 5509 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5510 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5511 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5512 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5513 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5514 | // 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] | 5515 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5516 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5517 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5518 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5519 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5520 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5521 | } |
| 5522 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5523 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5524 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5525 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5526 | } |
| 5527 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5528 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5529 | // Will be generated at use site. |
| 5530 | } |
| 5531 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5532 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5533 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5534 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5535 | InvokeRuntimeCallingConvention calling_convention; |
| 5536 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5537 | } |
| 5538 | |
| 5539 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5540 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5541 | instruction, |
| 5542 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5543 | if (instruction->IsEnter()) { |
| 5544 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5545 | } else { |
| 5546 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5547 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5548 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5549 | } |
| 5550 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5551 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5552 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5553 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5554 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5555 | case DataType::Type::kInt32: |
| 5556 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5557 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5558 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5559 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5560 | break; |
| 5561 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5562 | case DataType::Type::kFloat32: |
| 5563 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5564 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5565 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5566 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5567 | break; |
| 5568 | |
| 5569 | default: |
| 5570 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5571 | } |
| 5572 | } |
| 5573 | |
| 5574 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5575 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5576 | case DataType::Type::kInt32: |
| 5577 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5578 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5579 | break; |
| 5580 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5581 | case DataType::Type::kFloat32: |
| 5582 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5583 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5584 | break; |
| 5585 | |
| 5586 | default: |
| 5587 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5588 | } |
| 5589 | } |
| 5590 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5591 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5592 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5593 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5594 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5595 | case DataType::Type::kInt32: |
| 5596 | case DataType::Type::kInt64: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5597 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5598 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5599 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5600 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5601 | case DataType::Type::kFloat32: |
| 5602 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5603 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5604 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5605 | break; |
| 5606 | |
| 5607 | default: |
| 5608 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5609 | } |
| 5610 | } |
| 5611 | |
| 5612 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5613 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5614 | case DataType::Type::kInt32: |
| 5615 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5616 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5617 | break; |
| 5618 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5619 | case DataType::Type::kFloat32: |
| 5620 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5621 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5622 | break; |
| 5623 | |
| 5624 | default: |
| 5625 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5626 | } |
| 5627 | } |
| 5628 | |
| 5629 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5630 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5631 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5632 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5633 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5634 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5635 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5636 | } |
| 5637 | |
| 5638 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5639 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5640 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5641 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5642 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5643 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5644 | } |
| 5645 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5646 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5647 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5648 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5649 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5650 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5651 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5652 | } |
| 5653 | |
| 5654 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5655 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5656 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5657 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5658 | } |
| 5659 | |
| 5660 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5661 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5662 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5663 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5664 | } |
| 5665 | |
| 5666 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5667 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5668 | case DataType::Type::kInt32: |
| 5669 | case DataType::Type::kInt64: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5670 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5671 | break; |
| 5672 | |
| 5673 | default: |
| 5674 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5675 | } |
| 5676 | } |
| 5677 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5678 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5679 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5680 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5681 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5682 | } |
| 5683 | |
| 5684 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5685 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5686 | } |
| 5687 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5688 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5689 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5690 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5691 | } |
| 5692 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5693 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5694 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5695 | return; |
| 5696 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5697 | { |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 5698 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5699 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5700 | Location obj = instruction->GetLocations()->InAt(0); |
| 5701 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5702 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5703 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5704 | } |
| 5705 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5706 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5707 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5708 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5709 | |
| 5710 | LocationSummary* locations = instruction->GetLocations(); |
| 5711 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5712 | |
| 5713 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5714 | } |
| 5715 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5716 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5717 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5718 | } |
| 5719 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5720 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5721 | HandleBinaryOp(instruction); |
| 5722 | } |
| 5723 | |
| 5724 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5725 | HandleBinaryOp(instruction); |
| 5726 | } |
| 5727 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5728 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5729 | LOG(FATAL) << "Unreachable"; |
| 5730 | } |
| 5731 | |
| 5732 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5733 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5734 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5735 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5736 | // The back edge will generate the suspend check. |
| 5737 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5738 | } |
| 5739 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5740 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5741 | } |
| 5742 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5743 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5744 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5745 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5746 | if (location.IsStackSlot()) { |
| 5747 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5748 | } else if (location.IsDoubleStackSlot()) { |
| 5749 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5750 | } |
| 5751 | locations->SetOut(location); |
| 5752 | } |
| 5753 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5754 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5755 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5756 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5757 | } |
| 5758 | |
| 5759 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5760 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5761 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5762 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5763 | } |
| 5764 | |
| 5765 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5766 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5767 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5768 | } |
| 5769 | |
| 5770 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5771 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5772 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5773 | locations->SetInAt(i, Location::Any()); |
| 5774 | } |
| 5775 | locations->SetOut(Location::Any()); |
| 5776 | } |
| 5777 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5778 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5779 | LOG(FATAL) << "Unreachable"; |
| 5780 | } |
| 5781 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5782 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5783 | DataType::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5784 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5785 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5786 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5787 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5788 | |
| 5789 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5790 | case DataType::Type::kInt32: |
| 5791 | case DataType::Type::kInt64: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5792 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5793 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5794 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5795 | break; |
| 5796 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5797 | case DataType::Type::kFloat32: |
| 5798 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5799 | InvokeRuntimeCallingConvention calling_convention; |
| 5800 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5801 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5802 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5803 | |
| 5804 | break; |
| 5805 | } |
| 5806 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5807 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5808 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5809 | } |
| 5810 | } |
| 5811 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5812 | void InstructionCodeGeneratorARM64::GenerateIntRemForPower2Denom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5813 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5814 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 5815 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 5816 | |
| 5817 | Register out = OutputRegister(instruction); |
| 5818 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5819 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 5820 | if (HasNonNegativeOrMinIntInputAt(instruction, 0)) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 5821 | // No need to adjust the result for non-negative dividends or the INT32_MIN/INT64_MIN dividends. |
| 5822 | // NOTE: The generated code for HRem correctly works for the INT32_MIN/INT64_MIN dividends. |
| 5823 | // INT*_MIN % imm must be 0 for any imm of power 2. 'and' works only with bits |
| 5824 | // 0..30 (Int32 case)/0..62 (Int64 case) of a dividend. For INT32_MIN/INT64_MIN they are zeros. |
| 5825 | // So 'and' always produces zero. |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5826 | __ And(out, dividend, abs_imm - 1); |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 5827 | } else { |
| 5828 | if (abs_imm == 2) { |
| 5829 | __ Cmp(dividend, 0); |
| 5830 | __ And(out, dividend, 1); |
| 5831 | __ Csneg(out, out, out, ge); |
| 5832 | } else { |
| 5833 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5834 | Register temp = temps.AcquireSameSizeAs(out); |
| 5835 | |
| 5836 | __ Negs(temp, dividend); |
| 5837 | __ And(out, dividend, abs_imm - 1); |
| 5838 | __ And(temp, temp, abs_imm - 1); |
| 5839 | __ Csneg(out, out, temp, mi); |
| 5840 | } |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5841 | } |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5842 | } |
| 5843 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5844 | void InstructionCodeGeneratorARM64::GenerateIntRemForConstDenom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5845 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5846 | |
| 5847 | if (imm == 0) { |
| 5848 | // Do not generate anything. |
| 5849 | // DivZeroCheck would prevent any code to be executed. |
| 5850 | return; |
| 5851 | } |
| 5852 | |
Evgeny Astigeevich | f58dc65 | 2018-06-25 17:54:07 +0100 | [diff] [blame] | 5853 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 5854 | // Cases imm == -1 or imm == 1 are handled in constant folding by |
| 5855 | // InstructionWithAbsorbingInputSimplifier. |
| 5856 | // If the cases have survided till code generation they are handled in |
| 5857 | // GenerateIntRemForPower2Denom becauses -1 and 1 are the power of 2 (2^0). |
| 5858 | // The correct code is generated for them, just more instructions. |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5859 | GenerateIntRemForPower2Denom(instruction); |
| 5860 | } else { |
| 5861 | DCHECK(imm < -2 || imm > 2) << imm; |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 5862 | GenerateDivRemWithAnyConstant(instruction, imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5863 | } |
| 5864 | } |
| 5865 | |
| 5866 | void InstructionCodeGeneratorARM64::GenerateIntRem(HRem* instruction) { |
| 5867 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 5868 | << instruction->GetResultType(); |
| 5869 | |
| 5870 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 5871 | GenerateIntRemForConstDenom(instruction); |
| 5872 | } else { |
| 5873 | Register out = OutputRegister(instruction); |
| 5874 | Register dividend = InputRegisterAt(instruction, 0); |
| 5875 | Register divisor = InputRegisterAt(instruction, 1); |
| 5876 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5877 | Register temp = temps.AcquireSameSizeAs(out); |
| 5878 | __ Sdiv(temp, dividend, divisor); |
| 5879 | __ Msub(out, temp, divisor, dividend); |
| 5880 | } |
| 5881 | } |
| 5882 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5883 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5884 | DataType::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5885 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5886 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5887 | case DataType::Type::kInt32: |
| 5888 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5889 | GenerateIntRem(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5890 | break; |
| 5891 | } |
| 5892 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5893 | case DataType::Type::kFloat32: |
| 5894 | case DataType::Type::kFloat64: { |
| 5895 | QuickEntrypointEnum entrypoint = |
| 5896 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5897 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5898 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5899 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5900 | } else { |
| 5901 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5902 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5903 | break; |
| 5904 | } |
| 5905 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5906 | default: |
| 5907 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5908 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5909 | } |
| 5910 | } |
| 5911 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5912 | void LocationsBuilderARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5913 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5914 | } |
| 5915 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5916 | void InstructionCodeGeneratorARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5917 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5918 | } |
| 5919 | |
| 5920 | void LocationsBuilderARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5921 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5922 | } |
| 5923 | |
| 5924 | void InstructionCodeGeneratorARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5925 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5926 | } |
| 5927 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5928 | void LocationsBuilderARM64::VisitAbs(HAbs* abs) { |
| 5929 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 5930 | switch (abs->GetResultType()) { |
| 5931 | case DataType::Type::kInt32: |
| 5932 | case DataType::Type::kInt64: |
| 5933 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5934 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5935 | break; |
| 5936 | case DataType::Type::kFloat32: |
| 5937 | case DataType::Type::kFloat64: |
| 5938 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5939 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5940 | break; |
| 5941 | default: |
| 5942 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5943 | } |
| 5944 | } |
| 5945 | |
| 5946 | void InstructionCodeGeneratorARM64::VisitAbs(HAbs* abs) { |
| 5947 | switch (abs->GetResultType()) { |
| 5948 | case DataType::Type::kInt32: |
| 5949 | case DataType::Type::kInt64: { |
| 5950 | Register in_reg = InputRegisterAt(abs, 0); |
| 5951 | Register out_reg = OutputRegister(abs); |
| 5952 | __ Cmp(in_reg, Operand(0)); |
| 5953 | __ Cneg(out_reg, in_reg, lt); |
| 5954 | break; |
| 5955 | } |
| 5956 | case DataType::Type::kFloat32: |
| 5957 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 5958 | VRegister in_reg = InputFPRegisterAt(abs, 0); |
| 5959 | VRegister out_reg = OutputFPRegister(abs); |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5960 | __ Fabs(out_reg, in_reg); |
| 5961 | break; |
| 5962 | } |
| 5963 | default: |
| 5964 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5965 | } |
| 5966 | } |
| 5967 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5968 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5969 | constructor_fence->SetLocations(nullptr); |
| 5970 | } |
| 5971 | |
| 5972 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5973 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5974 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5975 | } |
| 5976 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5977 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5978 | memory_barrier->SetLocations(nullptr); |
| 5979 | } |
| 5980 | |
| 5981 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5982 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5983 | } |
| 5984 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5985 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5986 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5987 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5988 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5989 | } |
| 5990 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 5991 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* ret) { |
| 5992 | if (GetGraph()->IsCompilingOsr()) { |
| 5993 | // To simplify callers of an OSR method, we put the return value in both |
| 5994 | // floating point and core register. |
| 5995 | switch (ret->InputAt(0)->GetType()) { |
| 5996 | case DataType::Type::kFloat32: |
| 5997 | __ Fmov(w0, s0); |
| 5998 | break; |
| 5999 | case DataType::Type::kFloat64: |
| 6000 | __ Fmov(x0, d0); |
| 6001 | break; |
| 6002 | default: |
| 6003 | break; |
| 6004 | } |
| 6005 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6006 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6007 | } |
| 6008 | |
| 6009 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 6010 | instruction->SetLocations(nullptr); |
| 6011 | } |
| 6012 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6013 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6014 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6015 | } |
| 6016 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 6017 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 6018 | HandleBinaryOp(ror); |
| 6019 | } |
| 6020 | |
| 6021 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 6022 | HandleBinaryOp(ror); |
| 6023 | } |
| 6024 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6025 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 6026 | HandleShift(shl); |
| 6027 | } |
| 6028 | |
| 6029 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 6030 | HandleShift(shl); |
| 6031 | } |
| 6032 | |
| 6033 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 6034 | HandleShift(shr); |
| 6035 | } |
| 6036 | |
| 6037 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 6038 | HandleShift(shr); |
| 6039 | } |
| 6040 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6041 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6042 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6043 | } |
| 6044 | |
| 6045 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6046 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6047 | } |
| 6048 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6049 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6050 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 6054 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6055 | } |
| 6056 | |
| 6057 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 6058 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6059 | } |
| 6060 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6061 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6062 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6063 | } |
| 6064 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 6065 | void LocationsBuilderARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6066 | codegen_->CreateStringBuilderAppendLocations(instruction, LocationFrom(x0)); |
| 6067 | } |
| 6068 | |
| 6069 | void InstructionCodeGeneratorARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 6070 | __ Mov(w0, instruction->GetFormat()->GetValue()); |
| 6071 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 6072 | } |
| 6073 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6074 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 6075 | HUnresolvedInstanceFieldGet* instruction) { |
| 6076 | FieldAccessCallingConventionARM64 calling_convention; |
| 6077 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6078 | instruction, instruction->GetFieldType(), calling_convention); |
| 6079 | } |
| 6080 | |
| 6081 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 6082 | HUnresolvedInstanceFieldGet* instruction) { |
| 6083 | FieldAccessCallingConventionARM64 calling_convention; |
| 6084 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6085 | instruction->GetFieldType(), |
| 6086 | instruction->GetFieldIndex(), |
| 6087 | instruction->GetDexPc(), |
| 6088 | calling_convention); |
| 6089 | } |
| 6090 | |
| 6091 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 6092 | HUnresolvedInstanceFieldSet* instruction) { |
| 6093 | FieldAccessCallingConventionARM64 calling_convention; |
| 6094 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6095 | instruction, instruction->GetFieldType(), calling_convention); |
| 6096 | } |
| 6097 | |
| 6098 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 6099 | HUnresolvedInstanceFieldSet* instruction) { |
| 6100 | FieldAccessCallingConventionARM64 calling_convention; |
| 6101 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6102 | instruction->GetFieldType(), |
| 6103 | instruction->GetFieldIndex(), |
| 6104 | instruction->GetDexPc(), |
| 6105 | calling_convention); |
| 6106 | } |
| 6107 | |
| 6108 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 6109 | HUnresolvedStaticFieldGet* instruction) { |
| 6110 | FieldAccessCallingConventionARM64 calling_convention; |
| 6111 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6112 | instruction, instruction->GetFieldType(), calling_convention); |
| 6113 | } |
| 6114 | |
| 6115 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 6116 | HUnresolvedStaticFieldGet* instruction) { |
| 6117 | FieldAccessCallingConventionARM64 calling_convention; |
| 6118 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6119 | instruction->GetFieldType(), |
| 6120 | instruction->GetFieldIndex(), |
| 6121 | instruction->GetDexPc(), |
| 6122 | calling_convention); |
| 6123 | } |
| 6124 | |
| 6125 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 6126 | HUnresolvedStaticFieldSet* instruction) { |
| 6127 | FieldAccessCallingConventionARM64 calling_convention; |
| 6128 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6129 | instruction, instruction->GetFieldType(), calling_convention); |
| 6130 | } |
| 6131 | |
| 6132 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 6133 | HUnresolvedStaticFieldSet* instruction) { |
| 6134 | FieldAccessCallingConventionARM64 calling_convention; |
| 6135 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6136 | instruction->GetFieldType(), |
| 6137 | instruction->GetFieldIndex(), |
| 6138 | instruction->GetDexPc(), |
| 6139 | calling_convention); |
| 6140 | } |
| 6141 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6142 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6143 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6144 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 6145 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 6146 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 6147 | // registers in full width (since the runtime only saves/restores lower part). |
| 6148 | locations->SetCustomSlowPathCallerSaves( |
| 6149 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6150 | } |
| 6151 | |
| 6152 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6153 | HBasicBlock* block = instruction->GetBlock(); |
| 6154 | if (block->GetLoopInformation() != nullptr) { |
| 6155 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6156 | // The back edge will generate the suspend check. |
| 6157 | return; |
| 6158 | } |
| 6159 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6160 | // The goto will generate the suspend check. |
| 6161 | return; |
| 6162 | } |
| 6163 | GenerateSuspendCheck(instruction, nullptr); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6164 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6165 | } |
| 6166 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6167 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6168 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6169 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6170 | InvokeRuntimeCallingConvention calling_convention; |
| 6171 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6172 | } |
| 6173 | |
| 6174 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 6175 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 6176 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6177 | } |
| 6178 | |
| 6179 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 6180 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6181 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6182 | DataType::Type input_type = conversion->GetInputType(); |
| 6183 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6184 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6185 | << input_type << " -> " << result_type; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6186 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 6187 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6188 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6189 | } |
| 6190 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6191 | if (DataType::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6192 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6193 | } else { |
| 6194 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6195 | } |
| 6196 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6197 | if (DataType::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6198 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6199 | } else { |
| 6200 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6201 | } |
| 6202 | } |
| 6203 | |
| 6204 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6205 | DataType::Type result_type = conversion->GetResultType(); |
| 6206 | DataType::Type input_type = conversion->GetInputType(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6207 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6208 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6209 | << input_type << " -> " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6210 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6211 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 6212 | int result_size = DataType::Size(result_type); |
| 6213 | int input_size = DataType::Size(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6214 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6215 | Register output = OutputRegister(conversion); |
| 6216 | Register source = InputRegisterAt(conversion, 0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6217 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 6218 | // 'int' values are used directly as W registers, discarding the top |
| 6219 | // bits, so we don't need to sign-extend and can just perform a move. |
| 6220 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 6221 | // top 32 bits of the target register. We theoretically could leave those |
| 6222 | // bits unchanged, but we would have to make sure that no code uses a |
| 6223 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 6224 | // zero. |
| 6225 | __ Mov(output.W(), source.W()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6226 | } else if (DataType::IsUnsignedType(result_type) || |
| 6227 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 6228 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6229 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6230 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6231 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6232 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6233 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6234 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 6235 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6236 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6237 | } else if (DataType::IsFloatingPointType(result_type) && |
| 6238 | DataType::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6239 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 6240 | } else { |
| 6241 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6242 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6243 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6244 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6245 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6246 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 6247 | HandleShift(ushr); |
| 6248 | } |
| 6249 | |
| 6250 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 6251 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6252 | } |
| 6253 | |
| 6254 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 6255 | HandleBinaryOp(instruction); |
| 6256 | } |
| 6257 | |
| 6258 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 6259 | HandleBinaryOp(instruction); |
| 6260 | } |
| 6261 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6262 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6263 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6264 | LOG(FATAL) << "Unreachable"; |
| 6265 | } |
| 6266 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6267 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6268 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6269 | LOG(FATAL) << "Unreachable"; |
| 6270 | } |
| 6271 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6272 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6273 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6274 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6275 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6276 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6277 | } |
| 6278 | |
| 6279 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6280 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6281 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6282 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 6283 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6284 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6285 | // 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] | 6286 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6287 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 6288 | // make sure we don't emit it if the target may run out of range. |
| 6289 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 6290 | // ranges and emit the tables only as required. |
| 6291 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6292 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6293 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6294 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 6295 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 6296 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6297 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6298 | Register temp = temps.AcquireW(); |
| 6299 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 6300 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6301 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6302 | // Jump to successors[0] if value == lower_bound. |
| 6303 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 6304 | int32_t last_index = 0; |
| 6305 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6306 | __ Subs(temp, temp, Operand(2)); |
| 6307 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6308 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6309 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6310 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6311 | } |
| 6312 | if (num_entries - last_index == 2) { |
| 6313 | // The last missing case_value. |
| 6314 | __ Cmp(temp, Operand(1)); |
| 6315 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6316 | } |
| 6317 | |
| 6318 | // And the default for any other value. |
| 6319 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6320 | __ B(codegen_->GetLabelOf(default_block)); |
| 6321 | } |
| 6322 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 6323 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6324 | |
| 6325 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6326 | |
| 6327 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 6328 | // registers, we are free to block one. |
| 6329 | Register temp_w = temps.AcquireW(); |
| 6330 | Register index; |
| 6331 | // Remove the bias. |
| 6332 | if (lower_bound != 0) { |
| 6333 | index = temp_w; |
| 6334 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 6335 | } else { |
| 6336 | index = value_reg; |
| 6337 | } |
| 6338 | |
| 6339 | // Jump to default block if index is out of the range. |
| 6340 | __ Cmp(index, Operand(num_entries)); |
| 6341 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 6342 | |
| 6343 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 6344 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 6345 | // register pressure. |
| 6346 | Register table_base = temps.AcquireX(); |
| 6347 | // Load jump offset from the table. |
| 6348 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 6349 | Register jump_offset = temp_w; |
| 6350 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 6351 | |
| 6352 | // Jump to target block by branching to table_base(pc related) + offset. |
| 6353 | Register target_address = table_base; |
| 6354 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 6355 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6356 | } |
| 6357 | } |
| 6358 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6359 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 6360 | HInstruction* instruction, |
| 6361 | Location out, |
| 6362 | uint32_t offset, |
| 6363 | Location maybe_temp, |
| 6364 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6365 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6366 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6367 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6368 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6369 | if (kUseBakerReadBarrier) { |
| 6370 | // Load with fast path based Baker's read barrier. |
| 6371 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6372 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6373 | out, |
| 6374 | out_reg, |
| 6375 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6376 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6377 | /* needs_null_check= */ false, |
| 6378 | /* use_load_acquire= */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6379 | } else { |
| 6380 | // Load with slow path based read barrier. |
| 6381 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6382 | // in the following move operation, as we will need it for the |
| 6383 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6384 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6385 | __ Mov(temp_reg, out_reg); |
| 6386 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6387 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6388 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6389 | } |
| 6390 | } else { |
| 6391 | // Plain load with no read barrier. |
| 6392 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6393 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6394 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6395 | } |
| 6396 | } |
| 6397 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6398 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 6399 | HInstruction* instruction, |
| 6400 | Location out, |
| 6401 | Location obj, |
| 6402 | uint32_t offset, |
| 6403 | Location maybe_temp, |
| 6404 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6405 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6406 | Register out_reg = RegisterFrom(out, type); |
| 6407 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6408 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6409 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6410 | if (kUseBakerReadBarrier) { |
| 6411 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6412 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6413 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6414 | out, |
| 6415 | obj_reg, |
| 6416 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6417 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6418 | /* needs_null_check= */ false, |
| 6419 | /* use_load_acquire= */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6420 | } else { |
| 6421 | // Load with slow path based read barrier. |
| 6422 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6423 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6424 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6425 | } |
| 6426 | } else { |
| 6427 | // Plain load with no read barrier. |
| 6428 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6429 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6430 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6431 | } |
| 6432 | } |
| 6433 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6434 | void CodeGeneratorARM64::GenerateGcRootFieldLoad( |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6435 | HInstruction* instruction, |
| 6436 | Location root, |
| 6437 | Register obj, |
| 6438 | uint32_t offset, |
| 6439 | vixl::aarch64::Label* fixup_label, |
| 6440 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6441 | DCHECK(fixup_label == nullptr || offset == 0u); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6442 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6443 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6444 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6445 | if (kUseBakerReadBarrier) { |
| 6446 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6447 | // Baker's read barrier are used. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6448 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6449 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6450 | // the Marking Register) to decide whether we need to enter |
| 6451 | // the slow path to mark the GC root. |
| 6452 | // |
| 6453 | // We use shared thunks for the slow path; shared within the method |
| 6454 | // for JIT, across methods for AOT. That thunk checks the reference |
| 6455 | // and jumps to the entrypoint if needed. |
| 6456 | // |
| 6457 | // lr = &return_address; |
| 6458 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6459 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6460 | // goto gc_root_thunk<root_reg>(lr) |
| 6461 | // } |
| 6462 | // return_address: |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6463 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6464 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6465 | DCHECK(temps.IsAvailable(ip0)); |
| 6466 | DCHECK(temps.IsAvailable(ip1)); |
| 6467 | temps.Exclude(ip0, ip1); |
| 6468 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6469 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6470 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6471 | vixl::aarch64::Label return_address; |
| 6472 | __ adr(lr, &return_address); |
| 6473 | if (fixup_label != nullptr) { |
| 6474 | __ bind(fixup_label); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6475 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6476 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6477 | "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] | 6478 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6479 | EmitBakerReadBarrierCbnz(custom_data); |
| 6480 | __ bind(&return_address); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6481 | } else { |
| 6482 | // GC root loaded through a slow path for read barriers other |
| 6483 | // than Baker's. |
| 6484 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6485 | if (fixup_label == nullptr) { |
| 6486 | __ Add(root_reg.X(), obj.X(), offset); |
| 6487 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6488 | EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6489 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6490 | // /* mirror::Object* */ root = root->Read() |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6491 | GenerateReadBarrierForRootSlow(instruction, root, root); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6492 | } |
| 6493 | } else { |
| 6494 | // Plain GC root load with no read barrier. |
| 6495 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6496 | if (fixup_label == nullptr) { |
| 6497 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6498 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6499 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6500 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6501 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6502 | // do not have to unpoison `root_reg` here. |
| 6503 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6504 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6505 | } |
| 6506 | |
Vladimir Marko | c8178f5 | 2020-11-24 10:38:16 +0000 | [diff] [blame^] | 6507 | void CodeGeneratorARM64::GenerateIntrinsicCasMoveWithBakerReadBarrier( |
| 6508 | vixl::aarch64::Register marked_old_value, |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6509 | vixl::aarch64::Register old_value) { |
| 6510 | DCHECK(kEmitCompilerReadBarrier); |
| 6511 | DCHECK(kUseBakerReadBarrier); |
| 6512 | |
| 6513 | // 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^] | 6514 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(marked_old_value.GetCode()); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6515 | |
| 6516 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6517 | vixl::aarch64::Label return_address; |
| 6518 | __ adr(lr, &return_address); |
| 6519 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6520 | "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^] | 6521 | __ mov(marked_old_value, old_value); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6522 | EmitBakerReadBarrierCbnz(custom_data); |
| 6523 | __ bind(&return_address); |
| 6524 | } |
| 6525 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6526 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6527 | Location ref, |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6528 | vixl::aarch64::Register obj, |
| 6529 | const vixl::aarch64::MemOperand& src, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6530 | bool needs_null_check, |
| 6531 | bool use_load_acquire) { |
| 6532 | DCHECK(kEmitCompilerReadBarrier); |
| 6533 | DCHECK(kUseBakerReadBarrier); |
| 6534 | |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6535 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6536 | // Marking Register) to decide whether we need to enter the slow |
| 6537 | // path to mark the reference. Then, in the slow path, check the |
| 6538 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6539 | // decide whether to mark `ref` or not. |
| 6540 | // |
| 6541 | // We use shared thunks for the slow path; shared within the method |
| 6542 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6543 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6544 | // it creates a fake dependency and returns to the LDR instruction. |
| 6545 | // |
| 6546 | // lr = &gray_return_address; |
| 6547 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6548 | // goto field_thunk<holder_reg, base_reg, use_load_acquire>(lr) |
| 6549 | // } |
| 6550 | // not_gray_return_address: |
| 6551 | // // Original reference load. If the offset is too large to fit |
| 6552 | // // into LDR, we use an adjusted base register here. |
| 6553 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 6554 | // gray_return_address: |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6555 | |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6556 | DCHECK(src.GetAddrMode() == vixl::aarch64::Offset); |
| 6557 | DCHECK_ALIGNED(src.GetOffset(), sizeof(mirror::HeapReference<mirror::Object>)); |
| 6558 | |
| 6559 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6560 | DCHECK(temps.IsAvailable(ip0)); |
| 6561 | DCHECK(temps.IsAvailable(ip1)); |
| 6562 | temps.Exclude(ip0, ip1); |
| 6563 | uint32_t custom_data = use_load_acquire |
| 6564 | ? EncodeBakerReadBarrierAcquireData(src.GetBaseRegister().GetCode(), obj.GetCode()) |
| 6565 | : EncodeBakerReadBarrierFieldData(src.GetBaseRegister().GetCode(), obj.GetCode()); |
| 6566 | |
| 6567 | { |
| 6568 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6569 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6570 | vixl::aarch64::Label return_address; |
| 6571 | __ adr(lr, &return_address); |
| 6572 | EmitBakerReadBarrierCbnz(custom_data); |
| 6573 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6574 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6575 | " 2 instructions (8B) for heap poisoning."); |
| 6576 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 6577 | if (use_load_acquire) { |
| 6578 | DCHECK_EQ(src.GetOffset(), 0); |
| 6579 | __ ldar(ref_reg, src); |
| 6580 | } else { |
| 6581 | __ ldr(ref_reg, src); |
| 6582 | } |
| 6583 | if (needs_null_check) { |
| 6584 | MaybeRecordImplicitNullCheck(instruction); |
| 6585 | } |
| 6586 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6587 | // macro instructions disallowed in ExactAssemblyScope. |
| 6588 | if (kPoisonHeapReferences) { |
| 6589 | __ neg(ref_reg, Operand(ref_reg)); |
| 6590 | } |
| 6591 | __ bind(&return_address); |
| 6592 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6593 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6594 | } |
| 6595 | |
| 6596 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6597 | Location ref, |
| 6598 | Register obj, |
| 6599 | uint32_t offset, |
| 6600 | Location maybe_temp, |
| 6601 | bool needs_null_check, |
| 6602 | bool use_load_acquire) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6603 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6604 | Register base = obj; |
| 6605 | if (use_load_acquire) { |
| 6606 | DCHECK(maybe_temp.IsRegister()); |
| 6607 | base = WRegisterFrom(maybe_temp); |
| 6608 | __ Add(base, obj, offset); |
| 6609 | offset = 0u; |
| 6610 | } else if (offset >= kReferenceLoadMinFarOffset) { |
| 6611 | DCHECK(maybe_temp.IsRegister()); |
| 6612 | base = WRegisterFrom(maybe_temp); |
| 6613 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6614 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6615 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6616 | } |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6617 | MemOperand src(base.X(), offset); |
| 6618 | GenerateFieldLoadWithBakerReadBarrier( |
| 6619 | instruction, ref, obj, src, needs_null_check, use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6620 | } |
| 6621 | |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6622 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HArrayGet* instruction, |
| 6623 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6624 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6625 | uint32_t data_offset, |
| 6626 | Location index, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6627 | bool needs_null_check) { |
| 6628 | DCHECK(kEmitCompilerReadBarrier); |
| 6629 | DCHECK(kUseBakerReadBarrier); |
| 6630 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6631 | static_assert( |
| 6632 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6633 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6634 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6635 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6636 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6637 | // Marking Register) to decide whether we need to enter the slow |
| 6638 | // path to mark the reference. Then, in the slow path, check the |
| 6639 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6640 | // decide whether to mark `ref` or not. |
| 6641 | // |
| 6642 | // We use shared thunks for the slow path; shared within the method |
| 6643 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6644 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6645 | // it creates a fake dependency and returns to the LDR instruction. |
| 6646 | // |
| 6647 | // lr = &gray_return_address; |
| 6648 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6649 | // goto array_thunk<base_reg>(lr) |
| 6650 | // } |
| 6651 | // not_gray_return_address: |
| 6652 | // // Original reference load. If the offset is too large to fit |
| 6653 | // // into LDR, we use an adjusted base register here. |
| 6654 | // HeapReference<mirror::Object> reference = data[index]; |
| 6655 | // gray_return_address: |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6656 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6657 | DCHECK(index.IsValid()); |
| 6658 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 6659 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6660 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6661 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6662 | DCHECK(temps.IsAvailable(ip0)); |
| 6663 | DCHECK(temps.IsAvailable(ip1)); |
| 6664 | temps.Exclude(ip0, ip1); |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6665 | |
| 6666 | Register temp; |
| 6667 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 6668 | // We do not need to compute the intermediate address from the array: the |
| 6669 | // input instruction has done it already. See the comment in |
| 6670 | // `TryExtractArrayAccessAddress()`. |
| 6671 | if (kIsDebugBuild) { |
| 6672 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 6673 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 6674 | } |
| 6675 | temp = obj; |
| 6676 | } else { |
| 6677 | temp = WRegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 6678 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
| 6679 | } |
| 6680 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6681 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(temp.GetCode()); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6682 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6683 | { |
| 6684 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6685 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6686 | vixl::aarch64::Label return_address; |
| 6687 | __ adr(lr, &return_address); |
| 6688 | EmitBakerReadBarrierCbnz(custom_data); |
| 6689 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6690 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6691 | " 2 instructions (8B) for heap poisoning."); |
| 6692 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6693 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6694 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6695 | // macro instructions disallowed in ExactAssemblyScope. |
| 6696 | if (kPoisonHeapReferences) { |
| 6697 | __ neg(ref_reg, Operand(ref_reg)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6698 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6699 | __ bind(&return_address); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6700 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6701 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6702 | } |
| 6703 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6704 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6705 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6706 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6707 | // The following condition is a run-time one; it is executed after the |
| 6708 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6709 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6710 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6711 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6712 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6713 | } |
| 6714 | } |
| 6715 | } |
| 6716 | |
Vladimir Marko | 1bff99f | 2020-11-02 15:07:33 +0000 | [diff] [blame] | 6717 | SlowPathCodeARM64* CodeGeneratorARM64::AddReadBarrierSlowPath(HInstruction* instruction, |
| 6718 | Location out, |
| 6719 | Location ref, |
| 6720 | Location obj, |
| 6721 | uint32_t offset, |
| 6722 | Location index) { |
| 6723 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
| 6724 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6725 | AddSlowPath(slow_path); |
| 6726 | return slow_path; |
| 6727 | } |
| 6728 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6729 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6730 | Location out, |
| 6731 | Location ref, |
| 6732 | Location obj, |
| 6733 | uint32_t offset, |
| 6734 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6735 | DCHECK(kEmitCompilerReadBarrier); |
| 6736 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6737 | // Insert a slow path based read barrier *after* the reference load. |
| 6738 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6739 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6740 | // reference will be carried out by the runtime within the slow |
| 6741 | // path. |
| 6742 | // |
| 6743 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6744 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6745 | // not used by the artReadBarrierSlow entry point. |
| 6746 | // |
| 6747 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 1bff99f | 2020-11-02 15:07:33 +0000 | [diff] [blame] | 6748 | SlowPathCodeARM64* slow_path = AddReadBarrierSlowPath(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6749 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6750 | __ B(slow_path->GetEntryLabel()); |
| 6751 | __ Bind(slow_path->GetExitLabel()); |
| 6752 | } |
| 6753 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6754 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6755 | Location out, |
| 6756 | Location ref, |
| 6757 | Location obj, |
| 6758 | uint32_t offset, |
| 6759 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6760 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6761 | // Baker's read barriers shall be handled by the fast path |
| 6762 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6763 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6764 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6765 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6766 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6767 | } else if (kPoisonHeapReferences) { |
| 6768 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6769 | } |
| 6770 | } |
| 6771 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6772 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6773 | Location out, |
| 6774 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6775 | DCHECK(kEmitCompilerReadBarrier); |
| 6776 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6777 | // Insert a slow path based read barrier *after* the GC root load. |
| 6778 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6779 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6780 | // not need to do anything special for this here. |
| 6781 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6782 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6783 | AddSlowPath(slow_path); |
| 6784 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6785 | __ B(slow_path->GetEntryLabel()); |
| 6786 | __ Bind(slow_path->GetExitLabel()); |
| 6787 | } |
| 6788 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6789 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6790 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6791 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6792 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6793 | locations->SetOut(Location::RequiresRegister()); |
| 6794 | } |
| 6795 | |
| 6796 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6797 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6798 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6799 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6800 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6801 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6802 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6803 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6804 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6805 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6806 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6807 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6808 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6809 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6810 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6811 | } |
| 6812 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6813 | static void PatchJitRootUse(uint8_t* code, |
| 6814 | const uint8_t* roots_data, |
| 6815 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6816 | uint64_t index_in_table) { |
| 6817 | uint32_t literal_offset = literal->GetOffset(); |
| 6818 | uintptr_t address = |
| 6819 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6820 | uint8_t* data = code + literal_offset; |
| 6821 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6822 | } |
| 6823 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6824 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6825 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6826 | const StringReference& string_reference = entry.first; |
| 6827 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6828 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6829 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6830 | } |
| 6831 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6832 | const TypeReference& type_reference = entry.first; |
| 6833 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6834 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6835 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6836 | } |
| 6837 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6838 | |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 6839 | MemOperand InstructionCodeGeneratorARM64::VecNeonAddress( |
| 6840 | HVecMemoryOperation* instruction, |
| 6841 | UseScratchRegisterScope* temps_scope, |
| 6842 | size_t size, |
| 6843 | bool is_string_char_at, |
| 6844 | /*out*/ Register* scratch) { |
| 6845 | LocationSummary* locations = instruction->GetLocations(); |
| 6846 | Register base = InputRegisterAt(instruction, 0); |
| 6847 | |
| 6848 | if (instruction->InputAt(1)->IsIntermediateAddressIndex()) { |
| 6849 | DCHECK(!is_string_char_at); |
| 6850 | return MemOperand(base.X(), InputRegisterAt(instruction, 1).X()); |
| 6851 | } |
| 6852 | |
| 6853 | Location index = locations->InAt(1); |
| 6854 | uint32_t offset = is_string_char_at |
| 6855 | ? mirror::String::ValueOffset().Uint32Value() |
| 6856 | : mirror::Array::DataOffset(size).Uint32Value(); |
| 6857 | size_t shift = ComponentSizeShiftWidth(size); |
| 6858 | |
| 6859 | // HIntermediateAddress optimization is only applied for scalar ArrayGet and ArraySet. |
| 6860 | DCHECK(!instruction->InputAt(0)->IsIntermediateAddress()); |
| 6861 | |
| 6862 | if (index.IsConstant()) { |
| 6863 | offset += Int64FromLocation(index) << shift; |
| 6864 | return HeapOperand(base, offset); |
| 6865 | } else { |
| 6866 | *scratch = temps_scope->AcquireSameSizeAs(base); |
| 6867 | __ Add(*scratch, base, Operand(WRegisterFrom(index), LSL, shift)); |
| 6868 | return HeapOperand(*scratch, offset); |
| 6869 | } |
| 6870 | } |
| 6871 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6872 | #undef __ |
| 6873 | #undef QUICK_ENTRY_POINT |
| 6874 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6875 | #define __ assembler.GetVIXLAssembler()-> |
| 6876 | |
| 6877 | static void EmitGrayCheckAndFastPath(arm64::Arm64Assembler& assembler, |
| 6878 | vixl::aarch64::Register base_reg, |
| 6879 | vixl::aarch64::MemOperand& lock_word, |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6880 | vixl::aarch64::Label* slow_path, |
| 6881 | vixl::aarch64::Label* throw_npe = nullptr) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6882 | // Load the lock word containing the rb_state. |
| 6883 | __ Ldr(ip0.W(), lock_word); |
| 6884 | // 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] | 6885 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6886 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 6887 | __ Tbnz(ip0.W(), LockWord::kReadBarrierStateShift, slow_path); |
| 6888 | static_assert( |
| 6889 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET, |
| 6890 | "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] | 6891 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 6892 | if (throw_npe != nullptr) { |
| 6893 | __ Bind(throw_npe); |
| 6894 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6895 | // Adjust the return address back to the LDR (1 instruction; 2 for heap poisoning). |
| 6896 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6897 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6898 | " 2 instructions (8B) for heap poisoning."); |
| 6899 | __ Add(lr, lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6900 | // Introduce a dependency on the lock_word including rb_state, |
| 6901 | // to prevent load-load reordering, and without using |
| 6902 | // a memory barrier (which would be more expensive). |
| 6903 | __ Add(base_reg, base_reg, Operand(ip0, LSR, 32)); |
| 6904 | __ Br(lr); // And return back to the function. |
| 6905 | // Note: The fake dependency is unnecessary for the slow path. |
| 6906 | } |
| 6907 | |
| 6908 | // Load the read barrier introspection entrypoint in register `entrypoint`. |
| 6909 | static void LoadReadBarrierMarkIntrospectionEntrypoint(arm64::Arm64Assembler& assembler, |
| 6910 | vixl::aarch64::Register entrypoint) { |
| 6911 | // entrypoint = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6912 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6913 | const int32_t entry_point_offset = |
| 6914 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6915 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| 6916 | } |
| 6917 | |
| 6918 | void CodeGeneratorARM64::CompileBakerReadBarrierThunk(Arm64Assembler& assembler, |
| 6919 | uint32_t encoded_data, |
| 6920 | /*out*/ std::string* debug_name) { |
| 6921 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 6922 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6923 | case BakerReadBarrierKind::kField: |
| 6924 | case BakerReadBarrierKind::kAcquire: { |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 6925 | Register base_reg = |
| 6926 | vixl::aarch64::XRegister(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6927 | CheckValidReg(base_reg.GetCode()); |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 6928 | Register holder_reg = |
| 6929 | vixl::aarch64::XRegister(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6930 | CheckValidReg(holder_reg.GetCode()); |
| 6931 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6932 | temps.Exclude(ip0, ip1); |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 6933 | // In the case of a field load (with relaxed semantic), if `base_reg` differs from |
| 6934 | // `holder_reg`, the offset was too large and we must have emitted (during the construction |
| 6935 | // of the HIR graph, see `art::HInstructionBuilder::BuildInstanceFieldAccess`) and preserved |
| 6936 | // (see `art::PrepareForRegisterAllocation::VisitNullCheck`) an explicit null check before |
| 6937 | // the load. Otherwise, for implicit null checks, we need to null-check the holder as we do |
| 6938 | // not necessarily do that check before going to the thunk. |
| 6939 | // |
| 6940 | // In the case of a field load with load-acquire semantics (where `base_reg` always differs |
| 6941 | // from `holder_reg`), we also need an explicit null check when implicit null checks are |
| 6942 | // allowed, as we do not emit one before going to the thunk. |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6943 | vixl::aarch64::Label throw_npe_label; |
| 6944 | vixl::aarch64::Label* throw_npe = nullptr; |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 6945 | if (GetCompilerOptions().GetImplicitNullChecks() && |
| 6946 | (holder_reg.Is(base_reg) || (kind == BakerReadBarrierKind::kAcquire))) { |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6947 | throw_npe = &throw_npe_label; |
| 6948 | __ Cbz(holder_reg.W(), throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6949 | } |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6950 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 6951 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 6952 | // to load the reference and call the entrypoint that performs further checks on the |
| 6953 | // reference and marks it if needed. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6954 | vixl::aarch64::Label slow_path; |
| 6955 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6956 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6957 | __ Bind(&slow_path); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6958 | if (kind == BakerReadBarrierKind::kField) { |
| 6959 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6960 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (immediate) unsigned offset. |
| 6961 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6962 | __ Ubfx(ip0.W(), ip0.W(), 10, 12); // Extract the offset. |
| 6963 | __ Ldr(ip0.W(), MemOperand(base_reg, ip0, LSL, 2)); // Load the reference. |
| 6964 | } else { |
| 6965 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 6966 | DCHECK(!base_reg.Is(holder_reg)); |
| 6967 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6968 | __ Ldar(ip0.W(), MemOperand(base_reg)); |
| 6969 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6970 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 6971 | __ Br(ip1); // Jump to the entrypoint. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6972 | break; |
| 6973 | } |
| 6974 | case BakerReadBarrierKind::kArray: { |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 6975 | Register base_reg = |
| 6976 | vixl::aarch64::XRegister(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6977 | CheckValidReg(base_reg.GetCode()); |
| 6978 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6979 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6980 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6981 | temps.Exclude(ip0, ip1); |
| 6982 | vixl::aarch64::Label slow_path; |
| 6983 | int32_t data_offset = |
| 6984 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 6985 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 6986 | DCHECK_LT(lock_word.GetOffset(), 0); |
| 6987 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path); |
| 6988 | __ Bind(&slow_path); |
| 6989 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| 6990 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (register) unsigned offset. |
| 6991 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6992 | __ Ubfx(ip0, ip0, 16, 6); // Extract the index register, plus 32 (bit 21 is set). |
| 6993 | __ Bfi(ip1, ip0, 3, 6); // Insert ip0 to the entrypoint address to create |
| 6994 | // a switch case target based on the index register. |
| 6995 | __ Mov(ip0, base_reg); // Move the base register to ip0. |
| 6996 | __ Br(ip1); // Jump to the entrypoint's array switch case. |
| 6997 | break; |
| 6998 | } |
| 6999 | case BakerReadBarrierKind::kGcRoot: { |
| 7000 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 7001 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 7002 | // otherwise return the reference (or the extracted forwarding address). |
| 7003 | // There is no gray bit check for GC roots. |
Artem Serov | a07de55 | 2020-11-01 22:42:43 +0000 | [diff] [blame] | 7004 | Register root_reg = |
| 7005 | vixl::aarch64::WRegister(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7006 | CheckValidReg(root_reg.GetCode()); |
| 7007 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7008 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7009 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 7010 | temps.Exclude(ip0, ip1); |
| 7011 | vixl::aarch64::Label return_label, not_marked, forwarding_address; |
| 7012 | __ Cbz(root_reg, &return_label); |
| 7013 | MemOperand lock_word(root_reg.X(), mirror::Object::MonitorOffset().Int32Value()); |
| 7014 | __ Ldr(ip0.W(), lock_word); |
| 7015 | __ Tbz(ip0.W(), LockWord::kMarkBitStateShift, ¬_marked); |
| 7016 | __ Bind(&return_label); |
| 7017 | __ Br(lr); |
| 7018 | __ Bind(¬_marked); |
| 7019 | __ Tst(ip0.W(), Operand(ip0.W(), LSL, 1)); |
| 7020 | __ B(&forwarding_address, mi); |
| 7021 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 7022 | // Adjust the art_quick_read_barrier_mark_introspection address in IP1 to |
| 7023 | // art_quick_read_barrier_mark_introspection_gc_roots. |
| 7024 | __ Add(ip1, ip1, Operand(BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET)); |
| 7025 | __ Mov(ip0.W(), root_reg); |
| 7026 | __ Br(ip1); |
| 7027 | __ Bind(&forwarding_address); |
| 7028 | __ Lsl(root_reg, ip0.W(), LockWord::kForwardingAddressShift); |
| 7029 | __ Br(lr); |
| 7030 | break; |
| 7031 | } |
| 7032 | default: |
| 7033 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 7034 | UNREACHABLE(); |
| 7035 | } |
| 7036 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 7037 | // For JIT, the slow path is considered part of the compiled method, |
Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 7038 | // so JIT should pass null as `debug_name`. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 7039 | DCHECK(!GetCompilerOptions().IsJitCompiler() || debug_name == nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 7040 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7041 | std::ostringstream oss; |
| 7042 | oss << "BakerReadBarrierThunk"; |
| 7043 | switch (kind) { |
| 7044 | case BakerReadBarrierKind::kField: |
| 7045 | oss << "Field_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 7046 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 7047 | break; |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 7048 | case BakerReadBarrierKind::kAcquire: |
| 7049 | oss << "Acquire_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 7050 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 7051 | break; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7052 | case BakerReadBarrierKind::kArray: |
| 7053 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 7054 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7055 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7056 | break; |
| 7057 | case BakerReadBarrierKind::kGcRoot: |
| 7058 | oss << "GcRoot_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 7059 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 7060 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 7061 | break; |
| 7062 | } |
| 7063 | *debug_name = oss.str(); |
| 7064 | } |
| 7065 | } |
| 7066 | |
| 7067 | #undef __ |
| 7068 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 7069 | } // namespace arm64 |
| 7070 | } // namespace art |