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" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 33 | #include "intrinsics.h" |
| 34 | #include "intrinsics_arm64.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 35 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 36 | #include "lock_word.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 37 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 38 | #include "mirror/class-inl.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 39 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 40 | #include "thread.h" |
| 41 | #include "utils/arm64/assembler_arm64.h" |
| 42 | #include "utils/assembler.h" |
| 43 | #include "utils/stack_checks.h" |
| 44 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 45 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 46 | using vixl::ExactAssemblyScope; |
| 47 | using vixl::CodeBufferCheckScope; |
| 48 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 49 | |
| 50 | #ifdef __ |
| 51 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 52 | #endif |
| 53 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 54 | namespace art { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 55 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 56 | template<class MirrorType> |
| 57 | class GcRoot; |
| 58 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 59 | namespace arm64 { |
| 60 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 61 | using helpers::ARM64EncodableConstantOrRegister; |
| 62 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 63 | using helpers::CPURegisterFrom; |
| 64 | using helpers::DRegisterFrom; |
| 65 | using helpers::FPRegisterFrom; |
| 66 | using helpers::HeapOperand; |
| 67 | using helpers::HeapOperandFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 68 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 70 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 71 | using helpers::InputRegisterAt; |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 72 | using helpers::Int64FromLocation; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 73 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 74 | using helpers::LocationFrom; |
| 75 | using helpers::OperandFromMemOperand; |
| 76 | using helpers::OutputCPURegister; |
| 77 | using helpers::OutputFPRegister; |
| 78 | using helpers::OutputRegister; |
| 79 | using helpers::RegisterFrom; |
| 80 | using helpers::StackOperandFrom; |
| 81 | using helpers::VIXLRegCodeFromART; |
| 82 | using helpers::WRegisterFrom; |
| 83 | using helpers::XRegisterFrom; |
| 84 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 85 | // 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] | 86 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 87 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 88 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 89 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 90 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 91 | // 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] | 92 | // 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] | 93 | // the offset explicitly. |
| 94 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 95 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 96 | inline Condition ARM64Condition(IfCondition cond) { |
| 97 | switch (cond) { |
| 98 | case kCondEQ: return eq; |
| 99 | case kCondNE: return ne; |
| 100 | case kCondLT: return lt; |
| 101 | case kCondLE: return le; |
| 102 | case kCondGT: return gt; |
| 103 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 104 | case kCondB: return lo; |
| 105 | case kCondBE: return ls; |
| 106 | case kCondA: return hi; |
| 107 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 108 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 109 | LOG(FATAL) << "Unreachable"; |
| 110 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 113 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 114 | // The ARM64 condition codes can express all the necessary branches, see the |
| 115 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 116 | // There is no dex instruction or HIR that would need the missing conditions |
| 117 | // "equal or unordered" or "not equal". |
| 118 | switch (cond) { |
| 119 | case kCondEQ: return eq; |
| 120 | case kCondNE: return ne /* unordered */; |
| 121 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 122 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 123 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 124 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 125 | default: |
| 126 | LOG(FATAL) << "UNREACHABLE"; |
| 127 | UNREACHABLE(); |
| 128 | } |
| 129 | } |
| 130 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 131 | Location ARM64ReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 132 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 133 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 134 | // but we use the exact registers for clarity. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 135 | if (return_type == DataType::Type::kFloat32) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 136 | return LocationFrom(s0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 137 | } else if (return_type == DataType::Type::kFloat64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 138 | return LocationFrom(d0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 139 | } else if (return_type == DataType::Type::kInt64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 140 | return LocationFrom(x0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 141 | } else if (return_type == DataType::Type::kVoid) { |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 142 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 143 | } else { |
| 144 | return LocationFrom(w0); |
| 145 | } |
| 146 | } |
| 147 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 148 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 149 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 152 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 153 | InvokeRuntimeCallingConvention calling_convention; |
| 154 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 155 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 156 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 157 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 158 | DataType::Type::kReference).GetCode()); |
| 159 | return caller_saves; |
| 160 | } |
| 161 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 162 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 163 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 164 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 165 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 166 | // Calculate memory accessing operand for save/restore live registers. |
| 167 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 168 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 169 | int64_t spill_offset, |
| 170 | bool is_save) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 171 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
| 172 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 173 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 174 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 175 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 176 | codegen->GetNumberOfFloatingPointRegisters())); |
| 177 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 178 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 179 | const unsigned v_reg_size_in_bits = codegen->GetSlowPathFPWidth() * 8; |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 180 | DCHECK_LE(codegen->GetSIMDRegisterWidth(), kQRegSizeInBytes); |
Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 181 | 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] | 182 | |
| 183 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 184 | UseScratchRegisterScope temps(masm); |
| 185 | |
| 186 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 187 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 188 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 189 | int64_t reg_size = kXRegSizeInBytes; |
| 190 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 191 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 192 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 193 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 194 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 195 | // to compute the base address(float point registers spill base address). |
| 196 | Register new_base = temps.AcquireSameSizeAs(base); |
| 197 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 198 | base = new_base; |
| 199 | spill_offset = -core_spill_size; |
| 200 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 201 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 202 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 203 | } |
| 204 | |
| 205 | if (is_save) { |
| 206 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 207 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 208 | } else { |
| 209 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 210 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 215 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 216 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 217 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 218 | // If the register holds an object, update the stack mask. |
| 219 | if (locations->RegisterContainsObject(i)) { |
| 220 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 221 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 222 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 223 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 224 | saved_core_stack_offsets_[i] = stack_offset; |
| 225 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 226 | } |
| 227 | |
Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 228 | const size_t fp_reg_size = codegen->GetSlowPathFPWidth(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 229 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 230 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 231 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 232 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 233 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 234 | stack_offset += fp_reg_size; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 235 | } |
| 236 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 237 | SaveRestoreLiveRegistersHelper(codegen, |
| 238 | locations, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 239 | codegen->GetFirstRegisterSlotInSlowPath(), /* is_save= */ true); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 243 | SaveRestoreLiveRegistersHelper(codegen, |
| 244 | locations, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 245 | codegen->GetFirstRegisterSlotInSlowPath(), /* is_save= */ false); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 246 | } |
| 247 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 248 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 249 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 250 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 251 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 252 | void EmitNativeCode(CodeGenerator* codegen) override { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 253 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 254 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 255 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 256 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 257 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 258 | // Live registers will be restored in the catch block if caught. |
| 259 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 260 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 261 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 262 | // move resolver. |
| 263 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 264 | codegen->EmitParallelMoves(locations->InAt(0), |
| 265 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 266 | DataType::Type::kInt32, |
| 267 | locations->InAt(1), |
| 268 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 269 | DataType::Type::kInt32); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 270 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 271 | ? kQuickThrowStringBounds |
| 272 | : kQuickThrowArrayBounds; |
| 273 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 274 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 275 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 276 | } |
| 277 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 278 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 279 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 280 | const char* GetDescription() const override { return "BoundsCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 281 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 282 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 283 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 284 | }; |
| 285 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 286 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 287 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 288 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 289 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 290 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 291 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 292 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 293 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 294 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 297 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 298 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 299 | const char* GetDescription() const override { return "DivZeroCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 300 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 301 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 302 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 303 | }; |
| 304 | |
| 305 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 306 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 307 | LoadClassSlowPathARM64(HLoadClass* cls, HInstruction* at) |
| 308 | : SlowPathCodeARM64(at), cls_(cls) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 309 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 310 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 313 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 314 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 315 | Location out = locations->Out(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 316 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 317 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 318 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 319 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 320 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 321 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 322 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 323 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 324 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 325 | if (must_resolve_type) { |
| 326 | DCHECK(IsSameDexFile(cls_->GetDexFile(), arm64_codegen->GetGraph()->GetDexFile())); |
| 327 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 328 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 329 | arm64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 330 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 331 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 332 | } else { |
| 333 | DCHECK(must_do_clinit); |
| 334 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 335 | arm64_codegen->MoveLocation(LocationFrom(calling_convention.GetRegisterAt(0)), |
| 336 | source, |
| 337 | cls_->GetType()); |
| 338 | } |
| 339 | if (must_do_clinit) { |
| 340 | arm64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 341 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 342 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 343 | |
| 344 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 345 | if (out.IsValid()) { |
| 346 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 347 | DataType::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 348 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 349 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 350 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 351 | __ B(GetExitLabel()); |
| 352 | } |
| 353 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 354 | const char* GetDescription() const override { return "LoadClassSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 355 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 356 | private: |
| 357 | // The class this slow path will load. |
| 358 | HLoadClass* const cls_; |
| 359 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 360 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 361 | }; |
| 362 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 363 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 364 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 365 | explicit LoadStringSlowPathARM64(HLoadString* instruction) |
| 366 | : SlowPathCodeARM64(instruction) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 367 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 368 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 369 | LocationSummary* locations = instruction_->GetLocations(); |
| 370 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 371 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 372 | |
| 373 | __ Bind(GetEntryLabel()); |
| 374 | SaveLiveRegisters(codegen, locations); |
| 375 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 376 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 377 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 378 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 379 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 380 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 381 | DataType::Type type = instruction_->GetType(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 382 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 383 | |
| 384 | RestoreLiveRegisters(codegen, locations); |
| 385 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 386 | __ B(GetExitLabel()); |
| 387 | } |
| 388 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 389 | const char* GetDescription() const override { return "LoadStringSlowPathARM64"; } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 390 | |
| 391 | private: |
| 392 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 393 | }; |
| 394 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 395 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 396 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 397 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 398 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 399 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 400 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 401 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 402 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 403 | // Live registers will be restored in the catch block if caught. |
| 404 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 405 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 406 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 407 | instruction_, |
| 408 | instruction_->GetDexPc(), |
| 409 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 410 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 411 | } |
| 412 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 413 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 414 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 415 | const char* GetDescription() const override { return "NullCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 416 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 417 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 418 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 419 | }; |
| 420 | |
| 421 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 422 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 423 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 424 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 425 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 426 | void EmitNativeCode(CodeGenerator* codegen) override { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 427 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 428 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 429 | __ Bind(GetEntryLabel()); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 430 | SaveLiveRegisters(codegen, locations); // Only saves live vector regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 431 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 432 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 433 | RestoreLiveRegisters(codegen, locations); // Only restores live vector regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 434 | if (successor_ == nullptr) { |
| 435 | __ B(GetReturnLabel()); |
| 436 | } else { |
| 437 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 438 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 439 | } |
| 440 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 441 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 442 | DCHECK(successor_ == nullptr); |
| 443 | return &return_label_; |
| 444 | } |
| 445 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 446 | HBasicBlock* GetSuccessor() const { |
| 447 | return successor_; |
| 448 | } |
| 449 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 450 | const char* GetDescription() const override { return "SuspendCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 451 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 452 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 453 | // If not null, the block to branch to after the suspend check. |
| 454 | HBasicBlock* const successor_; |
| 455 | |
| 456 | // 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] | 457 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 458 | |
| 459 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 460 | }; |
| 461 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 462 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 463 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 464 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 465 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 466 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 467 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 468 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 469 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 470 | DCHECK(instruction_->IsCheckCast() |
| 471 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 472 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 473 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 474 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 475 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 476 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 477 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 478 | SaveLiveRegisters(codegen, locations); |
| 479 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 480 | |
| 481 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 482 | // move resolver. |
| 483 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 484 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 485 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 486 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 487 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 488 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 489 | DataType::Type::kReference); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 490 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 491 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 492 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 493 | DataType::Type ret_type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 494 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 495 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 496 | } else { |
| 497 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 498 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 499 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 502 | if (!is_fatal_) { |
| 503 | RestoreLiveRegisters(codegen, locations); |
| 504 | __ B(GetExitLabel()); |
| 505 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 508 | const char* GetDescription() const override { return "TypeCheckSlowPathARM64"; } |
| 509 | bool IsFatal() const override { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 510 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 511 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 512 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 513 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 514 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 515 | }; |
| 516 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 517 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 518 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 519 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 520 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 521 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 522 | void EmitNativeCode(CodeGenerator* codegen) override { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 523 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 524 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 525 | LocationSummary* locations = instruction_->GetLocations(); |
| 526 | SaveLiveRegisters(codegen, locations); |
| 527 | InvokeRuntimeCallingConvention calling_convention; |
| 528 | __ Mov(calling_convention.GetRegisterAt(0), |
| 529 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 530 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 531 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 534 | const char* GetDescription() const override { return "DeoptimizationSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 535 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 536 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 537 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 538 | }; |
| 539 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 540 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 541 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 542 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 543 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 544 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 545 | LocationSummary* locations = instruction_->GetLocations(); |
| 546 | __ Bind(GetEntryLabel()); |
| 547 | SaveLiveRegisters(codegen, locations); |
| 548 | |
| 549 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 550 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 551 | parallel_move.AddMove( |
| 552 | locations->InAt(0), |
| 553 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 554 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 555 | nullptr); |
| 556 | parallel_move.AddMove( |
| 557 | locations->InAt(1), |
| 558 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 559 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 560 | nullptr); |
| 561 | parallel_move.AddMove( |
| 562 | locations->InAt(2), |
| 563 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 564 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 565 | nullptr); |
| 566 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 567 | |
| 568 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 569 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 570 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 571 | RestoreLiveRegisters(codegen, locations); |
| 572 | __ B(GetExitLabel()); |
| 573 | } |
| 574 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 575 | const char* GetDescription() const override { return "ArraySetSlowPathARM64"; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 576 | |
| 577 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 578 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 579 | }; |
| 580 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 581 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 582 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 583 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 584 | |
| 585 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 586 | // 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] | 587 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 588 | num_entries * sizeof(int32_t), |
| 589 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 590 | |
| 591 | __ Bind(&table_start_); |
| 592 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 593 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 594 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 595 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 596 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 597 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 598 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 599 | Literal<int32_t> literal(jump_offset); |
| 600 | __ place(&literal); |
| 601 | } |
| 602 | } |
| 603 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 604 | // Slow path generating a read barrier for a heap reference. |
| 605 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 606 | public: |
| 607 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 608 | Location out, |
| 609 | Location ref, |
| 610 | Location obj, |
| 611 | uint32_t offset, |
| 612 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 613 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 614 | out_(out), |
| 615 | ref_(ref), |
| 616 | obj_(obj), |
| 617 | offset_(offset), |
| 618 | index_(index) { |
| 619 | DCHECK(kEmitCompilerReadBarrier); |
| 620 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 621 | // has been overwritten by (or after) the heap object reference load |
| 622 | // to be instrumented, e.g.: |
| 623 | // |
| 624 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 625 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 626 | // |
| 627 | // In that case, we have lost the information about the original |
| 628 | // object, and the emitted read barrier cannot work properly. |
| 629 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 630 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 631 | } |
| 632 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 633 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 634 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 635 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 636 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 637 | DCHECK(locations->CanCall()); |
| 638 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 639 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 640 | instruction_->IsStaticFieldGet() || |
| 641 | instruction_->IsArrayGet() || |
| 642 | instruction_->IsInstanceOf() || |
| 643 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 644 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 645 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 646 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 647 | // The read barrier instrumentation of object ArrayGet |
| 648 | // instructions does not support the HIntermediateAddress |
| 649 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 650 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 651 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 652 | |
| 653 | __ Bind(GetEntryLabel()); |
| 654 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 655 | SaveLiveRegisters(codegen, locations); |
| 656 | |
| 657 | // We may have to change the index's value, but as `index_` is a |
| 658 | // constant member (like other "inputs" of this slow path), |
| 659 | // introduce a copy of it, `index`. |
| 660 | Location index = index_; |
| 661 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 662 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 663 | if (instruction_->IsArrayGet()) { |
| 664 | // Compute the actual memory offset and store it in `index`. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 665 | Register index_reg = RegisterFrom(index_, DataType::Type::kInt32); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 666 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 667 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 668 | // We are about to change the value of `index_reg` (see the |
| 669 | // calls to vixl::MacroAssembler::Lsl and |
| 670 | // vixl::MacroAssembler::Mov below), but it has |
| 671 | // not been saved by the previous call to |
| 672 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 673 | // callee-save register -- |
| 674 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 675 | // callee-save registers, as it has been designed with the |
| 676 | // assumption that callee-save registers are supposed to be |
| 677 | // handled by the called function. So, as a callee-save |
| 678 | // register, `index_reg` _would_ eventually be saved onto |
| 679 | // the stack, but it would be too late: we would have |
| 680 | // changed its value earlier. Therefore, we manually save |
| 681 | // it here into another freely available register, |
| 682 | // `free_reg`, chosen of course among the caller-save |
| 683 | // registers (as a callee-save `free_reg` register would |
| 684 | // exhibit the same problem). |
| 685 | // |
| 686 | // Note we could have requested a temporary register from |
| 687 | // the register allocator instead; but we prefer not to, as |
| 688 | // this is a slow path, and we know we can find a |
| 689 | // caller-save register that is available. |
| 690 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 691 | __ Mov(free_reg.W(), index_reg); |
| 692 | index_reg = free_reg; |
| 693 | index = LocationFrom(index_reg); |
| 694 | } else { |
| 695 | // The initial register stored in `index_` has already been |
| 696 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 697 | // (as it is not a callee-save register), so we can freely |
| 698 | // use it. |
| 699 | } |
| 700 | // Shifting the index value contained in `index_reg` by the scale |
| 701 | // factor (2) cannot overflow in practice, as the runtime is |
| 702 | // unable to allocate object arrays with a size larger than |
| 703 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 704 | __ Lsl(index_reg, index_reg, DataType::SizeShift(type)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 705 | static_assert( |
| 706 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 707 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 708 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 709 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 710 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 711 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 712 | // (as in the case of ArrayGet), as it is actually an offset |
| 713 | // to an object field within an object. |
| 714 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 715 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 716 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 717 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 718 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 719 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 720 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | |
| 724 | // We're moving two or three locations to locations that could |
| 725 | // overlap, so we need a parallel move resolver. |
| 726 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 727 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 728 | parallel_move.AddMove(ref_, |
| 729 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 730 | type, |
| 731 | nullptr); |
| 732 | parallel_move.AddMove(obj_, |
| 733 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 734 | type, |
| 735 | nullptr); |
| 736 | if (index.IsValid()) { |
| 737 | parallel_move.AddMove(index, |
| 738 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 739 | DataType::Type::kInt32, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 740 | nullptr); |
| 741 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 742 | } else { |
| 743 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 744 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 745 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 746 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 747 | instruction_, |
| 748 | instruction_->GetDexPc(), |
| 749 | this); |
| 750 | CheckEntrypointTypes< |
| 751 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 752 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 753 | |
| 754 | RestoreLiveRegisters(codegen, locations); |
| 755 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 756 | __ B(GetExitLabel()); |
| 757 | } |
| 758 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 759 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 760 | |
| 761 | private: |
| 762 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 763 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 764 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 765 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 766 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 767 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 768 | } |
| 769 | } |
| 770 | // We shall never fail to find a free caller-save register, as |
| 771 | // there are more than two core caller-save registers on ARM64 |
| 772 | // (meaning it is possible to find one which is different from |
| 773 | // `ref` and `obj`). |
| 774 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 775 | LOG(FATAL) << "Could not find a free register"; |
| 776 | UNREACHABLE(); |
| 777 | } |
| 778 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 779 | const Location out_; |
| 780 | const Location ref_; |
| 781 | const Location obj_; |
| 782 | const uint32_t offset_; |
| 783 | // An additional location containing an index to an array. |
| 784 | // Only used for HArrayGet and the UnsafeGetObject & |
| 785 | // UnsafeGetObjectVolatile intrinsics. |
| 786 | const Location index_; |
| 787 | |
| 788 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 789 | }; |
| 790 | |
| 791 | // Slow path generating a read barrier for a GC root. |
| 792 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 793 | public: |
| 794 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 795 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 796 | DCHECK(kEmitCompilerReadBarrier); |
| 797 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 798 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 799 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 800 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 801 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 802 | DCHECK(locations->CanCall()); |
| 803 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 804 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 805 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 806 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 807 | |
| 808 | __ Bind(GetEntryLabel()); |
| 809 | SaveLiveRegisters(codegen, locations); |
| 810 | |
| 811 | InvokeRuntimeCallingConvention calling_convention; |
| 812 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 813 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 814 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 815 | // thus we need a 64-bit move here, and we cannot use |
| 816 | // |
| 817 | // arm64_codegen->MoveLocation( |
| 818 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 819 | // root_, |
| 820 | // type); |
| 821 | // |
| 822 | // 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] | 823 | // reference type (`DataType::Type::kReference`). |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 824 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 825 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 826 | instruction_, |
| 827 | instruction_->GetDexPc(), |
| 828 | this); |
| 829 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 830 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 831 | |
| 832 | RestoreLiveRegisters(codegen, locations); |
| 833 | __ B(GetExitLabel()); |
| 834 | } |
| 835 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 836 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathARM64"; } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 837 | |
| 838 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 839 | const Location out_; |
| 840 | const Location root_; |
| 841 | |
| 842 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 843 | }; |
| 844 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 845 | #undef __ |
| 846 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 847 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 848 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 849 | if (type == DataType::Type::kVoid) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 850 | LOG(FATAL) << "Unreachable type " << type; |
| 851 | } |
| 852 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 853 | if (DataType::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 854 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 855 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 856 | } else if (!DataType::IsFloatingPointType(type) && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 857 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 858 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 859 | } else { |
| 860 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 861 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 862 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 863 | } |
| 864 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 865 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 866 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 867 | return next_location; |
| 868 | } |
| 869 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 870 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 871 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 872 | } |
| 873 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 874 | Location CriticalNativeCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
| 875 | DCHECK_NE(type, DataType::Type::kReference); |
| 876 | |
| 877 | Location location = Location::NoLocation(); |
| 878 | if (DataType::IsFloatingPointType(type)) { |
| 879 | if (fpr_index_ < kParameterFPRegistersLength) { |
| 880 | location = LocationFrom(kParameterFPRegisters[fpr_index_]); |
| 881 | ++fpr_index_; |
| 882 | } |
| 883 | } else { |
| 884 | // Native ABI uses the same registers as managed, except that the method register x0 |
| 885 | // is a normal argument. |
| 886 | if (gpr_index_ < 1u + kParameterCoreRegistersLength) { |
| 887 | location = LocationFrom(gpr_index_ == 0u ? x0 : kParameterCoreRegisters[gpr_index_ - 1u]); |
| 888 | ++gpr_index_; |
| 889 | } |
| 890 | } |
| 891 | if (location.IsInvalid()) { |
| 892 | if (DataType::Is64BitType(type)) { |
| 893 | location = Location::DoubleStackSlot(stack_offset_); |
| 894 | } else { |
| 895 | location = Location::StackSlot(stack_offset_); |
| 896 | } |
| 897 | stack_offset_ += kFramePointerSize; |
| 898 | |
| 899 | if (for_register_allocation_) { |
| 900 | location = Location::Any(); |
| 901 | } |
| 902 | } |
| 903 | return location; |
| 904 | } |
| 905 | |
| 906 | Location CriticalNativeCallingConventionVisitorARM64::GetReturnLocation(DataType::Type type) const { |
| 907 | // We perform conversion to the managed ABI return register after the call if needed. |
| 908 | InvokeDexCallingConventionVisitorARM64 dex_calling_convention; |
| 909 | return dex_calling_convention.GetReturnLocation(type); |
| 910 | } |
| 911 | |
| 912 | Location CriticalNativeCallingConventionVisitorARM64::GetMethodLocation() const { |
| 913 | // Pass the method in the hidden argument x15. |
| 914 | return Location::RegisterLocation(x15.GetCode()); |
| 915 | } |
| 916 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 917 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 918 | const CompilerOptions& compiler_options, |
| 919 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 920 | : CodeGenerator(graph, |
| 921 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 922 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 923 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 924 | callee_saved_core_registers.GetList(), |
| 925 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 926 | compiler_options, |
| 927 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 928 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 929 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 930 | location_builder_neon_(graph, this), |
| 931 | instruction_visitor_neon_(graph, this), |
| 932 | location_builder_sve_(graph, this), |
| 933 | instruction_visitor_sve_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 934 | move_resolver_(graph->GetAllocator(), this), |
Artem Serov | aa6f483 | 2018-11-21 18:57:54 +0000 | [diff] [blame] | 935 | assembler_(graph->GetAllocator(), |
| 936 | compiler_options.GetInstructionSetFeatures()->AsArm64InstructionSetFeatures()), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 937 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 938 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 939 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 940 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 941 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 942 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 943 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 944 | call_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 945 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 946 | uint32_literals_(std::less<uint32_t>(), |
| 947 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 948 | uint64_literals_(std::less<uint64_t>(), |
| 949 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 950 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 951 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 952 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 953 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 954 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 955 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 956 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 957 | AddAllocatedRegister(LocationFrom(lr)); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 958 | |
| 959 | bool use_sve = ShouldUseSVE(); |
| 960 | if (use_sve) { |
| 961 | location_builder_ = &location_builder_sve_; |
| 962 | instruction_visitor_ = &instruction_visitor_sve_; |
| 963 | } else { |
| 964 | location_builder_ = &location_builder_neon_; |
| 965 | instruction_visitor_ = &instruction_visitor_neon_; |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | bool CodeGeneratorARM64::ShouldUseSVE() const { |
| 970 | return kArm64AllowSVE && GetInstructionSetFeatures().HasSVE(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 971 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 972 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 973 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 974 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 975 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 976 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 977 | jump_table->EmitTable(this); |
| 978 | } |
| 979 | } |
| 980 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 981 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 982 | EmitJumpTables(); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 983 | |
| 984 | // Emit JIT baker read barrier slow paths. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 985 | DCHECK(GetCompilerOptions().IsJitCompiler() || jit_baker_read_barrier_slow_paths_.empty()); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 986 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 987 | uint32_t encoded_data = entry.first; |
| 988 | vixl::aarch64::Label* slow_path_entry = &entry.second.label; |
| 989 | __ Bind(slow_path_entry); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 990 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name= */ nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 991 | } |
| 992 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 993 | // Ensure we emit the literal pool. |
| 994 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 995 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 996 | CodeGenerator::Finalize(allocator); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 997 | |
| 998 | // Verify Baker read barrier linker patches. |
| 999 | if (kIsDebugBuild) { |
| 1000 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 1001 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 1002 | DCHECK(info.label.IsBound()); |
| 1003 | uint32_t literal_offset = info.label.GetLocation(); |
| 1004 | DCHECK_ALIGNED(literal_offset, 4u); |
| 1005 | |
| 1006 | auto GetInsn = [&code](uint32_t offset) { |
| 1007 | DCHECK_ALIGNED(offset, 4u); |
| 1008 | return |
| 1009 | (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 1010 | (static_cast<uint32_t>(code[offset + 1]) << 8) + |
| 1011 | (static_cast<uint32_t>(code[offset + 2]) << 16)+ |
| 1012 | (static_cast<uint32_t>(code[offset + 3]) << 24); |
| 1013 | }; |
| 1014 | |
| 1015 | const uint32_t encoded_data = info.custom_data; |
| 1016 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 1017 | // Check that the next instruction matches the expected LDR. |
| 1018 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1019 | case BakerReadBarrierKind::kField: |
| 1020 | case BakerReadBarrierKind::kAcquire: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1021 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1022 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1023 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1024 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1025 | if (kind == BakerReadBarrierKind::kField) { |
| 1026 | // LDR (immediate) with correct base_reg. |
| 1027 | CHECK_EQ(next_insn & 0xffc003e0u, 0xb9400000u | (base_reg << 5)); |
| 1028 | } else { |
| 1029 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 1030 | // LDAR with correct base_reg. |
| 1031 | CHECK_EQ(next_insn & 0xffffffe0u, 0x88dffc00u | (base_reg << 5)); |
| 1032 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1033 | break; |
| 1034 | } |
| 1035 | case BakerReadBarrierKind::kArray: { |
| 1036 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1037 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 1038 | // LDR (register) with the correct base_reg, size=10 (32-bit), option=011 (extend = LSL), |
| 1039 | // and S=1 (shift amount = 2 for 32-bit version), i.e. LDR Wt, [Xn, Xm, LSL #2]. |
| 1040 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1041 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1042 | CHECK_EQ(next_insn & 0xffe0ffe0u, 0xb8607800u | (base_reg << 5)); |
| 1043 | CheckValidReg((next_insn >> 16) & 0x1f); // Check index register |
| 1044 | break; |
| 1045 | } |
| 1046 | case BakerReadBarrierKind::kGcRoot: { |
| 1047 | DCHECK_GE(literal_offset, 4u); |
| 1048 | uint32_t prev_insn = GetInsn(literal_offset - 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1049 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 1050 | // Usually LDR (immediate) with correct root_reg but |
| 1051 | // we may have a "MOV marked, old_value" for UnsafeCASObject. |
| 1052 | if ((prev_insn & 0xffe0ffff) != (0x2a0003e0 | root_reg)) { // MOV? |
| 1053 | CHECK_EQ(prev_insn & 0xffc0001fu, 0xb9400000u | root_reg); // LDR? |
| 1054 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1055 | break; |
| 1056 | } |
| 1057 | default: |
| 1058 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 1059 | UNREACHABLE(); |
| 1060 | } |
| 1061 | } |
| 1062 | } |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1065 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1066 | // Note: There are 6 kinds of moves: |
| 1067 | // 1. constant -> GPR/FPR (non-cycle) |
| 1068 | // 2. constant -> stack (non-cycle) |
| 1069 | // 3. GPR/FPR -> GPR/FPR |
| 1070 | // 4. GPR/FPR -> stack |
| 1071 | // 5. stack -> GPR/FPR |
| 1072 | // 6. stack -> stack (non-cycle) |
| 1073 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1074 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1075 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1076 | // dependency. |
| 1077 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1078 | } |
| 1079 | |
| 1080 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1081 | vixl_temps_.Close(); |
| 1082 | } |
| 1083 | |
| 1084 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1085 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1086 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1087 | || kind == Location::kSIMDStackSlot); |
| 1088 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1089 | ? Location::kFpuRegister |
| 1090 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1091 | Location scratch = GetScratchLocation(kind); |
| 1092 | if (!scratch.Equals(Location::NoLocation())) { |
| 1093 | return scratch; |
| 1094 | } |
| 1095 | // Allocate from VIXL temp registers. |
| 1096 | if (kind == Location::kRegister) { |
| 1097 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1098 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1099 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1100 | scratch = codegen_->GetGraph()->HasSIMD() |
| 1101 | ? codegen_->GetInstructionCodeGeneratorArm64()->AllocateSIMDScratchLocation(&vixl_temps_) |
| 1102 | : LocationFrom(vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1103 | } |
| 1104 | AddScratchLocation(scratch); |
| 1105 | return scratch; |
| 1106 | } |
| 1107 | |
| 1108 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1109 | if (loc.IsRegister()) { |
| 1110 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1111 | } else { |
| 1112 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1113 | if (codegen_->GetGraph()->HasSIMD()) { |
| 1114 | codegen_->GetInstructionCodeGeneratorArm64()->FreeSIMDScratchLocation(loc, &vixl_temps_); |
| 1115 | } else { |
| 1116 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1117 | } |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1118 | } |
| 1119 | RemoveScratchLocation(loc); |
| 1120 | } |
| 1121 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1122 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1123 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1124 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1127 | void CodeGeneratorARM64::MaybeIncrementHotness(bool is_frame_entry) { |
| 1128 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1129 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1130 | UseScratchRegisterScope temps(masm); |
| 1131 | Register counter = temps.AcquireX(); |
| 1132 | Register method = is_frame_entry ? kArtMethodRegister : temps.AcquireX(); |
| 1133 | if (!is_frame_entry) { |
| 1134 | __ Ldr(method, MemOperand(sp, 0)); |
| 1135 | } |
| 1136 | __ Ldrh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1137 | __ Add(counter, counter, 1); |
| 1138 | // Subtract one if the counter would overflow. |
| 1139 | __ Sub(counter, counter, Operand(counter, LSR, 16)); |
| 1140 | __ Strh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1141 | } |
| 1142 | |
| 1143 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| 1144 | ScopedObjectAccess soa(Thread::Current()); |
| 1145 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1146 | if (info != nullptr) { |
Nicolas Geoffray | c1cd133 | 2020-01-25 13:08:24 +0000 | [diff] [blame] | 1147 | uint64_t address = reinterpret_cast64<uint64_t>(info); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1148 | vixl::aarch64::Label done; |
| 1149 | UseScratchRegisterScope temps(masm); |
| 1150 | Register temp = temps.AcquireX(); |
| 1151 | Register counter = temps.AcquireW(); |
| 1152 | __ Mov(temp, address); |
| 1153 | __ Ldrh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 1154 | __ Add(counter, counter, 1); |
| 1155 | __ Strh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 1156 | __ Tst(counter, 0xffff); |
| 1157 | __ B(ne, &done); |
| 1158 | if (is_frame_entry) { |
| 1159 | if (HasEmptyFrame()) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1160 | // The entrypoint expects the method at the bottom of the stack. We |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1161 | // claim stack space necessary for alignment. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1162 | IncreaseFrame(kStackAlignment); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1163 | __ Stp(kArtMethodRegister, lr, MemOperand(sp, 0)); |
| 1164 | } else if (!RequiresCurrentMethod()) { |
| 1165 | __ Str(kArtMethodRegister, MemOperand(sp, 0)); |
| 1166 | } |
| 1167 | } else { |
| 1168 | CHECK(RequiresCurrentMethod()); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1169 | } |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1170 | uint32_t entrypoint_offset = |
| 1171 | GetThreadOffset<kArm64PointerSize>(kQuickCompileOptimized).Int32Value(); |
| 1172 | __ Ldr(lr, MemOperand(tr, entrypoint_offset)); |
| 1173 | // Note: we don't record the call here (and therefore don't generate a stack |
| 1174 | // map), as the entrypoint should never be suspended. |
| 1175 | __ Blr(lr); |
| 1176 | if (HasEmptyFrame()) { |
| 1177 | CHECK(is_frame_entry); |
| 1178 | __ Ldr(lr, MemOperand(sp, 8)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1179 | DecreaseFrame(kStackAlignment); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1180 | } |
| 1181 | __ Bind(&done); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1182 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1186 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1187 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1188 | __ Bind(&frame_entry_label_); |
| 1189 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1190 | bool do_overflow_check = |
| 1191 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1192 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1193 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1194 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1195 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1196 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1197 | { |
| 1198 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1199 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1200 | kInstructionSize, |
| 1201 | CodeBufferCheckScope::kExactSize); |
| 1202 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1203 | RecordPcInfo(nullptr, 0); |
| 1204 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1205 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1206 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1207 | if (!HasEmptyFrame()) { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1208 | // Stack layout: |
| 1209 | // sp[frame_size - 8] : lr. |
| 1210 | // ... : other preserved core registers. |
| 1211 | // ... : other preserved fp registers. |
| 1212 | // ... : reserved frame space. |
| 1213 | // sp[0] : current method. |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1214 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1215 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1216 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1217 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1218 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1219 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1220 | |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1221 | // Save the current method if we need it, or if using STP reduces code |
| 1222 | // size. Note that we do not do this in HCurrentMethod, as the |
| 1223 | // instruction might have been removed in the SSA graph. |
| 1224 | CPURegister lowest_spill; |
| 1225 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1226 | // If there is no gap between the method and the lowest core spill, use |
| 1227 | // aligned STP pre-index to store both. Max difference is 512. We do |
| 1228 | // that to reduce code size even if we do not have to save the method. |
| 1229 | DCHECK_LE(frame_size, 512); // 32 core registers are only 256 bytes. |
| 1230 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1231 | __ Stp(kArtMethodRegister, lowest_spill, MemOperand(sp, -frame_size, PreIndex)); |
| 1232 | } else if (RequiresCurrentMethod()) { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1233 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1234 | } else { |
| 1235 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1236 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1237 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1238 | if (lowest_spill.IsValid()) { |
| 1239 | GetAssembler()->cfi().RelOffset(DWARFReg(lowest_spill), core_spills_offset); |
| 1240 | core_spills_offset += kXRegSizeInBytes; |
| 1241 | } |
| 1242 | GetAssembler()->SpillRegisters(preserved_core_registers, core_spills_offset); |
| 1243 | GetAssembler()->SpillRegisters(preserved_fp_registers, fp_spills_offset); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1244 | |
| 1245 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1246 | // Initialize should_deoptimize flag to 0. |
| 1247 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1248 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1249 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1250 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1251 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1252 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1256 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1257 | if (!HasEmptyFrame()) { |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1258 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1259 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1260 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1261 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1262 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1263 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
| 1264 | |
| 1265 | CPURegister lowest_spill; |
| 1266 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1267 | // If there is no gap between the method and the lowest core spill, use |
| 1268 | // aligned LDP pre-index to pop both. Max difference is 504. We do |
| 1269 | // that to reduce code size even though the loaded method is unused. |
| 1270 | DCHECK_LE(frame_size, 504); // 32 core registers are only 256 bytes. |
| 1271 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1272 | core_spills_offset += kXRegSizeInBytes; |
| 1273 | } |
| 1274 | GetAssembler()->UnspillRegisters(preserved_fp_registers, fp_spills_offset); |
| 1275 | GetAssembler()->UnspillRegisters(preserved_core_registers, core_spills_offset); |
| 1276 | if (lowest_spill.IsValid()) { |
| 1277 | __ Ldp(xzr, lowest_spill, MemOperand(sp, frame_size, PostIndex)); |
| 1278 | GetAssembler()->cfi().Restore(DWARFReg(lowest_spill)); |
| 1279 | } else { |
| 1280 | __ Drop(frame_size); |
| 1281 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1282 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1283 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1284 | __ Ret(); |
| 1285 | GetAssembler()->cfi().RestoreState(); |
| 1286 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1287 | } |
| 1288 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1289 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1290 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1291 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1292 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1293 | } |
| 1294 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1295 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1296 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1297 | GetNumberOfFloatingPointRegisters())); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1298 | return CPURegList(CPURegister::kVRegister, kDRegSize, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1299 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1300 | } |
| 1301 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1302 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1303 | __ Bind(GetLabelOf(block)); |
| 1304 | } |
| 1305 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1306 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1307 | DCHECK(location.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1308 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1309 | } |
| 1310 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1311 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1312 | if (location.IsRegister()) { |
| 1313 | locations->AddTemp(location); |
| 1314 | } else { |
| 1315 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1316 | } |
| 1317 | } |
| 1318 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1319 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1320 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1321 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1322 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1323 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1324 | if (value_can_be_null) { |
| 1325 | __ Cbz(value, &done); |
| 1326 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1327 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1328 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1329 | // Calculate the offset (in the card table) of the card corresponding to |
| 1330 | // `object`. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1331 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1332 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 1333 | // `object`'s card. |
| 1334 | // |
| 1335 | // Register `card` contains the address of the card table. Note that the card |
| 1336 | // table's base is biased during its creation so that it always starts at an |
| 1337 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 1338 | // art::gc::accounting::CardTable::Create). Therefore the STRB instruction |
| 1339 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 1340 | // (located at `card + object >> kCardShift`). |
| 1341 | // |
| 1342 | // This dual use of the value in register `card` (1. to calculate the location |
| 1343 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 1344 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1345 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1346 | if (value_can_be_null) { |
| 1347 | __ Bind(&done); |
| 1348 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1349 | } |
| 1350 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1351 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1352 | // Blocked core registers: |
| 1353 | // lr : Runtime reserved. |
| 1354 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1355 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1356 | // ip1 : VIXL core temp. |
| 1357 | // ip0 : VIXL core temp. |
Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1358 | // x18 : Platform register. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1359 | // |
| 1360 | // Blocked fp registers: |
| 1361 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1362 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1363 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1364 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1365 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1366 | } |
Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1367 | blocked_core_registers_[X18] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1368 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1369 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1370 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1371 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1372 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1373 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1374 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1375 | // Stubs do not save callee-save floating point registers. If the graph |
| 1376 | // is debuggable, we need to deal with these registers differently. For |
| 1377 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1378 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1379 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1380 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1381 | } |
| 1382 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1383 | } |
| 1384 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1385 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1386 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1387 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1388 | return kArm64WordSize; |
| 1389 | } |
| 1390 | |
| 1391 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1392 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1393 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1394 | return kArm64WordSize; |
| 1395 | } |
| 1396 | |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1397 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1398 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1399 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1400 | << "use SaveRestoreLiveRegistersHelper"; |
| 1401 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1404 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1405 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1406 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1407 | << "use SaveRestoreLiveRegistersHelper"; |
| 1408 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1411 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1412 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1416 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1417 | } |
| 1418 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1419 | const Arm64InstructionSetFeatures& CodeGeneratorARM64::GetInstructionSetFeatures() const { |
| 1420 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArm64InstructionSetFeatures(); |
| 1421 | } |
| 1422 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1423 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1424 | if (constant->IsIntConstant()) { |
| 1425 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1426 | } else if (constant->IsLongConstant()) { |
| 1427 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1428 | } else if (constant->IsNullConstant()) { |
| 1429 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1430 | } else if (constant->IsFloatConstant()) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1431 | __ Fmov(VRegister(destination), constant->AsFloatConstant()->GetValue()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1432 | } else { |
| 1433 | DCHECK(constant->IsDoubleConstant()); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1434 | __ Fmov(VRegister(destination), constant->AsDoubleConstant()->GetValue()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1435 | } |
| 1436 | } |
| 1437 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1438 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1439 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1440 | DCHECK(constant.IsConstant()); |
| 1441 | HConstant* cst = constant.GetConstant(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1442 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1443 | // 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] | 1444 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1445 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1446 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1447 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1450 | // Allocate a scratch register from the VIXL pool, querying first |
| 1451 | // the floating-point register pool, and then the core register |
| 1452 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1453 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1454 | // using a different allocation strategy. |
| 1455 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1456 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1457 | int size_in_bits) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1458 | return masm->GetScratchVRegisterList()->IsEmpty() |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1459 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1460 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1461 | } |
| 1462 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1463 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1464 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1465 | DataType::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1466 | if (source.Equals(destination)) { |
| 1467 | return; |
| 1468 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1469 | |
| 1470 | // A valid move can always be inferred from the destination and source |
| 1471 | // locations. When moving from and to a register, the argument type can be |
| 1472 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1473 | // checks the coherency of the locations and the type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1474 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1475 | |
| 1476 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1477 | if (unspecified_type) { |
| 1478 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1479 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1480 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1481 | || src_cst->IsFloatConstant() |
| 1482 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1483 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1484 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1485 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1486 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1487 | // type is appropriate. Else the source is a register, and since the |
| 1488 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1489 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1490 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1491 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1492 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1493 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1494 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1495 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1496 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1497 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1498 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1499 | } else if (source.IsSIMDStackSlot()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1500 | GetInstructionCodeGeneratorArm64()->LoadSIMDRegFromStack(destination, source); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1501 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1502 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1503 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1504 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1505 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1506 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1507 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1508 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1509 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1510 | ? DataType::Type::kInt64 |
| 1511 | : DataType::Type::kInt32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1512 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1513 | } |
| 1514 | } else { |
| 1515 | DCHECK(source.IsFpuRegister()); |
| 1516 | if (destination.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1517 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1518 | ? DataType::Type::kFloat64 |
| 1519 | : DataType::Type::kFloat32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1520 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1521 | } else { |
| 1522 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1523 | if (GetGraph()->HasSIMD()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1524 | GetInstructionCodeGeneratorArm64()->MoveSIMDRegToSIMDReg(destination, source); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1525 | } else { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1526 | __ Fmov(VRegister(dst), FPRegisterFrom(source, dst_type)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1527 | } |
| 1528 | } |
| 1529 | } |
| 1530 | } else if (destination.IsSIMDStackSlot()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1531 | GetInstructionCodeGeneratorArm64()->MoveToSIMDStackSlot(destination, source); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1532 | } else { // The destination is not a register. It must be a stack slot. |
| 1533 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1534 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1535 | if (unspecified_type) { |
| 1536 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1537 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1538 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1539 | dst_type = |
| 1540 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1541 | } |
| 1542 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1543 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1544 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1545 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1546 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1547 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1548 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1549 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1550 | HConstant* src_cst = source.GetConstant(); |
| 1551 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1552 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1553 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1554 | ? Register(xzr) |
| 1555 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1556 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1557 | if (src_cst->IsIntConstant()) { |
| 1558 | temp = temps.AcquireW(); |
| 1559 | } else if (src_cst->IsLongConstant()) { |
| 1560 | temp = temps.AcquireX(); |
| 1561 | } else if (src_cst->IsFloatConstant()) { |
| 1562 | temp = temps.AcquireS(); |
| 1563 | } else { |
| 1564 | DCHECK(src_cst->IsDoubleConstant()); |
| 1565 | temp = temps.AcquireD(); |
| 1566 | } |
| 1567 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1568 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1569 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1570 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1571 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1572 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1573 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1574 | // Use any scratch register (a core or a floating-point one) |
| 1575 | // from VIXL scratch register pools as a temporary. |
| 1576 | // |
| 1577 | // We used to only use the FP scratch register pool, but in some |
| 1578 | // rare cases the only register from this pool (D31) would |
| 1579 | // already be used (e.g. within a ParallelMove instruction, when |
| 1580 | // a move is blocked by a another move requiring a scratch FP |
| 1581 | // register, which would reserve D31). To prevent this issue, we |
| 1582 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1583 | // |
| 1584 | // 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] | 1585 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1586 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1587 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1588 | // allocates core scratch registers first. |
| 1589 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1590 | GetVIXLAssembler(), |
| 1591 | &temps, |
| 1592 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1593 | __ Ldr(temp, StackOperandFrom(source)); |
| 1594 | __ Str(temp, StackOperandFrom(destination)); |
| 1595 | } |
| 1596 | } |
| 1597 | } |
| 1598 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1599 | void CodeGeneratorARM64::Load(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1600 | CPURegister dst, |
| 1601 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1602 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1603 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1604 | case DataType::Type::kUint8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1605 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1606 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1607 | case DataType::Type::kInt8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1608 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1609 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1610 | case DataType::Type::kUint16: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1611 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1612 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1613 | case DataType::Type::kInt16: |
| 1614 | __ Ldrsh(Register(dst), src); |
| 1615 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1616 | case DataType::Type::kInt32: |
| 1617 | case DataType::Type::kReference: |
| 1618 | case DataType::Type::kInt64: |
| 1619 | case DataType::Type::kFloat32: |
| 1620 | case DataType::Type::kFloat64: |
| 1621 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1622 | __ Ldr(dst, src); |
| 1623 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1624 | case DataType::Type::kUint32: |
| 1625 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1626 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1627 | LOG(FATAL) << "Unreachable type " << type; |
| 1628 | } |
| 1629 | } |
| 1630 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1631 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1632 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1633 | const MemOperand& src, |
| 1634 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1635 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1636 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1637 | Register temp_base = temps.AcquireX(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1638 | DataType::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1639 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1640 | DCHECK(!src.IsPreIndex()); |
| 1641 | DCHECK(!src.IsPostIndex()); |
| 1642 | |
| 1643 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1644 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1645 | { |
| 1646 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1647 | MemOperand base = MemOperand(temp_base); |
| 1648 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1649 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1650 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1651 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1652 | { |
| 1653 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1654 | __ ldarb(Register(dst), base); |
| 1655 | if (needs_null_check) { |
| 1656 | MaybeRecordImplicitNullCheck(instruction); |
| 1657 | } |
| 1658 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1659 | if (type == DataType::Type::kInt8) { |
| 1660 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1661 | } |
| 1662 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1663 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1664 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1665 | { |
| 1666 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1667 | __ ldarh(Register(dst), base); |
| 1668 | if (needs_null_check) { |
| 1669 | MaybeRecordImplicitNullCheck(instruction); |
| 1670 | } |
| 1671 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1672 | if (type == DataType::Type::kInt16) { |
| 1673 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 1674 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1675 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1676 | case DataType::Type::kInt32: |
| 1677 | case DataType::Type::kReference: |
| 1678 | case DataType::Type::kInt64: |
| 1679 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1680 | { |
| 1681 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1682 | __ ldar(Register(dst), base); |
| 1683 | if (needs_null_check) { |
| 1684 | MaybeRecordImplicitNullCheck(instruction); |
| 1685 | } |
| 1686 | } |
| 1687 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1688 | case DataType::Type::kFloat32: |
| 1689 | case DataType::Type::kFloat64: { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1690 | DCHECK(dst.IsFPRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1691 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1692 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1693 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1694 | { |
| 1695 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1696 | __ ldar(temp, base); |
| 1697 | if (needs_null_check) { |
| 1698 | MaybeRecordImplicitNullCheck(instruction); |
| 1699 | } |
| 1700 | } |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1701 | __ Fmov(VRegister(dst), temp); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1702 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1703 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1704 | case DataType::Type::kUint32: |
| 1705 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1706 | case DataType::Type::kVoid: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1707 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1708 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1709 | } |
| 1710 | } |
| 1711 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1712 | void CodeGeneratorARM64::Store(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1713 | CPURegister src, |
| 1714 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1715 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1716 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1717 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1718 | case DataType::Type::kInt8: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1719 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1720 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1721 | case DataType::Type::kUint16: |
| 1722 | case DataType::Type::kInt16: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1723 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1724 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1725 | case DataType::Type::kInt32: |
| 1726 | case DataType::Type::kReference: |
| 1727 | case DataType::Type::kInt64: |
| 1728 | case DataType::Type::kFloat32: |
| 1729 | case DataType::Type::kFloat64: |
| 1730 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1731 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1732 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1733 | case DataType::Type::kUint32: |
| 1734 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1735 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1736 | LOG(FATAL) << "Unreachable type " << type; |
| 1737 | } |
| 1738 | } |
| 1739 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1740 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1741 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1742 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1743 | const MemOperand& dst, |
| 1744 | bool needs_null_check) { |
| 1745 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1746 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1747 | Register temp_base = temps.AcquireX(); |
| 1748 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1749 | DCHECK(!dst.IsPreIndex()); |
| 1750 | DCHECK(!dst.IsPostIndex()); |
| 1751 | |
| 1752 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1753 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1754 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1755 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1756 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1757 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1758 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1759 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1760 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1761 | { |
| 1762 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1763 | __ stlrb(Register(src), base); |
| 1764 | if (needs_null_check) { |
| 1765 | MaybeRecordImplicitNullCheck(instruction); |
| 1766 | } |
| 1767 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1768 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1769 | case DataType::Type::kUint16: |
| 1770 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1771 | { |
| 1772 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1773 | __ stlrh(Register(src), base); |
| 1774 | if (needs_null_check) { |
| 1775 | MaybeRecordImplicitNullCheck(instruction); |
| 1776 | } |
| 1777 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1778 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1779 | case DataType::Type::kInt32: |
| 1780 | case DataType::Type::kReference: |
| 1781 | case DataType::Type::kInt64: |
| 1782 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1783 | { |
| 1784 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1785 | __ stlr(Register(src), base); |
| 1786 | if (needs_null_check) { |
| 1787 | MaybeRecordImplicitNullCheck(instruction); |
| 1788 | } |
| 1789 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1790 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1791 | case DataType::Type::kFloat32: |
| 1792 | case DataType::Type::kFloat64: { |
| 1793 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1794 | Register temp_src; |
| 1795 | if (src.IsZero()) { |
| 1796 | // The zero register is used to avoid synthesizing zero constants. |
| 1797 | temp_src = Register(src); |
| 1798 | } else { |
| 1799 | DCHECK(src.IsFPRegister()); |
| 1800 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1801 | __ Fmov(temp_src, VRegister(src)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1802 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1803 | { |
| 1804 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1805 | __ stlr(temp_src, base); |
| 1806 | if (needs_null_check) { |
| 1807 | MaybeRecordImplicitNullCheck(instruction); |
| 1808 | } |
| 1809 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1810 | break; |
| 1811 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1812 | case DataType::Type::kUint32: |
| 1813 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1814 | case DataType::Type::kVoid: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1815 | LOG(FATAL) << "Unreachable type " << type; |
| 1816 | } |
| 1817 | } |
| 1818 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1819 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1820 | HInstruction* instruction, |
| 1821 | uint32_t dex_pc, |
| 1822 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1823 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1824 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1825 | ThreadOffset64 entrypoint_offset = GetThreadOffset<kArm64PointerSize>(entrypoint); |
| 1826 | // Reduce code size for AOT by using shared trampolines for slow path runtime calls across the |
| 1827 | // entire oat file. This adds an extra branch and we do not want to slow down the main path. |
| 1828 | // 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] | 1829 | if (slow_path == nullptr || GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1830 | __ Ldr(lr, MemOperand(tr, entrypoint_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1831 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 1832 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1833 | __ blr(lr); |
| 1834 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1835 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1836 | } |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1837 | } else { |
| 1838 | // Ensure the pc position is recorded immediately after the `bl` instruction. |
| 1839 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1840 | EmitEntrypointThunkCall(entrypoint_offset); |
| 1841 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1842 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1843 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1844 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1845 | } |
| 1846 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1847 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1848 | HInstruction* instruction, |
| 1849 | SlowPathCode* slow_path) { |
| 1850 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1851 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1852 | __ Blr(lr); |
| 1853 | } |
| 1854 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1855 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1856 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1857 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1858 | Register temp = temps.AcquireW(); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1859 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
Vladimir Marko | 2bb44fe | 2019-10-04 12:28:14 +0100 | [diff] [blame] | 1860 | const size_t status_byte_offset = |
| 1861 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 1862 | constexpr uint32_t shifted_visibly_initialized_value = |
| 1863 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1864 | |
Vladimir Marko | 2bb44fe | 2019-10-04 12:28:14 +0100 | [diff] [blame] | 1865 | // CMP (immediate) is limited to imm12 or imm12<<12, so we would need to materialize |
| 1866 | // the constant 0xf0000000 for comparison with the full 32-bit field. To reduce the code |
| 1867 | // size, load only the high byte of the field and compare with 0xf0. |
| 1868 | // Note: The same code size could be achieved with LDR+MNV(asr #24)+CBNZ but benchmarks |
| 1869 | // show that this pattern is slower (tested on little cores). |
| 1870 | __ Ldrb(temp, HeapOperand(class_reg, status_byte_offset)); |
| 1871 | __ Cmp(temp, shifted_visibly_initialized_value); |
| 1872 | __ B(lo, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1873 | __ Bind(slow_path->GetExitLabel()); |
| 1874 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1875 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 1876 | void InstructionCodeGeneratorARM64::GenerateBitstringTypeCheckCompare( |
| 1877 | HTypeCheckInstruction* check, vixl::aarch64::Register temp) { |
| 1878 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 1879 | uint32_t mask = check->GetBitstringMask(); |
| 1880 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 1881 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 1882 | |
| 1883 | if (mask_bits == 16u) { |
| 1884 | // Load only the bitstring part of the status word. |
| 1885 | __ Ldrh(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1886 | } else { |
| 1887 | // /* uint32_t */ temp = temp->status_ |
| 1888 | __ Ldr(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1889 | // Extract the bitstring bits. |
| 1890 | __ Ubfx(temp, temp, 0, mask_bits); |
| 1891 | } |
| 1892 | // Compare the bitstring bits to `path_to_root`. |
| 1893 | __ Cmp(temp, path_to_root); |
| 1894 | } |
| 1895 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1896 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1897 | BarrierType type = BarrierAll; |
| 1898 | |
| 1899 | switch (kind) { |
| 1900 | case MemBarrierKind::kAnyAny: |
| 1901 | case MemBarrierKind::kAnyStore: { |
| 1902 | type = BarrierAll; |
| 1903 | break; |
| 1904 | } |
| 1905 | case MemBarrierKind::kLoadAny: { |
| 1906 | type = BarrierReads; |
| 1907 | break; |
| 1908 | } |
| 1909 | case MemBarrierKind::kStoreStore: { |
| 1910 | type = BarrierWrites; |
| 1911 | break; |
| 1912 | } |
| 1913 | default: |
| 1914 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1915 | } |
| 1916 | __ Dmb(InnerShareable, type); |
| 1917 | } |
| 1918 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1919 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1920 | HBasicBlock* successor) { |
| 1921 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1922 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1923 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1924 | slow_path = |
| 1925 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1926 | instruction->SetSlowPath(slow_path); |
| 1927 | codegen_->AddSlowPath(slow_path); |
| 1928 | if (successor != nullptr) { |
| 1929 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1930 | } |
| 1931 | } else { |
| 1932 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1933 | } |
| 1934 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1935 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1936 | Register temp = temps.AcquireW(); |
| 1937 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1938 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1939 | if (successor == nullptr) { |
| 1940 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1941 | __ Bind(slow_path->GetReturnLabel()); |
| 1942 | } else { |
| 1943 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1944 | __ B(slow_path->GetEntryLabel()); |
| 1945 | // slow_path will return to GetLabelOf(successor). |
| 1946 | } |
| 1947 | } |
| 1948 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1949 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1950 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1951 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1952 | assembler_(codegen->GetAssembler()), |
| 1953 | codegen_(codegen) {} |
| 1954 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1955 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1956 | DCHECK_EQ(instr->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1957 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1958 | DataType::Type type = instr->GetResultType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1959 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1960 | case DataType::Type::kInt32: |
| 1961 | case DataType::Type::kInt64: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1962 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1963 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1964 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1965 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1966 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1967 | case DataType::Type::kFloat32: |
| 1968 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1969 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1970 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1971 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1972 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1973 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1974 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1975 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1976 | } |
| 1977 | } |
| 1978 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1979 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 1980 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1981 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1982 | |
| 1983 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1984 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1985 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1986 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 1987 | object_field_get_with_read_barrier |
| 1988 | ? LocationSummary::kCallOnSlowPath |
| 1989 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1990 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1991 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1992 | // We need a temporary register for the read barrier load in |
| 1993 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 1994 | // only if the field is volatile or the offset is too big. |
| 1995 | if (field_info.IsVolatile() || |
| 1996 | field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 1997 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1998 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1999 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2000 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2001 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2002 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2003 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2004 | // The output overlaps for an object field get when read barriers |
| 2005 | // are enabled: we do not want the load to overwrite the object's |
| 2006 | // location, as we need it to emit the read barrier. |
| 2007 | locations->SetOut( |
| 2008 | Location::RequiresRegister(), |
| 2009 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2010 | } |
| 2011 | } |
| 2012 | |
| 2013 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2014 | const FieldInfo& field_info) { |
| 2015 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2016 | LocationSummary* locations = instruction->GetLocations(); |
| 2017 | Location base_loc = locations->InAt(0); |
| 2018 | Location out = locations->Out(); |
| 2019 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2020 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 2021 | DataType::Type load_type = instruction->GetType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2022 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2023 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2024 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2025 | load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2026 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2027 | // /* HeapReference<Object> */ out = *(base + offset) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2028 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2029 | Location maybe_temp = |
| 2030 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2031 | // Note that potential implicit null checks are handled in this |
| 2032 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2033 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2034 | instruction, |
| 2035 | out, |
| 2036 | base, |
| 2037 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2038 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2039 | /* needs_null_check= */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2040 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2041 | } else { |
| 2042 | // General case. |
| 2043 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2044 | // Note that a potential implicit null check is handled in this |
| 2045 | // CodeGeneratorARM64::LoadAcquire call. |
| 2046 | // NB: LoadAcquire will record the pc info if needed. |
| 2047 | codegen_->LoadAcquire( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2048 | instruction, OutputCPURegister(instruction), field, /* needs_null_check= */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2049 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2050 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2051 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2052 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2053 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2054 | } |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2055 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2056 | // If read barriers are enabled, emit read barriers other than |
| 2057 | // Baker's using a slow path (and also unpoison the loaded |
| 2058 | // reference, if heap poisoning is enabled). |
| 2059 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2060 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2061 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2065 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2066 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2067 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2068 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2069 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2070 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2071 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2072 | } else { |
| 2073 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2074 | } |
| 2075 | } |
| 2076 | |
| 2077 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2078 | const FieldInfo& field_info, |
| 2079 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2080 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2081 | |
| 2082 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2083 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2084 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2085 | Offset offset = field_info.GetFieldOffset(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2086 | DataType::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2087 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2088 | { |
| 2089 | // We use a block to end the scratch scope before the write barrier, thus |
| 2090 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2091 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2092 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2093 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2094 | DCHECK(value.IsW()); |
| 2095 | Register temp = temps.AcquireW(); |
| 2096 | __ Mov(temp, value.W()); |
| 2097 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2098 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2099 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2100 | |
| 2101 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2102 | codegen_->StoreRelease( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2103 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check= */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2104 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2105 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2106 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2107 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2108 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2109 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2113 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2114 | } |
| 2115 | } |
| 2116 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2117 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2118 | DataType::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2119 | |
| 2120 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2121 | case DataType::Type::kInt32: |
| 2122 | case DataType::Type::kInt64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2123 | Register dst = OutputRegister(instr); |
| 2124 | Register lhs = InputRegisterAt(instr, 0); |
| 2125 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2126 | if (instr->IsAdd()) { |
| 2127 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2128 | } else if (instr->IsAnd()) { |
| 2129 | __ And(dst, lhs, rhs); |
| 2130 | } else if (instr->IsOr()) { |
| 2131 | __ Orr(dst, lhs, rhs); |
| 2132 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2133 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2134 | } else if (instr->IsRor()) { |
| 2135 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2136 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2137 | __ Ror(dst, lhs, shift); |
| 2138 | } else { |
| 2139 | // Ensure shift distance is in the same size register as the result. If |
| 2140 | // we are rotating a long and the shift comes in a w register originally, |
| 2141 | // we don't need to sxtw for use as an x since the shift distances are |
| 2142 | // all & reg_bits - 1. |
| 2143 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2144 | } |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2145 | } else if (instr->IsMin() || instr->IsMax()) { |
| 2146 | __ Cmp(lhs, rhs); |
| 2147 | __ Csel(dst, lhs, rhs, instr->IsMin() ? lt : gt); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2148 | } else { |
| 2149 | DCHECK(instr->IsXor()); |
| 2150 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2151 | } |
| 2152 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2153 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2154 | case DataType::Type::kFloat32: |
| 2155 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 2156 | VRegister dst = OutputFPRegister(instr); |
| 2157 | VRegister lhs = InputFPRegisterAt(instr, 0); |
| 2158 | VRegister rhs = InputFPRegisterAt(instr, 1); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2159 | if (instr->IsAdd()) { |
| 2160 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2161 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2162 | __ Fsub(dst, lhs, rhs); |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2163 | } else if (instr->IsMin()) { |
| 2164 | __ Fmin(dst, lhs, rhs); |
| 2165 | } else if (instr->IsMax()) { |
| 2166 | __ Fmax(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2167 | } else { |
| 2168 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2169 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2170 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2171 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2172 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2173 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2174 | } |
| 2175 | } |
| 2176 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2177 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2178 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2179 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2180 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2181 | DataType::Type type = instr->GetResultType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2182 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2183 | case DataType::Type::kInt32: |
| 2184 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2185 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2186 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2187 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2188 | break; |
| 2189 | } |
| 2190 | default: |
| 2191 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2192 | } |
| 2193 | } |
| 2194 | |
| 2195 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2196 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2197 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2198 | DataType::Type type = instr->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2199 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2200 | case DataType::Type::kInt32: |
| 2201 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2202 | Register dst = OutputRegister(instr); |
| 2203 | Register lhs = InputRegisterAt(instr, 0); |
| 2204 | Operand rhs = InputOperandAt(instr, 1); |
| 2205 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2206 | uint32_t shift_value = rhs.GetImmediate() & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2207 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2208 | if (instr->IsShl()) { |
| 2209 | __ Lsl(dst, lhs, shift_value); |
| 2210 | } else if (instr->IsShr()) { |
| 2211 | __ Asr(dst, lhs, shift_value); |
| 2212 | } else { |
| 2213 | __ Lsr(dst, lhs, shift_value); |
| 2214 | } |
| 2215 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2216 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2217 | |
| 2218 | if (instr->IsShl()) { |
| 2219 | __ Lsl(dst, lhs, rhs_reg); |
| 2220 | } else if (instr->IsShr()) { |
| 2221 | __ Asr(dst, lhs, rhs_reg); |
| 2222 | } else { |
| 2223 | __ Lsr(dst, lhs, rhs_reg); |
| 2224 | } |
| 2225 | } |
| 2226 | break; |
| 2227 | } |
| 2228 | default: |
| 2229 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2230 | } |
| 2231 | } |
| 2232 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2233 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2234 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2238 | HandleBinaryOp(instruction); |
| 2239 | } |
| 2240 | |
| 2241 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2242 | HandleBinaryOp(instruction); |
| 2243 | } |
| 2244 | |
| 2245 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2246 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2247 | } |
| 2248 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2249 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2250 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2251 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2252 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2253 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2254 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2255 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2256 | } |
| 2257 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2258 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2259 | Register dst = OutputRegister(instr); |
| 2260 | Register lhs = InputRegisterAt(instr, 0); |
| 2261 | Register rhs = InputRegisterAt(instr, 1); |
| 2262 | |
| 2263 | switch (instr->GetOpKind()) { |
| 2264 | case HInstruction::kAnd: |
| 2265 | __ Bic(dst, lhs, rhs); |
| 2266 | break; |
| 2267 | case HInstruction::kOr: |
| 2268 | __ Orn(dst, lhs, rhs); |
| 2269 | break; |
| 2270 | case HInstruction::kXor: |
| 2271 | __ Eon(dst, lhs, rhs); |
| 2272 | break; |
| 2273 | default: |
| 2274 | LOG(FATAL) << "Unreachable"; |
| 2275 | } |
| 2276 | } |
| 2277 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2278 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2279 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2280 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2281 | instruction->GetType() == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2282 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2283 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2284 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2285 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2286 | } else { |
| 2287 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2288 | } |
| 2289 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2290 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2291 | } |
| 2292 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2293 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2294 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2295 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2296 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2297 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2298 | Register out = OutputRegister(instruction); |
| 2299 | Register left; |
| 2300 | if (kind != HInstruction::kNeg) { |
| 2301 | left = InputRegisterAt(instruction, 0); |
| 2302 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2303 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2304 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2305 | // conversion) can have a different type from the current instruction's type, |
| 2306 | // so we manually indicate the type. |
| 2307 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2308 | Operand right_operand(0); |
| 2309 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2310 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2311 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2312 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2313 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2314 | right_operand = Operand(right_reg, |
| 2315 | helpers::ShiftFromOpKind(op_kind), |
| 2316 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | // Logical binary operations do not support extension operations in the |
| 2320 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2321 | // the extension as a separate instruction. |
| 2322 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2323 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2324 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2325 | kind != HInstruction::kNeg)); |
| 2326 | switch (kind) { |
| 2327 | case HInstruction::kAdd: |
| 2328 | __ Add(out, left, right_operand); |
| 2329 | break; |
| 2330 | case HInstruction::kAnd: |
| 2331 | __ And(out, left, right_operand); |
| 2332 | break; |
| 2333 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2334 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2335 | __ Neg(out, right_operand); |
| 2336 | break; |
| 2337 | case HInstruction::kOr: |
| 2338 | __ Orr(out, left, right_operand); |
| 2339 | break; |
| 2340 | case HInstruction::kSub: |
| 2341 | __ Sub(out, left, right_operand); |
| 2342 | break; |
| 2343 | case HInstruction::kXor: |
| 2344 | __ Eor(out, left, right_operand); |
| 2345 | break; |
| 2346 | default: |
| 2347 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2348 | UNREACHABLE(); |
| 2349 | } |
| 2350 | } |
| 2351 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2352 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2353 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2354 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2355 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2356 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2357 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2358 | } |
| 2359 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2360 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2361 | __ Add(OutputRegister(instruction), |
| 2362 | InputRegisterAt(instruction, 0), |
| 2363 | Operand(InputOperandAt(instruction, 1))); |
| 2364 | } |
| 2365 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2366 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2367 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2368 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2369 | |
| 2370 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2371 | |
| 2372 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2373 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2374 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2375 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2376 | // loop. |
| 2377 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2378 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2379 | : Location::RequiresRegister()); |
| 2380 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2381 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2382 | } |
| 2383 | |
| 2384 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2385 | HIntermediateAddressIndex* instruction) { |
| 2386 | Register index_reg = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2387 | uint32_t shift = Int64FromLocation(instruction->GetLocations()->InAt(2)); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2388 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2389 | |
| 2390 | if (shift == 0) { |
| 2391 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2392 | } else { |
| 2393 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2394 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2395 | } |
| 2396 | } |
| 2397 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2398 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2399 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2400 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2401 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2402 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2403 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2404 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2405 | // Don't allocate register for Mneg instruction. |
| 2406 | } else { |
| 2407 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2408 | Location::RequiresRegister()); |
| 2409 | } |
| 2410 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2411 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2412 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2413 | } |
| 2414 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2415 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2416 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2417 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2418 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2419 | |
| 2420 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2421 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2422 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2423 | if (instr->GetType() == DataType::Type::kInt64 && |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2424 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2425 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2426 | vixl::aarch64::Instruction* prev = |
| 2427 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2428 | if (prev->IsLoadOrStore()) { |
| 2429 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2430 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2431 | __ nop(); |
| 2432 | } |
| 2433 | } |
| 2434 | |
| 2435 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2436 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2437 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2438 | } else { |
| 2439 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2440 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2441 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2442 | __ Mneg(res, mul_left, mul_right); |
| 2443 | } else { |
| 2444 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2445 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2446 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2447 | } |
| 2448 | } |
| 2449 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2450 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2451 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2452 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2453 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2454 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2455 | object_array_get_with_read_barrier |
| 2456 | ? LocationSummary::kCallOnSlowPath |
| 2457 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2458 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2459 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2460 | if (instruction->GetIndex()->IsConstant()) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2461 | // Array loads with constant index are treated as field loads. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2462 | // We need a temporary register for the read barrier load in |
| 2463 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2464 | // only if the offset is too big. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2465 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2466 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2467 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2468 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2469 | locations->AddTemp(FixedTempLocation()); |
| 2470 | } |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2471 | } else if (!instruction->GetArray()->IsIntermediateAddress()) { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2472 | // We need a non-scratch temporary for the array data pointer in |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2473 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier() for the case with no |
| 2474 | // intermediate address. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2475 | locations->AddTemp(Location::RequiresRegister()); |
| 2476 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2477 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2478 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2479 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2480 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2481 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2482 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2483 | // The output overlaps in the case of an object array get with |
| 2484 | // read barriers enabled: we do not want the move to overwrite the |
| 2485 | // array's location, as we need it to emit the read barrier. |
| 2486 | locations->SetOut( |
| 2487 | Location::RequiresRegister(), |
| 2488 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2489 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2493 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2494 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2495 | LocationSummary* locations = instruction->GetLocations(); |
| 2496 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2497 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2498 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2499 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2500 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2501 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2502 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2503 | |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2504 | // The non-Baker read barrier instrumentation of object ArrayGet instructions |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2505 | // does not support the HIntermediateAddress instruction. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2506 | DCHECK(!((type == DataType::Type::kReference) && |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2507 | instruction->GetArray()->IsIntermediateAddress() && |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2508 | kEmitCompilerReadBarrier && |
| 2509 | !kUseBakerReadBarrier)); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2510 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2511 | if (type == DataType::Type::kReference && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2512 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2513 | // Note that a potential implicit null check is handled in the |
| 2514 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2515 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2516 | if (index.IsConstant()) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2517 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2518 | // 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] | 2519 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2520 | Location maybe_temp = |
| 2521 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2522 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2523 | out, |
| 2524 | obj.W(), |
| 2525 | offset, |
| 2526 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2527 | /* needs_null_check= */ false, |
| 2528 | /* use_load_acquire= */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2529 | } else { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2530 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2531 | instruction, out, obj.W(), offset, index, /* needs_null_check= */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2532 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2533 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2534 | // General case. |
| 2535 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2536 | Register length; |
| 2537 | if (maybe_compressed_char_at) { |
| 2538 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2539 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2540 | { |
| 2541 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2542 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2543 | |
| 2544 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2545 | DCHECK_LT(count_offset, offset); |
| 2546 | int64_t adjusted_offset = |
| 2547 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2548 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2549 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2550 | } else { |
| 2551 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2552 | } |
| 2553 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2554 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2555 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2556 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2557 | if (maybe_compressed_char_at) { |
| 2558 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2559 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2560 | "Expecting 0=compressed, 1=uncompressed"); |
| 2561 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2562 | __ Ldrb(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2563 | HeapOperand(obj, offset + Int64FromLocation(index))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2564 | __ B(&done); |
| 2565 | __ Bind(&uncompressed_load); |
| 2566 | __ Ldrh(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2567 | HeapOperand(obj, offset + (Int64FromLocation(index) << 1))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2568 | __ Bind(&done); |
| 2569 | } else { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2570 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2571 | source = HeapOperand(obj, offset); |
| 2572 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2573 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2574 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2575 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2576 | // We do not need to compute the intermediate address from the array: the |
| 2577 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2578 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2579 | if (kIsDebugBuild) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2580 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2581 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2582 | } |
| 2583 | temp = obj; |
| 2584 | } else { |
| 2585 | __ Add(temp, obj, offset); |
| 2586 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2587 | if (maybe_compressed_char_at) { |
| 2588 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2589 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2590 | "Expecting 0=compressed, 1=uncompressed"); |
| 2591 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2592 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2593 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2594 | __ B(&done); |
| 2595 | __ Bind(&uncompressed_load); |
| 2596 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2597 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2598 | __ Bind(&done); |
| 2599 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2600 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2601 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2602 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2603 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2604 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2605 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2606 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2607 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2608 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2609 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2610 | if (type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2611 | static_assert( |
| 2612 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2613 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2614 | Location obj_loc = locations->InAt(0); |
| 2615 | if (index.IsConstant()) { |
| 2616 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2617 | } else { |
| 2618 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2619 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2620 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2621 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2622 | } |
| 2623 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2624 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2625 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2626 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2627 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2628 | } |
| 2629 | |
| 2630 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2631 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2632 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2633 | { |
| 2634 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2635 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2636 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2637 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2638 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2639 | // Mask out compression flag from String's array length. |
| 2640 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2641 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2642 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2643 | } |
| 2644 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2645 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2646 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2647 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2648 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2649 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2650 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2651 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2652 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2653 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2654 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2655 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2656 | } else if (DataType::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2657 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2658 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2659 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2660 | } |
| 2661 | } |
| 2662 | |
| 2663 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2664 | DataType::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2665 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2666 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2667 | bool needs_write_barrier = |
| 2668 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2669 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2670 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2671 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2672 | CPURegister source = value; |
| 2673 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2674 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2675 | MemOperand destination = HeapOperand(array); |
| 2676 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2677 | |
| 2678 | if (!needs_write_barrier) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2679 | DCHECK(!needs_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2680 | if (index.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2681 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2682 | destination = HeapOperand(array, offset); |
| 2683 | } else { |
| 2684 | UseScratchRegisterScope temps(masm); |
| 2685 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2686 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2687 | // We do not need to compute the intermediate address from the array: the |
| 2688 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2689 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2690 | if (kIsDebugBuild) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2691 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2692 | DCHECK(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2693 | } |
| 2694 | temp = array; |
| 2695 | } else { |
| 2696 | __ Add(temp, array, offset); |
| 2697 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2698 | destination = HeapOperand(temp, |
| 2699 | XRegisterFrom(index), |
| 2700 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2701 | DataType::SizeShift(value_type)); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2702 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2703 | { |
| 2704 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2705 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2706 | codegen_->Store(value_type, value, destination); |
| 2707 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2708 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2709 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2710 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2711 | |
| 2712 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 2713 | vixl::aarch64::Label do_store; |
| 2714 | if (can_value_be_null) { |
| 2715 | __ Cbz(Register(value), &do_store); |
| 2716 | } |
| 2717 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2718 | SlowPathCodeARM64* slow_path = nullptr; |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2719 | if (needs_type_check) { |
| 2720 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
| 2721 | codegen_->AddSlowPath(slow_path); |
| 2722 | |
| 2723 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2724 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2725 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2726 | |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2727 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2728 | Register temp = temps.AcquireSameSizeAs(array); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2729 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2730 | |
| 2731 | // Note that when Baker read barriers are enabled, the type |
| 2732 | // checks are performed without read barriers. This is fine, |
| 2733 | // even in the case where a class object is in the from-space |
| 2734 | // after the flip, as a comparison involving such a type would |
| 2735 | // not produce a false positive; it may of course produce a |
| 2736 | // false negative, in which case we would take the ArraySet |
| 2737 | // slow path. |
| 2738 | |
| 2739 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2740 | { |
| 2741 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2742 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2743 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2744 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2745 | } |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2746 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2747 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2748 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2749 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2750 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2751 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2752 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2753 | // nor `temp2`, as we are comparing two poisoned references. |
| 2754 | __ Cmp(temp, temp2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2755 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2756 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2757 | vixl::aarch64::Label do_put; |
| 2758 | __ B(eq, &do_put); |
| 2759 | // If heap poisoning is enabled, the `temp` reference has |
| 2760 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2761 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2762 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2763 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2764 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2765 | // If heap poisoning is enabled, no need to unpoison |
| 2766 | // `temp`, as we are comparing against null below. |
| 2767 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2768 | __ Bind(&do_put); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 2769 | } else { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2770 | __ B(ne, slow_path->GetEntryLabel()); |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2771 | } |
| 2772 | } |
| 2773 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2774 | codegen_->MarkGCCard(array, value.W(), /* value_can_be_null= */ false); |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2775 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2776 | if (can_value_be_null) { |
| 2777 | DCHECK(do_store.IsLinked()); |
| 2778 | __ Bind(&do_store); |
| 2779 | } |
| 2780 | |
| 2781 | UseScratchRegisterScope temps(masm); |
| 2782 | if (kPoisonHeapReferences) { |
| 2783 | Register temp_source = temps.AcquireSameSizeAs(array); |
| 2784 | DCHECK(value.IsW()); |
| 2785 | __ Mov(temp_source, value.W()); |
| 2786 | GetAssembler()->PoisonHeapReference(temp_source); |
| 2787 | source = temp_source; |
| 2788 | } |
| 2789 | |
| 2790 | if (index.IsConstant()) { |
| 2791 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
| 2792 | destination = HeapOperand(array, offset); |
| 2793 | } else { |
| 2794 | Register temp_base = temps.AcquireSameSizeAs(array); |
| 2795 | __ Add(temp_base, array, offset); |
| 2796 | destination = HeapOperand(temp_base, |
| 2797 | XRegisterFrom(index), |
| 2798 | LSL, |
| 2799 | DataType::SizeShift(value_type)); |
| 2800 | } |
| 2801 | |
| 2802 | { |
| 2803 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2804 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2805 | __ Str(source, destination); |
| 2806 | |
| 2807 | if (can_value_be_null || !needs_type_check) { |
| 2808 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2809 | } |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2810 | } |
| 2811 | |
| 2812 | if (slow_path != nullptr) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2813 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2814 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2815 | } |
| 2816 | } |
| 2817 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2818 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2819 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2820 | InvokeRuntimeCallingConvention calling_convention; |
| 2821 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 2822 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 2823 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2824 | |
| 2825 | // If both index and length are constant, we can check the bounds statically and |
| 2826 | // generate code accordingly. We want to make sure we generate constant locations |
| 2827 | // in that case, regardless of whether they are encodable in the comparison or not. |
| 2828 | HInstruction* index = instruction->InputAt(0); |
| 2829 | HInstruction* length = instruction->InputAt(1); |
| 2830 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 2831 | locations->SetInAt(0, both_const |
| 2832 | ? Location::ConstantLocation(index->AsConstant()) |
| 2833 | : ARM64EncodableConstantOrRegister(index, instruction)); |
| 2834 | locations->SetInAt(1, both_const |
| 2835 | ? Location::ConstantLocation(length->AsConstant()) |
| 2836 | : ARM64EncodableConstantOrRegister(length, instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2840 | LocationSummary* locations = instruction->GetLocations(); |
| 2841 | Location index_loc = locations->InAt(0); |
| 2842 | Location length_loc = locations->InAt(1); |
| 2843 | |
| 2844 | int cmp_first_input = 0; |
| 2845 | int cmp_second_input = 1; |
| 2846 | Condition cond = hs; |
| 2847 | |
| 2848 | if (index_loc.IsConstant()) { |
| 2849 | int64_t index = Int64FromLocation(index_loc); |
| 2850 | if (length_loc.IsConstant()) { |
| 2851 | int64_t length = Int64FromLocation(length_loc); |
| 2852 | if (index < 0 || index >= length) { |
| 2853 | BoundsCheckSlowPathARM64* slow_path = |
| 2854 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
| 2855 | codegen_->AddSlowPath(slow_path); |
| 2856 | __ B(slow_path->GetEntryLabel()); |
| 2857 | } else { |
| 2858 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 2859 | // However, some optimization after BCE may have generated this, and we should not |
| 2860 | // generate a bounds check if it is a valid range. |
| 2861 | } |
| 2862 | return; |
| 2863 | } |
| 2864 | // Only the index is constant: change the order of the operands and commute the condition |
| 2865 | // so we can use an immediate constant for the index (only the second input to a cmp |
| 2866 | // instruction can be an immediate). |
| 2867 | cmp_first_input = 1; |
| 2868 | cmp_second_input = 0; |
| 2869 | cond = ls; |
| 2870 | } |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2871 | BoundsCheckSlowPathARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2872 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2873 | __ Cmp(InputRegisterAt(instruction, cmp_first_input), |
| 2874 | InputOperandAt(instruction, cmp_second_input)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2875 | codegen_->AddSlowPath(slow_path); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2876 | __ B(slow_path->GetEntryLabel(), cond); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2877 | } |
| 2878 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2879 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2880 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2881 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2882 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2883 | if (check->HasUses()) { |
| 2884 | locations->SetOut(Location::SameAsFirstInput()); |
| 2885 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 2886 | // Rely on the type initialization to save everything we need. |
| 2887 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2891 | // We assume the class is not null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 2892 | SlowPathCodeARM64* slow_path = |
| 2893 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(check->GetLoadClass(), check); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2894 | codegen_->AddSlowPath(slow_path); |
| 2895 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2896 | } |
| 2897 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2898 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2899 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2900 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2901 | } |
| 2902 | |
| 2903 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 2904 | VRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2905 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2906 | if (rhs_loc.IsConstant()) { |
| 2907 | // 0.0 is the only immediate that can be encoded directly in |
| 2908 | // an FCMP instruction. |
| 2909 | // |
| 2910 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2911 | // specify that in a floating-point comparison, positive zero |
| 2912 | // and negative zero are considered equal, so we can use the |
| 2913 | // literal 0.0 for both cases here. |
| 2914 | // |
| 2915 | // Note however that some methods (Float.equal, Float.compare, |
| 2916 | // Float.compareTo, Double.equal, Double.compare, |
| 2917 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2918 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2919 | // -0.0. So if we ever translate calls to these methods into a |
| 2920 | // HCompare instruction, we must handle the -0.0 case with |
| 2921 | // care here. |
| 2922 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2923 | __ Fcmp(lhs_reg, 0.0); |
| 2924 | } else { |
| 2925 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2926 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2927 | } |
| 2928 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2929 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2930 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2931 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2932 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2933 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2934 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2935 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2936 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2937 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2938 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2939 | case DataType::Type::kInt32: |
| 2940 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2941 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2942 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2943 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2944 | break; |
| 2945 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2946 | case DataType::Type::kFloat32: |
| 2947 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2948 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2949 | locations->SetInAt(1, |
| 2950 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2951 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2952 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2953 | locations->SetOut(Location::RequiresRegister()); |
| 2954 | break; |
| 2955 | } |
| 2956 | default: |
| 2957 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2958 | } |
| 2959 | } |
| 2960 | |
| 2961 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2962 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2963 | |
| 2964 | // 0 if: left == right |
| 2965 | // 1 if: left > right |
| 2966 | // -1 if: left < right |
| 2967 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2968 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2969 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2970 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2971 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2972 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2973 | case DataType::Type::kInt32: |
| 2974 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2975 | Register result = OutputRegister(compare); |
| 2976 | Register left = InputRegisterAt(compare, 0); |
| 2977 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2978 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2979 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 2980 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2981 | break; |
| 2982 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2983 | case DataType::Type::kFloat32: |
| 2984 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2985 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2986 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2987 | __ Cset(result, ne); |
| 2988 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2989 | break; |
| 2990 | } |
| 2991 | default: |
| 2992 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2993 | } |
| 2994 | } |
| 2995 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2996 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2997 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2998 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2999 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3000 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3001 | locations->SetInAt(1, |
| 3002 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3003 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3004 | : Location::RequiresFpuRegister()); |
| 3005 | } else { |
| 3006 | // Integer cases. |
| 3007 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3008 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3009 | } |
| 3010 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3011 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3012 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3013 | } |
| 3014 | } |
| 3015 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3016 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3017 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3018 | return; |
| 3019 | } |
| 3020 | |
| 3021 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3022 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3023 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3024 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3025 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3026 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3027 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3028 | } else { |
| 3029 | // Integer cases. |
| 3030 | Register lhs = InputRegisterAt(instruction, 0); |
| 3031 | Operand rhs = InputOperandAt(instruction, 1); |
| 3032 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3033 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3034 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3038 | M(Equal) \ |
| 3039 | M(NotEqual) \ |
| 3040 | M(LessThan) \ |
| 3041 | M(LessThanOrEqual) \ |
| 3042 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3043 | M(GreaterThanOrEqual) \ |
| 3044 | M(Below) \ |
| 3045 | M(BelowOrEqual) \ |
| 3046 | M(Above) \ |
| 3047 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3048 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3049 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3050 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3051 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3052 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3053 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3054 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3055 | void InstructionCodeGeneratorARM64::GenerateIntDivForPower2Denom(HDiv* instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3056 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3057 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3058 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 3059 | |
| 3060 | Register out = OutputRegister(instruction); |
| 3061 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3062 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3063 | Register final_dividend; |
| 3064 | if (HasNonNegativeResultOrMinInt(instruction->GetLeft())) { |
| 3065 | // No need to adjust the result for non-negative dividends or the INT32_MIN/INT64_MIN dividends. |
| 3066 | // NOTE: The generated code for HDiv correctly works for the INT32_MIN/INT64_MIN dividends: |
| 3067 | // imm == 2 |
| 3068 | // add out, dividend(0x80000000), dividend(0x80000000), lsr #31 => out = 0x80000001 |
| 3069 | // asr out, out(0x80000001), #1 => out = 0xc0000000 |
| 3070 | // This is the same as 'asr out, 0x80000000, #1' |
| 3071 | // |
| 3072 | // imm > 2 |
| 3073 | // add temp, dividend(0x80000000), imm - 1 => temp = 0b10..01..1, where the number |
| 3074 | // of the rightmost 1s is ctz_imm. |
| 3075 | // cmp dividend(0x80000000), 0 => N = 1, V = 0 (lt is true) |
| 3076 | // csel out, temp(0b10..01..1), dividend(0x80000000), lt => out = 0b10..01..1 |
| 3077 | // asr out, out(0b10..01..1), #ctz_imm => out = 0b1..10..0, where the number of the |
| 3078 | // leftmost 1s is ctz_imm + 1. |
| 3079 | // This is the same as 'asr out, dividend(0x80000000), #ctz_imm'. |
| 3080 | // |
| 3081 | // imm == INT32_MIN |
| 3082 | // add tmp, dividend(0x80000000), #0x7fffffff => tmp = -1 |
| 3083 | // cmp dividend(0x80000000), 0 => N = 1, V = 0 (lt is true) |
| 3084 | // csel out, temp(-1), dividend(0x80000000), lt => out = -1 |
| 3085 | // neg out, out(-1), asr #31 => out = 1 |
| 3086 | // This is the same as 'neg out, dividend(0x80000000), asr #31'. |
| 3087 | final_dividend = dividend; |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3088 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3089 | if (abs_imm == 2) { |
| 3090 | int bits = DataType::Size(instruction->GetResultType()) * kBitsPerByte; |
| 3091 | __ Add(out, dividend, Operand(dividend, LSR, bits - 1)); |
| 3092 | } else { |
| 3093 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3094 | Register temp = temps.AcquireSameSizeAs(out); |
| 3095 | __ Add(temp, dividend, abs_imm - 1); |
| 3096 | __ Cmp(dividend, 0); |
| 3097 | __ Csel(out, temp, dividend, lt); |
| 3098 | } |
| 3099 | final_dividend = out; |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3100 | } |
| 3101 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3102 | int ctz_imm = CTZ(abs_imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3103 | if (imm > 0) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3104 | __ Asr(out, final_dividend, ctz_imm); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3105 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3106 | __ Neg(out, Operand(final_dividend, ASR, ctz_imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3107 | } |
| 3108 | } |
| 3109 | |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3110 | // Return true if the magic number was modified by subtracting 2^32. So dividend needs to be added. |
| 3111 | static inline bool NeedToAddDividend(int64_t magic_number, int64_t divisor) { |
| 3112 | return divisor > 0 && magic_number < 0; |
| 3113 | } |
| 3114 | |
| 3115 | // Return true if the magic number was modified by adding 2^32. So dividend needs to be subtracted. |
| 3116 | static inline bool NeedToSubDividend(int64_t magic_number, int64_t divisor) { |
| 3117 | return divisor < 0 && magic_number > 0; |
| 3118 | } |
| 3119 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3120 | // Generate code which increments the value in register 'in' by 1 if the value is negative. |
| 3121 | // It is done with 'add out, in, in, lsr #31 or #63'. |
| 3122 | // If the value is a result of an operation setting the N flag, CINC MI can be used |
| 3123 | // instead of ADD. 'use_cond_inc' controls this. |
| 3124 | void InstructionCodeGeneratorARM64::GenerateIncrementNegativeByOne( |
| 3125 | Register out, |
| 3126 | Register in, |
| 3127 | bool use_cond_inc) { |
| 3128 | if (use_cond_inc) { |
| 3129 | __ Cinc(out, in, mi); |
| 3130 | } else { |
| 3131 | __ Add(out, in, Operand(in, LSR, in.GetSizeInBits() - 1)); |
| 3132 | } |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3133 | } |
| 3134 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3135 | // Helper to generate code producing the result of HRem with a constant divisor. |
| 3136 | void InstructionCodeGeneratorARM64::GenerateResultRemWithAnyConstant( |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3137 | Register out, |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3138 | Register dividend, |
| 3139 | Register quotient, |
| 3140 | int64_t divisor, |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3141 | UseScratchRegisterScope* temps_scope) { |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3142 | Register temp_imm = temps_scope->AcquireSameSizeAs(out); |
| 3143 | __ Mov(temp_imm, divisor); |
| 3144 | __ Msub(out, quotient, temp_imm, dividend); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | void InstructionCodeGeneratorARM64::GenerateInt64DivRemWithAnyConstant( |
| 3148 | HBinaryOperation* instruction) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3149 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3150 | DCHECK(instruction->GetResultType() == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3151 | |
| 3152 | LocationSummary* locations = instruction->GetLocations(); |
| 3153 | Location second = locations->InAt(1); |
| 3154 | DCHECK(second.IsConstant()); |
| 3155 | |
| 3156 | Register out = OutputRegister(instruction); |
| 3157 | Register dividend = InputRegisterAt(instruction, 0); |
| 3158 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3159 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3160 | int64_t magic; |
| 3161 | int shift; |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3162 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ true, &magic, &shift); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3163 | |
| 3164 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3165 | Register temp = temps.AcquireSameSizeAs(out); |
| 3166 | |
| 3167 | // temp = get_high(dividend * magic) |
| 3168 | __ Mov(temp, magic); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3169 | __ Smulh(temp, dividend, temp); |
| 3170 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3171 | // The multiplication result might need some corrections to be finalized. |
| 3172 | // The last correction is to increment by 1, if the result is negative. |
| 3173 | // Currently it is done with 'add result, temp_result, temp_result, lsr #31 or #63'. |
| 3174 | // Such ADD usually has latency 2, e.g. on Cortex-A55. |
| 3175 | // However if one of the corrections is ADD or SUB, the sign can be detected |
| 3176 | // with ADDS/SUBS. They set the N flag if the result is negative. |
| 3177 | // This allows to use CINC MI which has latency 1. |
| 3178 | bool use_cond_inc = false; |
| 3179 | |
| 3180 | // As magic_number can be modified to fit into 32 bits, check whether the correction is needed. |
| 3181 | if (NeedToAddDividend(magic, imm)) { |
| 3182 | __ Adds(temp, temp, dividend); |
| 3183 | use_cond_inc = true; |
| 3184 | } else if (NeedToSubDividend(magic, imm)) { |
| 3185 | __ Subs(temp, temp, dividend); |
| 3186 | use_cond_inc = true; |
| 3187 | } |
| 3188 | |
| 3189 | if (shift != 0) { |
| 3190 | __ Asr(temp, temp, shift); |
| 3191 | } |
| 3192 | |
| 3193 | if (instruction->IsRem()) { |
| 3194 | GenerateIncrementNegativeByOne(temp, temp, use_cond_inc); |
| 3195 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3196 | } else { |
| 3197 | GenerateIncrementNegativeByOne(out, temp, use_cond_inc); |
| 3198 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | void InstructionCodeGeneratorARM64::GenerateInt32DivRemWithAnyConstant( |
| 3202 | HBinaryOperation* instruction) { |
| 3203 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3204 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 3205 | |
| 3206 | LocationSummary* locations = instruction->GetLocations(); |
| 3207 | Location second = locations->InAt(1); |
| 3208 | DCHECK(second.IsConstant()); |
| 3209 | |
| 3210 | Register out = OutputRegister(instruction); |
| 3211 | Register dividend = InputRegisterAt(instruction, 0); |
| 3212 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3213 | |
| 3214 | int64_t magic; |
| 3215 | int shift; |
| 3216 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| 3217 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3218 | Register temp = temps.AcquireSameSizeAs(out); |
| 3219 | |
| 3220 | // temp = get_high(dividend * magic) |
| 3221 | __ Mov(temp, magic); |
| 3222 | __ Smull(temp.X(), dividend, temp); |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3223 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3224 | // The multiplication result might need some corrections to be finalized. |
| 3225 | // The last correction is to increment by 1, if the result is negative. |
| 3226 | // Currently it is done with 'add result, temp_result, temp_result, lsr #31 or #63'. |
| 3227 | // Such ADD usually has latency 2, e.g. on Cortex-A55. |
| 3228 | // However if one of the corrections is ADD or SUB, the sign can be detected |
| 3229 | // with ADDS/SUBS. They set the N flag if the result is negative. |
| 3230 | // This allows to use CINC MI which has latency 1. |
| 3231 | bool use_cond_inc = false; |
| 3232 | |
| 3233 | // ADD/SUB correction is performed in the high 32 bits |
| 3234 | // as high 32 bits are ignored because type are kInt32. |
| 3235 | if (NeedToAddDividend(magic, imm)) { |
| 3236 | __ Adds(temp.X(), temp.X(), Operand(dividend.X(), LSL, 32)); |
| 3237 | use_cond_inc = true; |
| 3238 | } else if (NeedToSubDividend(magic, imm)) { |
| 3239 | __ Subs(temp.X(), temp.X(), Operand(dividend.X(), LSL, 32)); |
| 3240 | use_cond_inc = true; |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3241 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3242 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3243 | // Extract the result from the high 32 bits and apply the final right shift. |
| 3244 | DCHECK_LT(shift, 32); |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 3245 | if (imm > 0 && IsGEZero(instruction->GetLeft())) { |
| 3246 | // No need to adjust the result for a non-negative dividend and a positive divisor. |
| 3247 | if (instruction->IsDiv()) { |
| 3248 | __ Lsr(out.X(), temp.X(), 32 + shift); |
| 3249 | } else { |
| 3250 | __ Lsr(temp.X(), temp.X(), 32 + shift); |
| 3251 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3252 | } |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3253 | } else { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 3254 | __ Asr(temp.X(), temp.X(), 32 + shift); |
| 3255 | |
| 3256 | if (instruction->IsRem()) { |
| 3257 | GenerateIncrementNegativeByOne(temp, temp, use_cond_inc); |
| 3258 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3259 | } else { |
| 3260 | GenerateIncrementNegativeByOne(out, temp, use_cond_inc); |
| 3261 | } |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3262 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3266 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3267 | if (instruction->GetResultType() == DataType::Type::kInt64) { |
| 3268 | GenerateInt64DivRemWithAnyConstant(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3269 | } else { |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3270 | GenerateInt32DivRemWithAnyConstant(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3271 | } |
| 3272 | } |
| 3273 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3274 | void InstructionCodeGeneratorARM64::GenerateIntDivForConstDenom(HDiv *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3275 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3276 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3277 | if (imm == 0) { |
| 3278 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3279 | return; |
| 3280 | } |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3281 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3282 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3283 | GenerateIntDivForPower2Denom(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3284 | } else { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3285 | // Cases imm == -1 or imm == 1 are handled by InstructionSimplifier. |
| 3286 | DCHECK(imm < -2 || imm > 2) << imm; |
| 3287 | GenerateDivRemWithAnyConstant(instruction); |
| 3288 | } |
| 3289 | } |
| 3290 | |
| 3291 | void InstructionCodeGeneratorARM64::GenerateIntDiv(HDiv *instruction) { |
| 3292 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 3293 | << instruction->GetResultType(); |
| 3294 | |
| 3295 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 3296 | GenerateIntDivForConstDenom(instruction); |
| 3297 | } else { |
| 3298 | Register out = OutputRegister(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3299 | Register dividend = InputRegisterAt(instruction, 0); |
| 3300 | Register divisor = InputRegisterAt(instruction, 1); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3301 | __ Sdiv(out, dividend, divisor); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3302 | } |
| 3303 | } |
| 3304 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3305 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3306 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3307 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3308 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3309 | case DataType::Type::kInt32: |
| 3310 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3311 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3312 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3313 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3314 | break; |
| 3315 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3316 | case DataType::Type::kFloat32: |
| 3317 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3318 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3319 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3320 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3321 | break; |
| 3322 | |
| 3323 | default: |
| 3324 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3325 | } |
| 3326 | } |
| 3327 | |
| 3328 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3329 | DataType::Type type = div->GetResultType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3330 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3331 | case DataType::Type::kInt32: |
| 3332 | case DataType::Type::kInt64: |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3333 | GenerateIntDiv(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3334 | break; |
| 3335 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3336 | case DataType::Type::kFloat32: |
| 3337 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3338 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3339 | break; |
| 3340 | |
| 3341 | default: |
| 3342 | LOG(FATAL) << "Unexpected div type " << type; |
| 3343 | } |
| 3344 | } |
| 3345 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3346 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3347 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3348 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3349 | } |
| 3350 | |
| 3351 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3352 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3353 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3354 | codegen_->AddSlowPath(slow_path); |
| 3355 | Location value = instruction->GetLocations()->InAt(0); |
| 3356 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3357 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3358 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3359 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3360 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3361 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3362 | } |
| 3363 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3364 | if (value.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3365 | int64_t divisor = Int64FromLocation(value); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3366 | if (divisor == 0) { |
| 3367 | __ B(slow_path->GetEntryLabel()); |
| 3368 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3369 | // A division by a non-null constant is valid. We don't need to perform |
| 3370 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3371 | } |
| 3372 | } else { |
| 3373 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3374 | } |
| 3375 | } |
| 3376 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3377 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3378 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3379 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3380 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3381 | } |
| 3382 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3383 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3384 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3385 | // Will be generated at use site. |
| 3386 | } |
| 3387 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3388 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3389 | exit->SetLocations(nullptr); |
| 3390 | } |
| 3391 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3392 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3393 | } |
| 3394 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3395 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3396 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3397 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3398 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3399 | } |
| 3400 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3401 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3402 | // Will be generated at use site. |
| 3403 | } |
| 3404 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3405 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3406 | if (successor->IsExitBlock()) { |
| 3407 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3408 | return; // no code needed |
| 3409 | } |
| 3410 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3411 | HBasicBlock* block = got->GetBlock(); |
| 3412 | HInstruction* previous = got->GetPrevious(); |
| 3413 | HLoopInformation* info = block->GetLoopInformation(); |
| 3414 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3415 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 3416 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3417 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3418 | return; |
| 3419 | } |
| 3420 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3421 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3422 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3423 | } |
| 3424 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3425 | __ B(codegen_->GetLabelOf(successor)); |
| 3426 | } |
| 3427 | } |
| 3428 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3429 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3430 | got->SetLocations(nullptr); |
| 3431 | } |
| 3432 | |
| 3433 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3434 | HandleGoto(got, got->GetSuccessor()); |
| 3435 | } |
| 3436 | |
| 3437 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3438 | try_boundary->SetLocations(nullptr); |
| 3439 | } |
| 3440 | |
| 3441 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3442 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3443 | if (!successor->IsExitBlock()) { |
| 3444 | HandleGoto(try_boundary, successor); |
| 3445 | } |
| 3446 | } |
| 3447 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3448 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3449 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3450 | vixl::aarch64::Label* true_target, |
| 3451 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3452 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3453 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3454 | if (true_target == nullptr && false_target == nullptr) { |
| 3455 | // Nothing to do. The code always falls through. |
| 3456 | return; |
| 3457 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3458 | // Constant condition, statically compared against "true" (integer value 1). |
| 3459 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3460 | if (true_target != nullptr) { |
| 3461 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3462 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3463 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3464 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3465 | if (false_target != nullptr) { |
| 3466 | __ B(false_target); |
| 3467 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3468 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3469 | return; |
| 3470 | } |
| 3471 | |
| 3472 | // The following code generates these patterns: |
| 3473 | // (1) true_target == nullptr && false_target != nullptr |
| 3474 | // - opposite condition true => branch to false_target |
| 3475 | // (2) true_target != nullptr && false_target == nullptr |
| 3476 | // - condition true => branch to true_target |
| 3477 | // (3) true_target != nullptr && false_target != nullptr |
| 3478 | // - condition true => branch to true_target |
| 3479 | // - branch to false_target |
| 3480 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3481 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3482 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3483 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3484 | if (true_target == nullptr) { |
| 3485 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3486 | } else { |
| 3487 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3488 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3489 | } else { |
| 3490 | // The condition instruction has not been materialized, use its inputs as |
| 3491 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3492 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3493 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3494 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3495 | if (DataType::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3496 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3497 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3498 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3499 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3500 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3501 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3502 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3503 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3504 | // Integer cases. |
| 3505 | Register lhs = InputRegisterAt(condition, 0); |
| 3506 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3507 | |
| 3508 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3509 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3510 | if (true_target == nullptr) { |
| 3511 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3512 | non_fallthrough_target = false_target; |
| 3513 | } else { |
| 3514 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3515 | non_fallthrough_target = true_target; |
| 3516 | } |
| 3517 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3518 | 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] | 3519 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3520 | switch (arm64_cond) { |
| 3521 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3522 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3523 | break; |
| 3524 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3525 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3526 | break; |
| 3527 | case lt: |
| 3528 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3529 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3530 | break; |
| 3531 | case ge: |
| 3532 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3533 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3534 | break; |
| 3535 | default: |
| 3536 | // Without the `static_cast` the compiler throws an error for |
| 3537 | // `-Werror=sign-promo`. |
| 3538 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3539 | } |
| 3540 | } else { |
| 3541 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3542 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3543 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3544 | } |
| 3545 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3546 | |
| 3547 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3548 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3549 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3550 | __ B(false_target); |
| 3551 | } |
| 3552 | } |
| 3553 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3554 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3555 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3556 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3557 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3558 | } |
| 3559 | } |
| 3560 | |
| 3561 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3562 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3563 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3564 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3565 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3566 | true_target = nullptr; |
| 3567 | } |
| 3568 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3569 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3570 | false_target = nullptr; |
| 3571 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3572 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3573 | } |
| 3574 | |
| 3575 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3576 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3577 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3578 | InvokeRuntimeCallingConvention calling_convention; |
| 3579 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3580 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3581 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3582 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3583 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3584 | } |
| 3585 | } |
| 3586 | |
| 3587 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3588 | SlowPathCodeARM64* slow_path = |
| 3589 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3590 | GenerateTestAndBranch(deoptimize, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3591 | /* condition_input_index= */ 0, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3592 | slow_path->GetEntryLabel(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3593 | /* false_target= */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3594 | } |
| 3595 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3596 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3597 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3598 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3599 | locations->SetOut(Location::RequiresRegister()); |
| 3600 | } |
| 3601 | |
| 3602 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3603 | __ Ldr(OutputRegister(flag), |
| 3604 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3605 | } |
| 3606 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3607 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3608 | return condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3609 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3610 | } |
| 3611 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3612 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3613 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3614 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3615 | : ARM64Condition(cond); |
| 3616 | } |
| 3617 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3618 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3619 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3620 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3621 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3622 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3623 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3624 | } else { |
| 3625 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3626 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3627 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3628 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3629 | // Ask VIXL whether we should synthesize constants in registers. |
| 3630 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3631 | Operand true_op = is_true_value_constant ? |
| 3632 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3633 | Operand false_op = is_false_value_constant ? |
| 3634 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3635 | bool true_value_in_register = false; |
| 3636 | bool false_value_in_register = false; |
| 3637 | MacroAssembler::GetCselSynthesisInformation( |
| 3638 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3639 | true_value_in_register |= !is_true_value_constant; |
| 3640 | false_value_in_register |= !is_false_value_constant; |
| 3641 | |
| 3642 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3643 | : Location::ConstantLocation(cst_true_value)); |
| 3644 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3645 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3646 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3647 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3648 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3649 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3650 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3651 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3652 | } |
| 3653 | |
| 3654 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3655 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3656 | Condition csel_cond; |
| 3657 | |
| 3658 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3659 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3660 | // Use the condition flags set by the previous instruction. |
| 3661 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3662 | } else { |
| 3663 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3664 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3665 | } |
| 3666 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3667 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3668 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3669 | } else { |
| 3670 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3671 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3672 | } |
| 3673 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3674 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3675 | __ Fcsel(OutputFPRegister(select), |
| 3676 | InputFPRegisterAt(select, 1), |
| 3677 | InputFPRegisterAt(select, 0), |
| 3678 | csel_cond); |
| 3679 | } else { |
| 3680 | __ Csel(OutputRegister(select), |
| 3681 | InputOperandAt(select, 1), |
| 3682 | InputOperandAt(select, 0), |
| 3683 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3684 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3685 | } |
| 3686 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3687 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3688 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3689 | } |
| 3690 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3691 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3692 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3693 | } |
| 3694 | |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3695 | void CodeGeneratorARM64::IncreaseFrame(size_t adjustment) { |
| 3696 | __ Claim(adjustment); |
| 3697 | GetAssembler()->cfi().AdjustCFAOffset(adjustment); |
| 3698 | } |
| 3699 | |
| 3700 | void CodeGeneratorARM64::DecreaseFrame(size_t adjustment) { |
| 3701 | __ Drop(adjustment); |
| 3702 | GetAssembler()->cfi().AdjustCFAOffset(-adjustment); |
| 3703 | } |
| 3704 | |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3705 | void CodeGeneratorARM64::GenerateNop() { |
| 3706 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3707 | } |
| 3708 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3709 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3710 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3711 | } |
| 3712 | |
| 3713 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3714 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3715 | } |
| 3716 | |
| 3717 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3718 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3722 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3723 | } |
| 3724 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3725 | // Temp is used for read barrier. |
| 3726 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3727 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3728 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3729 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3730 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3731 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3732 | return 1; |
| 3733 | } |
| 3734 | return 0; |
| 3735 | } |
| 3736 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3737 | // 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] | 3738 | // interface pointer, one for loading the current interface. |
| 3739 | // The other checks have one temp for loading the object's class. |
| 3740 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3741 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3742 | return 3; |
| 3743 | } |
| 3744 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3745 | } |
| 3746 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3747 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3748 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3749 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3750 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3751 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3752 | case TypeCheckKind::kExactCheck: |
| 3753 | case TypeCheckKind::kAbstractClassCheck: |
| 3754 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3755 | case TypeCheckKind::kArrayObjectCheck: { |
| 3756 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 3757 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 3758 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3759 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3760 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3761 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3762 | case TypeCheckKind::kUnresolvedCheck: |
| 3763 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3764 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3765 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3766 | case TypeCheckKind::kBitstringCheck: |
| 3767 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3768 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3769 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3770 | LocationSummary* locations = |
| 3771 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3772 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3773 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3774 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3775 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3776 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3777 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3778 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3779 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3780 | } else { |
| 3781 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3782 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3783 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3784 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3785 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3786 | // Add temps if necessary for read barriers. |
| 3787 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3791 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3792 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3793 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3794 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3795 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 3796 | ? Register() |
| 3797 | : InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3798 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3799 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3800 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3801 | DCHECK_LE(num_temps, 1u); |
| 3802 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3803 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3804 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3805 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3806 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3807 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3808 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3809 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3810 | |
| 3811 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3812 | // Avoid null check if we know `obj` is not null. |
| 3813 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3814 | __ Cbz(obj, &zero); |
| 3815 | } |
| 3816 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3817 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3818 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3819 | ReadBarrierOption read_barrier_option = |
| 3820 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3821 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3822 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3823 | out_loc, |
| 3824 | obj_loc, |
| 3825 | class_offset, |
| 3826 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3827 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3828 | __ Cmp(out, cls); |
| 3829 | __ Cset(out, eq); |
| 3830 | if (zero.IsLinked()) { |
| 3831 | __ B(&done); |
| 3832 | } |
| 3833 | break; |
| 3834 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3835 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3836 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3837 | ReadBarrierOption read_barrier_option = |
| 3838 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3839 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3840 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3841 | out_loc, |
| 3842 | obj_loc, |
| 3843 | class_offset, |
| 3844 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3845 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3846 | // If the class is abstract, we eagerly fetch the super class of the |
| 3847 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3848 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3849 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3850 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3851 | GenerateReferenceLoadOneRegister(instruction, |
| 3852 | out_loc, |
| 3853 | super_offset, |
| 3854 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3855 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3856 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3857 | __ Cbz(out, &done); |
| 3858 | __ Cmp(out, cls); |
| 3859 | __ B(ne, &loop); |
| 3860 | __ Mov(out, 1); |
| 3861 | if (zero.IsLinked()) { |
| 3862 | __ B(&done); |
| 3863 | } |
| 3864 | break; |
| 3865 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3866 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3867 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3868 | ReadBarrierOption read_barrier_option = |
| 3869 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3870 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3871 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3872 | out_loc, |
| 3873 | obj_loc, |
| 3874 | class_offset, |
| 3875 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3876 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3877 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3878 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3879 | __ Bind(&loop); |
| 3880 | __ Cmp(out, cls); |
| 3881 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3882 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3883 | GenerateReferenceLoadOneRegister(instruction, |
| 3884 | out_loc, |
| 3885 | super_offset, |
| 3886 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3887 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3888 | __ Cbnz(out, &loop); |
| 3889 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3890 | __ B(&done); |
| 3891 | __ Bind(&success); |
| 3892 | __ Mov(out, 1); |
| 3893 | if (zero.IsLinked()) { |
| 3894 | __ B(&done); |
| 3895 | } |
| 3896 | break; |
| 3897 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3898 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3899 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3900 | ReadBarrierOption read_barrier_option = |
| 3901 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3902 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3903 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3904 | out_loc, |
| 3905 | obj_loc, |
| 3906 | class_offset, |
| 3907 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3908 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3909 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3910 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3911 | __ Cmp(out, cls); |
| 3912 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3913 | // 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] | 3914 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3915 | GenerateReferenceLoadOneRegister(instruction, |
| 3916 | out_loc, |
| 3917 | component_offset, |
| 3918 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3919 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3920 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3921 | __ Cbz(out, &done); |
| 3922 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3923 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3924 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3925 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3926 | __ Mov(out, 1); |
| 3927 | __ B(&done); |
| 3928 | break; |
| 3929 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3930 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3931 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3932 | // No read barrier since the slow path will retry upon failure. |
| 3933 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3934 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3935 | out_loc, |
| 3936 | obj_loc, |
| 3937 | class_offset, |
| 3938 | maybe_temp_loc, |
| 3939 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3940 | __ Cmp(out, cls); |
| 3941 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3942 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3943 | instruction, /* is_fatal= */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3944 | codegen_->AddSlowPath(slow_path); |
| 3945 | __ B(ne, slow_path->GetEntryLabel()); |
| 3946 | __ Mov(out, 1); |
| 3947 | if (zero.IsLinked()) { |
| 3948 | __ B(&done); |
| 3949 | } |
| 3950 | break; |
| 3951 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3952 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3953 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3954 | case TypeCheckKind::kInterfaceCheck: { |
| 3955 | // Note that we indeed only call on slow path, but we always go |
| 3956 | // into the slow path for the unresolved and interface check |
| 3957 | // cases. |
| 3958 | // |
| 3959 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3960 | // entry point without resorting to a type checking slow path |
| 3961 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3962 | // require to assign fixed registers for the inputs of this |
| 3963 | // HInstanceOf instruction (following the runtime calling |
| 3964 | // convention), which might be cluttered by the potential first |
| 3965 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3966 | // |
| 3967 | // TODO: Introduce a new runtime entry point taking the object |
| 3968 | // to test (instead of its class) as argument, and let it deal |
| 3969 | // with the read barrier issues. This will let us refactor this |
| 3970 | // case of the `switch` code as it was previously (with a direct |
| 3971 | // call to the runtime not using a type checking slow path). |
| 3972 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3973 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3974 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3975 | instruction, /* is_fatal= */ false); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3976 | codegen_->AddSlowPath(slow_path); |
| 3977 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3978 | if (zero.IsLinked()) { |
| 3979 | __ B(&done); |
| 3980 | } |
| 3981 | break; |
| 3982 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3983 | |
| 3984 | case TypeCheckKind::kBitstringCheck: { |
| 3985 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3986 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3987 | out_loc, |
| 3988 | obj_loc, |
| 3989 | class_offset, |
| 3990 | maybe_temp_loc, |
| 3991 | kWithoutReadBarrier); |
| 3992 | |
| 3993 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 3994 | __ Cset(out, eq); |
| 3995 | if (zero.IsLinked()) { |
| 3996 | __ B(&done); |
| 3997 | } |
| 3998 | break; |
| 3999 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | if (zero.IsLinked()) { |
| 4003 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4004 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4005 | } |
| 4006 | |
| 4007 | if (done.IsLinked()) { |
| 4008 | __ Bind(&done); |
| 4009 | } |
| 4010 | |
| 4011 | if (slow_path != nullptr) { |
| 4012 | __ Bind(slow_path->GetExitLabel()); |
| 4013 | } |
| 4014 | } |
| 4015 | |
| 4016 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4017 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4018 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4019 | LocationSummary* locations = |
| 4020 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4021 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4022 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 4023 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 4024 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 4025 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 4026 | } else { |
| 4027 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4028 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4029 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4030 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4031 | } |
| 4032 | |
| 4033 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4034 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4035 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4036 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4037 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4038 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 4039 | ? Register() |
| 4040 | : InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4041 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4042 | DCHECK_GE(num_temps, 1u); |
| 4043 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4044 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4045 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4046 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4047 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4048 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4049 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4050 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4051 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4052 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4053 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4054 | const uint32_t object_array_data_offset = |
| 4055 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4056 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4057 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4058 | SlowPathCodeARM64* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4059 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4060 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4061 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4062 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4063 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4064 | // Avoid null check if we know obj is not null. |
| 4065 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4066 | __ Cbz(obj, &done); |
| 4067 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4068 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4069 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4070 | case TypeCheckKind::kExactCheck: |
| 4071 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4072 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4073 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4074 | temp_loc, |
| 4075 | obj_loc, |
| 4076 | class_offset, |
| 4077 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4078 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4079 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4080 | __ Cmp(temp, cls); |
| 4081 | // Jump to slow path for throwing the exception or doing a |
| 4082 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4083 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4084 | break; |
| 4085 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4086 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4087 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4088 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4089 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4090 | temp_loc, |
| 4091 | obj_loc, |
| 4092 | class_offset, |
| 4093 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4094 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4095 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4096 | // If the class is abstract, we eagerly fetch the super class of the |
| 4097 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4098 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4099 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4100 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4101 | GenerateReferenceLoadOneRegister(instruction, |
| 4102 | temp_loc, |
| 4103 | super_offset, |
| 4104 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4105 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4106 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4107 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4108 | // exception. |
| 4109 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4110 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4111 | __ Cmp(temp, cls); |
| 4112 | __ B(ne, &loop); |
| 4113 | break; |
| 4114 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4115 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4116 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4117 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4118 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4119 | temp_loc, |
| 4120 | obj_loc, |
| 4121 | class_offset, |
| 4122 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4123 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4124 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4125 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4126 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4127 | __ Bind(&loop); |
| 4128 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4129 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4130 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4131 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4132 | GenerateReferenceLoadOneRegister(instruction, |
| 4133 | temp_loc, |
| 4134 | super_offset, |
| 4135 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4136 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4137 | |
| 4138 | // If the class reference currently in `temp` is not null, jump |
| 4139 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4140 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4141 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4142 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4143 | break; |
| 4144 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4145 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4146 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4147 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4148 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4149 | temp_loc, |
| 4150 | obj_loc, |
| 4151 | class_offset, |
| 4152 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4153 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4154 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4155 | // Do an exact check. |
| 4156 | __ Cmp(temp, cls); |
| 4157 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4158 | |
| 4159 | // 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] | 4160 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4161 | GenerateReferenceLoadOneRegister(instruction, |
| 4162 | temp_loc, |
| 4163 | component_offset, |
| 4164 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4165 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4166 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4167 | // If the component type is null, jump to the slow path to throw the exception. |
| 4168 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4169 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4170 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4171 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4172 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4173 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4174 | break; |
| 4175 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4176 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4177 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4178 | // 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] | 4179 | // |
| 4180 | // We cannot directly call the CheckCast runtime entry point |
| 4181 | // without resorting to a type checking slow path here (i.e. by |
| 4182 | // calling InvokeRuntime directly), as it would require to |
| 4183 | // assign fixed registers for the inputs of this HInstanceOf |
| 4184 | // instruction (following the runtime calling convention), which |
| 4185 | // might be cluttered by the potential first read barrier |
| 4186 | // emission at the beginning of this method. |
| 4187 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4188 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4189 | case TypeCheckKind::kInterfaceCheck: { |
| 4190 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4191 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4192 | temp_loc, |
| 4193 | obj_loc, |
| 4194 | class_offset, |
| 4195 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4196 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4197 | |
| 4198 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4199 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4200 | temp_loc, |
| 4201 | temp_loc, |
| 4202 | iftable_offset, |
| 4203 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4204 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4205 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4206 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4207 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4208 | vixl::aarch64::Label start_loop; |
| 4209 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4210 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4211 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4212 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4213 | // Go to next interface. |
| 4214 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4215 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4216 | // Compare the classes and continue the loop if they do not match. |
| 4217 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4218 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4219 | break; |
| 4220 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4221 | |
| 4222 | case TypeCheckKind::kBitstringCheck: { |
| 4223 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4224 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4225 | temp_loc, |
| 4226 | obj_loc, |
| 4227 | class_offset, |
| 4228 | maybe_temp2_loc, |
| 4229 | kWithoutReadBarrier); |
| 4230 | |
| 4231 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 4232 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 4233 | break; |
| 4234 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4235 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4236 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4237 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4238 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4239 | } |
| 4240 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4241 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4242 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4243 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4244 | } |
| 4245 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4246 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4247 | // Will be generated at use site. |
| 4248 | } |
| 4249 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4250 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4251 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4252 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4253 | } |
| 4254 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4255 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4256 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4257 | } |
| 4258 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4259 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4260 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4261 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4262 | // the method_idx. |
| 4263 | HandleInvoke(invoke); |
| 4264 | } |
| 4265 | |
| 4266 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4267 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4268 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4269 | } |
| 4270 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4271 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4272 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4273 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4274 | } |
| 4275 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4276 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4277 | HandleInvoke(invoke); |
| 4278 | } |
| 4279 | |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4280 | void CodeGeneratorARM64::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 4281 | Register klass) { |
| 4282 | DCHECK_EQ(klass.GetCode(), 0u); |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4283 | // We know the destination of an intrinsic, so no need to record inline |
| 4284 | // caches. |
| 4285 | if (!instruction->GetLocations()->Intrinsified() && |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 4286 | GetGraph()->IsCompilingBaseline() && |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4287 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4288 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
| 4289 | ScopedObjectAccess soa(Thread::Current()); |
| 4290 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 4291 | if (info != nullptr) { |
| 4292 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 4293 | uint64_t address = reinterpret_cast64<uint64_t>(cache); |
| 4294 | vixl::aarch64::Label done; |
| 4295 | __ Mov(x8, address); |
| 4296 | __ Ldr(x9, MemOperand(x8, InlineCache::ClassesOffset().Int32Value())); |
| 4297 | // Fast path for a monomorphic cache. |
| 4298 | __ Cmp(klass, x9); |
| 4299 | __ B(eq, &done); |
| 4300 | InvokeRuntime(kQuickUpdateInlineCache, instruction, instruction->GetDexPc()); |
| 4301 | __ Bind(&done); |
| 4302 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4303 | } |
| 4304 | } |
| 4305 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4306 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4307 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4308 | LocationSummary* locations = invoke->GetLocations(); |
| 4309 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4310 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4311 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4312 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4313 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4314 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4315 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4316 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4317 | { |
| 4318 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4319 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4320 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4321 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4322 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4323 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4324 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4325 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4326 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4327 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4328 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4329 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4330 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4331 | // emit a read barrier for the previous class reference load. |
| 4332 | // However this is not required in practice, as this is an |
| 4333 | // intermediate/temporary reference and because the current |
| 4334 | // concurrent copying collector keeps the from-space memory |
| 4335 | // intact/accessible until the end of the marking phase (the |
| 4336 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4337 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4338 | |
| 4339 | // If we're compiling baseline, update the inline cache. |
| 4340 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4341 | |
| 4342 | // The register ip1 is required to be used for the hidden argument in |
| 4343 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
| 4344 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4345 | UseScratchRegisterScope scratch_scope(masm); |
| 4346 | scratch_scope.Exclude(ip1); |
| 4347 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4348 | |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4349 | __ Ldr(temp, |
| 4350 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4351 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4352 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4353 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4354 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4355 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4356 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4357 | |
| 4358 | { |
| 4359 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4360 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4361 | |
| 4362 | // lr(); |
| 4363 | __ blr(lr); |
| 4364 | DCHECK(!codegen_->IsLeafMethod()); |
| 4365 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4366 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4367 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4368 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4369 | } |
| 4370 | |
| 4371 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4372 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4373 | if (intrinsic.TryDispatch(invoke)) { |
| 4374 | return; |
| 4375 | } |
| 4376 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4377 | HandleInvoke(invoke); |
| 4378 | } |
| 4379 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4380 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4381 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4382 | // art::PrepareForRegisterAllocation. |
| 4383 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4384 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4385 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4386 | if (intrinsic.TryDispatch(invoke)) { |
| 4387 | return; |
| 4388 | } |
| 4389 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4390 | if (invoke->GetCodePtrLocation() == HInvokeStaticOrDirect::CodePtrLocation::kCallCriticalNative) { |
| 4391 | CriticalNativeCallingConventionVisitorARM64 calling_convention_visitor( |
| 4392 | /*for_register_allocation=*/ true); |
| 4393 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 4394 | } else { |
| 4395 | HandleInvoke(invoke); |
| 4396 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4397 | } |
| 4398 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4399 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4400 | if (invoke->GetLocations()->Intrinsified()) { |
| 4401 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4402 | intrinsic.Dispatch(invoke); |
| 4403 | return true; |
| 4404 | } |
| 4405 | return false; |
| 4406 | } |
| 4407 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4408 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4409 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4410 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4411 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4412 | return desired_dispatch_info; |
| 4413 | } |
| 4414 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4415 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4416 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4417 | // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4418 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4419 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4420 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4421 | uint32_t offset = |
| 4422 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4423 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4424 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4425 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4426 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4427 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4428 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4429 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4430 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4431 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4432 | // Add ADRP with its PC-relative method patch. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4433 | vixl::aarch64::Label* adrp_label = NewBootImageMethodPatch(invoke->GetTargetMethod()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4434 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4435 | // Add ADD with its PC-relative method patch. |
| 4436 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4437 | NewBootImageMethodPatch(invoke->GetTargetMethod(), adrp_label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4438 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4439 | break; |
| 4440 | } |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4441 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4442 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4443 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4444 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_offset); |
| 4445 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4446 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| 4447 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| 4448 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 4449 | EmitLdrOffsetPlaceholder(ldr_label, WRegisterFrom(temp), XRegisterFrom(temp)); |
| 4450 | break; |
| 4451 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4452 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4453 | // Add ADRP with its PC-relative .bss entry patch. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4454 | MethodReference target_method(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4455 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(target_method); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4456 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4457 | // Add LDR with its PC-relative .bss entry patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4458 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4459 | NewMethodBssEntryPatch(target_method, adrp_label); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 4460 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4461 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4462 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4463 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4464 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 4465 | // Load method address from literal pool. |
| 4466 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
| 4467 | break; |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4468 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4469 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4470 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4471 | } |
| 4472 | } |
| 4473 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4474 | auto call_code_pointer_member = [&](MemberOffset offset) { |
| 4475 | // LR = callee_method->member; |
| 4476 | __ Ldr(lr, MemOperand(XRegisterFrom(callee_method), offset.Int32Value())); |
| 4477 | { |
| 4478 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4479 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4480 | kInstructionSize, |
| 4481 | CodeBufferCheckScope::kExactSize); |
| 4482 | // lr() |
| 4483 | __ blr(lr); |
| 4484 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4485 | } |
| 4486 | }; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4487 | switch (invoke->GetCodePtrLocation()) { |
| 4488 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4489 | { |
| 4490 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4491 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4492 | kInstructionSize, |
| 4493 | CodeBufferCheckScope::kExactSize); |
| 4494 | __ bl(&frame_entry_label_); |
| 4495 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4496 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4497 | break; |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4498 | case HInvokeStaticOrDirect::CodePtrLocation::kCallCriticalNative: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4499 | size_t out_frame_size = |
| 4500 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorARM64, |
| 4501 | kAapcs64StackAlignment, |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 4502 | GetCriticalNativeDirectCallFrameSize>(invoke); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4503 | call_code_pointer_member(ArtMethod::EntryPointFromJniOffset(kArm64PointerSize)); |
| 4504 | // Zero-/sign-extend the result when needed due to native and managed ABI mismatch. |
| 4505 | switch (invoke->GetType()) { |
| 4506 | case DataType::Type::kBool: |
| 4507 | __ Ubfx(w0, w0, 0, 8); |
| 4508 | break; |
| 4509 | case DataType::Type::kInt8: |
| 4510 | __ Sbfx(w0, w0, 0, 8); |
| 4511 | break; |
| 4512 | case DataType::Type::kUint16: |
| 4513 | __ Ubfx(w0, w0, 0, 16); |
| 4514 | break; |
| 4515 | case DataType::Type::kInt16: |
| 4516 | __ Sbfx(w0, w0, 0, 16); |
| 4517 | break; |
| 4518 | case DataType::Type::kInt32: |
| 4519 | case DataType::Type::kInt64: |
| 4520 | case DataType::Type::kFloat32: |
| 4521 | case DataType::Type::kFloat64: |
| 4522 | case DataType::Type::kVoid: |
| 4523 | break; |
| 4524 | default: |
| 4525 | DCHECK(false) << invoke->GetType(); |
| 4526 | break; |
| 4527 | } |
| 4528 | if (out_frame_size != 0u) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 4529 | DecreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4530 | } |
| 4531 | break; |
| 4532 | } |
| 4533 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4534 | call_code_pointer_member(ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4535 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4536 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4537 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4538 | DCHECK(!IsLeafMethod()); |
| 4539 | } |
| 4540 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4541 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4542 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4543 | // Use the calling convention instead of the location of the receiver, as |
| 4544 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4545 | // slow path, the arguments have been moved to the right place, so here we are |
| 4546 | // guaranteed that the receiver is the first register of the calling convention. |
| 4547 | InvokeDexCallingConvention calling_convention; |
| 4548 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4549 | Register temp = XRegisterFrom(temp_in); |
| 4550 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4551 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4552 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4553 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4554 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4555 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4556 | |
| 4557 | { |
| 4558 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4559 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4560 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4561 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4562 | MaybeRecordImplicitNullCheck(invoke); |
| 4563 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4564 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4565 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4566 | // intermediate/temporary reference and because the current |
| 4567 | // concurrent copying collector keeps the from-space memory |
| 4568 | // intact/accessible until the end of the marking phase (the |
| 4569 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4570 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4571 | |
| 4572 | // If we're compiling baseline, update the inline cache. |
| 4573 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4574 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4575 | // temp = temp->GetMethodAt(method_offset); |
| 4576 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4577 | // lr = temp->GetEntryPoint(); |
| 4578 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4579 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4580 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4581 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4582 | // lr(); |
| 4583 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4584 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4585 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4586 | } |
| 4587 | |
Vladimir Marko | 9922f00 | 2020-06-08 15:05:15 +0100 | [diff] [blame] | 4588 | void CodeGeneratorARM64::MoveFromReturnRegister(Location trg, DataType::Type type) { |
| 4589 | if (!trg.IsValid()) { |
| 4590 | DCHECK(type == DataType::Type::kVoid); |
| 4591 | return; |
| 4592 | } |
| 4593 | |
| 4594 | DCHECK_NE(type, DataType::Type::kVoid); |
| 4595 | |
| 4596 | if (DataType::IsIntegralType(type) || type == DataType::Type::kReference) { |
| 4597 | Register trg_reg = RegisterFrom(trg, type); |
| 4598 | Register res_reg = RegisterFrom(ARM64ReturnLocation(type), type); |
| 4599 | __ Mov(trg_reg, res_reg, kDiscardForSameWReg); |
| 4600 | } else { |
| 4601 | VRegister trg_reg = FPRegisterFrom(trg, type); |
| 4602 | VRegister res_reg = FPRegisterFrom(ARM64ReturnLocation(type), type); |
| 4603 | __ Fmov(trg_reg, res_reg); |
| 4604 | } |
| 4605 | } |
| 4606 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4607 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4608 | HandleInvoke(invoke); |
| 4609 | } |
| 4610 | |
| 4611 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4612 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4613 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4614 | } |
| 4615 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4616 | void LocationsBuilderARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4617 | HandleInvoke(invoke); |
| 4618 | } |
| 4619 | |
| 4620 | void InstructionCodeGeneratorARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4621 | codegen_->GenerateInvokeCustomCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4622 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4623 | } |
| 4624 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4625 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageIntrinsicPatch( |
| 4626 | uint32_t intrinsic_data, |
| 4627 | vixl::aarch64::Label* adrp_label) { |
| 4628 | return NewPcRelativePatch( |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4629 | /* dex_file= */ nullptr, intrinsic_data, adrp_label, &boot_image_other_patches_); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4630 | } |
| 4631 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4632 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageRelRoPatch( |
| 4633 | uint32_t boot_image_offset, |
| 4634 | vixl::aarch64::Label* adrp_label) { |
| 4635 | return NewPcRelativePatch( |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4636 | /* dex_file= */ nullptr, boot_image_offset, adrp_label, &boot_image_other_patches_); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4637 | } |
| 4638 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4639 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageMethodPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4640 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4641 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4642 | return NewPcRelativePatch( |
| 4643 | 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] | 4644 | } |
| 4645 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4646 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4647 | MethodReference target_method, |
| 4648 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4649 | return NewPcRelativePatch( |
| 4650 | 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] | 4651 | } |
| 4652 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4653 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageTypePatch( |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4654 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4655 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4656 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4657 | 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] | 4658 | } |
| 4659 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4660 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4661 | const DexFile& dex_file, |
| 4662 | dex::TypeIndex type_index, |
| 4663 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4664 | return NewPcRelativePatch(&dex_file, type_index.index_, adrp_label, &type_bss_entry_patches_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4665 | } |
| 4666 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4667 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageStringPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4668 | const DexFile& dex_file, |
| 4669 | dex::StringIndex string_index, |
| 4670 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4671 | return NewPcRelativePatch( |
| 4672 | &dex_file, string_index.index_, adrp_label, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4673 | } |
| 4674 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4675 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4676 | const DexFile& dex_file, |
| 4677 | dex::StringIndex string_index, |
| 4678 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4679 | 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] | 4680 | } |
| 4681 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4682 | void CodeGeneratorARM64::EmitEntrypointThunkCall(ThreadOffset64 entrypoint_offset) { |
| 4683 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 4684 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4685 | call_entrypoint_patches_.emplace_back(/*dex_file*/ nullptr, entrypoint_offset.Uint32Value()); |
| 4686 | vixl::aarch64::Label* bl_label = &call_entrypoint_patches_.back().label; |
| 4687 | __ bind(bl_label); |
| 4688 | __ bl(static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 4689 | } |
| 4690 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 4691 | void CodeGeneratorARM64::EmitBakerReadBarrierCbnz(uint32_t custom_data) { |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 4692 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 4693 | if (GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 4694 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 4695 | vixl::aarch64::Label* slow_path_entry = &it->second.label; |
| 4696 | __ cbnz(mr, slow_path_entry); |
| 4697 | } else { |
| 4698 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4699 | vixl::aarch64::Label* cbnz_label = &baker_read_barrier_patches_.back().label; |
| 4700 | __ bind(cbnz_label); |
| 4701 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 4702 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4703 | } |
| 4704 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4705 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4706 | const DexFile* dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4707 | uint32_t offset_or_index, |
| 4708 | vixl::aarch64::Label* adrp_label, |
| 4709 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4710 | // Add a patch entry and return the label. |
| 4711 | patches->emplace_back(dex_file, offset_or_index); |
| 4712 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4713 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4714 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4715 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4716 | return label; |
| 4717 | } |
| 4718 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4719 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4720 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4721 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4722 | } |
| 4723 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4724 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4725 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4726 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4727 | return jit_string_patches_.GetOrCreate( |
| 4728 | StringReference(&dex_file, string_index), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4729 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4730 | } |
| 4731 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4732 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4733 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4734 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4735 | return jit_class_patches_.GetOrCreate( |
| 4736 | TypeReference(&dex_file, type_index), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4737 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4738 | } |
| 4739 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4740 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4741 | vixl::aarch64::Register reg) { |
| 4742 | DCHECK(reg.IsX()); |
| 4743 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4744 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4745 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4749 | vixl::aarch64::Register out, |
| 4750 | vixl::aarch64::Register base) { |
| 4751 | DCHECK(out.IsX()); |
| 4752 | DCHECK(base.IsX()); |
| 4753 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4754 | __ Bind(fixup_label); |
| 4755 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4756 | } |
| 4757 | |
| 4758 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4759 | vixl::aarch64::Register out, |
| 4760 | vixl::aarch64::Register base) { |
| 4761 | DCHECK(base.IsX()); |
| 4762 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4763 | __ Bind(fixup_label); |
| 4764 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4765 | } |
| 4766 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4767 | void CodeGeneratorARM64::LoadBootImageAddress(vixl::aarch64::Register reg, |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4768 | uint32_t boot_image_reference) { |
| 4769 | if (GetCompilerOptions().IsBootImage()) { |
| 4770 | // Add ADRP with its PC-relative type patch. |
| 4771 | vixl::aarch64::Label* adrp_label = NewBootImageIntrinsicPatch(boot_image_reference); |
| 4772 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4773 | // Add ADD with its PC-relative type patch. |
| 4774 | vixl::aarch64::Label* add_label = NewBootImageIntrinsicPatch(boot_image_reference, adrp_label); |
| 4775 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 4776 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4777 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4778 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4779 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4780 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4781 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_reference, adrp_label); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4782 | EmitLdrOffsetPlaceholder(ldr_label, reg.W(), reg.X()); |
| 4783 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 4784 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4785 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 4786 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4787 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4788 | __ Ldr(reg.W(), DeduplicateBootImageAddressLiteral(reinterpret_cast<uintptr_t>(address))); |
| 4789 | } |
| 4790 | } |
| 4791 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4792 | void CodeGeneratorARM64::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 4793 | uint32_t boot_image_offset) { |
| 4794 | DCHECK(invoke->IsStatic()); |
| 4795 | InvokeRuntimeCallingConvention calling_convention; |
| 4796 | Register argument = calling_convention.GetRegisterAt(0); |
| 4797 | if (GetCompilerOptions().IsBootImage()) { |
| 4798 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 4799 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 4800 | MethodReference target_method = invoke->GetTargetMethod(); |
| 4801 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 4802 | // Add ADRP with its PC-relative type patch. |
| 4803 | vixl::aarch64::Label* adrp_label = NewBootImageTypePatch(*target_method.dex_file, type_idx); |
| 4804 | EmitAdrpPlaceholder(adrp_label, argument.X()); |
| 4805 | // Add ADD with its PC-relative type patch. |
| 4806 | vixl::aarch64::Label* add_label = |
| 4807 | NewBootImageTypePatch(*target_method.dex_file, type_idx, adrp_label); |
| 4808 | EmitAddPlaceholder(add_label, argument.X(), argument.X()); |
| 4809 | } else { |
| 4810 | LoadBootImageAddress(argument, boot_image_offset); |
| 4811 | } |
| 4812 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 4813 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4814 | } |
| 4815 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4816 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4817 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4818 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4819 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4820 | for (const PcRelativePatchInfo& info : infos) { |
| 4821 | linker_patches->push_back(Factory(info.label.GetLocation(), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4822 | info.target_dex_file, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4823 | info.pc_insn_label->GetLocation(), |
| 4824 | info.offset_or_index)); |
| 4825 | } |
| 4826 | } |
| 4827 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4828 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 4829 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 4830 | const DexFile* target_dex_file, |
| 4831 | uint32_t pc_insn_offset, |
| 4832 | uint32_t boot_image_offset) { |
| 4833 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 4834 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4835 | } |
| 4836 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4837 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4838 | DCHECK(linker_patches->empty()); |
| 4839 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4840 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4841 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4842 | boot_image_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4843 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4844 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4845 | string_bss_entry_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4846 | boot_image_other_patches_.size() + |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4847 | call_entrypoint_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4848 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4849 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4850 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4851 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4852 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4853 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4854 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4855 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4856 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4857 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4858 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4859 | DCHECK(boot_image_type_patches_.empty()); |
| 4860 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4861 | } |
| 4862 | if (GetCompilerOptions().IsBootImage()) { |
| 4863 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 4864 | boot_image_other_patches_, linker_patches); |
| 4865 | } else { |
| 4866 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 4867 | boot_image_other_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4868 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4869 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4870 | method_bss_entry_patches_, linker_patches); |
| 4871 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4872 | type_bss_entry_patches_, linker_patches); |
| 4873 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4874 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4875 | for (const PatchInfo<vixl::aarch64::Label>& info : call_entrypoint_patches_) { |
| 4876 | DCHECK(info.target_dex_file == nullptr); |
| 4877 | linker_patches->push_back(linker::LinkerPatch::CallEntrypointPatch( |
| 4878 | info.label.GetLocation(), info.offset_or_index)); |
| 4879 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4880 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4881 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 4882 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4883 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4884 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4885 | } |
| 4886 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4887 | bool CodeGeneratorARM64::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4888 | return patch.GetType() == linker::LinkerPatch::Type::kCallEntrypoint || |
| 4889 | patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4890 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 4891 | } |
| 4892 | |
| 4893 | void CodeGeneratorARM64::EmitThunkCode(const linker::LinkerPatch& patch, |
| 4894 | /*out*/ ArenaVector<uint8_t>* code, |
| 4895 | /*out*/ std::string* debug_name) { |
| 4896 | Arm64Assembler assembler(GetGraph()->GetAllocator()); |
| 4897 | switch (patch.GetType()) { |
| 4898 | case linker::LinkerPatch::Type::kCallRelative: { |
| 4899 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 4900 | // to the generic JNI and interpreter trampolines. |
| 4901 | Offset offset(ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4902 | kArm64PointerSize).Int32Value()); |
| 4903 | assembler.JumpTo(ManagedRegister(arm64::X0), offset, ManagedRegister(arm64::IP0)); |
| 4904 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 4905 | *debug_name = "MethodCallThunk"; |
| 4906 | } |
| 4907 | break; |
| 4908 | } |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4909 | case linker::LinkerPatch::Type::kCallEntrypoint: { |
| 4910 | Offset offset(patch.EntrypointOffset()); |
| 4911 | assembler.JumpTo(ManagedRegister(arm64::TR), offset, ManagedRegister(arm64::IP0)); |
| 4912 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 4913 | *debug_name = "EntrypointCallThunk_" + std::to_string(offset.Uint32Value()); |
| 4914 | } |
| 4915 | break; |
| 4916 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4917 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| 4918 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 4919 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 4920 | break; |
| 4921 | } |
| 4922 | default: |
| 4923 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 4924 | UNREACHABLE(); |
| 4925 | } |
| 4926 | |
| 4927 | // Ensure we emit the literal pool if any. |
| 4928 | assembler.FinalizeCode(); |
| 4929 | code->resize(assembler.CodeSize()); |
| 4930 | MemoryRegion code_region(code->data(), code->size()); |
| 4931 | assembler.FinalizeInstructions(code_region); |
| 4932 | } |
| 4933 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4934 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4935 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4936 | value, |
| 4937 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4938 | } |
| 4939 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4940 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4941 | return uint64_literals_.GetOrCreate( |
| 4942 | value, |
| 4943 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4944 | } |
| 4945 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4946 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4947 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4948 | // art::PrepareForRegisterAllocation. |
| 4949 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4950 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4951 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4952 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4953 | return; |
| 4954 | } |
| 4955 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4956 | LocationSummary* locations = invoke->GetLocations(); |
| 4957 | codegen_->GenerateStaticOrDirectCall( |
| 4958 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4959 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4960 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4961 | } |
| 4962 | |
| 4963 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4964 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4965 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4966 | return; |
| 4967 | } |
| 4968 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4969 | { |
| 4970 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4971 | // are no pools emitted. |
| 4972 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4973 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 4974 | DCHECK(!codegen_->IsLeafMethod()); |
| 4975 | } |
| 4976 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4977 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4978 | } |
| 4979 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4980 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4981 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4982 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4983 | case HLoadClass::LoadKind::kInvalid: |
| 4984 | LOG(FATAL) << "UNREACHABLE"; |
| 4985 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4986 | case HLoadClass::LoadKind::kReferrersClass: |
| 4987 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4988 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4989 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4990 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 4991 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4992 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4993 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4994 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 4995 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4996 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4997 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4998 | break; |
| 4999 | } |
| 5000 | return desired_class_load_kind; |
| 5001 | } |
| 5002 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5003 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5004 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5005 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5006 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5007 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5008 | cls, |
| 5009 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5010 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5011 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5012 | return; |
| 5013 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5014 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5015 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5016 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5017 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5018 | ? LocationSummary::kCallOnSlowPath |
| 5019 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5020 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5021 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5022 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5023 | } |
| 5024 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5025 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5026 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5027 | } |
| 5028 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5029 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 5030 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5031 | // 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] | 5032 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5033 | } else { |
| 5034 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5035 | } |
| 5036 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5039 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5040 | // move. |
| 5041 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5042 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5043 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5044 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5045 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5046 | return; |
| 5047 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5048 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5049 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5050 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5051 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5052 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5053 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5054 | ? kWithoutReadBarrier |
| 5055 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5056 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5057 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5058 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5059 | DCHECK(!cls->CanCallRuntime()); |
| 5060 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5061 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5062 | Register current_method = InputRegisterAt(cls, 0); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5063 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5064 | out_loc, |
| 5065 | current_method, |
| 5066 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5067 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5068 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5069 | break; |
| 5070 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5071 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5072 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 5073 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5074 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5075 | // Add ADRP with its PC-relative type patch. |
| 5076 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5077 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5078 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5079 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5080 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5081 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5082 | codegen_->NewBootImageTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5083 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5084 | break; |
| 5085 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5086 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5087 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5088 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls); |
| 5089 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5090 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5091 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5092 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5093 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5094 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5095 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5096 | break; |
| 5097 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5098 | case HLoadClass::LoadKind::kBssEntry: { |
| 5099 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 5100 | const DexFile& dex_file = cls->GetDexFile(); |
| 5101 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5102 | vixl::aarch64::Register temp = XRegisterFrom(out_loc); |
| 5103 | vixl::aarch64::Label* adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 5104 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5105 | // Add LDR with its PC-relative Class .bss entry patch. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5106 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5107 | codegen_->NewBssEntryTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5108 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5109 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5110 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5111 | out_loc, |
| 5112 | temp, |
| 5113 | /* offset placeholder */ 0u, |
| 5114 | ldr_label, |
| 5115 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5116 | generate_null_check = true; |
| 5117 | break; |
| 5118 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5119 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 5120 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 5121 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 5122 | DCHECK_NE(address, 0u); |
| 5123 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5124 | break; |
| 5125 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5126 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5127 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5128 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5129 | cls->GetClass())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5130 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5131 | out_loc, |
| 5132 | out.X(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5133 | /* offset= */ 0, |
| 5134 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5135 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5136 | break; |
| 5137 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5138 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5139 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5140 | LOG(FATAL) << "UNREACHABLE"; |
| 5141 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5142 | } |
| 5143 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5144 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5145 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5146 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 5147 | SlowPathCodeARM64* slow_path = |
| 5148 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5149 | codegen_->AddSlowPath(slow_path); |
| 5150 | if (generate_null_check) { |
| 5151 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5152 | } |
| 5153 | if (cls->MustGenerateClinitCheck()) { |
| 5154 | GenerateClassInitializationCheck(slow_path, out); |
| 5155 | } else { |
| 5156 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5157 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5158 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5159 | } |
| 5160 | } |
| 5161 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 5162 | void LocationsBuilderARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5163 | InvokeRuntimeCallingConvention calling_convention; |
| 5164 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5165 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 5166 | } |
| 5167 | |
| 5168 | void InstructionCodeGeneratorARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5169 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 5170 | } |
| 5171 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 5172 | void LocationsBuilderARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5173 | InvokeRuntimeCallingConvention calling_convention; |
| 5174 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5175 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 5176 | } |
| 5177 | |
| 5178 | void InstructionCodeGeneratorARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5179 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 5180 | } |
| 5181 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5182 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5183 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5184 | } |
| 5185 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5186 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5187 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5188 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5189 | locations->SetOut(Location::RequiresRegister()); |
| 5190 | } |
| 5191 | |
| 5192 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5193 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5194 | } |
| 5195 | |
| 5196 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5197 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5198 | } |
| 5199 | |
| 5200 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5201 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5202 | } |
| 5203 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5204 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5205 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5206 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5207 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5208 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5209 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5210 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5211 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5212 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5213 | case HLoadString::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5214 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5215 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5216 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5217 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5218 | } |
| 5219 | return desired_string_load_kind; |
| 5220 | } |
| 5221 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5222 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5223 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5224 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5225 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5226 | InvokeRuntimeCallingConvention calling_convention; |
| 5227 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5228 | } else { |
| 5229 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5230 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5231 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5232 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 5233 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5234 | } else { |
| 5235 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5236 | } |
| 5237 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5238 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5239 | } |
| 5240 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5241 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5242 | // move. |
| 5243 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5244 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5245 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5246 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5247 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5248 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5249 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 5250 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5251 | // Add ADRP with its PC-relative String patch. |
| 5252 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5253 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5254 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5255 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5256 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5257 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5258 | codegen_->NewBootImageStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5259 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5260 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5261 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5262 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5263 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5264 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5265 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(load); |
| 5266 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5267 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5268 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5269 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5270 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5271 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 5272 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5273 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5274 | case HLoadString::LoadKind::kBssEntry: { |
| 5275 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5276 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5277 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5278 | Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5279 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5280 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5281 | // Add LDR with its PC-relative String .bss entry patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5282 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5283 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5284 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5285 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5286 | codegen_->GenerateGcRootFieldLoad(load, |
| 5287 | out_loc, |
| 5288 | temp, |
| 5289 | /* offset placeholder */ 0u, |
| 5290 | ldr_label, |
| 5291 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5292 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5293 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5294 | codegen_->AddSlowPath(slow_path); |
| 5295 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5296 | __ Bind(slow_path->GetExitLabel()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5297 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5298 | return; |
| 5299 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5300 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 5301 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 5302 | DCHECK_NE(address, 0u); |
| 5303 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5304 | return; |
| 5305 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5306 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5307 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5308 | load->GetStringIndex(), |
| 5309 | load->GetString())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5310 | codegen_->GenerateGcRootFieldLoad(load, |
| 5311 | out_loc, |
| 5312 | out.X(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5313 | /* offset= */ 0, |
| 5314 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5315 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5316 | return; |
| 5317 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5318 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5319 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5320 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5321 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5322 | // 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] | 5323 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5324 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5325 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5326 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5327 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5328 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5329 | } |
| 5330 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5331 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5332 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5333 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5334 | } |
| 5335 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5336 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5337 | // Will be generated at use site. |
| 5338 | } |
| 5339 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5340 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5341 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5342 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5343 | InvokeRuntimeCallingConvention calling_convention; |
| 5344 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5345 | } |
| 5346 | |
| 5347 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5348 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5349 | instruction, |
| 5350 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5351 | if (instruction->IsEnter()) { |
| 5352 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5353 | } else { |
| 5354 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5355 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5356 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5357 | } |
| 5358 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5359 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5360 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5361 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5362 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5363 | case DataType::Type::kInt32: |
| 5364 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5365 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5366 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5367 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5368 | break; |
| 5369 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5370 | case DataType::Type::kFloat32: |
| 5371 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5372 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5373 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5374 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5375 | break; |
| 5376 | |
| 5377 | default: |
| 5378 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5379 | } |
| 5380 | } |
| 5381 | |
| 5382 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5383 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5384 | case DataType::Type::kInt32: |
| 5385 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5386 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5387 | break; |
| 5388 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5389 | case DataType::Type::kFloat32: |
| 5390 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5391 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5392 | break; |
| 5393 | |
| 5394 | default: |
| 5395 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5396 | } |
| 5397 | } |
| 5398 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5399 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5400 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5401 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5402 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5403 | case DataType::Type::kInt32: |
| 5404 | case DataType::Type::kInt64: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5405 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5406 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5407 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5408 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5409 | case DataType::Type::kFloat32: |
| 5410 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5411 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5412 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5413 | break; |
| 5414 | |
| 5415 | default: |
| 5416 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5417 | } |
| 5418 | } |
| 5419 | |
| 5420 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5421 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5422 | case DataType::Type::kInt32: |
| 5423 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5424 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5425 | break; |
| 5426 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5427 | case DataType::Type::kFloat32: |
| 5428 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5429 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5430 | break; |
| 5431 | |
| 5432 | default: |
| 5433 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5434 | } |
| 5435 | } |
| 5436 | |
| 5437 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5438 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5439 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5440 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5441 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5442 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5443 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5444 | } |
| 5445 | |
| 5446 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5447 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5448 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5449 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5450 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5451 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5452 | } |
| 5453 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5454 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5455 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5456 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5457 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5458 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5459 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5460 | } |
| 5461 | |
| 5462 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5463 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5464 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5465 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5466 | } |
| 5467 | |
| 5468 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5469 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5470 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5471 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5472 | } |
| 5473 | |
| 5474 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5475 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5476 | case DataType::Type::kInt32: |
| 5477 | case DataType::Type::kInt64: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5478 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5479 | break; |
| 5480 | |
| 5481 | default: |
| 5482 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5483 | } |
| 5484 | } |
| 5485 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5486 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5487 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5488 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5489 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5490 | } |
| 5491 | |
| 5492 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5493 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5494 | } |
| 5495 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5496 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5497 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5498 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5499 | } |
| 5500 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5501 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5502 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5503 | return; |
| 5504 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5505 | { |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 5506 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5507 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5508 | Location obj = instruction->GetLocations()->InAt(0); |
| 5509 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5510 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5511 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5512 | } |
| 5513 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5514 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5515 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5516 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5517 | |
| 5518 | LocationSummary* locations = instruction->GetLocations(); |
| 5519 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5520 | |
| 5521 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5522 | } |
| 5523 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5524 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5525 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5526 | } |
| 5527 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5528 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5529 | HandleBinaryOp(instruction); |
| 5530 | } |
| 5531 | |
| 5532 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5533 | HandleBinaryOp(instruction); |
| 5534 | } |
| 5535 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5536 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5537 | LOG(FATAL) << "Unreachable"; |
| 5538 | } |
| 5539 | |
| 5540 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5541 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5542 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5543 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5544 | // The back edge will generate the suspend check. |
| 5545 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5546 | } |
| 5547 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5548 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5549 | } |
| 5550 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5551 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5552 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5553 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5554 | if (location.IsStackSlot()) { |
| 5555 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5556 | } else if (location.IsDoubleStackSlot()) { |
| 5557 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5558 | } |
| 5559 | locations->SetOut(location); |
| 5560 | } |
| 5561 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5562 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5563 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5564 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5565 | } |
| 5566 | |
| 5567 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5568 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5569 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5570 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5571 | } |
| 5572 | |
| 5573 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5574 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5575 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5576 | } |
| 5577 | |
| 5578 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5579 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5580 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5581 | locations->SetInAt(i, Location::Any()); |
| 5582 | } |
| 5583 | locations->SetOut(Location::Any()); |
| 5584 | } |
| 5585 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5586 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5587 | LOG(FATAL) << "Unreachable"; |
| 5588 | } |
| 5589 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5590 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5591 | DataType::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5592 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5593 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5594 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5595 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5596 | |
| 5597 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5598 | case DataType::Type::kInt32: |
| 5599 | case DataType::Type::kInt64: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5600 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5601 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5602 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5603 | break; |
| 5604 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5605 | case DataType::Type::kFloat32: |
| 5606 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5607 | InvokeRuntimeCallingConvention calling_convention; |
| 5608 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5609 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5610 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5611 | |
| 5612 | break; |
| 5613 | } |
| 5614 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5615 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5616 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5617 | } |
| 5618 | } |
| 5619 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5620 | void InstructionCodeGeneratorARM64::GenerateIntRemForPower2Denom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5621 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5622 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 5623 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 5624 | |
| 5625 | Register out = OutputRegister(instruction); |
| 5626 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5627 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 5628 | if (HasNonNegativeResultOrMinInt(instruction->GetLeft())) { |
| 5629 | // No need to adjust the result for non-negative dividends or the INT32_MIN/INT64_MIN dividends. |
| 5630 | // NOTE: The generated code for HRem correctly works for the INT32_MIN/INT64_MIN dividends. |
| 5631 | // INT*_MIN % imm must be 0 for any imm of power 2. 'and' works only with bits |
| 5632 | // 0..30 (Int32 case)/0..62 (Int64 case) of a dividend. For INT32_MIN/INT64_MIN they are zeros. |
| 5633 | // So 'and' always produces zero. |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5634 | __ And(out, dividend, abs_imm - 1); |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 5635 | } else { |
| 5636 | if (abs_imm == 2) { |
| 5637 | __ Cmp(dividend, 0); |
| 5638 | __ And(out, dividend, 1); |
| 5639 | __ Csneg(out, out, out, ge); |
| 5640 | } else { |
| 5641 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5642 | Register temp = temps.AcquireSameSizeAs(out); |
| 5643 | |
| 5644 | __ Negs(temp, dividend); |
| 5645 | __ And(out, dividend, abs_imm - 1); |
| 5646 | __ And(temp, temp, abs_imm - 1); |
| 5647 | __ Csneg(out, out, temp, mi); |
| 5648 | } |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5649 | } |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5650 | } |
| 5651 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5652 | void InstructionCodeGeneratorARM64::GenerateIntRemForConstDenom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5653 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5654 | |
| 5655 | if (imm == 0) { |
| 5656 | // Do not generate anything. |
| 5657 | // DivZeroCheck would prevent any code to be executed. |
| 5658 | return; |
| 5659 | } |
| 5660 | |
Evgeny Astigeevich | f58dc65 | 2018-06-25 17:54:07 +0100 | [diff] [blame] | 5661 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 5662 | // Cases imm == -1 or imm == 1 are handled in constant folding by |
| 5663 | // InstructionWithAbsorbingInputSimplifier. |
| 5664 | // If the cases have survided till code generation they are handled in |
| 5665 | // GenerateIntRemForPower2Denom becauses -1 and 1 are the power of 2 (2^0). |
| 5666 | // The correct code is generated for them, just more instructions. |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5667 | GenerateIntRemForPower2Denom(instruction); |
| 5668 | } else { |
| 5669 | DCHECK(imm < -2 || imm > 2) << imm; |
| 5670 | GenerateDivRemWithAnyConstant(instruction); |
| 5671 | } |
| 5672 | } |
| 5673 | |
| 5674 | void InstructionCodeGeneratorARM64::GenerateIntRem(HRem* instruction) { |
| 5675 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 5676 | << instruction->GetResultType(); |
| 5677 | |
| 5678 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 5679 | GenerateIntRemForConstDenom(instruction); |
| 5680 | } else { |
| 5681 | Register out = OutputRegister(instruction); |
| 5682 | Register dividend = InputRegisterAt(instruction, 0); |
| 5683 | Register divisor = InputRegisterAt(instruction, 1); |
| 5684 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5685 | Register temp = temps.AcquireSameSizeAs(out); |
| 5686 | __ Sdiv(temp, dividend, divisor); |
| 5687 | __ Msub(out, temp, divisor, dividend); |
| 5688 | } |
| 5689 | } |
| 5690 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5691 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5692 | DataType::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5693 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5694 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5695 | case DataType::Type::kInt32: |
| 5696 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5697 | GenerateIntRem(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5698 | break; |
| 5699 | } |
| 5700 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5701 | case DataType::Type::kFloat32: |
| 5702 | case DataType::Type::kFloat64: { |
| 5703 | QuickEntrypointEnum entrypoint = |
| 5704 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5705 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5706 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5707 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5708 | } else { |
| 5709 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5710 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5711 | break; |
| 5712 | } |
| 5713 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5714 | default: |
| 5715 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5716 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5717 | } |
| 5718 | } |
| 5719 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5720 | void LocationsBuilderARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5721 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5722 | } |
| 5723 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5724 | void InstructionCodeGeneratorARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5725 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5726 | } |
| 5727 | |
| 5728 | void LocationsBuilderARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5729 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5730 | } |
| 5731 | |
| 5732 | void InstructionCodeGeneratorARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5733 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5734 | } |
| 5735 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5736 | void LocationsBuilderARM64::VisitAbs(HAbs* abs) { |
| 5737 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 5738 | switch (abs->GetResultType()) { |
| 5739 | case DataType::Type::kInt32: |
| 5740 | case DataType::Type::kInt64: |
| 5741 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5742 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5743 | break; |
| 5744 | case DataType::Type::kFloat32: |
| 5745 | case DataType::Type::kFloat64: |
| 5746 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5747 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5748 | break; |
| 5749 | default: |
| 5750 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5751 | } |
| 5752 | } |
| 5753 | |
| 5754 | void InstructionCodeGeneratorARM64::VisitAbs(HAbs* abs) { |
| 5755 | switch (abs->GetResultType()) { |
| 5756 | case DataType::Type::kInt32: |
| 5757 | case DataType::Type::kInt64: { |
| 5758 | Register in_reg = InputRegisterAt(abs, 0); |
| 5759 | Register out_reg = OutputRegister(abs); |
| 5760 | __ Cmp(in_reg, Operand(0)); |
| 5761 | __ Cneg(out_reg, in_reg, lt); |
| 5762 | break; |
| 5763 | } |
| 5764 | case DataType::Type::kFloat32: |
| 5765 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 5766 | VRegister in_reg = InputFPRegisterAt(abs, 0); |
| 5767 | VRegister out_reg = OutputFPRegister(abs); |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5768 | __ Fabs(out_reg, in_reg); |
| 5769 | break; |
| 5770 | } |
| 5771 | default: |
| 5772 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5773 | } |
| 5774 | } |
| 5775 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5776 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5777 | constructor_fence->SetLocations(nullptr); |
| 5778 | } |
| 5779 | |
| 5780 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5781 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5782 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5783 | } |
| 5784 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5785 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5786 | memory_barrier->SetLocations(nullptr); |
| 5787 | } |
| 5788 | |
| 5789 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5790 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5791 | } |
| 5792 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5793 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5794 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5795 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5796 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5797 | } |
| 5798 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 5799 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* ret) { |
| 5800 | if (GetGraph()->IsCompilingOsr()) { |
| 5801 | // To simplify callers of an OSR method, we put the return value in both |
| 5802 | // floating point and core register. |
| 5803 | switch (ret->InputAt(0)->GetType()) { |
| 5804 | case DataType::Type::kFloat32: |
| 5805 | __ Fmov(w0, s0); |
| 5806 | break; |
| 5807 | case DataType::Type::kFloat64: |
| 5808 | __ Fmov(x0, d0); |
| 5809 | break; |
| 5810 | default: |
| 5811 | break; |
| 5812 | } |
| 5813 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5814 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5815 | } |
| 5816 | |
| 5817 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5818 | instruction->SetLocations(nullptr); |
| 5819 | } |
| 5820 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5821 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5822 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5823 | } |
| 5824 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5825 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5826 | HandleBinaryOp(ror); |
| 5827 | } |
| 5828 | |
| 5829 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5830 | HandleBinaryOp(ror); |
| 5831 | } |
| 5832 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5833 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5834 | HandleShift(shl); |
| 5835 | } |
| 5836 | |
| 5837 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5838 | HandleShift(shl); |
| 5839 | } |
| 5840 | |
| 5841 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5842 | HandleShift(shr); |
| 5843 | } |
| 5844 | |
| 5845 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5846 | HandleShift(shr); |
| 5847 | } |
| 5848 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5849 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5850 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5851 | } |
| 5852 | |
| 5853 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5854 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5855 | } |
| 5856 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5857 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5858 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5859 | } |
| 5860 | |
| 5861 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5862 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5863 | } |
| 5864 | |
| 5865 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5866 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5867 | } |
| 5868 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5869 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5870 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5871 | } |
| 5872 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 5873 | void LocationsBuilderARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5874 | codegen_->CreateStringBuilderAppendLocations(instruction, LocationFrom(x0)); |
| 5875 | } |
| 5876 | |
| 5877 | void InstructionCodeGeneratorARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5878 | __ Mov(w0, instruction->GetFormat()->GetValue()); |
| 5879 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 5880 | } |
| 5881 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5882 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5883 | HUnresolvedInstanceFieldGet* instruction) { |
| 5884 | FieldAccessCallingConventionARM64 calling_convention; |
| 5885 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5886 | instruction, instruction->GetFieldType(), calling_convention); |
| 5887 | } |
| 5888 | |
| 5889 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5890 | HUnresolvedInstanceFieldGet* instruction) { |
| 5891 | FieldAccessCallingConventionARM64 calling_convention; |
| 5892 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5893 | instruction->GetFieldType(), |
| 5894 | instruction->GetFieldIndex(), |
| 5895 | instruction->GetDexPc(), |
| 5896 | calling_convention); |
| 5897 | } |
| 5898 | |
| 5899 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5900 | HUnresolvedInstanceFieldSet* instruction) { |
| 5901 | FieldAccessCallingConventionARM64 calling_convention; |
| 5902 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5903 | instruction, instruction->GetFieldType(), calling_convention); |
| 5904 | } |
| 5905 | |
| 5906 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5907 | HUnresolvedInstanceFieldSet* instruction) { |
| 5908 | FieldAccessCallingConventionARM64 calling_convention; |
| 5909 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5910 | instruction->GetFieldType(), |
| 5911 | instruction->GetFieldIndex(), |
| 5912 | instruction->GetDexPc(), |
| 5913 | calling_convention); |
| 5914 | } |
| 5915 | |
| 5916 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5917 | HUnresolvedStaticFieldGet* instruction) { |
| 5918 | FieldAccessCallingConventionARM64 calling_convention; |
| 5919 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5920 | instruction, instruction->GetFieldType(), calling_convention); |
| 5921 | } |
| 5922 | |
| 5923 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5924 | HUnresolvedStaticFieldGet* instruction) { |
| 5925 | FieldAccessCallingConventionARM64 calling_convention; |
| 5926 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5927 | instruction->GetFieldType(), |
| 5928 | instruction->GetFieldIndex(), |
| 5929 | instruction->GetDexPc(), |
| 5930 | calling_convention); |
| 5931 | } |
| 5932 | |
| 5933 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5934 | HUnresolvedStaticFieldSet* instruction) { |
| 5935 | FieldAccessCallingConventionARM64 calling_convention; |
| 5936 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5937 | instruction, instruction->GetFieldType(), calling_convention); |
| 5938 | } |
| 5939 | |
| 5940 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5941 | HUnresolvedStaticFieldSet* instruction) { |
| 5942 | FieldAccessCallingConventionARM64 calling_convention; |
| 5943 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5944 | instruction->GetFieldType(), |
| 5945 | instruction->GetFieldIndex(), |
| 5946 | instruction->GetDexPc(), |
| 5947 | calling_convention); |
| 5948 | } |
| 5949 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5950 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5951 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5952 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5953 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5954 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5955 | // registers in full width (since the runtime only saves/restores lower part). |
| 5956 | locations->SetCustomSlowPathCallerSaves( |
| 5957 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5958 | } |
| 5959 | |
| 5960 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5961 | HBasicBlock* block = instruction->GetBlock(); |
| 5962 | if (block->GetLoopInformation() != nullptr) { |
| 5963 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5964 | // The back edge will generate the suspend check. |
| 5965 | return; |
| 5966 | } |
| 5967 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5968 | // The goto will generate the suspend check. |
| 5969 | return; |
| 5970 | } |
| 5971 | GenerateSuspendCheck(instruction, nullptr); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5972 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5973 | } |
| 5974 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5975 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5976 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5977 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5978 | InvokeRuntimeCallingConvention calling_convention; |
| 5979 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5980 | } |
| 5981 | |
| 5982 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5983 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5984 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5985 | } |
| 5986 | |
| 5987 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5988 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5989 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5990 | DataType::Type input_type = conversion->GetInputType(); |
| 5991 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5992 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5993 | << input_type << " -> " << result_type; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5994 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 5995 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5996 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5997 | } |
| 5998 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5999 | if (DataType::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6000 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6001 | } else { |
| 6002 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6003 | } |
| 6004 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6005 | if (DataType::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6006 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6007 | } else { |
| 6008 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6009 | } |
| 6010 | } |
| 6011 | |
| 6012 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6013 | DataType::Type result_type = conversion->GetResultType(); |
| 6014 | DataType::Type input_type = conversion->GetInputType(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6015 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6016 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6017 | << input_type << " -> " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6018 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6019 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 6020 | int result_size = DataType::Size(result_type); |
| 6021 | int input_size = DataType::Size(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6022 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6023 | Register output = OutputRegister(conversion); |
| 6024 | Register source = InputRegisterAt(conversion, 0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6025 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 6026 | // 'int' values are used directly as W registers, discarding the top |
| 6027 | // bits, so we don't need to sign-extend and can just perform a move. |
| 6028 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 6029 | // top 32 bits of the target register. We theoretically could leave those |
| 6030 | // bits unchanged, but we would have to make sure that no code uses a |
| 6031 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 6032 | // zero. |
| 6033 | __ Mov(output.W(), source.W()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6034 | } else if (DataType::IsUnsignedType(result_type) || |
| 6035 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 6036 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6037 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6038 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6039 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6040 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6041 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6042 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 6043 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6044 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6045 | } else if (DataType::IsFloatingPointType(result_type) && |
| 6046 | DataType::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6047 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 6048 | } else { |
| 6049 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6050 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6051 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6052 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6053 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6054 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 6055 | HandleShift(ushr); |
| 6056 | } |
| 6057 | |
| 6058 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 6059 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6060 | } |
| 6061 | |
| 6062 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 6063 | HandleBinaryOp(instruction); |
| 6064 | } |
| 6065 | |
| 6066 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 6067 | HandleBinaryOp(instruction); |
| 6068 | } |
| 6069 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6070 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6071 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6072 | LOG(FATAL) << "Unreachable"; |
| 6073 | } |
| 6074 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6075 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6076 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6077 | LOG(FATAL) << "Unreachable"; |
| 6078 | } |
| 6079 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6080 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6081 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6082 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6083 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6084 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6085 | } |
| 6086 | |
| 6087 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6088 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6089 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6090 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 6091 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6092 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6093 | // 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] | 6094 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6095 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 6096 | // make sure we don't emit it if the target may run out of range. |
| 6097 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 6098 | // ranges and emit the tables only as required. |
| 6099 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6100 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6101 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6102 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 6103 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 6104 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6105 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6106 | Register temp = temps.AcquireW(); |
| 6107 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 6108 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6109 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6110 | // Jump to successors[0] if value == lower_bound. |
| 6111 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 6112 | int32_t last_index = 0; |
| 6113 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6114 | __ Subs(temp, temp, Operand(2)); |
| 6115 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6116 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6117 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6118 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6119 | } |
| 6120 | if (num_entries - last_index == 2) { |
| 6121 | // The last missing case_value. |
| 6122 | __ Cmp(temp, Operand(1)); |
| 6123 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6124 | } |
| 6125 | |
| 6126 | // And the default for any other value. |
| 6127 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6128 | __ B(codegen_->GetLabelOf(default_block)); |
| 6129 | } |
| 6130 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 6131 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6132 | |
| 6133 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6134 | |
| 6135 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 6136 | // registers, we are free to block one. |
| 6137 | Register temp_w = temps.AcquireW(); |
| 6138 | Register index; |
| 6139 | // Remove the bias. |
| 6140 | if (lower_bound != 0) { |
| 6141 | index = temp_w; |
| 6142 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 6143 | } else { |
| 6144 | index = value_reg; |
| 6145 | } |
| 6146 | |
| 6147 | // Jump to default block if index is out of the range. |
| 6148 | __ Cmp(index, Operand(num_entries)); |
| 6149 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 6150 | |
| 6151 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 6152 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 6153 | // register pressure. |
| 6154 | Register table_base = temps.AcquireX(); |
| 6155 | // Load jump offset from the table. |
| 6156 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 6157 | Register jump_offset = temp_w; |
| 6158 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 6159 | |
| 6160 | // Jump to target block by branching to table_base(pc related) + offset. |
| 6161 | Register target_address = table_base; |
| 6162 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 6163 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6164 | } |
| 6165 | } |
| 6166 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6167 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 6168 | HInstruction* instruction, |
| 6169 | Location out, |
| 6170 | uint32_t offset, |
| 6171 | Location maybe_temp, |
| 6172 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6173 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6174 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6175 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6176 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6177 | if (kUseBakerReadBarrier) { |
| 6178 | // Load with fast path based Baker's read barrier. |
| 6179 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6180 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6181 | out, |
| 6182 | out_reg, |
| 6183 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6184 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6185 | /* needs_null_check= */ false, |
| 6186 | /* use_load_acquire= */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6187 | } else { |
| 6188 | // Load with slow path based read barrier. |
| 6189 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6190 | // in the following move operation, as we will need it for the |
| 6191 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6192 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6193 | __ Mov(temp_reg, out_reg); |
| 6194 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6195 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6196 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6197 | } |
| 6198 | } else { |
| 6199 | // Plain load with no read barrier. |
| 6200 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6201 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6202 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6203 | } |
| 6204 | } |
| 6205 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6206 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 6207 | HInstruction* instruction, |
| 6208 | Location out, |
| 6209 | Location obj, |
| 6210 | uint32_t offset, |
| 6211 | Location maybe_temp, |
| 6212 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6213 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6214 | Register out_reg = RegisterFrom(out, type); |
| 6215 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6216 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6217 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6218 | if (kUseBakerReadBarrier) { |
| 6219 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6220 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6221 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6222 | out, |
| 6223 | obj_reg, |
| 6224 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6225 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6226 | /* needs_null_check= */ false, |
| 6227 | /* use_load_acquire= */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6228 | } else { |
| 6229 | // Load with slow path based read barrier. |
| 6230 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6231 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6232 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6233 | } |
| 6234 | } else { |
| 6235 | // Plain load with no read barrier. |
| 6236 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6237 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6238 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6239 | } |
| 6240 | } |
| 6241 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6242 | void CodeGeneratorARM64::GenerateGcRootFieldLoad( |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6243 | HInstruction* instruction, |
| 6244 | Location root, |
| 6245 | Register obj, |
| 6246 | uint32_t offset, |
| 6247 | vixl::aarch64::Label* fixup_label, |
| 6248 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6249 | DCHECK(fixup_label == nullptr || offset == 0u); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6250 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6251 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6252 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6253 | if (kUseBakerReadBarrier) { |
| 6254 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6255 | // Baker's read barrier are used. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6256 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6257 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6258 | // the Marking Register) to decide whether we need to enter |
| 6259 | // the slow path to mark the GC root. |
| 6260 | // |
| 6261 | // We use shared thunks for the slow path; shared within the method |
| 6262 | // for JIT, across methods for AOT. That thunk checks the reference |
| 6263 | // and jumps to the entrypoint if needed. |
| 6264 | // |
| 6265 | // lr = &return_address; |
| 6266 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6267 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6268 | // goto gc_root_thunk<root_reg>(lr) |
| 6269 | // } |
| 6270 | // return_address: |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6271 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6272 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6273 | DCHECK(temps.IsAvailable(ip0)); |
| 6274 | DCHECK(temps.IsAvailable(ip1)); |
| 6275 | temps.Exclude(ip0, ip1); |
| 6276 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6277 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6278 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6279 | vixl::aarch64::Label return_address; |
| 6280 | __ adr(lr, &return_address); |
| 6281 | if (fixup_label != nullptr) { |
| 6282 | __ bind(fixup_label); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6283 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6284 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6285 | "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] | 6286 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6287 | EmitBakerReadBarrierCbnz(custom_data); |
| 6288 | __ bind(&return_address); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6289 | } else { |
| 6290 | // GC root loaded through a slow path for read barriers other |
| 6291 | // than Baker's. |
| 6292 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6293 | if (fixup_label == nullptr) { |
| 6294 | __ Add(root_reg.X(), obj.X(), offset); |
| 6295 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6296 | EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6297 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6298 | // /* mirror::Object* */ root = root->Read() |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6299 | GenerateReadBarrierForRootSlow(instruction, root, root); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6300 | } |
| 6301 | } else { |
| 6302 | // Plain GC root load with no read barrier. |
| 6303 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6304 | if (fixup_label == nullptr) { |
| 6305 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6306 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6307 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6308 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6309 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6310 | // do not have to unpoison `root_reg` here. |
| 6311 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6312 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6313 | } |
| 6314 | |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6315 | void CodeGeneratorARM64::GenerateUnsafeCasOldValueMovWithBakerReadBarrier( |
| 6316 | vixl::aarch64::Register marked, |
| 6317 | vixl::aarch64::Register old_value) { |
| 6318 | DCHECK(kEmitCompilerReadBarrier); |
| 6319 | DCHECK(kUseBakerReadBarrier); |
| 6320 | |
| 6321 | // Similar to the Baker RB path in GenerateGcRootFieldLoad(), with a MOV instead of LDR. |
| 6322 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(marked.GetCode()); |
| 6323 | |
| 6324 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6325 | vixl::aarch64::Label return_address; |
| 6326 | __ adr(lr, &return_address); |
| 6327 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6328 | "GC root LDR must be 2 instructions (8B) before the return address label."); |
| 6329 | __ mov(marked, old_value); |
| 6330 | EmitBakerReadBarrierCbnz(custom_data); |
| 6331 | __ bind(&return_address); |
| 6332 | } |
| 6333 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6334 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6335 | Location ref, |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6336 | vixl::aarch64::Register obj, |
| 6337 | const vixl::aarch64::MemOperand& src, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6338 | bool needs_null_check, |
| 6339 | bool use_load_acquire) { |
| 6340 | DCHECK(kEmitCompilerReadBarrier); |
| 6341 | DCHECK(kUseBakerReadBarrier); |
| 6342 | |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6343 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6344 | // Marking Register) to decide whether we need to enter the slow |
| 6345 | // path to mark the reference. Then, in the slow path, check the |
| 6346 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6347 | // decide whether to mark `ref` or not. |
| 6348 | // |
| 6349 | // We use shared thunks for the slow path; shared within the method |
| 6350 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6351 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6352 | // it creates a fake dependency and returns to the LDR instruction. |
| 6353 | // |
| 6354 | // lr = &gray_return_address; |
| 6355 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6356 | // goto field_thunk<holder_reg, base_reg, use_load_acquire>(lr) |
| 6357 | // } |
| 6358 | // not_gray_return_address: |
| 6359 | // // Original reference load. If the offset is too large to fit |
| 6360 | // // into LDR, we use an adjusted base register here. |
| 6361 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 6362 | // gray_return_address: |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6363 | |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6364 | DCHECK(src.GetAddrMode() == vixl::aarch64::Offset); |
| 6365 | DCHECK_ALIGNED(src.GetOffset(), sizeof(mirror::HeapReference<mirror::Object>)); |
| 6366 | |
| 6367 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6368 | DCHECK(temps.IsAvailable(ip0)); |
| 6369 | DCHECK(temps.IsAvailable(ip1)); |
| 6370 | temps.Exclude(ip0, ip1); |
| 6371 | uint32_t custom_data = use_load_acquire |
| 6372 | ? EncodeBakerReadBarrierAcquireData(src.GetBaseRegister().GetCode(), obj.GetCode()) |
| 6373 | : EncodeBakerReadBarrierFieldData(src.GetBaseRegister().GetCode(), obj.GetCode()); |
| 6374 | |
| 6375 | { |
| 6376 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6377 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6378 | vixl::aarch64::Label return_address; |
| 6379 | __ adr(lr, &return_address); |
| 6380 | EmitBakerReadBarrierCbnz(custom_data); |
| 6381 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6382 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6383 | " 2 instructions (8B) for heap poisoning."); |
| 6384 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 6385 | if (use_load_acquire) { |
| 6386 | DCHECK_EQ(src.GetOffset(), 0); |
| 6387 | __ ldar(ref_reg, src); |
| 6388 | } else { |
| 6389 | __ ldr(ref_reg, src); |
| 6390 | } |
| 6391 | if (needs_null_check) { |
| 6392 | MaybeRecordImplicitNullCheck(instruction); |
| 6393 | } |
| 6394 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6395 | // macro instructions disallowed in ExactAssemblyScope. |
| 6396 | if (kPoisonHeapReferences) { |
| 6397 | __ neg(ref_reg, Operand(ref_reg)); |
| 6398 | } |
| 6399 | __ bind(&return_address); |
| 6400 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6401 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6402 | } |
| 6403 | |
| 6404 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6405 | Location ref, |
| 6406 | Register obj, |
| 6407 | uint32_t offset, |
| 6408 | Location maybe_temp, |
| 6409 | bool needs_null_check, |
| 6410 | bool use_load_acquire) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6411 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6412 | Register base = obj; |
| 6413 | if (use_load_acquire) { |
| 6414 | DCHECK(maybe_temp.IsRegister()); |
| 6415 | base = WRegisterFrom(maybe_temp); |
| 6416 | __ Add(base, obj, offset); |
| 6417 | offset = 0u; |
| 6418 | } else if (offset >= kReferenceLoadMinFarOffset) { |
| 6419 | DCHECK(maybe_temp.IsRegister()); |
| 6420 | base = WRegisterFrom(maybe_temp); |
| 6421 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6422 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6423 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6424 | } |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6425 | MemOperand src(base.X(), offset); |
| 6426 | GenerateFieldLoadWithBakerReadBarrier( |
| 6427 | instruction, ref, obj, src, needs_null_check, use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6428 | } |
| 6429 | |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6430 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HArrayGet* instruction, |
| 6431 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6432 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6433 | uint32_t data_offset, |
| 6434 | Location index, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6435 | bool needs_null_check) { |
| 6436 | DCHECK(kEmitCompilerReadBarrier); |
| 6437 | DCHECK(kUseBakerReadBarrier); |
| 6438 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6439 | static_assert( |
| 6440 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6441 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6442 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6443 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6444 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6445 | // Marking Register) to decide whether we need to enter the slow |
| 6446 | // path to mark the reference. Then, in the slow path, check the |
| 6447 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6448 | // decide whether to mark `ref` or not. |
| 6449 | // |
| 6450 | // We use shared thunks for the slow path; shared within the method |
| 6451 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6452 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6453 | // it creates a fake dependency and returns to the LDR instruction. |
| 6454 | // |
| 6455 | // lr = &gray_return_address; |
| 6456 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6457 | // goto array_thunk<base_reg>(lr) |
| 6458 | // } |
| 6459 | // not_gray_return_address: |
| 6460 | // // Original reference load. If the offset is too large to fit |
| 6461 | // // into LDR, we use an adjusted base register here. |
| 6462 | // HeapReference<mirror::Object> reference = data[index]; |
| 6463 | // gray_return_address: |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6464 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6465 | DCHECK(index.IsValid()); |
| 6466 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 6467 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6468 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6469 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6470 | DCHECK(temps.IsAvailable(ip0)); |
| 6471 | DCHECK(temps.IsAvailable(ip1)); |
| 6472 | temps.Exclude(ip0, ip1); |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6473 | |
| 6474 | Register temp; |
| 6475 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 6476 | // We do not need to compute the intermediate address from the array: the |
| 6477 | // input instruction has done it already. See the comment in |
| 6478 | // `TryExtractArrayAccessAddress()`. |
| 6479 | if (kIsDebugBuild) { |
| 6480 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 6481 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 6482 | } |
| 6483 | temp = obj; |
| 6484 | } else { |
| 6485 | temp = WRegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 6486 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
| 6487 | } |
| 6488 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6489 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(temp.GetCode()); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6490 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6491 | { |
| 6492 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6493 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6494 | vixl::aarch64::Label return_address; |
| 6495 | __ adr(lr, &return_address); |
| 6496 | EmitBakerReadBarrierCbnz(custom_data); |
| 6497 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6498 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6499 | " 2 instructions (8B) for heap poisoning."); |
| 6500 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6501 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6502 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6503 | // macro instructions disallowed in ExactAssemblyScope. |
| 6504 | if (kPoisonHeapReferences) { |
| 6505 | __ neg(ref_reg, Operand(ref_reg)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6506 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6507 | __ bind(&return_address); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6508 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6509 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6510 | } |
| 6511 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6512 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6513 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6514 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6515 | // The following condition is a run-time one; it is executed after the |
| 6516 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6517 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6518 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6519 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6520 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6521 | } |
| 6522 | } |
| 6523 | } |
| 6524 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6525 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6526 | Location out, |
| 6527 | Location ref, |
| 6528 | Location obj, |
| 6529 | uint32_t offset, |
| 6530 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6531 | DCHECK(kEmitCompilerReadBarrier); |
| 6532 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6533 | // Insert a slow path based read barrier *after* the reference load. |
| 6534 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6535 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6536 | // reference will be carried out by the runtime within the slow |
| 6537 | // path. |
| 6538 | // |
| 6539 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6540 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6541 | // not used by the artReadBarrierSlow entry point. |
| 6542 | // |
| 6543 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6544 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6545 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6546 | AddSlowPath(slow_path); |
| 6547 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6548 | __ B(slow_path->GetEntryLabel()); |
| 6549 | __ Bind(slow_path->GetExitLabel()); |
| 6550 | } |
| 6551 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6552 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6553 | Location out, |
| 6554 | Location ref, |
| 6555 | Location obj, |
| 6556 | uint32_t offset, |
| 6557 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6558 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6559 | // Baker's read barriers shall be handled by the fast path |
| 6560 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6561 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6562 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6563 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6564 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6565 | } else if (kPoisonHeapReferences) { |
| 6566 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6567 | } |
| 6568 | } |
| 6569 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6570 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6571 | Location out, |
| 6572 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6573 | DCHECK(kEmitCompilerReadBarrier); |
| 6574 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6575 | // Insert a slow path based read barrier *after* the GC root load. |
| 6576 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6577 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6578 | // not need to do anything special for this here. |
| 6579 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6580 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6581 | AddSlowPath(slow_path); |
| 6582 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6583 | __ B(slow_path->GetEntryLabel()); |
| 6584 | __ Bind(slow_path->GetExitLabel()); |
| 6585 | } |
| 6586 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6587 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6588 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6589 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6590 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6591 | locations->SetOut(Location::RequiresRegister()); |
| 6592 | } |
| 6593 | |
| 6594 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6595 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6596 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6597 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6598 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6599 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6600 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6601 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6602 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6603 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6604 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6605 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6606 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6607 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6608 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6609 | } |
| 6610 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6611 | static void PatchJitRootUse(uint8_t* code, |
| 6612 | const uint8_t* roots_data, |
| 6613 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6614 | uint64_t index_in_table) { |
| 6615 | uint32_t literal_offset = literal->GetOffset(); |
| 6616 | uintptr_t address = |
| 6617 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6618 | uint8_t* data = code + literal_offset; |
| 6619 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6620 | } |
| 6621 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6622 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6623 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6624 | const StringReference& string_reference = entry.first; |
| 6625 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6626 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6627 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6628 | } |
| 6629 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6630 | const TypeReference& type_reference = entry.first; |
| 6631 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6632 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6633 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6634 | } |
| 6635 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6636 | |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 6637 | MemOperand InstructionCodeGeneratorARM64::VecNeonAddress( |
| 6638 | HVecMemoryOperation* instruction, |
| 6639 | UseScratchRegisterScope* temps_scope, |
| 6640 | size_t size, |
| 6641 | bool is_string_char_at, |
| 6642 | /*out*/ Register* scratch) { |
| 6643 | LocationSummary* locations = instruction->GetLocations(); |
| 6644 | Register base = InputRegisterAt(instruction, 0); |
| 6645 | |
| 6646 | if (instruction->InputAt(1)->IsIntermediateAddressIndex()) { |
| 6647 | DCHECK(!is_string_char_at); |
| 6648 | return MemOperand(base.X(), InputRegisterAt(instruction, 1).X()); |
| 6649 | } |
| 6650 | |
| 6651 | Location index = locations->InAt(1); |
| 6652 | uint32_t offset = is_string_char_at |
| 6653 | ? mirror::String::ValueOffset().Uint32Value() |
| 6654 | : mirror::Array::DataOffset(size).Uint32Value(); |
| 6655 | size_t shift = ComponentSizeShiftWidth(size); |
| 6656 | |
| 6657 | // HIntermediateAddress optimization is only applied for scalar ArrayGet and ArraySet. |
| 6658 | DCHECK(!instruction->InputAt(0)->IsIntermediateAddress()); |
| 6659 | |
| 6660 | if (index.IsConstant()) { |
| 6661 | offset += Int64FromLocation(index) << shift; |
| 6662 | return HeapOperand(base, offset); |
| 6663 | } else { |
| 6664 | *scratch = temps_scope->AcquireSameSizeAs(base); |
| 6665 | __ Add(*scratch, base, Operand(WRegisterFrom(index), LSL, shift)); |
| 6666 | return HeapOperand(*scratch, offset); |
| 6667 | } |
| 6668 | } |
| 6669 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6670 | #undef __ |
| 6671 | #undef QUICK_ENTRY_POINT |
| 6672 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6673 | #define __ assembler.GetVIXLAssembler()-> |
| 6674 | |
| 6675 | static void EmitGrayCheckAndFastPath(arm64::Arm64Assembler& assembler, |
| 6676 | vixl::aarch64::Register base_reg, |
| 6677 | vixl::aarch64::MemOperand& lock_word, |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6678 | vixl::aarch64::Label* slow_path, |
| 6679 | vixl::aarch64::Label* throw_npe = nullptr) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6680 | // Load the lock word containing the rb_state. |
| 6681 | __ Ldr(ip0.W(), lock_word); |
| 6682 | // 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] | 6683 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6684 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 6685 | __ Tbnz(ip0.W(), LockWord::kReadBarrierStateShift, slow_path); |
| 6686 | static_assert( |
| 6687 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET, |
| 6688 | "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] | 6689 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 6690 | if (throw_npe != nullptr) { |
| 6691 | __ Bind(throw_npe); |
| 6692 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6693 | // Adjust the return address back to the LDR (1 instruction; 2 for heap poisoning). |
| 6694 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6695 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6696 | " 2 instructions (8B) for heap poisoning."); |
| 6697 | __ Add(lr, lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6698 | // Introduce a dependency on the lock_word including rb_state, |
| 6699 | // to prevent load-load reordering, and without using |
| 6700 | // a memory barrier (which would be more expensive). |
| 6701 | __ Add(base_reg, base_reg, Operand(ip0, LSR, 32)); |
| 6702 | __ Br(lr); // And return back to the function. |
| 6703 | // Note: The fake dependency is unnecessary for the slow path. |
| 6704 | } |
| 6705 | |
| 6706 | // Load the read barrier introspection entrypoint in register `entrypoint`. |
| 6707 | static void LoadReadBarrierMarkIntrospectionEntrypoint(arm64::Arm64Assembler& assembler, |
| 6708 | vixl::aarch64::Register entrypoint) { |
| 6709 | // entrypoint = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6710 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6711 | const int32_t entry_point_offset = |
| 6712 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6713 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| 6714 | } |
| 6715 | |
| 6716 | void CodeGeneratorARM64::CompileBakerReadBarrierThunk(Arm64Assembler& assembler, |
| 6717 | uint32_t encoded_data, |
| 6718 | /*out*/ std::string* debug_name) { |
| 6719 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 6720 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6721 | case BakerReadBarrierKind::kField: |
| 6722 | case BakerReadBarrierKind::kAcquire: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6723 | auto base_reg = |
| 6724 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6725 | CheckValidReg(base_reg.GetCode()); |
| 6726 | auto holder_reg = |
| 6727 | Register::GetXRegFromCode(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6728 | CheckValidReg(holder_reg.GetCode()); |
| 6729 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6730 | temps.Exclude(ip0, ip1); |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 6731 | // In the case of a field load (with relaxed semantic), if `base_reg` differs from |
| 6732 | // `holder_reg`, the offset was too large and we must have emitted (during the construction |
| 6733 | // of the HIR graph, see `art::HInstructionBuilder::BuildInstanceFieldAccess`) and preserved |
| 6734 | // (see `art::PrepareForRegisterAllocation::VisitNullCheck`) an explicit null check before |
| 6735 | // the load. Otherwise, for implicit null checks, we need to null-check the holder as we do |
| 6736 | // not necessarily do that check before going to the thunk. |
| 6737 | // |
| 6738 | // In the case of a field load with load-acquire semantics (where `base_reg` always differs |
| 6739 | // from `holder_reg`), we also need an explicit null check when implicit null checks are |
| 6740 | // allowed, as we do not emit one before going to the thunk. |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6741 | vixl::aarch64::Label throw_npe_label; |
| 6742 | vixl::aarch64::Label* throw_npe = nullptr; |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 6743 | if (GetCompilerOptions().GetImplicitNullChecks() && |
| 6744 | (holder_reg.Is(base_reg) || (kind == BakerReadBarrierKind::kAcquire))) { |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6745 | throw_npe = &throw_npe_label; |
| 6746 | __ Cbz(holder_reg.W(), throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6747 | } |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6748 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 6749 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 6750 | // to load the reference and call the entrypoint that performs further checks on the |
| 6751 | // reference and marks it if needed. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6752 | vixl::aarch64::Label slow_path; |
| 6753 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6754 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6755 | __ Bind(&slow_path); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6756 | if (kind == BakerReadBarrierKind::kField) { |
| 6757 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6758 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (immediate) unsigned offset. |
| 6759 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6760 | __ Ubfx(ip0.W(), ip0.W(), 10, 12); // Extract the offset. |
| 6761 | __ Ldr(ip0.W(), MemOperand(base_reg, ip0, LSL, 2)); // Load the reference. |
| 6762 | } else { |
| 6763 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 6764 | DCHECK(!base_reg.Is(holder_reg)); |
| 6765 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6766 | __ Ldar(ip0.W(), MemOperand(base_reg)); |
| 6767 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6768 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 6769 | __ Br(ip1); // Jump to the entrypoint. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6770 | break; |
| 6771 | } |
| 6772 | case BakerReadBarrierKind::kArray: { |
| 6773 | auto base_reg = |
| 6774 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6775 | CheckValidReg(base_reg.GetCode()); |
| 6776 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6777 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6778 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6779 | temps.Exclude(ip0, ip1); |
| 6780 | vixl::aarch64::Label slow_path; |
| 6781 | int32_t data_offset = |
| 6782 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 6783 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 6784 | DCHECK_LT(lock_word.GetOffset(), 0); |
| 6785 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path); |
| 6786 | __ Bind(&slow_path); |
| 6787 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| 6788 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (register) unsigned offset. |
| 6789 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6790 | __ Ubfx(ip0, ip0, 16, 6); // Extract the index register, plus 32 (bit 21 is set). |
| 6791 | __ Bfi(ip1, ip0, 3, 6); // Insert ip0 to the entrypoint address to create |
| 6792 | // a switch case target based on the index register. |
| 6793 | __ Mov(ip0, base_reg); // Move the base register to ip0. |
| 6794 | __ Br(ip1); // Jump to the entrypoint's array switch case. |
| 6795 | break; |
| 6796 | } |
| 6797 | case BakerReadBarrierKind::kGcRoot: { |
| 6798 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 6799 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 6800 | // otherwise return the reference (or the extracted forwarding address). |
| 6801 | // There is no gray bit check for GC roots. |
| 6802 | auto root_reg = |
| 6803 | Register::GetWRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6804 | CheckValidReg(root_reg.GetCode()); |
| 6805 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6806 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6807 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6808 | temps.Exclude(ip0, ip1); |
| 6809 | vixl::aarch64::Label return_label, not_marked, forwarding_address; |
| 6810 | __ Cbz(root_reg, &return_label); |
| 6811 | MemOperand lock_word(root_reg.X(), mirror::Object::MonitorOffset().Int32Value()); |
| 6812 | __ Ldr(ip0.W(), lock_word); |
| 6813 | __ Tbz(ip0.W(), LockWord::kMarkBitStateShift, ¬_marked); |
| 6814 | __ Bind(&return_label); |
| 6815 | __ Br(lr); |
| 6816 | __ Bind(¬_marked); |
| 6817 | __ Tst(ip0.W(), Operand(ip0.W(), LSL, 1)); |
| 6818 | __ B(&forwarding_address, mi); |
| 6819 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6820 | // Adjust the art_quick_read_barrier_mark_introspection address in IP1 to |
| 6821 | // art_quick_read_barrier_mark_introspection_gc_roots. |
| 6822 | __ Add(ip1, ip1, Operand(BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET)); |
| 6823 | __ Mov(ip0.W(), root_reg); |
| 6824 | __ Br(ip1); |
| 6825 | __ Bind(&forwarding_address); |
| 6826 | __ Lsl(root_reg, ip0.W(), LockWord::kForwardingAddressShift); |
| 6827 | __ Br(lr); |
| 6828 | break; |
| 6829 | } |
| 6830 | default: |
| 6831 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 6832 | UNREACHABLE(); |
| 6833 | } |
| 6834 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6835 | // For JIT, the slow path is considered part of the compiled method, |
Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 6836 | // so JIT should pass null as `debug_name`. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 6837 | DCHECK(!GetCompilerOptions().IsJitCompiler() || debug_name == nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6838 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6839 | std::ostringstream oss; |
| 6840 | oss << "BakerReadBarrierThunk"; |
| 6841 | switch (kind) { |
| 6842 | case BakerReadBarrierKind::kField: |
| 6843 | oss << "Field_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 6844 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 6845 | break; |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6846 | case BakerReadBarrierKind::kAcquire: |
| 6847 | oss << "Acquire_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 6848 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 6849 | break; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6850 | case BakerReadBarrierKind::kArray: |
| 6851 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6852 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6853 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6854 | break; |
| 6855 | case BakerReadBarrierKind::kGcRoot: |
| 6856 | oss << "GcRoot_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6857 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6858 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6859 | break; |
| 6860 | } |
| 6861 | *debug_name = oss.str(); |
| 6862 | } |
| 6863 | } |
| 6864 | |
| 6865 | #undef __ |
| 6866 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6867 | } // namespace arm64 |
| 6868 | } // namespace art |