Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm64.h" |
| 18 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 19 | #include "arch/arm64/asm_support_arm64.h" |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 20 | #include "arch/arm64/instruction_set_features_arm64.h" |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 21 | #include "arch/arm64/jni_frame_arm64.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 22 | #include "art_method-inl.h" |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 23 | #include "base/bit_utils.h" |
| 24 | #include "base/bit_utils_iterator.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 25 | #include "class_table.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 26 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 27 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 28 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 29 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 30 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 31 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 32 | #include "heap_poisoning.h" |
Nicolas Geoffray | 4313ccb | 2020-08-26 17:01:15 +0100 | [diff] [blame] | 33 | #include "interpreter/mterp/nterp.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 34 | #include "intrinsics.h" |
| 35 | #include "intrinsics_arm64.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 36 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 37 | #include "lock_word.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 38 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 39 | #include "mirror/class-inl.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 40 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 41 | #include "thread.h" |
| 42 | #include "utils/arm64/assembler_arm64.h" |
| 43 | #include "utils/assembler.h" |
| 44 | #include "utils/stack_checks.h" |
| 45 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 46 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 47 | using vixl::ExactAssemblyScope; |
| 48 | using vixl::CodeBufferCheckScope; |
| 49 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 50 | |
| 51 | #ifdef __ |
| 52 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 53 | #endif |
| 54 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 55 | namespace art { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 56 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 57 | template<class MirrorType> |
| 58 | class GcRoot; |
| 59 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 60 | namespace arm64 { |
| 61 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 62 | using helpers::ARM64EncodableConstantOrRegister; |
| 63 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 64 | using helpers::CPURegisterFrom; |
| 65 | using helpers::DRegisterFrom; |
| 66 | using helpers::FPRegisterFrom; |
| 67 | using helpers::HeapOperand; |
| 68 | using helpers::HeapOperandFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 69 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 70 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 71 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 72 | using helpers::InputRegisterAt; |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 73 | using helpers::Int64FromLocation; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 74 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 75 | using helpers::LocationFrom; |
| 76 | using helpers::OperandFromMemOperand; |
| 77 | using helpers::OutputCPURegister; |
| 78 | using helpers::OutputFPRegister; |
| 79 | using helpers::OutputRegister; |
| 80 | using helpers::RegisterFrom; |
| 81 | using helpers::StackOperandFrom; |
| 82 | using helpers::VIXLRegCodeFromART; |
| 83 | using helpers::WRegisterFrom; |
| 84 | using helpers::XRegisterFrom; |
| 85 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 86 | // 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] | 87 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 88 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 89 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 90 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 91 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 92 | // 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] | 93 | // 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] | 94 | // the offset explicitly. |
| 95 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 96 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 97 | inline Condition ARM64Condition(IfCondition cond) { |
| 98 | switch (cond) { |
| 99 | case kCondEQ: return eq; |
| 100 | case kCondNE: return ne; |
| 101 | case kCondLT: return lt; |
| 102 | case kCondLE: return le; |
| 103 | case kCondGT: return gt; |
| 104 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 105 | case kCondB: return lo; |
| 106 | case kCondBE: return ls; |
| 107 | case kCondA: return hi; |
| 108 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 109 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 110 | LOG(FATAL) << "Unreachable"; |
| 111 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 112 | } |
| 113 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 114 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 115 | // The ARM64 condition codes can express all the necessary branches, see the |
| 116 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 117 | // There is no dex instruction or HIR that would need the missing conditions |
| 118 | // "equal or unordered" or "not equal". |
| 119 | switch (cond) { |
| 120 | case kCondEQ: return eq; |
| 121 | case kCondNE: return ne /* unordered */; |
| 122 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 123 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 124 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 125 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 126 | default: |
| 127 | LOG(FATAL) << "UNREACHABLE"; |
| 128 | UNREACHABLE(); |
| 129 | } |
| 130 | } |
| 131 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 132 | Location ARM64ReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 133 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 134 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 135 | // but we use the exact registers for clarity. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 136 | if (return_type == DataType::Type::kFloat32) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 137 | return LocationFrom(s0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 138 | } else if (return_type == DataType::Type::kFloat64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 139 | return LocationFrom(d0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 140 | } else if (return_type == DataType::Type::kInt64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 141 | return LocationFrom(x0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 142 | } else if (return_type == DataType::Type::kVoid) { |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 143 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 144 | } else { |
| 145 | return LocationFrom(w0); |
| 146 | } |
| 147 | } |
| 148 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 149 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 150 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 151 | } |
| 152 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 153 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 154 | InvokeRuntimeCallingConvention calling_convention; |
| 155 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 156 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 157 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 158 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 159 | DataType::Type::kReference).GetCode()); |
| 160 | return caller_saves; |
| 161 | } |
| 162 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 163 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 164 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 165 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 166 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 167 | // Calculate memory accessing operand for save/restore live registers. |
| 168 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 169 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 170 | int64_t spill_offset, |
| 171 | bool is_save) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 172 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
| 173 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 174 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 175 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 176 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 177 | codegen->GetNumberOfFloatingPointRegisters())); |
| 178 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 179 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 180 | const unsigned v_reg_size_in_bits = codegen->GetSlowPathFPWidth() * 8; |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 181 | DCHECK_LE(codegen->GetSIMDRegisterWidth(), kQRegSizeInBytes); |
Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 182 | 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] | 183 | |
| 184 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 185 | UseScratchRegisterScope temps(masm); |
| 186 | |
| 187 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 188 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 189 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 190 | int64_t reg_size = kXRegSizeInBytes; |
| 191 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 192 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 193 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 194 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 195 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 196 | // to compute the base address(float point registers spill base address). |
| 197 | Register new_base = temps.AcquireSameSizeAs(base); |
| 198 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 199 | base = new_base; |
| 200 | spill_offset = -core_spill_size; |
| 201 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 202 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 203 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 204 | } |
| 205 | |
| 206 | if (is_save) { |
| 207 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 208 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 209 | } else { |
| 210 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 211 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 216 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 217 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 218 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 219 | // If the register holds an object, update the stack mask. |
| 220 | if (locations->RegisterContainsObject(i)) { |
| 221 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 222 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 223 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 224 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 225 | saved_core_stack_offsets_[i] = stack_offset; |
| 226 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 227 | } |
| 228 | |
Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 229 | const size_t fp_reg_size = codegen->GetSlowPathFPWidth(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 230 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 231 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 232 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 233 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 234 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 235 | stack_offset += fp_reg_size; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 236 | } |
| 237 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 238 | SaveRestoreLiveRegistersHelper(codegen, |
| 239 | locations, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 240 | codegen->GetFirstRegisterSlotInSlowPath(), /* is_save= */ true); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 244 | SaveRestoreLiveRegistersHelper(codegen, |
| 245 | locations, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 246 | codegen->GetFirstRegisterSlotInSlowPath(), /* is_save= */ false); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 247 | } |
| 248 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 249 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 250 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 251 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 252 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 253 | void EmitNativeCode(CodeGenerator* codegen) override { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 254 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 255 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 256 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 257 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 258 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 259 | // Live registers will be restored in the catch block if caught. |
| 260 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 261 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 262 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 263 | // move resolver. |
| 264 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 265 | codegen->EmitParallelMoves(locations->InAt(0), |
| 266 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 267 | DataType::Type::kInt32, |
| 268 | locations->InAt(1), |
| 269 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 270 | DataType::Type::kInt32); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 271 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 272 | ? kQuickThrowStringBounds |
| 273 | : kQuickThrowArrayBounds; |
| 274 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 275 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 276 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 277 | } |
| 278 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 279 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 280 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 281 | const char* GetDescription() const override { return "BoundsCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 282 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 283 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 284 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 285 | }; |
| 286 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 287 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 288 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 289 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 290 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 291 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 292 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 293 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 294 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 295 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 298 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 299 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 300 | const char* GetDescription() const override { return "DivZeroCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 301 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 302 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 303 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 304 | }; |
| 305 | |
| 306 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 307 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 308 | LoadClassSlowPathARM64(HLoadClass* cls, HInstruction* at) |
| 309 | : SlowPathCodeARM64(at), cls_(cls) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 310 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 311 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 314 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 315 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 316 | Location out = locations->Out(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 317 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 318 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 319 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 320 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 321 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 322 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 323 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 324 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 325 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 326 | if (must_resolve_type) { |
| 327 | DCHECK(IsSameDexFile(cls_->GetDexFile(), arm64_codegen->GetGraph()->GetDexFile())); |
| 328 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 329 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 330 | arm64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 331 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 332 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 333 | } else { |
| 334 | DCHECK(must_do_clinit); |
| 335 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 336 | arm64_codegen->MoveLocation(LocationFrom(calling_convention.GetRegisterAt(0)), |
| 337 | source, |
| 338 | cls_->GetType()); |
| 339 | } |
| 340 | if (must_do_clinit) { |
| 341 | arm64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 342 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 343 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 344 | |
| 345 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 346 | if (out.IsValid()) { |
| 347 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 348 | DataType::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 349 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 350 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 351 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 352 | __ B(GetExitLabel()); |
| 353 | } |
| 354 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 355 | const char* GetDescription() const override { return "LoadClassSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 356 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 357 | private: |
| 358 | // The class this slow path will load. |
| 359 | HLoadClass* const cls_; |
| 360 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 361 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 362 | }; |
| 363 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 364 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 365 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 366 | explicit LoadStringSlowPathARM64(HLoadString* instruction) |
| 367 | : SlowPathCodeARM64(instruction) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 368 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 369 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 370 | LocationSummary* locations = instruction_->GetLocations(); |
| 371 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 372 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 373 | |
| 374 | __ Bind(GetEntryLabel()); |
| 375 | SaveLiveRegisters(codegen, locations); |
| 376 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 377 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 378 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 379 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 380 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 381 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 382 | DataType::Type type = instruction_->GetType(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 383 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 384 | |
| 385 | RestoreLiveRegisters(codegen, locations); |
| 386 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 387 | __ B(GetExitLabel()); |
| 388 | } |
| 389 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 390 | const char* GetDescription() const override { return "LoadStringSlowPathARM64"; } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 391 | |
| 392 | private: |
| 393 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 394 | }; |
| 395 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 396 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 397 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 398 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 399 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 400 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 401 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 402 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 403 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 404 | // Live registers will be restored in the catch block if caught. |
| 405 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 406 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 407 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 408 | instruction_, |
| 409 | instruction_->GetDexPc(), |
| 410 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 411 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 412 | } |
| 413 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 414 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 415 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 416 | const char* GetDescription() const override { return "NullCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 417 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 418 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 419 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 420 | }; |
| 421 | |
| 422 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 423 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 424 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 425 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 426 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 427 | void EmitNativeCode(CodeGenerator* codegen) override { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 428 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 429 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 430 | __ Bind(GetEntryLabel()); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 431 | SaveLiveRegisters(codegen, locations); // Only saves live vector regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 432 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 433 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 434 | RestoreLiveRegisters(codegen, locations); // Only restores live vector regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 435 | if (successor_ == nullptr) { |
| 436 | __ B(GetReturnLabel()); |
| 437 | } else { |
| 438 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 439 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 440 | } |
| 441 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 442 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 443 | DCHECK(successor_ == nullptr); |
| 444 | return &return_label_; |
| 445 | } |
| 446 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 447 | HBasicBlock* GetSuccessor() const { |
| 448 | return successor_; |
| 449 | } |
| 450 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 451 | const char* GetDescription() const override { return "SuspendCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 452 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 453 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 454 | // If not null, the block to branch to after the suspend check. |
| 455 | HBasicBlock* const successor_; |
| 456 | |
| 457 | // 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] | 458 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 459 | |
| 460 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 461 | }; |
| 462 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 463 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 464 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 465 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 466 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 467 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 468 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 469 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 470 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 471 | DCHECK(instruction_->IsCheckCast() |
| 472 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 473 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 474 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 475 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 476 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 477 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 478 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 479 | SaveLiveRegisters(codegen, locations); |
| 480 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 481 | |
| 482 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 483 | // move resolver. |
| 484 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 485 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 486 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 487 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 488 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 489 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 490 | DataType::Type::kReference); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 491 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 492 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 493 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 494 | DataType::Type ret_type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 495 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 496 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 497 | } else { |
| 498 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 499 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 500 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 503 | if (!is_fatal_) { |
| 504 | RestoreLiveRegisters(codegen, locations); |
| 505 | __ B(GetExitLabel()); |
| 506 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 509 | const char* GetDescription() const override { return "TypeCheckSlowPathARM64"; } |
| 510 | bool IsFatal() const override { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 511 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 512 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 513 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 514 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 515 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 516 | }; |
| 517 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 518 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 519 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 520 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 521 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 522 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 523 | void EmitNativeCode(CodeGenerator* codegen) override { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 524 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 525 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 526 | LocationSummary* locations = instruction_->GetLocations(); |
| 527 | SaveLiveRegisters(codegen, locations); |
| 528 | InvokeRuntimeCallingConvention calling_convention; |
| 529 | __ Mov(calling_convention.GetRegisterAt(0), |
| 530 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 531 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 532 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 533 | } |
| 534 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 535 | const char* GetDescription() const override { return "DeoptimizationSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 536 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 537 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 538 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 539 | }; |
| 540 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 541 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 542 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 543 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 544 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 545 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 546 | LocationSummary* locations = instruction_->GetLocations(); |
| 547 | __ Bind(GetEntryLabel()); |
| 548 | SaveLiveRegisters(codegen, locations); |
| 549 | |
| 550 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 551 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 552 | parallel_move.AddMove( |
| 553 | locations->InAt(0), |
| 554 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 555 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 556 | nullptr); |
| 557 | parallel_move.AddMove( |
| 558 | locations->InAt(1), |
| 559 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 560 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 561 | nullptr); |
| 562 | parallel_move.AddMove( |
| 563 | locations->InAt(2), |
| 564 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 565 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 566 | nullptr); |
| 567 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 568 | |
| 569 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 570 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 571 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 572 | RestoreLiveRegisters(codegen, locations); |
| 573 | __ B(GetExitLabel()); |
| 574 | } |
| 575 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 576 | const char* GetDescription() const override { return "ArraySetSlowPathARM64"; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 577 | |
| 578 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 579 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 580 | }; |
| 581 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 582 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 583 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 584 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 585 | |
| 586 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 587 | // 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] | 588 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 589 | num_entries * sizeof(int32_t), |
| 590 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 591 | |
| 592 | __ Bind(&table_start_); |
| 593 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 594 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 595 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 596 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 597 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 598 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 599 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 600 | Literal<int32_t> literal(jump_offset); |
| 601 | __ place(&literal); |
| 602 | } |
| 603 | } |
| 604 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 605 | // Slow path generating a read barrier for a heap reference. |
| 606 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 607 | public: |
| 608 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 609 | Location out, |
| 610 | Location ref, |
| 611 | Location obj, |
| 612 | uint32_t offset, |
| 613 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 614 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 615 | out_(out), |
| 616 | ref_(ref), |
| 617 | obj_(obj), |
| 618 | offset_(offset), |
| 619 | index_(index) { |
| 620 | DCHECK(kEmitCompilerReadBarrier); |
| 621 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 622 | // has been overwritten by (or after) the heap object reference load |
| 623 | // to be instrumented, e.g.: |
| 624 | // |
| 625 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 626 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 627 | // |
| 628 | // In that case, we have lost the information about the original |
| 629 | // object, and the emitted read barrier cannot work properly. |
| 630 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 631 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 632 | } |
| 633 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 634 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 635 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 636 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 637 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 638 | DCHECK(locations->CanCall()); |
| 639 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 640 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 641 | instruction_->IsStaticFieldGet() || |
| 642 | instruction_->IsArrayGet() || |
| 643 | instruction_->IsInstanceOf() || |
| 644 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 645 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 646 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 647 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 648 | // The read barrier instrumentation of object ArrayGet |
| 649 | // instructions does not support the HIntermediateAddress |
| 650 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 651 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 652 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 653 | |
| 654 | __ Bind(GetEntryLabel()); |
| 655 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 656 | SaveLiveRegisters(codegen, locations); |
| 657 | |
| 658 | // We may have to change the index's value, but as `index_` is a |
| 659 | // constant member (like other "inputs" of this slow path), |
| 660 | // introduce a copy of it, `index`. |
| 661 | Location index = index_; |
| 662 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 663 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 664 | if (instruction_->IsArrayGet()) { |
| 665 | // Compute the actual memory offset and store it in `index`. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 666 | Register index_reg = RegisterFrom(index_, DataType::Type::kInt32); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 667 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 668 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 669 | // We are about to change the value of `index_reg` (see the |
| 670 | // calls to vixl::MacroAssembler::Lsl and |
| 671 | // vixl::MacroAssembler::Mov below), but it has |
| 672 | // not been saved by the previous call to |
| 673 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 674 | // callee-save register -- |
| 675 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 676 | // callee-save registers, as it has been designed with the |
| 677 | // assumption that callee-save registers are supposed to be |
| 678 | // handled by the called function. So, as a callee-save |
| 679 | // register, `index_reg` _would_ eventually be saved onto |
| 680 | // the stack, but it would be too late: we would have |
| 681 | // changed its value earlier. Therefore, we manually save |
| 682 | // it here into another freely available register, |
| 683 | // `free_reg`, chosen of course among the caller-save |
| 684 | // registers (as a callee-save `free_reg` register would |
| 685 | // exhibit the same problem). |
| 686 | // |
| 687 | // Note we could have requested a temporary register from |
| 688 | // the register allocator instead; but we prefer not to, as |
| 689 | // this is a slow path, and we know we can find a |
| 690 | // caller-save register that is available. |
| 691 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 692 | __ Mov(free_reg.W(), index_reg); |
| 693 | index_reg = free_reg; |
| 694 | index = LocationFrom(index_reg); |
| 695 | } else { |
| 696 | // The initial register stored in `index_` has already been |
| 697 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 698 | // (as it is not a callee-save register), so we can freely |
| 699 | // use it. |
| 700 | } |
| 701 | // Shifting the index value contained in `index_reg` by the scale |
| 702 | // factor (2) cannot overflow in practice, as the runtime is |
| 703 | // unable to allocate object arrays with a size larger than |
| 704 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 705 | __ Lsl(index_reg, index_reg, DataType::SizeShift(type)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 706 | static_assert( |
| 707 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 708 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 709 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 710 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 711 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 712 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 713 | // (as in the case of ArrayGet), as it is actually an offset |
| 714 | // to an object field within an object. |
| 715 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 716 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 717 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 718 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 719 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 720 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 721 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 722 | } |
| 723 | } |
| 724 | |
| 725 | // We're moving two or three locations to locations that could |
| 726 | // overlap, so we need a parallel move resolver. |
| 727 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 728 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 729 | parallel_move.AddMove(ref_, |
| 730 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 731 | type, |
| 732 | nullptr); |
| 733 | parallel_move.AddMove(obj_, |
| 734 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 735 | type, |
| 736 | nullptr); |
| 737 | if (index.IsValid()) { |
| 738 | parallel_move.AddMove(index, |
| 739 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 740 | DataType::Type::kInt32, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 741 | nullptr); |
| 742 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 743 | } else { |
| 744 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 745 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 746 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 747 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 748 | instruction_, |
| 749 | instruction_->GetDexPc(), |
| 750 | this); |
| 751 | CheckEntrypointTypes< |
| 752 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 753 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 754 | |
| 755 | RestoreLiveRegisters(codegen, locations); |
| 756 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 757 | __ B(GetExitLabel()); |
| 758 | } |
| 759 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 760 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 761 | |
| 762 | private: |
| 763 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 764 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 765 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 766 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 767 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 768 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 769 | } |
| 770 | } |
| 771 | // We shall never fail to find a free caller-save register, as |
| 772 | // there are more than two core caller-save registers on ARM64 |
| 773 | // (meaning it is possible to find one which is different from |
| 774 | // `ref` and `obj`). |
| 775 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 776 | LOG(FATAL) << "Could not find a free register"; |
| 777 | UNREACHABLE(); |
| 778 | } |
| 779 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 780 | const Location out_; |
| 781 | const Location ref_; |
| 782 | const Location obj_; |
| 783 | const uint32_t offset_; |
| 784 | // An additional location containing an index to an array. |
| 785 | // Only used for HArrayGet and the UnsafeGetObject & |
| 786 | // UnsafeGetObjectVolatile intrinsics. |
| 787 | const Location index_; |
| 788 | |
| 789 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 790 | }; |
| 791 | |
| 792 | // Slow path generating a read barrier for a GC root. |
| 793 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 794 | public: |
| 795 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 796 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 797 | DCHECK(kEmitCompilerReadBarrier); |
| 798 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 799 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 800 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 801 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 802 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 803 | DCHECK(locations->CanCall()); |
| 804 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 805 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 806 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 807 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 808 | |
| 809 | __ Bind(GetEntryLabel()); |
| 810 | SaveLiveRegisters(codegen, locations); |
| 811 | |
| 812 | InvokeRuntimeCallingConvention calling_convention; |
| 813 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 814 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 815 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 816 | // thus we need a 64-bit move here, and we cannot use |
| 817 | // |
| 818 | // arm64_codegen->MoveLocation( |
| 819 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 820 | // root_, |
| 821 | // type); |
| 822 | // |
| 823 | // 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] | 824 | // reference type (`DataType::Type::kReference`). |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 825 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 826 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 827 | instruction_, |
| 828 | instruction_->GetDexPc(), |
| 829 | this); |
| 830 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 831 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 832 | |
| 833 | RestoreLiveRegisters(codegen, locations); |
| 834 | __ B(GetExitLabel()); |
| 835 | } |
| 836 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 837 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathARM64"; } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 838 | |
| 839 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 840 | const Location out_; |
| 841 | const Location root_; |
| 842 | |
| 843 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 844 | }; |
| 845 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 846 | #undef __ |
| 847 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 848 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 849 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 850 | if (type == DataType::Type::kVoid) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 851 | LOG(FATAL) << "Unreachable type " << type; |
| 852 | } |
| 853 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 854 | if (DataType::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 855 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 856 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 857 | } else if (!DataType::IsFloatingPointType(type) && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 858 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 859 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 860 | } else { |
| 861 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 862 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 863 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 864 | } |
| 865 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 866 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 867 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 868 | return next_location; |
| 869 | } |
| 870 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 871 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 872 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 873 | } |
| 874 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 875 | Location CriticalNativeCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
| 876 | DCHECK_NE(type, DataType::Type::kReference); |
| 877 | |
| 878 | Location location = Location::NoLocation(); |
| 879 | if (DataType::IsFloatingPointType(type)) { |
| 880 | if (fpr_index_ < kParameterFPRegistersLength) { |
| 881 | location = LocationFrom(kParameterFPRegisters[fpr_index_]); |
| 882 | ++fpr_index_; |
| 883 | } |
| 884 | } else { |
| 885 | // Native ABI uses the same registers as managed, except that the method register x0 |
| 886 | // is a normal argument. |
| 887 | if (gpr_index_ < 1u + kParameterCoreRegistersLength) { |
| 888 | location = LocationFrom(gpr_index_ == 0u ? x0 : kParameterCoreRegisters[gpr_index_ - 1u]); |
| 889 | ++gpr_index_; |
| 890 | } |
| 891 | } |
| 892 | if (location.IsInvalid()) { |
| 893 | if (DataType::Is64BitType(type)) { |
| 894 | location = Location::DoubleStackSlot(stack_offset_); |
| 895 | } else { |
| 896 | location = Location::StackSlot(stack_offset_); |
| 897 | } |
| 898 | stack_offset_ += kFramePointerSize; |
| 899 | |
| 900 | if (for_register_allocation_) { |
| 901 | location = Location::Any(); |
| 902 | } |
| 903 | } |
| 904 | return location; |
| 905 | } |
| 906 | |
| 907 | Location CriticalNativeCallingConventionVisitorARM64::GetReturnLocation(DataType::Type type) const { |
| 908 | // We perform conversion to the managed ABI return register after the call if needed. |
| 909 | InvokeDexCallingConventionVisitorARM64 dex_calling_convention; |
| 910 | return dex_calling_convention.GetReturnLocation(type); |
| 911 | } |
| 912 | |
| 913 | Location CriticalNativeCallingConventionVisitorARM64::GetMethodLocation() const { |
| 914 | // Pass the method in the hidden argument x15. |
| 915 | return Location::RegisterLocation(x15.GetCode()); |
| 916 | } |
| 917 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 918 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 919 | const CompilerOptions& compiler_options, |
| 920 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 921 | : CodeGenerator(graph, |
| 922 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 923 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 924 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 925 | callee_saved_core_registers.GetList(), |
| 926 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 927 | compiler_options, |
| 928 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 929 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 930 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 931 | location_builder_neon_(graph, this), |
| 932 | instruction_visitor_neon_(graph, this), |
| 933 | location_builder_sve_(graph, this), |
| 934 | instruction_visitor_sve_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 935 | move_resolver_(graph->GetAllocator(), this), |
Artem Serov | aa6f483 | 2018-11-21 18:57:54 +0000 | [diff] [blame] | 936 | assembler_(graph->GetAllocator(), |
| 937 | compiler_options.GetInstructionSetFeatures()->AsArm64InstructionSetFeatures()), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 938 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 939 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 940 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 941 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 942 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 943 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 944 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 945 | call_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 946 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 947 | uint32_literals_(std::less<uint32_t>(), |
| 948 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 949 | uint64_literals_(std::less<uint64_t>(), |
| 950 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 951 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 952 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 953 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 954 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 955 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 956 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 957 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 958 | AddAllocatedRegister(LocationFrom(lr)); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 959 | |
| 960 | bool use_sve = ShouldUseSVE(); |
| 961 | if (use_sve) { |
| 962 | location_builder_ = &location_builder_sve_; |
| 963 | instruction_visitor_ = &instruction_visitor_sve_; |
| 964 | } else { |
| 965 | location_builder_ = &location_builder_neon_; |
| 966 | instruction_visitor_ = &instruction_visitor_neon_; |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | bool CodeGeneratorARM64::ShouldUseSVE() const { |
| 971 | return kArm64AllowSVE && GetInstructionSetFeatures().HasSVE(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 972 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 973 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 974 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 975 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 976 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 977 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 978 | jump_table->EmitTable(this); |
| 979 | } |
| 980 | } |
| 981 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 982 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 983 | EmitJumpTables(); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 984 | |
| 985 | // Emit JIT baker read barrier slow paths. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 986 | DCHECK(GetCompilerOptions().IsJitCompiler() || jit_baker_read_barrier_slow_paths_.empty()); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 987 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 988 | uint32_t encoded_data = entry.first; |
| 989 | vixl::aarch64::Label* slow_path_entry = &entry.second.label; |
| 990 | __ Bind(slow_path_entry); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 991 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name= */ nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 992 | } |
| 993 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 994 | // Ensure we emit the literal pool. |
| 995 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 996 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 997 | CodeGenerator::Finalize(allocator); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 998 | |
| 999 | // Verify Baker read barrier linker patches. |
| 1000 | if (kIsDebugBuild) { |
| 1001 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 1002 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 1003 | DCHECK(info.label.IsBound()); |
| 1004 | uint32_t literal_offset = info.label.GetLocation(); |
| 1005 | DCHECK_ALIGNED(literal_offset, 4u); |
| 1006 | |
| 1007 | auto GetInsn = [&code](uint32_t offset) { |
| 1008 | DCHECK_ALIGNED(offset, 4u); |
| 1009 | return |
| 1010 | (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 1011 | (static_cast<uint32_t>(code[offset + 1]) << 8) + |
| 1012 | (static_cast<uint32_t>(code[offset + 2]) << 16)+ |
| 1013 | (static_cast<uint32_t>(code[offset + 3]) << 24); |
| 1014 | }; |
| 1015 | |
| 1016 | const uint32_t encoded_data = info.custom_data; |
| 1017 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 1018 | // Check that the next instruction matches the expected LDR. |
| 1019 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1020 | case BakerReadBarrierKind::kField: |
| 1021 | case BakerReadBarrierKind::kAcquire: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1022 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1023 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1024 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1025 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1026 | if (kind == BakerReadBarrierKind::kField) { |
| 1027 | // LDR (immediate) with correct base_reg. |
| 1028 | CHECK_EQ(next_insn & 0xffc003e0u, 0xb9400000u | (base_reg << 5)); |
| 1029 | } else { |
| 1030 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 1031 | // LDAR with correct base_reg. |
| 1032 | CHECK_EQ(next_insn & 0xffffffe0u, 0x88dffc00u | (base_reg << 5)); |
| 1033 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1034 | break; |
| 1035 | } |
| 1036 | case BakerReadBarrierKind::kArray: { |
| 1037 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1038 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 1039 | // LDR (register) with the correct base_reg, size=10 (32-bit), option=011 (extend = LSL), |
| 1040 | // and S=1 (shift amount = 2 for 32-bit version), i.e. LDR Wt, [Xn, Xm, LSL #2]. |
| 1041 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1042 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1043 | CHECK_EQ(next_insn & 0xffe0ffe0u, 0xb8607800u | (base_reg << 5)); |
| 1044 | CheckValidReg((next_insn >> 16) & 0x1f); // Check index register |
| 1045 | break; |
| 1046 | } |
| 1047 | case BakerReadBarrierKind::kGcRoot: { |
| 1048 | DCHECK_GE(literal_offset, 4u); |
| 1049 | uint32_t prev_insn = GetInsn(literal_offset - 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1050 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 1051 | // Usually LDR (immediate) with correct root_reg but |
| 1052 | // we may have a "MOV marked, old_value" for UnsafeCASObject. |
| 1053 | if ((prev_insn & 0xffe0ffff) != (0x2a0003e0 | root_reg)) { // MOV? |
| 1054 | CHECK_EQ(prev_insn & 0xffc0001fu, 0xb9400000u | root_reg); // LDR? |
| 1055 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1056 | break; |
| 1057 | } |
| 1058 | default: |
| 1059 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 1060 | UNREACHABLE(); |
| 1061 | } |
| 1062 | } |
| 1063 | } |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1066 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1067 | // Note: There are 6 kinds of moves: |
| 1068 | // 1. constant -> GPR/FPR (non-cycle) |
| 1069 | // 2. constant -> stack (non-cycle) |
| 1070 | // 3. GPR/FPR -> GPR/FPR |
| 1071 | // 4. GPR/FPR -> stack |
| 1072 | // 5. stack -> GPR/FPR |
| 1073 | // 6. stack -> stack (non-cycle) |
| 1074 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1075 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1076 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1077 | // dependency. |
| 1078 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1079 | } |
| 1080 | |
| 1081 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1082 | vixl_temps_.Close(); |
| 1083 | } |
| 1084 | |
| 1085 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1086 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1087 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1088 | || kind == Location::kSIMDStackSlot); |
| 1089 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1090 | ? Location::kFpuRegister |
| 1091 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1092 | Location scratch = GetScratchLocation(kind); |
| 1093 | if (!scratch.Equals(Location::NoLocation())) { |
| 1094 | return scratch; |
| 1095 | } |
| 1096 | // Allocate from VIXL temp registers. |
| 1097 | if (kind == Location::kRegister) { |
| 1098 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1099 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1100 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1101 | scratch = codegen_->GetGraph()->HasSIMD() |
| 1102 | ? codegen_->GetInstructionCodeGeneratorArm64()->AllocateSIMDScratchLocation(&vixl_temps_) |
| 1103 | : LocationFrom(vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1104 | } |
| 1105 | AddScratchLocation(scratch); |
| 1106 | return scratch; |
| 1107 | } |
| 1108 | |
| 1109 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1110 | if (loc.IsRegister()) { |
| 1111 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1112 | } else { |
| 1113 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1114 | if (codegen_->GetGraph()->HasSIMD()) { |
| 1115 | codegen_->GetInstructionCodeGeneratorArm64()->FreeSIMDScratchLocation(loc, &vixl_temps_); |
| 1116 | } else { |
| 1117 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1118 | } |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1119 | } |
| 1120 | RemoveScratchLocation(loc); |
| 1121 | } |
| 1122 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1123 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1124 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1125 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1128 | void CodeGeneratorARM64::MaybeIncrementHotness(bool is_frame_entry) { |
| 1129 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1130 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1131 | UseScratchRegisterScope temps(masm); |
| 1132 | Register counter = temps.AcquireX(); |
| 1133 | Register method = is_frame_entry ? kArtMethodRegister : temps.AcquireX(); |
| 1134 | if (!is_frame_entry) { |
| 1135 | __ Ldr(method, MemOperand(sp, 0)); |
| 1136 | } |
| 1137 | __ Ldrh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1138 | __ Add(counter, counter, 1); |
| 1139 | // Subtract one if the counter would overflow. |
| 1140 | __ Sub(counter, counter, Operand(counter, LSR, 16)); |
| 1141 | __ Strh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1142 | } |
| 1143 | |
| 1144 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 1145 | ScopedProfilingInfoUse spiu( |
| 1146 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 1147 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1148 | if (info != nullptr) { |
Nicolas Geoffray | c1cd133 | 2020-01-25 13:08:24 +0000 | [diff] [blame] | 1149 | uint64_t address = reinterpret_cast64<uint64_t>(info); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1150 | vixl::aarch64::Label done; |
| 1151 | UseScratchRegisterScope temps(masm); |
| 1152 | Register temp = temps.AcquireX(); |
| 1153 | Register counter = temps.AcquireW(); |
| 1154 | __ Mov(temp, address); |
| 1155 | __ Ldrh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 1156 | __ Add(counter, counter, 1); |
Nicolas Geoffray | 4313ccb | 2020-08-26 17:01:15 +0100 | [diff] [blame] | 1157 | __ And(counter, counter, interpreter::kTieredHotnessMask); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1158 | __ Strh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
Nicolas Geoffray | 4313ccb | 2020-08-26 17:01:15 +0100 | [diff] [blame] | 1159 | __ Cbnz(counter, &done); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1160 | if (is_frame_entry) { |
| 1161 | if (HasEmptyFrame()) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1162 | // The entrypoint expects the method at the bottom of the stack. We |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1163 | // claim stack space necessary for alignment. |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1164 | IncreaseFrame(kStackAlignment); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1165 | __ Stp(kArtMethodRegister, lr, MemOperand(sp, 0)); |
| 1166 | } else if (!RequiresCurrentMethod()) { |
| 1167 | __ Str(kArtMethodRegister, MemOperand(sp, 0)); |
| 1168 | } |
| 1169 | } else { |
| 1170 | CHECK(RequiresCurrentMethod()); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1171 | } |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1172 | uint32_t entrypoint_offset = |
| 1173 | GetThreadOffset<kArm64PointerSize>(kQuickCompileOptimized).Int32Value(); |
| 1174 | __ Ldr(lr, MemOperand(tr, entrypoint_offset)); |
| 1175 | // Note: we don't record the call here (and therefore don't generate a stack |
| 1176 | // map), as the entrypoint should never be suspended. |
| 1177 | __ Blr(lr); |
| 1178 | if (HasEmptyFrame()) { |
| 1179 | CHECK(is_frame_entry); |
| 1180 | __ Ldr(lr, MemOperand(sp, 8)); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1181 | DecreaseFrame(kStackAlignment); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1182 | } |
| 1183 | __ Bind(&done); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1184 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1185 | } |
| 1186 | } |
| 1187 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1188 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1189 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1190 | __ Bind(&frame_entry_label_); |
| 1191 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1192 | bool do_overflow_check = |
| 1193 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1194 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1195 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1196 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1197 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1198 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1199 | { |
| 1200 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1201 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1202 | kInstructionSize, |
| 1203 | CodeBufferCheckScope::kExactSize); |
| 1204 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1205 | RecordPcInfo(nullptr, 0); |
| 1206 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1207 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1208 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1209 | if (!HasEmptyFrame()) { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1210 | // Stack layout: |
| 1211 | // sp[frame_size - 8] : lr. |
| 1212 | // ... : other preserved core registers. |
| 1213 | // ... : other preserved fp registers. |
| 1214 | // ... : reserved frame space. |
| 1215 | // sp[0] : current method. |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1216 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1217 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1218 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1219 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1220 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1221 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1222 | |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1223 | // Save the current method if we need it, or if using STP reduces code |
| 1224 | // size. Note that we do not do this in HCurrentMethod, as the |
| 1225 | // instruction might have been removed in the SSA graph. |
| 1226 | CPURegister lowest_spill; |
| 1227 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1228 | // If there is no gap between the method and the lowest core spill, use |
| 1229 | // aligned STP pre-index to store both. Max difference is 512. We do |
| 1230 | // that to reduce code size even if we do not have to save the method. |
| 1231 | DCHECK_LE(frame_size, 512); // 32 core registers are only 256 bytes. |
| 1232 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1233 | __ Stp(kArtMethodRegister, lowest_spill, MemOperand(sp, -frame_size, PreIndex)); |
| 1234 | } else if (RequiresCurrentMethod()) { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1235 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1236 | } else { |
| 1237 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1238 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1239 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1240 | if (lowest_spill.IsValid()) { |
| 1241 | GetAssembler()->cfi().RelOffset(DWARFReg(lowest_spill), core_spills_offset); |
| 1242 | core_spills_offset += kXRegSizeInBytes; |
| 1243 | } |
| 1244 | GetAssembler()->SpillRegisters(preserved_core_registers, core_spills_offset); |
| 1245 | GetAssembler()->SpillRegisters(preserved_fp_registers, fp_spills_offset); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1246 | |
| 1247 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1248 | // Initialize should_deoptimize flag to 0. |
| 1249 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1250 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1251 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1252 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1253 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1254 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1258 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1259 | if (!HasEmptyFrame()) { |
Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1260 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1261 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1262 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1263 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1264 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1265 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
| 1266 | |
| 1267 | CPURegister lowest_spill; |
| 1268 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1269 | // If there is no gap between the method and the lowest core spill, use |
| 1270 | // aligned LDP pre-index to pop both. Max difference is 504. We do |
| 1271 | // that to reduce code size even though the loaded method is unused. |
| 1272 | DCHECK_LE(frame_size, 504); // 32 core registers are only 256 bytes. |
| 1273 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1274 | core_spills_offset += kXRegSizeInBytes; |
| 1275 | } |
| 1276 | GetAssembler()->UnspillRegisters(preserved_fp_registers, fp_spills_offset); |
| 1277 | GetAssembler()->UnspillRegisters(preserved_core_registers, core_spills_offset); |
| 1278 | if (lowest_spill.IsValid()) { |
| 1279 | __ Ldp(xzr, lowest_spill, MemOperand(sp, frame_size, PostIndex)); |
| 1280 | GetAssembler()->cfi().Restore(DWARFReg(lowest_spill)); |
| 1281 | } else { |
| 1282 | __ Drop(frame_size); |
| 1283 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1284 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1285 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1286 | __ Ret(); |
| 1287 | GetAssembler()->cfi().RestoreState(); |
| 1288 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1289 | } |
| 1290 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1291 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1292 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1293 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1294 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1295 | } |
| 1296 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1297 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1298 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1299 | GetNumberOfFloatingPointRegisters())); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1300 | return CPURegList(CPURegister::kVRegister, kDRegSize, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1301 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1302 | } |
| 1303 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1304 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1305 | __ Bind(GetLabelOf(block)); |
| 1306 | } |
| 1307 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1308 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1309 | DCHECK(location.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1310 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1311 | } |
| 1312 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1313 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1314 | if (location.IsRegister()) { |
| 1315 | locations->AddTemp(location); |
| 1316 | } else { |
| 1317 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1318 | } |
| 1319 | } |
| 1320 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1321 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1322 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1323 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1324 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1325 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1326 | if (value_can_be_null) { |
| 1327 | __ Cbz(value, &done); |
| 1328 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1329 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1330 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1331 | // Calculate the offset (in the card table) of the card corresponding to |
| 1332 | // `object`. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1333 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1334 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 1335 | // `object`'s card. |
| 1336 | // |
| 1337 | // Register `card` contains the address of the card table. Note that the card |
| 1338 | // table's base is biased during its creation so that it always starts at an |
| 1339 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 1340 | // art::gc::accounting::CardTable::Create). Therefore the STRB instruction |
| 1341 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 1342 | // (located at `card + object >> kCardShift`). |
| 1343 | // |
| 1344 | // This dual use of the value in register `card` (1. to calculate the location |
| 1345 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 1346 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1347 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1348 | if (value_can_be_null) { |
| 1349 | __ Bind(&done); |
| 1350 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1351 | } |
| 1352 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1353 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1354 | // Blocked core registers: |
| 1355 | // lr : Runtime reserved. |
| 1356 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1357 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1358 | // ip1 : VIXL core temp. |
| 1359 | // ip0 : VIXL core temp. |
Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1360 | // x18 : Platform register. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1361 | // |
| 1362 | // Blocked fp registers: |
| 1363 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1364 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1365 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1366 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1367 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1368 | } |
Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1369 | blocked_core_registers_[X18] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1370 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1371 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1372 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1373 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1374 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1375 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1376 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1377 | // Stubs do not save callee-save floating point registers. If the graph |
| 1378 | // is debuggable, we need to deal with these registers differently. For |
| 1379 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1380 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1381 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1382 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1383 | } |
| 1384 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1385 | } |
| 1386 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1387 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1388 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1389 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1390 | return kArm64WordSize; |
| 1391 | } |
| 1392 | |
| 1393 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1394 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1395 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1396 | return kArm64WordSize; |
| 1397 | } |
| 1398 | |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1399 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1400 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1401 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1402 | << "use SaveRestoreLiveRegistersHelper"; |
| 1403 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1406 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1407 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1408 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1409 | << "use SaveRestoreLiveRegistersHelper"; |
| 1410 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1413 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1414 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1418 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1419 | } |
| 1420 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1421 | const Arm64InstructionSetFeatures& CodeGeneratorARM64::GetInstructionSetFeatures() const { |
| 1422 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArm64InstructionSetFeatures(); |
| 1423 | } |
| 1424 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1425 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1426 | if (constant->IsIntConstant()) { |
| 1427 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1428 | } else if (constant->IsLongConstant()) { |
| 1429 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1430 | } else if (constant->IsNullConstant()) { |
| 1431 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1432 | } else if (constant->IsFloatConstant()) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1433 | __ Fmov(VRegister(destination), constant->AsFloatConstant()->GetValue()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1434 | } else { |
| 1435 | DCHECK(constant->IsDoubleConstant()); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1436 | __ Fmov(VRegister(destination), constant->AsDoubleConstant()->GetValue()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1437 | } |
| 1438 | } |
| 1439 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1440 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1441 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1442 | DCHECK(constant.IsConstant()); |
| 1443 | HConstant* cst = constant.GetConstant(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1444 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1445 | // 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] | 1446 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1447 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1448 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1449 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1452 | // Allocate a scratch register from the VIXL pool, querying first |
| 1453 | // the floating-point register pool, and then the core register |
| 1454 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1455 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1456 | // using a different allocation strategy. |
| 1457 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1458 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1459 | int size_in_bits) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1460 | return masm->GetScratchVRegisterList()->IsEmpty() |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1461 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1462 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1463 | } |
| 1464 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1465 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1466 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1467 | DataType::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1468 | if (source.Equals(destination)) { |
| 1469 | return; |
| 1470 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1471 | |
| 1472 | // A valid move can always be inferred from the destination and source |
| 1473 | // locations. When moving from and to a register, the argument type can be |
| 1474 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1475 | // checks the coherency of the locations and the type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1476 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1477 | |
| 1478 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1479 | if (unspecified_type) { |
| 1480 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1481 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1482 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1483 | || src_cst->IsFloatConstant() |
| 1484 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1485 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1486 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1487 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1488 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1489 | // type is appropriate. Else the source is a register, and since the |
| 1490 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1491 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1492 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1493 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1494 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1495 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1496 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1497 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1498 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1499 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1500 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1501 | } else if (source.IsSIMDStackSlot()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1502 | GetInstructionCodeGeneratorArm64()->LoadSIMDRegFromStack(destination, source); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1503 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1504 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1505 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1506 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1507 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1508 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1509 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1510 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1511 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1512 | ? DataType::Type::kInt64 |
| 1513 | : DataType::Type::kInt32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1514 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1515 | } |
| 1516 | } else { |
| 1517 | DCHECK(source.IsFpuRegister()); |
| 1518 | if (destination.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1519 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1520 | ? DataType::Type::kFloat64 |
| 1521 | : DataType::Type::kFloat32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1522 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1523 | } else { |
| 1524 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1525 | if (GetGraph()->HasSIMD()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1526 | GetInstructionCodeGeneratorArm64()->MoveSIMDRegToSIMDReg(destination, source); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1527 | } else { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1528 | __ Fmov(VRegister(dst), FPRegisterFrom(source, dst_type)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1529 | } |
| 1530 | } |
| 1531 | } |
| 1532 | } else if (destination.IsSIMDStackSlot()) { |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1533 | GetInstructionCodeGeneratorArm64()->MoveToSIMDStackSlot(destination, source); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1534 | } else { // The destination is not a register. It must be a stack slot. |
| 1535 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1536 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1537 | if (unspecified_type) { |
| 1538 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1539 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1540 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1541 | dst_type = |
| 1542 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1543 | } |
| 1544 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1545 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1546 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1547 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1548 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1549 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1550 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1551 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1552 | HConstant* src_cst = source.GetConstant(); |
| 1553 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1554 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1555 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1556 | ? Register(xzr) |
| 1557 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1558 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1559 | if (src_cst->IsIntConstant()) { |
| 1560 | temp = temps.AcquireW(); |
| 1561 | } else if (src_cst->IsLongConstant()) { |
| 1562 | temp = temps.AcquireX(); |
| 1563 | } else if (src_cst->IsFloatConstant()) { |
| 1564 | temp = temps.AcquireS(); |
| 1565 | } else { |
| 1566 | DCHECK(src_cst->IsDoubleConstant()); |
| 1567 | temp = temps.AcquireD(); |
| 1568 | } |
| 1569 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1570 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1571 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1572 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1573 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1574 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1575 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1576 | // Use any scratch register (a core or a floating-point one) |
| 1577 | // from VIXL scratch register pools as a temporary. |
| 1578 | // |
| 1579 | // We used to only use the FP scratch register pool, but in some |
| 1580 | // rare cases the only register from this pool (D31) would |
| 1581 | // already be used (e.g. within a ParallelMove instruction, when |
| 1582 | // a move is blocked by a another move requiring a scratch FP |
| 1583 | // register, which would reserve D31). To prevent this issue, we |
| 1584 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1585 | // |
| 1586 | // 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] | 1587 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1588 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1589 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1590 | // allocates core scratch registers first. |
| 1591 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1592 | GetVIXLAssembler(), |
| 1593 | &temps, |
| 1594 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1595 | __ Ldr(temp, StackOperandFrom(source)); |
| 1596 | __ Str(temp, StackOperandFrom(destination)); |
| 1597 | } |
| 1598 | } |
| 1599 | } |
| 1600 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1601 | void CodeGeneratorARM64::Load(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1602 | CPURegister dst, |
| 1603 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1604 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1605 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1606 | case DataType::Type::kUint8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1607 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1608 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1609 | case DataType::Type::kInt8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1610 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1611 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1612 | case DataType::Type::kUint16: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1613 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1614 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1615 | case DataType::Type::kInt16: |
| 1616 | __ Ldrsh(Register(dst), src); |
| 1617 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1618 | case DataType::Type::kInt32: |
| 1619 | case DataType::Type::kReference: |
| 1620 | case DataType::Type::kInt64: |
| 1621 | case DataType::Type::kFloat32: |
| 1622 | case DataType::Type::kFloat64: |
| 1623 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1624 | __ Ldr(dst, src); |
| 1625 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1626 | case DataType::Type::kUint32: |
| 1627 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1628 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1629 | LOG(FATAL) << "Unreachable type " << type; |
| 1630 | } |
| 1631 | } |
| 1632 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1633 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1634 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1635 | const MemOperand& src, |
| 1636 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1637 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1638 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1639 | Register temp_base = temps.AcquireX(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1640 | DataType::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1641 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1642 | DCHECK(!src.IsPreIndex()); |
| 1643 | DCHECK(!src.IsPostIndex()); |
| 1644 | |
| 1645 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1646 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1647 | { |
| 1648 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1649 | MemOperand base = MemOperand(temp_base); |
| 1650 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1651 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1652 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1653 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1654 | { |
| 1655 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1656 | __ ldarb(Register(dst), base); |
| 1657 | if (needs_null_check) { |
| 1658 | MaybeRecordImplicitNullCheck(instruction); |
| 1659 | } |
| 1660 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1661 | if (type == DataType::Type::kInt8) { |
| 1662 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1663 | } |
| 1664 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1665 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1666 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1667 | { |
| 1668 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1669 | __ ldarh(Register(dst), base); |
| 1670 | if (needs_null_check) { |
| 1671 | MaybeRecordImplicitNullCheck(instruction); |
| 1672 | } |
| 1673 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1674 | if (type == DataType::Type::kInt16) { |
| 1675 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 1676 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1677 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1678 | case DataType::Type::kInt32: |
| 1679 | case DataType::Type::kReference: |
| 1680 | case DataType::Type::kInt64: |
| 1681 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1682 | { |
| 1683 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1684 | __ ldar(Register(dst), base); |
| 1685 | if (needs_null_check) { |
| 1686 | MaybeRecordImplicitNullCheck(instruction); |
| 1687 | } |
| 1688 | } |
| 1689 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1690 | case DataType::Type::kFloat32: |
| 1691 | case DataType::Type::kFloat64: { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1692 | DCHECK(dst.IsFPRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1693 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1694 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1695 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1696 | { |
| 1697 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1698 | __ ldar(temp, base); |
| 1699 | if (needs_null_check) { |
| 1700 | MaybeRecordImplicitNullCheck(instruction); |
| 1701 | } |
| 1702 | } |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1703 | __ Fmov(VRegister(dst), temp); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1704 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1705 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1706 | case DataType::Type::kUint32: |
| 1707 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1708 | case DataType::Type::kVoid: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1709 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1710 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1711 | } |
| 1712 | } |
| 1713 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1714 | void CodeGeneratorARM64::Store(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1715 | CPURegister src, |
| 1716 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1717 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1718 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1719 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1720 | case DataType::Type::kInt8: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1721 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1722 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1723 | case DataType::Type::kUint16: |
| 1724 | case DataType::Type::kInt16: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1725 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1726 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1727 | case DataType::Type::kInt32: |
| 1728 | case DataType::Type::kReference: |
| 1729 | case DataType::Type::kInt64: |
| 1730 | case DataType::Type::kFloat32: |
| 1731 | case DataType::Type::kFloat64: |
| 1732 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1733 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1734 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1735 | case DataType::Type::kUint32: |
| 1736 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1737 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1738 | LOG(FATAL) << "Unreachable type " << type; |
| 1739 | } |
| 1740 | } |
| 1741 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1742 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1743 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1744 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1745 | const MemOperand& dst, |
| 1746 | bool needs_null_check) { |
| 1747 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1748 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1749 | Register temp_base = temps.AcquireX(); |
| 1750 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1751 | DCHECK(!dst.IsPreIndex()); |
| 1752 | DCHECK(!dst.IsPostIndex()); |
| 1753 | |
| 1754 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1755 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1756 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1757 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1758 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1759 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1760 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1761 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1762 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1763 | { |
| 1764 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1765 | __ stlrb(Register(src), base); |
| 1766 | if (needs_null_check) { |
| 1767 | MaybeRecordImplicitNullCheck(instruction); |
| 1768 | } |
| 1769 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1770 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1771 | case DataType::Type::kUint16: |
| 1772 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1773 | { |
| 1774 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1775 | __ stlrh(Register(src), base); |
| 1776 | if (needs_null_check) { |
| 1777 | MaybeRecordImplicitNullCheck(instruction); |
| 1778 | } |
| 1779 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1780 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1781 | case DataType::Type::kInt32: |
| 1782 | case DataType::Type::kReference: |
| 1783 | case DataType::Type::kInt64: |
| 1784 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1785 | { |
| 1786 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1787 | __ stlr(Register(src), base); |
| 1788 | if (needs_null_check) { |
| 1789 | MaybeRecordImplicitNullCheck(instruction); |
| 1790 | } |
| 1791 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1792 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1793 | case DataType::Type::kFloat32: |
| 1794 | case DataType::Type::kFloat64: { |
| 1795 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1796 | Register temp_src; |
| 1797 | if (src.IsZero()) { |
| 1798 | // The zero register is used to avoid synthesizing zero constants. |
| 1799 | temp_src = Register(src); |
| 1800 | } else { |
| 1801 | DCHECK(src.IsFPRegister()); |
| 1802 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1803 | __ Fmov(temp_src, VRegister(src)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1804 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1805 | { |
| 1806 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1807 | __ stlr(temp_src, base); |
| 1808 | if (needs_null_check) { |
| 1809 | MaybeRecordImplicitNullCheck(instruction); |
| 1810 | } |
| 1811 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1812 | break; |
| 1813 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1814 | case DataType::Type::kUint32: |
| 1815 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1816 | case DataType::Type::kVoid: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1817 | LOG(FATAL) << "Unreachable type " << type; |
| 1818 | } |
| 1819 | } |
| 1820 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1821 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1822 | HInstruction* instruction, |
| 1823 | uint32_t dex_pc, |
| 1824 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1825 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1826 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1827 | ThreadOffset64 entrypoint_offset = GetThreadOffset<kArm64PointerSize>(entrypoint); |
| 1828 | // Reduce code size for AOT by using shared trampolines for slow path runtime calls across the |
| 1829 | // entire oat file. This adds an extra branch and we do not want to slow down the main path. |
| 1830 | // 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] | 1831 | if (slow_path == nullptr || GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1832 | __ Ldr(lr, MemOperand(tr, entrypoint_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1833 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 1834 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1835 | __ blr(lr); |
| 1836 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1837 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1838 | } |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1839 | } else { |
| 1840 | // Ensure the pc position is recorded immediately after the `bl` instruction. |
| 1841 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1842 | EmitEntrypointThunkCall(entrypoint_offset); |
| 1843 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1844 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1845 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1846 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1849 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1850 | HInstruction* instruction, |
| 1851 | SlowPathCode* slow_path) { |
| 1852 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1853 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1854 | __ Blr(lr); |
| 1855 | } |
| 1856 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1857 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1858 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1859 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1860 | Register temp = temps.AcquireW(); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1861 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
Vladimir Marko | 2bb44fe | 2019-10-04 12:28:14 +0100 | [diff] [blame] | 1862 | const size_t status_byte_offset = |
| 1863 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 1864 | constexpr uint32_t shifted_visibly_initialized_value = |
| 1865 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1866 | |
Vladimir Marko | 2bb44fe | 2019-10-04 12:28:14 +0100 | [diff] [blame] | 1867 | // CMP (immediate) is limited to imm12 or imm12<<12, so we would need to materialize |
| 1868 | // the constant 0xf0000000 for comparison with the full 32-bit field. To reduce the code |
| 1869 | // size, load only the high byte of the field and compare with 0xf0. |
| 1870 | // Note: The same code size could be achieved with LDR+MNV(asr #24)+CBNZ but benchmarks |
| 1871 | // show that this pattern is slower (tested on little cores). |
| 1872 | __ Ldrb(temp, HeapOperand(class_reg, status_byte_offset)); |
| 1873 | __ Cmp(temp, shifted_visibly_initialized_value); |
| 1874 | __ B(lo, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1875 | __ Bind(slow_path->GetExitLabel()); |
| 1876 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1877 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 1878 | void InstructionCodeGeneratorARM64::GenerateBitstringTypeCheckCompare( |
| 1879 | HTypeCheckInstruction* check, vixl::aarch64::Register temp) { |
| 1880 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 1881 | uint32_t mask = check->GetBitstringMask(); |
| 1882 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 1883 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 1884 | |
| 1885 | if (mask_bits == 16u) { |
| 1886 | // Load only the bitstring part of the status word. |
| 1887 | __ Ldrh(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1888 | } else { |
| 1889 | // /* uint32_t */ temp = temp->status_ |
| 1890 | __ Ldr(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1891 | // Extract the bitstring bits. |
| 1892 | __ Ubfx(temp, temp, 0, mask_bits); |
| 1893 | } |
| 1894 | // Compare the bitstring bits to `path_to_root`. |
| 1895 | __ Cmp(temp, path_to_root); |
| 1896 | } |
| 1897 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1898 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1899 | BarrierType type = BarrierAll; |
| 1900 | |
| 1901 | switch (kind) { |
| 1902 | case MemBarrierKind::kAnyAny: |
| 1903 | case MemBarrierKind::kAnyStore: { |
| 1904 | type = BarrierAll; |
| 1905 | break; |
| 1906 | } |
| 1907 | case MemBarrierKind::kLoadAny: { |
| 1908 | type = BarrierReads; |
| 1909 | break; |
| 1910 | } |
| 1911 | case MemBarrierKind::kStoreStore: { |
| 1912 | type = BarrierWrites; |
| 1913 | break; |
| 1914 | } |
| 1915 | default: |
| 1916 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1917 | } |
| 1918 | __ Dmb(InnerShareable, type); |
| 1919 | } |
| 1920 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1921 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1922 | HBasicBlock* successor) { |
| 1923 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1924 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1925 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1926 | slow_path = |
| 1927 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1928 | instruction->SetSlowPath(slow_path); |
| 1929 | codegen_->AddSlowPath(slow_path); |
| 1930 | if (successor != nullptr) { |
| 1931 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1932 | } |
| 1933 | } else { |
| 1934 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1935 | } |
| 1936 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1937 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1938 | Register temp = temps.AcquireW(); |
| 1939 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1940 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1941 | if (successor == nullptr) { |
| 1942 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1943 | __ Bind(slow_path->GetReturnLabel()); |
| 1944 | } else { |
| 1945 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1946 | __ B(slow_path->GetEntryLabel()); |
| 1947 | // slow_path will return to GetLabelOf(successor). |
| 1948 | } |
| 1949 | } |
| 1950 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1951 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1952 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1953 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1954 | assembler_(codegen->GetAssembler()), |
| 1955 | codegen_(codegen) {} |
| 1956 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1957 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1958 | DCHECK_EQ(instr->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1959 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1960 | DataType::Type type = instr->GetResultType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1961 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1962 | case DataType::Type::kInt32: |
| 1963 | case DataType::Type::kInt64: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1964 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1965 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1966 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1967 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1968 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1969 | case DataType::Type::kFloat32: |
| 1970 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1971 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1972 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1973 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1974 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1975 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1976 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1977 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1978 | } |
| 1979 | } |
| 1980 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1981 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 1982 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1983 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1984 | |
| 1985 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1986 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1987 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1988 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 1989 | object_field_get_with_read_barrier |
| 1990 | ? LocationSummary::kCallOnSlowPath |
| 1991 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1992 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1993 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1994 | // We need a temporary register for the read barrier load in |
| 1995 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 1996 | // only if the field is volatile or the offset is too big. |
| 1997 | if (field_info.IsVolatile() || |
| 1998 | field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 1999 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2000 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2001 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2002 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2003 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2004 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2005 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2006 | // The output overlaps for an object field get when read barriers |
| 2007 | // are enabled: we do not want the load to overwrite the object's |
| 2008 | // location, as we need it to emit the read barrier. |
| 2009 | locations->SetOut( |
| 2010 | Location::RequiresRegister(), |
| 2011 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2016 | const FieldInfo& field_info) { |
| 2017 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2018 | LocationSummary* locations = instruction->GetLocations(); |
| 2019 | Location base_loc = locations->InAt(0); |
| 2020 | Location out = locations->Out(); |
| 2021 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2022 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 2023 | DataType::Type load_type = instruction->GetType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2024 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2025 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2026 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2027 | load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2028 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2029 | // /* HeapReference<Object> */ out = *(base + offset) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2030 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2031 | Location maybe_temp = |
| 2032 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2033 | // Note that potential implicit null checks are handled in this |
| 2034 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2035 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2036 | instruction, |
| 2037 | out, |
| 2038 | base, |
| 2039 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2040 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2041 | /* needs_null_check= */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2042 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2043 | } else { |
| 2044 | // General case. |
| 2045 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2046 | // Note that a potential implicit null check is handled in this |
| 2047 | // CodeGeneratorARM64::LoadAcquire call. |
| 2048 | // NB: LoadAcquire will record the pc info if needed. |
| 2049 | codegen_->LoadAcquire( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2050 | instruction, OutputCPURegister(instruction), field, /* needs_null_check= */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2051 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2052 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2053 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2054 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2055 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2056 | } |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2057 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2058 | // If read barriers are enabled, emit read barriers other than |
| 2059 | // Baker's using a slow path (and also unpoison the loaded |
| 2060 | // reference, if heap poisoning is enabled). |
| 2061 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2062 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2063 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2067 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2068 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2069 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2070 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2071 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2072 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2073 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2074 | } else { |
| 2075 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2076 | } |
| 2077 | } |
| 2078 | |
| 2079 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2080 | const FieldInfo& field_info, |
| 2081 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2082 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2083 | |
| 2084 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2085 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2086 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2087 | Offset offset = field_info.GetFieldOffset(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2088 | DataType::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2089 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2090 | { |
| 2091 | // We use a block to end the scratch scope before the write barrier, thus |
| 2092 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2093 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2094 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2095 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2096 | DCHECK(value.IsW()); |
| 2097 | Register temp = temps.AcquireW(); |
| 2098 | __ Mov(temp, value.W()); |
| 2099 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2100 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2101 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2102 | |
| 2103 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2104 | codegen_->StoreRelease( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2105 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check= */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2106 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2107 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2108 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2109 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2110 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2111 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2115 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2116 | } |
| 2117 | } |
| 2118 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2119 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2120 | DataType::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2121 | |
| 2122 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2123 | case DataType::Type::kInt32: |
| 2124 | case DataType::Type::kInt64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2125 | Register dst = OutputRegister(instr); |
| 2126 | Register lhs = InputRegisterAt(instr, 0); |
| 2127 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2128 | if (instr->IsAdd()) { |
| 2129 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2130 | } else if (instr->IsAnd()) { |
| 2131 | __ And(dst, lhs, rhs); |
| 2132 | } else if (instr->IsOr()) { |
| 2133 | __ Orr(dst, lhs, rhs); |
| 2134 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2135 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2136 | } else if (instr->IsRor()) { |
| 2137 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2138 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2139 | __ Ror(dst, lhs, shift); |
| 2140 | } else { |
| 2141 | // Ensure shift distance is in the same size register as the result. If |
| 2142 | // we are rotating a long and the shift comes in a w register originally, |
| 2143 | // we don't need to sxtw for use as an x since the shift distances are |
| 2144 | // all & reg_bits - 1. |
| 2145 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2146 | } |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2147 | } else if (instr->IsMin() || instr->IsMax()) { |
| 2148 | __ Cmp(lhs, rhs); |
| 2149 | __ Csel(dst, lhs, rhs, instr->IsMin() ? lt : gt); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2150 | } else { |
| 2151 | DCHECK(instr->IsXor()); |
| 2152 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2153 | } |
| 2154 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2155 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2156 | case DataType::Type::kFloat32: |
| 2157 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 2158 | VRegister dst = OutputFPRegister(instr); |
| 2159 | VRegister lhs = InputFPRegisterAt(instr, 0); |
| 2160 | VRegister rhs = InputFPRegisterAt(instr, 1); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2161 | if (instr->IsAdd()) { |
| 2162 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2163 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2164 | __ Fsub(dst, lhs, rhs); |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2165 | } else if (instr->IsMin()) { |
| 2166 | __ Fmin(dst, lhs, rhs); |
| 2167 | } else if (instr->IsMax()) { |
| 2168 | __ Fmax(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2169 | } else { |
| 2170 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
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 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2173 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2174 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2175 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2176 | } |
| 2177 | } |
| 2178 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2179 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2180 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2181 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2182 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2183 | DataType::Type type = instr->GetResultType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2184 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2185 | case DataType::Type::kInt32: |
| 2186 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2187 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2188 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2189 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2190 | break; |
| 2191 | } |
| 2192 | default: |
| 2193 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2194 | } |
| 2195 | } |
| 2196 | |
| 2197 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2198 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2199 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2200 | DataType::Type type = instr->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2201 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2202 | case DataType::Type::kInt32: |
| 2203 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2204 | Register dst = OutputRegister(instr); |
| 2205 | Register lhs = InputRegisterAt(instr, 0); |
| 2206 | Operand rhs = InputOperandAt(instr, 1); |
| 2207 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2208 | uint32_t shift_value = rhs.GetImmediate() & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2209 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2210 | if (instr->IsShl()) { |
| 2211 | __ Lsl(dst, lhs, shift_value); |
| 2212 | } else if (instr->IsShr()) { |
| 2213 | __ Asr(dst, lhs, shift_value); |
| 2214 | } else { |
| 2215 | __ Lsr(dst, lhs, shift_value); |
| 2216 | } |
| 2217 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2218 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2219 | |
| 2220 | if (instr->IsShl()) { |
| 2221 | __ Lsl(dst, lhs, rhs_reg); |
| 2222 | } else if (instr->IsShr()) { |
| 2223 | __ Asr(dst, lhs, rhs_reg); |
| 2224 | } else { |
| 2225 | __ Lsr(dst, lhs, rhs_reg); |
| 2226 | } |
| 2227 | } |
| 2228 | break; |
| 2229 | } |
| 2230 | default: |
| 2231 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2232 | } |
| 2233 | } |
| 2234 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2235 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2236 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2240 | HandleBinaryOp(instruction); |
| 2241 | } |
| 2242 | |
| 2243 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2244 | HandleBinaryOp(instruction); |
| 2245 | } |
| 2246 | |
| 2247 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2248 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2249 | } |
| 2250 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2251 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2252 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2253 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2254 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2255 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2256 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2257 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2258 | } |
| 2259 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2260 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2261 | Register dst = OutputRegister(instr); |
| 2262 | Register lhs = InputRegisterAt(instr, 0); |
| 2263 | Register rhs = InputRegisterAt(instr, 1); |
| 2264 | |
| 2265 | switch (instr->GetOpKind()) { |
| 2266 | case HInstruction::kAnd: |
| 2267 | __ Bic(dst, lhs, rhs); |
| 2268 | break; |
| 2269 | case HInstruction::kOr: |
| 2270 | __ Orn(dst, lhs, rhs); |
| 2271 | break; |
| 2272 | case HInstruction::kXor: |
| 2273 | __ Eon(dst, lhs, rhs); |
| 2274 | break; |
| 2275 | default: |
| 2276 | LOG(FATAL) << "Unreachable"; |
| 2277 | } |
| 2278 | } |
| 2279 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2280 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2281 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2282 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2283 | instruction->GetType() == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2284 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2285 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2286 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2287 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2288 | } else { |
| 2289 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2290 | } |
| 2291 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2292 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2293 | } |
| 2294 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2295 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2296 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2297 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2298 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2299 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2300 | Register out = OutputRegister(instruction); |
| 2301 | Register left; |
| 2302 | if (kind != HInstruction::kNeg) { |
| 2303 | left = InputRegisterAt(instruction, 0); |
| 2304 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2305 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2306 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2307 | // conversion) can have a different type from the current instruction's type, |
| 2308 | // so we manually indicate the type. |
| 2309 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2310 | Operand right_operand(0); |
| 2311 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2312 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2313 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2314 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2315 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2316 | right_operand = Operand(right_reg, |
| 2317 | helpers::ShiftFromOpKind(op_kind), |
| 2318 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | // Logical binary operations do not support extension operations in the |
| 2322 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2323 | // the extension as a separate instruction. |
| 2324 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2325 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2326 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2327 | kind != HInstruction::kNeg)); |
| 2328 | switch (kind) { |
| 2329 | case HInstruction::kAdd: |
| 2330 | __ Add(out, left, right_operand); |
| 2331 | break; |
| 2332 | case HInstruction::kAnd: |
| 2333 | __ And(out, left, right_operand); |
| 2334 | break; |
| 2335 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2336 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2337 | __ Neg(out, right_operand); |
| 2338 | break; |
| 2339 | case HInstruction::kOr: |
| 2340 | __ Orr(out, left, right_operand); |
| 2341 | break; |
| 2342 | case HInstruction::kSub: |
| 2343 | __ Sub(out, left, right_operand); |
| 2344 | break; |
| 2345 | case HInstruction::kXor: |
| 2346 | __ Eor(out, left, right_operand); |
| 2347 | break; |
| 2348 | default: |
| 2349 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2350 | UNREACHABLE(); |
| 2351 | } |
| 2352 | } |
| 2353 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2354 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2355 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2356 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2357 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2358 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2359 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2360 | } |
| 2361 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2362 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2363 | __ Add(OutputRegister(instruction), |
| 2364 | InputRegisterAt(instruction, 0), |
| 2365 | Operand(InputOperandAt(instruction, 1))); |
| 2366 | } |
| 2367 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2368 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2369 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2370 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2371 | |
| 2372 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2373 | |
| 2374 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2375 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2376 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2377 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2378 | // loop. |
| 2379 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2380 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2381 | : Location::RequiresRegister()); |
| 2382 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2383 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2384 | } |
| 2385 | |
| 2386 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2387 | HIntermediateAddressIndex* instruction) { |
| 2388 | Register index_reg = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2389 | uint32_t shift = Int64FromLocation(instruction->GetLocations()->InAt(2)); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2390 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2391 | |
| 2392 | if (shift == 0) { |
| 2393 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2394 | } else { |
| 2395 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2396 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2397 | } |
| 2398 | } |
| 2399 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2400 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2401 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2402 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2403 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2404 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2405 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2406 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2407 | // Don't allocate register for Mneg instruction. |
| 2408 | } else { |
| 2409 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2410 | Location::RequiresRegister()); |
| 2411 | } |
| 2412 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2413 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2414 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2415 | } |
| 2416 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2417 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2418 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2419 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2420 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2421 | |
| 2422 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2423 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2424 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2425 | if (instr->GetType() == DataType::Type::kInt64 && |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2426 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2427 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2428 | vixl::aarch64::Instruction* prev = |
| 2429 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2430 | if (prev->IsLoadOrStore()) { |
| 2431 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2432 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2433 | __ nop(); |
| 2434 | } |
| 2435 | } |
| 2436 | |
| 2437 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2438 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2439 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2440 | } else { |
| 2441 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2442 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2443 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2444 | __ Mneg(res, mul_left, mul_right); |
| 2445 | } else { |
| 2446 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2447 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2448 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2449 | } |
| 2450 | } |
| 2451 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2452 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2453 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2454 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2455 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2456 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2457 | object_array_get_with_read_barrier |
| 2458 | ? LocationSummary::kCallOnSlowPath |
| 2459 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2460 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2461 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2462 | if (instruction->GetIndex()->IsConstant()) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2463 | // Array loads with constant index are treated as field loads. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2464 | // We need a temporary register for the read barrier load in |
| 2465 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2466 | // only if the offset is too big. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2467 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2468 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2469 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2470 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2471 | locations->AddTemp(FixedTempLocation()); |
| 2472 | } |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2473 | } else if (!instruction->GetArray()->IsIntermediateAddress()) { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2474 | // We need a non-scratch temporary for the array data pointer in |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2475 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier() for the case with no |
| 2476 | // intermediate address. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2477 | locations->AddTemp(Location::RequiresRegister()); |
| 2478 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2479 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2480 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2481 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2482 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2483 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2484 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2485 | // The output overlaps in the case of an object array get with |
| 2486 | // read barriers enabled: we do not want the move to overwrite the |
| 2487 | // array's location, as we need it to emit the read barrier. |
| 2488 | locations->SetOut( |
| 2489 | Location::RequiresRegister(), |
| 2490 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2491 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2495 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2496 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2497 | LocationSummary* locations = instruction->GetLocations(); |
| 2498 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2499 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2500 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2501 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2502 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2503 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2504 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2505 | |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2506 | // The non-Baker read barrier instrumentation of object ArrayGet instructions |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2507 | // does not support the HIntermediateAddress instruction. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2508 | DCHECK(!((type == DataType::Type::kReference) && |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2509 | instruction->GetArray()->IsIntermediateAddress() && |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2510 | kEmitCompilerReadBarrier && |
| 2511 | !kUseBakerReadBarrier)); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2512 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2513 | if (type == DataType::Type::kReference && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2514 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2515 | // Note that a potential implicit null check is handled in the |
| 2516 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2517 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2518 | if (index.IsConstant()) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2519 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2520 | // 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] | 2521 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2522 | Location maybe_temp = |
| 2523 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2524 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2525 | out, |
| 2526 | obj.W(), |
| 2527 | offset, |
| 2528 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2529 | /* needs_null_check= */ false, |
| 2530 | /* use_load_acquire= */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2531 | } else { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2532 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2533 | instruction, out, obj.W(), offset, index, /* needs_null_check= */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2534 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2535 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2536 | // General case. |
| 2537 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2538 | Register length; |
| 2539 | if (maybe_compressed_char_at) { |
| 2540 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2541 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2542 | { |
| 2543 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2544 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2545 | |
| 2546 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2547 | DCHECK_LT(count_offset, offset); |
| 2548 | int64_t adjusted_offset = |
| 2549 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2550 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2551 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2552 | } else { |
| 2553 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2554 | } |
| 2555 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2556 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2557 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2558 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2559 | if (maybe_compressed_char_at) { |
| 2560 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2561 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2562 | "Expecting 0=compressed, 1=uncompressed"); |
| 2563 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2564 | __ Ldrb(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2565 | HeapOperand(obj, offset + Int64FromLocation(index))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2566 | __ B(&done); |
| 2567 | __ Bind(&uncompressed_load); |
| 2568 | __ Ldrh(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2569 | HeapOperand(obj, offset + (Int64FromLocation(index) << 1))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2570 | __ Bind(&done); |
| 2571 | } else { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2572 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2573 | source = HeapOperand(obj, offset); |
| 2574 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2575 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2576 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2577 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2578 | // We do not need to compute the intermediate address from the array: the |
| 2579 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2580 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2581 | if (kIsDebugBuild) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2582 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2583 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2584 | } |
| 2585 | temp = obj; |
| 2586 | } else { |
| 2587 | __ Add(temp, obj, offset); |
| 2588 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2589 | if (maybe_compressed_char_at) { |
| 2590 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2591 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2592 | "Expecting 0=compressed, 1=uncompressed"); |
| 2593 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2594 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2595 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2596 | __ B(&done); |
| 2597 | __ Bind(&uncompressed_load); |
| 2598 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2599 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2600 | __ Bind(&done); |
| 2601 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2602 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2603 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2604 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2605 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2606 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2607 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2608 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2609 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2610 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2611 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2612 | if (type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2613 | static_assert( |
| 2614 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2615 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2616 | Location obj_loc = locations->InAt(0); |
| 2617 | if (index.IsConstant()) { |
| 2618 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2619 | } else { |
| 2620 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2621 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2622 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2623 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2624 | } |
| 2625 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2626 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2627 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2628 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2629 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2633 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2634 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2635 | { |
| 2636 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2637 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2638 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2639 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2640 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2641 | // Mask out compression flag from String's array length. |
| 2642 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2643 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2644 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2645 | } |
| 2646 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2647 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2648 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2649 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2650 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2651 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2652 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2653 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2654 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2655 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2656 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2657 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2658 | } else if (DataType::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2659 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2660 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2661 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2662 | } |
| 2663 | } |
| 2664 | |
| 2665 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2666 | DataType::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2667 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2668 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2669 | bool needs_write_barrier = |
| 2670 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2671 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2672 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2673 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2674 | CPURegister source = value; |
| 2675 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2676 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2677 | MemOperand destination = HeapOperand(array); |
| 2678 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2679 | |
| 2680 | if (!needs_write_barrier) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2681 | DCHECK(!needs_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2682 | if (index.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2683 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2684 | destination = HeapOperand(array, offset); |
| 2685 | } else { |
| 2686 | UseScratchRegisterScope temps(masm); |
| 2687 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2688 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2689 | // We do not need to compute the intermediate address from the array: the |
| 2690 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2691 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2692 | if (kIsDebugBuild) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2693 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2694 | DCHECK(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2695 | } |
| 2696 | temp = array; |
| 2697 | } else { |
| 2698 | __ Add(temp, array, offset); |
| 2699 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2700 | destination = HeapOperand(temp, |
| 2701 | XRegisterFrom(index), |
| 2702 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2703 | DataType::SizeShift(value_type)); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2704 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2705 | { |
| 2706 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2707 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2708 | codegen_->Store(value_type, value, destination); |
| 2709 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2710 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2711 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2712 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2713 | |
| 2714 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 2715 | vixl::aarch64::Label do_store; |
| 2716 | if (can_value_be_null) { |
| 2717 | __ Cbz(Register(value), &do_store); |
| 2718 | } |
| 2719 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2720 | SlowPathCodeARM64* slow_path = nullptr; |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2721 | if (needs_type_check) { |
| 2722 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
| 2723 | codegen_->AddSlowPath(slow_path); |
| 2724 | |
| 2725 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2726 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2727 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2728 | |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2729 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2730 | Register temp = temps.AcquireSameSizeAs(array); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2731 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2732 | |
| 2733 | // Note that when Baker read barriers are enabled, the type |
| 2734 | // checks are performed without read barriers. This is fine, |
| 2735 | // even in the case where a class object is in the from-space |
| 2736 | // after the flip, as a comparison involving such a type would |
| 2737 | // not produce a false positive; it may of course produce a |
| 2738 | // false negative, in which case we would take the ArraySet |
| 2739 | // slow path. |
| 2740 | |
| 2741 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2742 | { |
| 2743 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2744 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2745 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2746 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
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 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2749 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2750 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2751 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2752 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2753 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2754 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2755 | // nor `temp2`, as we are comparing two poisoned references. |
| 2756 | __ Cmp(temp, temp2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2757 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2758 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2759 | vixl::aarch64::Label do_put; |
| 2760 | __ B(eq, &do_put); |
| 2761 | // If heap poisoning is enabled, the `temp` reference has |
| 2762 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2763 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2764 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2765 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2766 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2767 | // If heap poisoning is enabled, no need to unpoison |
| 2768 | // `temp`, as we are comparing against null below. |
| 2769 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2770 | __ Bind(&do_put); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 2771 | } else { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2772 | __ B(ne, slow_path->GetEntryLabel()); |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2773 | } |
| 2774 | } |
| 2775 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2776 | codegen_->MarkGCCard(array, value.W(), /* value_can_be_null= */ false); |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2777 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2778 | if (can_value_be_null) { |
| 2779 | DCHECK(do_store.IsLinked()); |
| 2780 | __ Bind(&do_store); |
| 2781 | } |
| 2782 | |
| 2783 | UseScratchRegisterScope temps(masm); |
| 2784 | if (kPoisonHeapReferences) { |
| 2785 | Register temp_source = temps.AcquireSameSizeAs(array); |
| 2786 | DCHECK(value.IsW()); |
| 2787 | __ Mov(temp_source, value.W()); |
| 2788 | GetAssembler()->PoisonHeapReference(temp_source); |
| 2789 | source = temp_source; |
| 2790 | } |
| 2791 | |
| 2792 | if (index.IsConstant()) { |
| 2793 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
| 2794 | destination = HeapOperand(array, offset); |
| 2795 | } else { |
| 2796 | Register temp_base = temps.AcquireSameSizeAs(array); |
| 2797 | __ Add(temp_base, array, offset); |
| 2798 | destination = HeapOperand(temp_base, |
| 2799 | XRegisterFrom(index), |
| 2800 | LSL, |
| 2801 | DataType::SizeShift(value_type)); |
| 2802 | } |
| 2803 | |
| 2804 | { |
| 2805 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2806 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2807 | __ Str(source, destination); |
| 2808 | |
| 2809 | if (can_value_be_null || !needs_type_check) { |
| 2810 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2811 | } |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | if (slow_path != nullptr) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2815 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2816 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2817 | } |
| 2818 | } |
| 2819 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2820 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2821 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2822 | InvokeRuntimeCallingConvention calling_convention; |
| 2823 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 2824 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 2825 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2826 | |
| 2827 | // If both index and length are constant, we can check the bounds statically and |
| 2828 | // generate code accordingly. We want to make sure we generate constant locations |
| 2829 | // in that case, regardless of whether they are encodable in the comparison or not. |
| 2830 | HInstruction* index = instruction->InputAt(0); |
| 2831 | HInstruction* length = instruction->InputAt(1); |
| 2832 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 2833 | locations->SetInAt(0, both_const |
| 2834 | ? Location::ConstantLocation(index->AsConstant()) |
| 2835 | : ARM64EncodableConstantOrRegister(index, instruction)); |
| 2836 | locations->SetInAt(1, both_const |
| 2837 | ? Location::ConstantLocation(length->AsConstant()) |
| 2838 | : ARM64EncodableConstantOrRegister(length, instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2842 | LocationSummary* locations = instruction->GetLocations(); |
| 2843 | Location index_loc = locations->InAt(0); |
| 2844 | Location length_loc = locations->InAt(1); |
| 2845 | |
| 2846 | int cmp_first_input = 0; |
| 2847 | int cmp_second_input = 1; |
| 2848 | Condition cond = hs; |
| 2849 | |
| 2850 | if (index_loc.IsConstant()) { |
| 2851 | int64_t index = Int64FromLocation(index_loc); |
| 2852 | if (length_loc.IsConstant()) { |
| 2853 | int64_t length = Int64FromLocation(length_loc); |
| 2854 | if (index < 0 || index >= length) { |
| 2855 | BoundsCheckSlowPathARM64* slow_path = |
| 2856 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
| 2857 | codegen_->AddSlowPath(slow_path); |
| 2858 | __ B(slow_path->GetEntryLabel()); |
| 2859 | } else { |
| 2860 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 2861 | // However, some optimization after BCE may have generated this, and we should not |
| 2862 | // generate a bounds check if it is a valid range. |
| 2863 | } |
| 2864 | return; |
| 2865 | } |
| 2866 | // Only the index is constant: change the order of the operands and commute the condition |
| 2867 | // so we can use an immediate constant for the index (only the second input to a cmp |
| 2868 | // instruction can be an immediate). |
| 2869 | cmp_first_input = 1; |
| 2870 | cmp_second_input = 0; |
| 2871 | cond = ls; |
| 2872 | } |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2873 | BoundsCheckSlowPathARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2874 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2875 | __ Cmp(InputRegisterAt(instruction, cmp_first_input), |
| 2876 | InputOperandAt(instruction, cmp_second_input)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2877 | codegen_->AddSlowPath(slow_path); |
Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2878 | __ B(slow_path->GetEntryLabel(), cond); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2879 | } |
| 2880 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2881 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2882 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2883 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2884 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2885 | if (check->HasUses()) { |
| 2886 | locations->SetOut(Location::SameAsFirstInput()); |
| 2887 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 2888 | // Rely on the type initialization to save everything we need. |
| 2889 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2890 | } |
| 2891 | |
| 2892 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2893 | // We assume the class is not null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 2894 | SlowPathCodeARM64* slow_path = |
| 2895 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(check->GetLoadClass(), check); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2896 | codegen_->AddSlowPath(slow_path); |
| 2897 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2898 | } |
| 2899 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2900 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2901 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2902 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2903 | } |
| 2904 | |
| 2905 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 2906 | VRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2907 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2908 | if (rhs_loc.IsConstant()) { |
| 2909 | // 0.0 is the only immediate that can be encoded directly in |
| 2910 | // an FCMP instruction. |
| 2911 | // |
| 2912 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2913 | // specify that in a floating-point comparison, positive zero |
| 2914 | // and negative zero are considered equal, so we can use the |
| 2915 | // literal 0.0 for both cases here. |
| 2916 | // |
| 2917 | // Note however that some methods (Float.equal, Float.compare, |
| 2918 | // Float.compareTo, Double.equal, Double.compare, |
| 2919 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2920 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2921 | // -0.0. So if we ever translate calls to these methods into a |
| 2922 | // HCompare instruction, we must handle the -0.0 case with |
| 2923 | // care here. |
| 2924 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2925 | __ Fcmp(lhs_reg, 0.0); |
| 2926 | } else { |
| 2927 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2928 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2929 | } |
| 2930 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2931 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2932 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2933 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2934 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2935 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2936 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2937 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2938 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2939 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2940 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2941 | case DataType::Type::kInt32: |
| 2942 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2943 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2944 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2945 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2946 | break; |
| 2947 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2948 | case DataType::Type::kFloat32: |
| 2949 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2950 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2951 | locations->SetInAt(1, |
| 2952 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2953 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2954 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2955 | locations->SetOut(Location::RequiresRegister()); |
| 2956 | break; |
| 2957 | } |
| 2958 | default: |
| 2959 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2964 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2965 | |
| 2966 | // 0 if: left == right |
| 2967 | // 1 if: left > right |
| 2968 | // -1 if: left < right |
| 2969 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2970 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2971 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2972 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2973 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2974 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2975 | case DataType::Type::kInt32: |
| 2976 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2977 | Register result = OutputRegister(compare); |
| 2978 | Register left = InputRegisterAt(compare, 0); |
| 2979 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2980 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2981 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 2982 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2983 | break; |
| 2984 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2985 | case DataType::Type::kFloat32: |
| 2986 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2987 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2988 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2989 | __ Cset(result, ne); |
| 2990 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2991 | break; |
| 2992 | } |
| 2993 | default: |
| 2994 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2995 | } |
| 2996 | } |
| 2997 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2998 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2999 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3000 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3001 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3002 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3003 | locations->SetInAt(1, |
| 3004 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3005 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3006 | : Location::RequiresFpuRegister()); |
| 3007 | } else { |
| 3008 | // Integer cases. |
| 3009 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3010 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3011 | } |
| 3012 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3013 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3014 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3015 | } |
| 3016 | } |
| 3017 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3018 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3019 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3020 | return; |
| 3021 | } |
| 3022 | |
| 3023 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3024 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3025 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3026 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3027 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3028 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3029 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3030 | } else { |
| 3031 | // Integer cases. |
| 3032 | Register lhs = InputRegisterAt(instruction, 0); |
| 3033 | Operand rhs = InputOperandAt(instruction, 1); |
| 3034 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3035 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3036 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3040 | M(Equal) \ |
| 3041 | M(NotEqual) \ |
| 3042 | M(LessThan) \ |
| 3043 | M(LessThanOrEqual) \ |
| 3044 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3045 | M(GreaterThanOrEqual) \ |
| 3046 | M(Below) \ |
| 3047 | M(BelowOrEqual) \ |
| 3048 | M(Above) \ |
| 3049 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3050 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3051 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3052 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3053 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3054 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3055 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3056 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3057 | void InstructionCodeGeneratorARM64::GenerateIntDivForPower2Denom(HDiv* instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3058 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3059 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3060 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 3061 | |
| 3062 | Register out = OutputRegister(instruction); |
| 3063 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3064 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3065 | Register final_dividend; |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3066 | if (HasNonNegativeOrMinIntInputAt(instruction, 0)) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3067 | // No need to adjust the result for non-negative dividends or the INT32_MIN/INT64_MIN dividends. |
| 3068 | // NOTE: The generated code for HDiv correctly works for the INT32_MIN/INT64_MIN dividends: |
| 3069 | // imm == 2 |
| 3070 | // add out, dividend(0x80000000), dividend(0x80000000), lsr #31 => out = 0x80000001 |
| 3071 | // asr out, out(0x80000001), #1 => out = 0xc0000000 |
| 3072 | // This is the same as 'asr out, 0x80000000, #1' |
| 3073 | // |
| 3074 | // imm > 2 |
| 3075 | // add temp, dividend(0x80000000), imm - 1 => temp = 0b10..01..1, where the number |
| 3076 | // of the rightmost 1s is ctz_imm. |
| 3077 | // cmp dividend(0x80000000), 0 => N = 1, V = 0 (lt is true) |
| 3078 | // csel out, temp(0b10..01..1), dividend(0x80000000), lt => out = 0b10..01..1 |
| 3079 | // asr out, out(0b10..01..1), #ctz_imm => out = 0b1..10..0, where the number of the |
| 3080 | // leftmost 1s is ctz_imm + 1. |
| 3081 | // This is the same as 'asr out, dividend(0x80000000), #ctz_imm'. |
| 3082 | // |
| 3083 | // imm == INT32_MIN |
| 3084 | // add tmp, dividend(0x80000000), #0x7fffffff => tmp = -1 |
| 3085 | // cmp dividend(0x80000000), 0 => N = 1, V = 0 (lt is true) |
| 3086 | // csel out, temp(-1), dividend(0x80000000), lt => out = -1 |
| 3087 | // neg out, out(-1), asr #31 => out = 1 |
| 3088 | // This is the same as 'neg out, dividend(0x80000000), asr #31'. |
| 3089 | final_dividend = dividend; |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3090 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3091 | if (abs_imm == 2) { |
| 3092 | int bits = DataType::Size(instruction->GetResultType()) * kBitsPerByte; |
| 3093 | __ Add(out, dividend, Operand(dividend, LSR, bits - 1)); |
| 3094 | } else { |
| 3095 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3096 | Register temp = temps.AcquireSameSizeAs(out); |
| 3097 | __ Add(temp, dividend, abs_imm - 1); |
| 3098 | __ Cmp(dividend, 0); |
| 3099 | __ Csel(out, temp, dividend, lt); |
| 3100 | } |
| 3101 | final_dividend = out; |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3102 | } |
| 3103 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3104 | int ctz_imm = CTZ(abs_imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3105 | if (imm > 0) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3106 | __ Asr(out, final_dividend, ctz_imm); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3107 | } else { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 3108 | __ Neg(out, Operand(final_dividend, ASR, ctz_imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3109 | } |
| 3110 | } |
| 3111 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3112 | // Return true if the magic number was modified by subtracting 2^32(Int32 div) or 2^64(Int64 div). |
| 3113 | // So dividend needs to be added. |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3114 | static inline bool NeedToAddDividend(int64_t magic_number, int64_t divisor) { |
| 3115 | return divisor > 0 && magic_number < 0; |
| 3116 | } |
| 3117 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3118 | // Return true if the magic number was modified by adding 2^32(Int32 div) or 2^64(Int64 div). |
| 3119 | // So dividend needs to be subtracted. |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3120 | static inline bool NeedToSubDividend(int64_t magic_number, int64_t divisor) { |
| 3121 | return divisor < 0 && magic_number > 0; |
| 3122 | } |
| 3123 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3124 | // Generate code which increments the value in register 'in' by 1 if the value is negative. |
| 3125 | // It is done with 'add out, in, in, lsr #31 or #63'. |
| 3126 | // If the value is a result of an operation setting the N flag, CINC MI can be used |
| 3127 | // instead of ADD. 'use_cond_inc' controls this. |
| 3128 | void InstructionCodeGeneratorARM64::GenerateIncrementNegativeByOne( |
| 3129 | Register out, |
| 3130 | Register in, |
| 3131 | bool use_cond_inc) { |
| 3132 | if (use_cond_inc) { |
| 3133 | __ Cinc(out, in, mi); |
| 3134 | } else { |
| 3135 | __ Add(out, in, Operand(in, LSR, in.GetSizeInBits() - 1)); |
| 3136 | } |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3137 | } |
| 3138 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3139 | // Helper to generate code producing the result of HRem with a constant divisor. |
| 3140 | void InstructionCodeGeneratorARM64::GenerateResultRemWithAnyConstant( |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3141 | Register out, |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3142 | Register dividend, |
| 3143 | Register quotient, |
| 3144 | int64_t divisor, |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3145 | UseScratchRegisterScope* temps_scope) { |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3146 | Register temp_imm = temps_scope->AcquireSameSizeAs(out); |
| 3147 | __ Mov(temp_imm, divisor); |
| 3148 | __ Msub(out, quotient, temp_imm, dividend); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3149 | } |
| 3150 | |
| 3151 | void InstructionCodeGeneratorARM64::GenerateInt64DivRemWithAnyConstant( |
| 3152 | HBinaryOperation* instruction) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3153 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3154 | DCHECK(instruction->GetResultType() == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3155 | |
| 3156 | LocationSummary* locations = instruction->GetLocations(); |
| 3157 | Location second = locations->InAt(1); |
| 3158 | DCHECK(second.IsConstant()); |
| 3159 | |
| 3160 | Register out = OutputRegister(instruction); |
| 3161 | Register dividend = InputRegisterAt(instruction, 0); |
| 3162 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3163 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3164 | int64_t magic; |
| 3165 | int shift; |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3166 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ true, &magic, &shift); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3167 | |
| 3168 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3169 | Register temp = temps.AcquireSameSizeAs(out); |
| 3170 | |
| 3171 | // temp = get_high(dividend * magic) |
| 3172 | __ Mov(temp, magic); |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3173 | __ Smulh(temp, dividend, temp); |
| 3174 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3175 | // The multiplication result might need some corrections to be finalized. |
| 3176 | // The last correction is to increment by 1, if the result is negative. |
| 3177 | // Currently it is done with 'add result, temp_result, temp_result, lsr #31 or #63'. |
| 3178 | // Such ADD usually has latency 2, e.g. on Cortex-A55. |
| 3179 | // However if one of the corrections is ADD or SUB, the sign can be detected |
| 3180 | // with ADDS/SUBS. They set the N flag if the result is negative. |
| 3181 | // This allows to use CINC MI which has latency 1. |
| 3182 | bool use_cond_inc = false; |
| 3183 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3184 | // Some combinations of magic_number and the divisor require to correct the result. |
| 3185 | // Check whether the correction is needed. |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3186 | if (NeedToAddDividend(magic, imm)) { |
| 3187 | __ Adds(temp, temp, dividend); |
| 3188 | use_cond_inc = true; |
| 3189 | } else if (NeedToSubDividend(magic, imm)) { |
| 3190 | __ Subs(temp, temp, dividend); |
| 3191 | use_cond_inc = true; |
| 3192 | } |
| 3193 | |
| 3194 | if (shift != 0) { |
| 3195 | __ Asr(temp, temp, shift); |
| 3196 | } |
| 3197 | |
| 3198 | if (instruction->IsRem()) { |
| 3199 | GenerateIncrementNegativeByOne(temp, temp, use_cond_inc); |
| 3200 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3201 | } else { |
| 3202 | GenerateIncrementNegativeByOne(out, temp, use_cond_inc); |
| 3203 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3204 | } |
| 3205 | |
| 3206 | void InstructionCodeGeneratorARM64::GenerateInt32DivRemWithAnyConstant( |
| 3207 | HBinaryOperation* instruction) { |
| 3208 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3209 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 3210 | |
| 3211 | LocationSummary* locations = instruction->GetLocations(); |
| 3212 | Location second = locations->InAt(1); |
| 3213 | DCHECK(second.IsConstant()); |
| 3214 | |
| 3215 | Register out = OutputRegister(instruction); |
| 3216 | Register dividend = InputRegisterAt(instruction, 0); |
| 3217 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3218 | |
| 3219 | int64_t magic; |
| 3220 | int shift; |
| 3221 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| 3222 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3223 | Register temp = temps.AcquireSameSizeAs(out); |
| 3224 | |
| 3225 | // temp = get_high(dividend * magic) |
| 3226 | __ Mov(temp, magic); |
| 3227 | __ Smull(temp.X(), dividend, temp); |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3228 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3229 | // The multiplication result might need some corrections to be finalized. |
| 3230 | // The last correction is to increment by 1, if the result is negative. |
| 3231 | // Currently it is done with 'add result, temp_result, temp_result, lsr #31 or #63'. |
| 3232 | // Such ADD usually has latency 2, e.g. on Cortex-A55. |
| 3233 | // However if one of the corrections is ADD or SUB, the sign can be detected |
| 3234 | // with ADDS/SUBS. They set the N flag if the result is negative. |
| 3235 | // This allows to use CINC MI which has latency 1. |
| 3236 | bool use_cond_inc = false; |
| 3237 | |
| 3238 | // ADD/SUB correction is performed in the high 32 bits |
| 3239 | // as high 32 bits are ignored because type are kInt32. |
| 3240 | if (NeedToAddDividend(magic, imm)) { |
| 3241 | __ Adds(temp.X(), temp.X(), Operand(dividend.X(), LSL, 32)); |
| 3242 | use_cond_inc = true; |
| 3243 | } else if (NeedToSubDividend(magic, imm)) { |
| 3244 | __ Subs(temp.X(), temp.X(), Operand(dividend.X(), LSL, 32)); |
| 3245 | use_cond_inc = true; |
Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3246 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3247 | |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3248 | // Extract the result from the high 32 bits and apply the final right shift. |
| 3249 | DCHECK_LT(shift, 32); |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 3250 | if (imm > 0 && HasNonNegativeInputAt(instruction, 0)) { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 3251 | // No need to adjust the result for a non-negative dividend and a positive divisor. |
| 3252 | if (instruction->IsDiv()) { |
| 3253 | __ Lsr(out.X(), temp.X(), 32 + shift); |
| 3254 | } else { |
| 3255 | __ Lsr(temp.X(), temp.X(), 32 + shift); |
| 3256 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3257 | } |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3258 | } else { |
Evgeny Astigeevich | f938841 | 2020-07-02 15:25:13 +0100 | [diff] [blame] | 3259 | __ Asr(temp.X(), temp.X(), 32 + shift); |
| 3260 | |
| 3261 | if (instruction->IsRem()) { |
| 3262 | GenerateIncrementNegativeByOne(temp, temp, use_cond_inc); |
| 3263 | GenerateResultRemWithAnyConstant(out, dividend, temp, imm, &temps); |
| 3264 | } else { |
| 3265 | GenerateIncrementNegativeByOne(out, temp, use_cond_inc); |
| 3266 | } |
Evgeny Astigeevich | 0ddb338 | 2020-05-18 11:15:46 +0100 | [diff] [blame] | 3267 | } |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3271 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3272 | if (instruction->GetResultType() == DataType::Type::kInt64) { |
| 3273 | GenerateInt64DivRemWithAnyConstant(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3274 | } else { |
Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3275 | GenerateInt32DivRemWithAnyConstant(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3276 | } |
| 3277 | } |
| 3278 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3279 | void InstructionCodeGeneratorARM64::GenerateIntDivForConstDenom(HDiv *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3280 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
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 (imm == 0) { |
| 3283 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3284 | return; |
| 3285 | } |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3286 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3287 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3288 | GenerateIntDivForPower2Denom(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3289 | } else { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3290 | // Cases imm == -1 or imm == 1 are handled by InstructionSimplifier. |
| 3291 | DCHECK(imm < -2 || imm > 2) << imm; |
| 3292 | GenerateDivRemWithAnyConstant(instruction); |
| 3293 | } |
| 3294 | } |
| 3295 | |
| 3296 | void InstructionCodeGeneratorARM64::GenerateIntDiv(HDiv *instruction) { |
| 3297 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 3298 | << instruction->GetResultType(); |
| 3299 | |
| 3300 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 3301 | GenerateIntDivForConstDenom(instruction); |
| 3302 | } else { |
| 3303 | Register out = OutputRegister(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3304 | Register dividend = InputRegisterAt(instruction, 0); |
| 3305 | Register divisor = InputRegisterAt(instruction, 1); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3306 | __ Sdiv(out, dividend, divisor); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3307 | } |
| 3308 | } |
| 3309 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3310 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3311 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3312 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3313 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3314 | case DataType::Type::kInt32: |
| 3315 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3316 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3317 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3318 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3319 | break; |
| 3320 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3321 | case DataType::Type::kFloat32: |
| 3322 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3323 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3324 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3325 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3326 | break; |
| 3327 | |
| 3328 | default: |
| 3329 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3330 | } |
| 3331 | } |
| 3332 | |
| 3333 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3334 | DataType::Type type = div->GetResultType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3335 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3336 | case DataType::Type::kInt32: |
| 3337 | case DataType::Type::kInt64: |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3338 | GenerateIntDiv(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3339 | break; |
| 3340 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3341 | case DataType::Type::kFloat32: |
| 3342 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3343 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3344 | break; |
| 3345 | |
| 3346 | default: |
| 3347 | LOG(FATAL) << "Unexpected div type " << type; |
| 3348 | } |
| 3349 | } |
| 3350 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3351 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3352 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3353 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3357 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3358 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3359 | codegen_->AddSlowPath(slow_path); |
| 3360 | Location value = instruction->GetLocations()->InAt(0); |
| 3361 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3362 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3363 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3364 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3365 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3366 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3367 | } |
| 3368 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3369 | if (value.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3370 | int64_t divisor = Int64FromLocation(value); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3371 | if (divisor == 0) { |
| 3372 | __ B(slow_path->GetEntryLabel()); |
| 3373 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3374 | // A division by a non-null constant is valid. We don't need to perform |
| 3375 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3376 | } |
| 3377 | } else { |
| 3378 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3379 | } |
| 3380 | } |
| 3381 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3382 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3383 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3384 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3385 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3386 | } |
| 3387 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3388 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3389 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3390 | // Will be generated at use site. |
| 3391 | } |
| 3392 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3393 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3394 | exit->SetLocations(nullptr); |
| 3395 | } |
| 3396 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3397 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3398 | } |
| 3399 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3400 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3401 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3402 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3403 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3404 | } |
| 3405 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3406 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3407 | // Will be generated at use site. |
| 3408 | } |
| 3409 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3410 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3411 | if (successor->IsExitBlock()) { |
| 3412 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3413 | return; // no code needed |
| 3414 | } |
| 3415 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3416 | HBasicBlock* block = got->GetBlock(); |
| 3417 | HInstruction* previous = got->GetPrevious(); |
| 3418 | HLoopInformation* info = block->GetLoopInformation(); |
| 3419 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3420 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 3421 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3422 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3423 | return; |
| 3424 | } |
| 3425 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3426 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3427 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3428 | } |
| 3429 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3430 | __ B(codegen_->GetLabelOf(successor)); |
| 3431 | } |
| 3432 | } |
| 3433 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3434 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3435 | got->SetLocations(nullptr); |
| 3436 | } |
| 3437 | |
| 3438 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3439 | HandleGoto(got, got->GetSuccessor()); |
| 3440 | } |
| 3441 | |
| 3442 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3443 | try_boundary->SetLocations(nullptr); |
| 3444 | } |
| 3445 | |
| 3446 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3447 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3448 | if (!successor->IsExitBlock()) { |
| 3449 | HandleGoto(try_boundary, successor); |
| 3450 | } |
| 3451 | } |
| 3452 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3453 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3454 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3455 | vixl::aarch64::Label* true_target, |
| 3456 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3457 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3458 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3459 | if (true_target == nullptr && false_target == nullptr) { |
| 3460 | // Nothing to do. The code always falls through. |
| 3461 | return; |
| 3462 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3463 | // Constant condition, statically compared against "true" (integer value 1). |
| 3464 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3465 | if (true_target != nullptr) { |
| 3466 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3467 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3468 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3469 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3470 | if (false_target != nullptr) { |
| 3471 | __ B(false_target); |
| 3472 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3473 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3474 | return; |
| 3475 | } |
| 3476 | |
| 3477 | // The following code generates these patterns: |
| 3478 | // (1) true_target == nullptr && false_target != nullptr |
| 3479 | // - opposite condition true => branch to false_target |
| 3480 | // (2) true_target != nullptr && false_target == nullptr |
| 3481 | // - condition true => branch to true_target |
| 3482 | // (3) true_target != nullptr && false_target != nullptr |
| 3483 | // - condition true => branch to true_target |
| 3484 | // - branch to false_target |
| 3485 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3486 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3487 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3488 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3489 | if (true_target == nullptr) { |
| 3490 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3491 | } else { |
| 3492 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3493 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3494 | } else { |
| 3495 | // The condition instruction has not been materialized, use its inputs as |
| 3496 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3497 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3498 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3499 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3500 | if (DataType::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3501 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3502 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3503 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3504 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3505 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3506 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3507 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3508 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3509 | // Integer cases. |
| 3510 | Register lhs = InputRegisterAt(condition, 0); |
| 3511 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3512 | |
| 3513 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3514 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3515 | if (true_target == nullptr) { |
| 3516 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3517 | non_fallthrough_target = false_target; |
| 3518 | } else { |
| 3519 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3520 | non_fallthrough_target = true_target; |
| 3521 | } |
| 3522 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3523 | 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] | 3524 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3525 | switch (arm64_cond) { |
| 3526 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3527 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3528 | break; |
| 3529 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3530 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3531 | break; |
| 3532 | case lt: |
| 3533 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3534 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3535 | break; |
| 3536 | case ge: |
| 3537 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3538 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3539 | break; |
| 3540 | default: |
| 3541 | // Without the `static_cast` the compiler throws an error for |
| 3542 | // `-Werror=sign-promo`. |
| 3543 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3544 | } |
| 3545 | } else { |
| 3546 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3547 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3548 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3549 | } |
| 3550 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3551 | |
| 3552 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3553 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3554 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3555 | __ B(false_target); |
| 3556 | } |
| 3557 | } |
| 3558 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3559 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3560 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3561 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3562 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3563 | } |
| 3564 | } |
| 3565 | |
| 3566 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3567 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3568 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3569 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3570 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3571 | true_target = nullptr; |
| 3572 | } |
| 3573 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3574 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3575 | false_target = nullptr; |
| 3576 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3577 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3578 | } |
| 3579 | |
| 3580 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3581 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3582 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3583 | InvokeRuntimeCallingConvention calling_convention; |
| 3584 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3585 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3586 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3587 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3588 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3589 | } |
| 3590 | } |
| 3591 | |
| 3592 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3593 | SlowPathCodeARM64* slow_path = |
| 3594 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3595 | GenerateTestAndBranch(deoptimize, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3596 | /* condition_input_index= */ 0, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3597 | slow_path->GetEntryLabel(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3598 | /* false_target= */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3599 | } |
| 3600 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3601 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3602 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3603 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3604 | locations->SetOut(Location::RequiresRegister()); |
| 3605 | } |
| 3606 | |
| 3607 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3608 | __ Ldr(OutputRegister(flag), |
| 3609 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3610 | } |
| 3611 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3612 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3613 | return condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3614 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3615 | } |
| 3616 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3617 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3618 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3619 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3620 | : ARM64Condition(cond); |
| 3621 | } |
| 3622 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3623 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3624 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3625 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3626 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3627 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3628 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3629 | } else { |
| 3630 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3631 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3632 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3633 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3634 | // Ask VIXL whether we should synthesize constants in registers. |
| 3635 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3636 | Operand true_op = is_true_value_constant ? |
| 3637 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3638 | Operand false_op = is_false_value_constant ? |
| 3639 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3640 | bool true_value_in_register = false; |
| 3641 | bool false_value_in_register = false; |
| 3642 | MacroAssembler::GetCselSynthesisInformation( |
| 3643 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3644 | true_value_in_register |= !is_true_value_constant; |
| 3645 | false_value_in_register |= !is_false_value_constant; |
| 3646 | |
| 3647 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3648 | : Location::ConstantLocation(cst_true_value)); |
| 3649 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3650 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3651 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3652 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3653 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3654 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3655 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3656 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3660 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3661 | Condition csel_cond; |
| 3662 | |
| 3663 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3664 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3665 | // Use the condition flags set by the previous instruction. |
| 3666 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3667 | } else { |
| 3668 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3669 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3670 | } |
| 3671 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3672 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3673 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3674 | } else { |
| 3675 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3676 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3677 | } |
| 3678 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3679 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3680 | __ Fcsel(OutputFPRegister(select), |
| 3681 | InputFPRegisterAt(select, 1), |
| 3682 | InputFPRegisterAt(select, 0), |
| 3683 | csel_cond); |
| 3684 | } else { |
| 3685 | __ Csel(OutputRegister(select), |
| 3686 | InputOperandAt(select, 1), |
| 3687 | InputOperandAt(select, 0), |
| 3688 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3689 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3690 | } |
| 3691 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3692 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3693 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3694 | } |
| 3695 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3696 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3697 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3698 | } |
| 3699 | |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 3700 | void CodeGeneratorARM64::IncreaseFrame(size_t adjustment) { |
| 3701 | __ Claim(adjustment); |
| 3702 | GetAssembler()->cfi().AdjustCFAOffset(adjustment); |
| 3703 | } |
| 3704 | |
| 3705 | void CodeGeneratorARM64::DecreaseFrame(size_t adjustment) { |
| 3706 | __ Drop(adjustment); |
| 3707 | GetAssembler()->cfi().AdjustCFAOffset(-adjustment); |
| 3708 | } |
| 3709 | |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3710 | void CodeGeneratorARM64::GenerateNop() { |
| 3711 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3712 | } |
| 3713 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3714 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3715 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3716 | } |
| 3717 | |
| 3718 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3719 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3720 | } |
| 3721 | |
| 3722 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3723 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3727 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3728 | } |
| 3729 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3730 | // Temp is used for read barrier. |
| 3731 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3732 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3733 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3734 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3735 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3736 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3737 | return 1; |
| 3738 | } |
| 3739 | return 0; |
| 3740 | } |
| 3741 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3742 | // 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] | 3743 | // interface pointer, one for loading the current interface. |
| 3744 | // The other checks have one temp for loading the object's class. |
| 3745 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3746 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3747 | return 3; |
| 3748 | } |
| 3749 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3750 | } |
| 3751 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3752 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3753 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3754 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3755 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3756 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3757 | case TypeCheckKind::kExactCheck: |
| 3758 | case TypeCheckKind::kAbstractClassCheck: |
| 3759 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3760 | case TypeCheckKind::kArrayObjectCheck: { |
| 3761 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 3762 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 3763 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3764 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3765 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3766 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3767 | case TypeCheckKind::kUnresolvedCheck: |
| 3768 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3769 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3770 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3771 | case TypeCheckKind::kBitstringCheck: |
| 3772 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3773 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3774 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3775 | LocationSummary* locations = |
| 3776 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3777 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3778 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3779 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3780 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3781 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3782 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3783 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3784 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3785 | } else { |
| 3786 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3787 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3788 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3789 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3790 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3791 | // Add temps if necessary for read barriers. |
| 3792 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3793 | } |
| 3794 | |
| 3795 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3796 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3797 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3798 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3799 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3800 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 3801 | ? Register() |
| 3802 | : InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3803 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3804 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3805 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3806 | DCHECK_LE(num_temps, 1u); |
| 3807 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3808 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3809 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3810 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3811 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3812 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3813 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3814 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3815 | |
| 3816 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3817 | // Avoid null check if we know `obj` is not null. |
| 3818 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3819 | __ Cbz(obj, &zero); |
| 3820 | } |
| 3821 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3822 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3823 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3824 | ReadBarrierOption read_barrier_option = |
| 3825 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3826 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3827 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3828 | out_loc, |
| 3829 | obj_loc, |
| 3830 | class_offset, |
| 3831 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3832 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3833 | __ Cmp(out, cls); |
| 3834 | __ Cset(out, eq); |
| 3835 | if (zero.IsLinked()) { |
| 3836 | __ B(&done); |
| 3837 | } |
| 3838 | break; |
| 3839 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3840 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3841 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3842 | ReadBarrierOption read_barrier_option = |
| 3843 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3844 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3845 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3846 | out_loc, |
| 3847 | obj_loc, |
| 3848 | class_offset, |
| 3849 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3850 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3851 | // If the class is abstract, we eagerly fetch the super class of the |
| 3852 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3853 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3854 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3855 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3856 | GenerateReferenceLoadOneRegister(instruction, |
| 3857 | out_loc, |
| 3858 | super_offset, |
| 3859 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3860 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3861 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3862 | __ Cbz(out, &done); |
| 3863 | __ Cmp(out, cls); |
| 3864 | __ B(ne, &loop); |
| 3865 | __ Mov(out, 1); |
| 3866 | if (zero.IsLinked()) { |
| 3867 | __ B(&done); |
| 3868 | } |
| 3869 | break; |
| 3870 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3871 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3872 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3873 | ReadBarrierOption read_barrier_option = |
| 3874 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3875 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3876 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3877 | out_loc, |
| 3878 | obj_loc, |
| 3879 | class_offset, |
| 3880 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3881 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3882 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3883 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3884 | __ Bind(&loop); |
| 3885 | __ Cmp(out, cls); |
| 3886 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3887 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3888 | GenerateReferenceLoadOneRegister(instruction, |
| 3889 | out_loc, |
| 3890 | super_offset, |
| 3891 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3892 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3893 | __ Cbnz(out, &loop); |
| 3894 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3895 | __ B(&done); |
| 3896 | __ Bind(&success); |
| 3897 | __ Mov(out, 1); |
| 3898 | if (zero.IsLinked()) { |
| 3899 | __ B(&done); |
| 3900 | } |
| 3901 | break; |
| 3902 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3903 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3904 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3905 | ReadBarrierOption read_barrier_option = |
| 3906 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3907 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3908 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3909 | out_loc, |
| 3910 | obj_loc, |
| 3911 | class_offset, |
| 3912 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3913 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3914 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3915 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3916 | __ Cmp(out, cls); |
| 3917 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3918 | // 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] | 3919 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3920 | GenerateReferenceLoadOneRegister(instruction, |
| 3921 | out_loc, |
| 3922 | component_offset, |
| 3923 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3924 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3925 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3926 | __ Cbz(out, &done); |
| 3927 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3928 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3929 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3930 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3931 | __ Mov(out, 1); |
| 3932 | __ B(&done); |
| 3933 | break; |
| 3934 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3935 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3936 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3937 | // No read barrier since the slow path will retry upon failure. |
| 3938 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3939 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3940 | out_loc, |
| 3941 | obj_loc, |
| 3942 | class_offset, |
| 3943 | maybe_temp_loc, |
| 3944 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3945 | __ Cmp(out, cls); |
| 3946 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3947 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3948 | instruction, /* is_fatal= */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3949 | codegen_->AddSlowPath(slow_path); |
| 3950 | __ B(ne, slow_path->GetEntryLabel()); |
| 3951 | __ Mov(out, 1); |
| 3952 | if (zero.IsLinked()) { |
| 3953 | __ B(&done); |
| 3954 | } |
| 3955 | break; |
| 3956 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3957 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3958 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3959 | case TypeCheckKind::kInterfaceCheck: { |
| 3960 | // Note that we indeed only call on slow path, but we always go |
| 3961 | // into the slow path for the unresolved and interface check |
| 3962 | // cases. |
| 3963 | // |
| 3964 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3965 | // entry point without resorting to a type checking slow path |
| 3966 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3967 | // require to assign fixed registers for the inputs of this |
| 3968 | // HInstanceOf instruction (following the runtime calling |
| 3969 | // convention), which might be cluttered by the potential first |
| 3970 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3971 | // |
| 3972 | // TODO: Introduce a new runtime entry point taking the object |
| 3973 | // to test (instead of its class) as argument, and let it deal |
| 3974 | // with the read barrier issues. This will let us refactor this |
| 3975 | // case of the `switch` code as it was previously (with a direct |
| 3976 | // call to the runtime not using a type checking slow path). |
| 3977 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3978 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3979 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3980 | instruction, /* is_fatal= */ false); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3981 | codegen_->AddSlowPath(slow_path); |
| 3982 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3983 | if (zero.IsLinked()) { |
| 3984 | __ B(&done); |
| 3985 | } |
| 3986 | break; |
| 3987 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3988 | |
| 3989 | case TypeCheckKind::kBitstringCheck: { |
| 3990 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3991 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3992 | out_loc, |
| 3993 | obj_loc, |
| 3994 | class_offset, |
| 3995 | maybe_temp_loc, |
| 3996 | kWithoutReadBarrier); |
| 3997 | |
| 3998 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 3999 | __ Cset(out, eq); |
| 4000 | if (zero.IsLinked()) { |
| 4001 | __ B(&done); |
| 4002 | } |
| 4003 | break; |
| 4004 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4005 | } |
| 4006 | |
| 4007 | if (zero.IsLinked()) { |
| 4008 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4009 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | if (done.IsLinked()) { |
| 4013 | __ Bind(&done); |
| 4014 | } |
| 4015 | |
| 4016 | if (slow_path != nullptr) { |
| 4017 | __ Bind(slow_path->GetExitLabel()); |
| 4018 | } |
| 4019 | } |
| 4020 | |
| 4021 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4022 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4023 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4024 | LocationSummary* locations = |
| 4025 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4026 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4027 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 4028 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 4029 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 4030 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 4031 | } else { |
| 4032 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4033 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4034 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4035 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4039 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4040 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4041 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4042 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4043 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 4044 | ? Register() |
| 4045 | : InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4046 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4047 | DCHECK_GE(num_temps, 1u); |
| 4048 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4049 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4050 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4051 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4052 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4053 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4054 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4055 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4056 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4057 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4058 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4059 | const uint32_t object_array_data_offset = |
| 4060 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4061 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4062 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4063 | SlowPathCodeARM64* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4064 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4065 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4066 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4067 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4068 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4069 | // Avoid null check if we know obj is not null. |
| 4070 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4071 | __ Cbz(obj, &done); |
| 4072 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4073 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4074 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4075 | case TypeCheckKind::kExactCheck: |
| 4076 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4077 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4078 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4079 | temp_loc, |
| 4080 | obj_loc, |
| 4081 | class_offset, |
| 4082 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4083 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4084 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4085 | __ Cmp(temp, cls); |
| 4086 | // Jump to slow path for throwing the exception or doing a |
| 4087 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4088 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4089 | break; |
| 4090 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4091 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4092 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4093 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4094 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4095 | temp_loc, |
| 4096 | obj_loc, |
| 4097 | class_offset, |
| 4098 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4099 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4100 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4101 | // If the class is abstract, we eagerly fetch the super class of the |
| 4102 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4103 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4104 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4105 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4106 | GenerateReferenceLoadOneRegister(instruction, |
| 4107 | temp_loc, |
| 4108 | super_offset, |
| 4109 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4110 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4111 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4112 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4113 | // exception. |
| 4114 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4115 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4116 | __ Cmp(temp, cls); |
| 4117 | __ B(ne, &loop); |
| 4118 | break; |
| 4119 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4120 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4121 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4122 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4123 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4124 | temp_loc, |
| 4125 | obj_loc, |
| 4126 | class_offset, |
| 4127 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4128 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4129 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4130 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4131 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4132 | __ Bind(&loop); |
| 4133 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4134 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4135 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4136 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4137 | GenerateReferenceLoadOneRegister(instruction, |
| 4138 | temp_loc, |
| 4139 | super_offset, |
| 4140 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4141 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4142 | |
| 4143 | // If the class reference currently in `temp` is not null, jump |
| 4144 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4145 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4146 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4147 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4148 | break; |
| 4149 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4150 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4151 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4152 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4153 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4154 | temp_loc, |
| 4155 | obj_loc, |
| 4156 | class_offset, |
| 4157 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4158 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4159 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4160 | // Do an exact check. |
| 4161 | __ Cmp(temp, cls); |
| 4162 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4163 | |
| 4164 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4165 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4166 | GenerateReferenceLoadOneRegister(instruction, |
| 4167 | temp_loc, |
| 4168 | component_offset, |
| 4169 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4170 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4171 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4172 | // If the component type is null, jump to the slow path to throw the exception. |
| 4173 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4174 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4175 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4176 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4177 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4178 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4179 | break; |
| 4180 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4181 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4182 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4183 | // 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] | 4184 | // |
| 4185 | // We cannot directly call the CheckCast runtime entry point |
| 4186 | // without resorting to a type checking slow path here (i.e. by |
| 4187 | // calling InvokeRuntime directly), as it would require to |
| 4188 | // assign fixed registers for the inputs of this HInstanceOf |
| 4189 | // instruction (following the runtime calling convention), which |
| 4190 | // might be cluttered by the potential first read barrier |
| 4191 | // emission at the beginning of this method. |
| 4192 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4193 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4194 | case TypeCheckKind::kInterfaceCheck: { |
| 4195 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4196 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4197 | temp_loc, |
| 4198 | obj_loc, |
| 4199 | class_offset, |
| 4200 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4201 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4202 | |
| 4203 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4204 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4205 | temp_loc, |
| 4206 | temp_loc, |
| 4207 | iftable_offset, |
| 4208 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4209 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4210 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4211 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4212 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4213 | vixl::aarch64::Label start_loop; |
| 4214 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4215 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4216 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4217 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4218 | // Go to next interface. |
| 4219 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4220 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4221 | // Compare the classes and continue the loop if they do not match. |
| 4222 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4223 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4224 | break; |
| 4225 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4226 | |
| 4227 | case TypeCheckKind::kBitstringCheck: { |
| 4228 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4229 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4230 | temp_loc, |
| 4231 | obj_loc, |
| 4232 | class_offset, |
| 4233 | maybe_temp2_loc, |
| 4234 | kWithoutReadBarrier); |
| 4235 | |
| 4236 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 4237 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 4238 | break; |
| 4239 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4240 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4241 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4242 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4243 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4244 | } |
| 4245 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4246 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4247 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4248 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4249 | } |
| 4250 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4251 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4252 | // Will be generated at use site. |
| 4253 | } |
| 4254 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4255 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4256 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4257 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4258 | } |
| 4259 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4260 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4261 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4262 | } |
| 4263 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4264 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4265 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4266 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4267 | // the method_idx. |
| 4268 | HandleInvoke(invoke); |
| 4269 | } |
| 4270 | |
| 4271 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4272 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4273 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4274 | } |
| 4275 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4276 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4277 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4278 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4279 | } |
| 4280 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4281 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4282 | HandleInvoke(invoke); |
| 4283 | } |
| 4284 | |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4285 | void CodeGeneratorARM64::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 4286 | Register klass) { |
| 4287 | DCHECK_EQ(klass.GetCode(), 0u); |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4288 | // We know the destination of an intrinsic, so no need to record inline |
| 4289 | // caches. |
| 4290 | if (!instruction->GetLocations()->Intrinsified() && |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 4291 | GetGraph()->IsCompilingBaseline() && |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4292 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4293 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 4294 | ScopedProfilingInfoUse spiu( |
| 4295 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 4296 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 4297 | if (info != nullptr) { |
| 4298 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 4299 | uint64_t address = reinterpret_cast64<uint64_t>(cache); |
| 4300 | vixl::aarch64::Label done; |
| 4301 | __ Mov(x8, address); |
| 4302 | __ Ldr(x9, MemOperand(x8, InlineCache::ClassesOffset().Int32Value())); |
| 4303 | // Fast path for a monomorphic cache. |
| 4304 | __ Cmp(klass, x9); |
| 4305 | __ B(eq, &done); |
| 4306 | InvokeRuntime(kQuickUpdateInlineCache, instruction, instruction->GetDexPc()); |
| 4307 | __ Bind(&done); |
| 4308 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4309 | } |
| 4310 | } |
| 4311 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4312 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4313 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4314 | LocationSummary* locations = invoke->GetLocations(); |
| 4315 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4316 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4317 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4318 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4319 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4320 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4321 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4322 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4323 | { |
| 4324 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4325 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4326 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4327 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4328 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4329 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4330 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4331 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4332 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4333 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4334 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4335 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4336 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4337 | // emit a read barrier for the previous class reference load. |
| 4338 | // However this is not required in practice, as this is an |
| 4339 | // intermediate/temporary reference and because the current |
| 4340 | // concurrent copying collector keeps the from-space memory |
| 4341 | // intact/accessible until the end of the marking phase (the |
| 4342 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4343 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4344 | |
| 4345 | // If we're compiling baseline, update the inline cache. |
| 4346 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4347 | |
| 4348 | // The register ip1 is required to be used for the hidden argument in |
| 4349 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
| 4350 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4351 | UseScratchRegisterScope scratch_scope(masm); |
| 4352 | scratch_scope.Exclude(ip1); |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame^] | 4353 | __ Mov(ip1, invoke->GetMethodReference().index); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4354 | |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4355 | __ Ldr(temp, |
| 4356 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4357 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4358 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4359 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4360 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4361 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4362 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4363 | |
| 4364 | { |
| 4365 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4366 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4367 | |
| 4368 | // lr(); |
| 4369 | __ blr(lr); |
| 4370 | DCHECK(!codegen_->IsLeafMethod()); |
| 4371 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4372 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4373 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4374 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4375 | } |
| 4376 | |
| 4377 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4378 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4379 | if (intrinsic.TryDispatch(invoke)) { |
| 4380 | return; |
| 4381 | } |
| 4382 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4383 | HandleInvoke(invoke); |
| 4384 | } |
| 4385 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4386 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4387 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4388 | // art::PrepareForRegisterAllocation. |
| 4389 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4390 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4391 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4392 | if (intrinsic.TryDispatch(invoke)) { |
| 4393 | return; |
| 4394 | } |
| 4395 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4396 | if (invoke->GetCodePtrLocation() == HInvokeStaticOrDirect::CodePtrLocation::kCallCriticalNative) { |
| 4397 | CriticalNativeCallingConventionVisitorARM64 calling_convention_visitor( |
| 4398 | /*for_register_allocation=*/ true); |
| 4399 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 4400 | } else { |
| 4401 | HandleInvoke(invoke); |
| 4402 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4403 | } |
| 4404 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4405 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4406 | if (invoke->GetLocations()->Intrinsified()) { |
| 4407 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4408 | intrinsic.Dispatch(invoke); |
| 4409 | return true; |
| 4410 | } |
| 4411 | return false; |
| 4412 | } |
| 4413 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4414 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4415 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4416 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4417 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4418 | return desired_dispatch_info; |
| 4419 | } |
| 4420 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4421 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4422 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4423 | // 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] | 4424 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4425 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4426 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4427 | uint32_t offset = |
| 4428 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4429 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4430 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4431 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4432 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4433 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4434 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4435 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4436 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4437 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4438 | // Add ADRP with its PC-relative method patch. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame^] | 4439 | vixl::aarch64::Label* adrp_label = |
| 4440 | NewBootImageMethodPatch(invoke->GetResolvedMethodReference()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4441 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4442 | // Add ADD with its PC-relative method patch. |
| 4443 | vixl::aarch64::Label* add_label = |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame^] | 4444 | NewBootImageMethodPatch(invoke->GetResolvedMethodReference(), adrp_label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4445 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4446 | break; |
| 4447 | } |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4448 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4449 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4450 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4451 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_offset); |
| 4452 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4453 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| 4454 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| 4455 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 4456 | EmitLdrOffsetPlaceholder(ldr_label, WRegisterFrom(temp), XRegisterFrom(temp)); |
| 4457 | break; |
| 4458 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4459 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4460 | // Add ADRP with its PC-relative .bss entry patch. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame^] | 4461 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(invoke->GetMethodReference()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4462 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4463 | // Add LDR with its PC-relative .bss entry patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4464 | vixl::aarch64::Label* ldr_label = |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame^] | 4465 | NewMethodBssEntryPatch(invoke->GetMethodReference(), adrp_label); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 4466 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4467 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4468 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4469 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4470 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 4471 | // Load method address from literal pool. |
| 4472 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
| 4473 | break; |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4474 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4475 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4476 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4477 | } |
| 4478 | } |
| 4479 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4480 | auto call_code_pointer_member = [&](MemberOffset offset) { |
| 4481 | // LR = callee_method->member; |
| 4482 | __ Ldr(lr, MemOperand(XRegisterFrom(callee_method), offset.Int32Value())); |
| 4483 | { |
| 4484 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4485 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4486 | kInstructionSize, |
| 4487 | CodeBufferCheckScope::kExactSize); |
| 4488 | // lr() |
| 4489 | __ blr(lr); |
| 4490 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4491 | } |
| 4492 | }; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4493 | switch (invoke->GetCodePtrLocation()) { |
| 4494 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4495 | { |
| 4496 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4497 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4498 | kInstructionSize, |
| 4499 | CodeBufferCheckScope::kExactSize); |
| 4500 | __ bl(&frame_entry_label_); |
| 4501 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4502 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4503 | break; |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4504 | case HInvokeStaticOrDirect::CodePtrLocation::kCallCriticalNative: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4505 | size_t out_frame_size = |
| 4506 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorARM64, |
| 4507 | kAapcs64StackAlignment, |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 4508 | GetCriticalNativeDirectCallFrameSize>(invoke); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4509 | call_code_pointer_member(ArtMethod::EntryPointFromJniOffset(kArm64PointerSize)); |
| 4510 | // Zero-/sign-extend the result when needed due to native and managed ABI mismatch. |
| 4511 | switch (invoke->GetType()) { |
| 4512 | case DataType::Type::kBool: |
| 4513 | __ Ubfx(w0, w0, 0, 8); |
| 4514 | break; |
| 4515 | case DataType::Type::kInt8: |
| 4516 | __ Sbfx(w0, w0, 0, 8); |
| 4517 | break; |
| 4518 | case DataType::Type::kUint16: |
| 4519 | __ Ubfx(w0, w0, 0, 16); |
| 4520 | break; |
| 4521 | case DataType::Type::kInt16: |
| 4522 | __ Sbfx(w0, w0, 0, 16); |
| 4523 | break; |
| 4524 | case DataType::Type::kInt32: |
| 4525 | case DataType::Type::kInt64: |
| 4526 | case DataType::Type::kFloat32: |
| 4527 | case DataType::Type::kFloat64: |
| 4528 | case DataType::Type::kVoid: |
| 4529 | break; |
| 4530 | default: |
| 4531 | DCHECK(false) << invoke->GetType(); |
| 4532 | break; |
| 4533 | } |
| 4534 | if (out_frame_size != 0u) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 4535 | DecreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4536 | } |
| 4537 | break; |
| 4538 | } |
| 4539 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4540 | call_code_pointer_member(ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4541 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4542 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4543 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4544 | DCHECK(!IsLeafMethod()); |
| 4545 | } |
| 4546 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4547 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4548 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4549 | // Use the calling convention instead of the location of the receiver, as |
| 4550 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4551 | // slow path, the arguments have been moved to the right place, so here we are |
| 4552 | // guaranteed that the receiver is the first register of the calling convention. |
| 4553 | InvokeDexCallingConvention calling_convention; |
| 4554 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4555 | Register temp = XRegisterFrom(temp_in); |
| 4556 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4557 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4558 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4559 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4560 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4561 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4562 | |
| 4563 | { |
| 4564 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4565 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4566 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4567 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4568 | MaybeRecordImplicitNullCheck(invoke); |
| 4569 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4570 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4571 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4572 | // intermediate/temporary reference and because the current |
| 4573 | // concurrent copying collector keeps the from-space memory |
| 4574 | // intact/accessible until the end of the marking phase (the |
| 4575 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4576 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4577 | |
| 4578 | // If we're compiling baseline, update the inline cache. |
| 4579 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4580 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4581 | // temp = temp->GetMethodAt(method_offset); |
| 4582 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4583 | // lr = temp->GetEntryPoint(); |
| 4584 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4585 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4586 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4587 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4588 | // lr(); |
| 4589 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4590 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4591 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4592 | } |
| 4593 | |
Vladimir Marko | 9922f00 | 2020-06-08 15:05:15 +0100 | [diff] [blame] | 4594 | void CodeGeneratorARM64::MoveFromReturnRegister(Location trg, DataType::Type type) { |
| 4595 | if (!trg.IsValid()) { |
| 4596 | DCHECK(type == DataType::Type::kVoid); |
| 4597 | return; |
| 4598 | } |
| 4599 | |
| 4600 | DCHECK_NE(type, DataType::Type::kVoid); |
| 4601 | |
| 4602 | if (DataType::IsIntegralType(type) || type == DataType::Type::kReference) { |
| 4603 | Register trg_reg = RegisterFrom(trg, type); |
| 4604 | Register res_reg = RegisterFrom(ARM64ReturnLocation(type), type); |
| 4605 | __ Mov(trg_reg, res_reg, kDiscardForSameWReg); |
| 4606 | } else { |
| 4607 | VRegister trg_reg = FPRegisterFrom(trg, type); |
| 4608 | VRegister res_reg = FPRegisterFrom(ARM64ReturnLocation(type), type); |
| 4609 | __ Fmov(trg_reg, res_reg); |
| 4610 | } |
| 4611 | } |
| 4612 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4613 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 4614 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
| 4615 | if (intrinsic.TryDispatch(invoke)) { |
| 4616 | return; |
| 4617 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4618 | HandleInvoke(invoke); |
| 4619 | } |
| 4620 | |
| 4621 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 4622 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4623 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| 4624 | return; |
| 4625 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4626 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4627 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4628 | } |
| 4629 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4630 | void LocationsBuilderARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4631 | HandleInvoke(invoke); |
| 4632 | } |
| 4633 | |
| 4634 | void InstructionCodeGeneratorARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4635 | codegen_->GenerateInvokeCustomCall(invoke); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4636 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4637 | } |
| 4638 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4639 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageIntrinsicPatch( |
| 4640 | uint32_t intrinsic_data, |
| 4641 | vixl::aarch64::Label* adrp_label) { |
| 4642 | return NewPcRelativePatch( |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4643 | /* dex_file= */ nullptr, intrinsic_data, adrp_label, &boot_image_other_patches_); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4644 | } |
| 4645 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4646 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageRelRoPatch( |
| 4647 | uint32_t boot_image_offset, |
| 4648 | vixl::aarch64::Label* adrp_label) { |
| 4649 | return NewPcRelativePatch( |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4650 | /* dex_file= */ nullptr, boot_image_offset, adrp_label, &boot_image_other_patches_); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4651 | } |
| 4652 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4653 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageMethodPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4654 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4655 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4656 | return NewPcRelativePatch( |
| 4657 | 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] | 4658 | } |
| 4659 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4660 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4661 | MethodReference target_method, |
| 4662 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4663 | return NewPcRelativePatch( |
| 4664 | 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] | 4665 | } |
| 4666 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4667 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageTypePatch( |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4668 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4669 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4670 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4671 | 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] | 4672 | } |
| 4673 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4674 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4675 | const DexFile& dex_file, |
| 4676 | dex::TypeIndex type_index, |
| 4677 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4678 | 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] | 4679 | } |
| 4680 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4681 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageStringPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4682 | const DexFile& dex_file, |
| 4683 | dex::StringIndex string_index, |
| 4684 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4685 | return NewPcRelativePatch( |
| 4686 | &dex_file, string_index.index_, adrp_label, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4687 | } |
| 4688 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4689 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4690 | const DexFile& dex_file, |
| 4691 | dex::StringIndex string_index, |
| 4692 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4693 | 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] | 4694 | } |
| 4695 | |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4696 | void CodeGeneratorARM64::EmitEntrypointThunkCall(ThreadOffset64 entrypoint_offset) { |
| 4697 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 4698 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4699 | call_entrypoint_patches_.emplace_back(/*dex_file*/ nullptr, entrypoint_offset.Uint32Value()); |
| 4700 | vixl::aarch64::Label* bl_label = &call_entrypoint_patches_.back().label; |
| 4701 | __ bind(bl_label); |
| 4702 | __ bl(static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 4703 | } |
| 4704 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 4705 | void CodeGeneratorARM64::EmitBakerReadBarrierCbnz(uint32_t custom_data) { |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 4706 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 4707 | if (GetCompilerOptions().IsJitCompiler()) { |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 4708 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 4709 | vixl::aarch64::Label* slow_path_entry = &it->second.label; |
| 4710 | __ cbnz(mr, slow_path_entry); |
| 4711 | } else { |
| 4712 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4713 | vixl::aarch64::Label* cbnz_label = &baker_read_barrier_patches_.back().label; |
| 4714 | __ bind(cbnz_label); |
| 4715 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 4716 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4717 | } |
| 4718 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4719 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4720 | const DexFile* dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4721 | uint32_t offset_or_index, |
| 4722 | vixl::aarch64::Label* adrp_label, |
| 4723 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4724 | // Add a patch entry and return the label. |
| 4725 | patches->emplace_back(dex_file, offset_or_index); |
| 4726 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4727 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4728 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4729 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4730 | return label; |
| 4731 | } |
| 4732 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4733 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4734 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4735 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4736 | } |
| 4737 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4738 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4739 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4740 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4741 | return jit_string_patches_.GetOrCreate( |
| 4742 | StringReference(&dex_file, string_index), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4743 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4744 | } |
| 4745 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4746 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4747 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4748 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4749 | return jit_class_patches_.GetOrCreate( |
| 4750 | TypeReference(&dex_file, type_index), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4751 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4752 | } |
| 4753 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4754 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4755 | vixl::aarch64::Register reg) { |
| 4756 | DCHECK(reg.IsX()); |
| 4757 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4758 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4759 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4763 | vixl::aarch64::Register out, |
| 4764 | vixl::aarch64::Register base) { |
| 4765 | DCHECK(out.IsX()); |
| 4766 | DCHECK(base.IsX()); |
| 4767 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4768 | __ Bind(fixup_label); |
| 4769 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4770 | } |
| 4771 | |
| 4772 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4773 | vixl::aarch64::Register out, |
| 4774 | vixl::aarch64::Register base) { |
| 4775 | DCHECK(base.IsX()); |
| 4776 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4777 | __ Bind(fixup_label); |
| 4778 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4779 | } |
| 4780 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4781 | void CodeGeneratorARM64::LoadBootImageAddress(vixl::aarch64::Register reg, |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4782 | uint32_t boot_image_reference) { |
| 4783 | if (GetCompilerOptions().IsBootImage()) { |
| 4784 | // Add ADRP with its PC-relative type patch. |
| 4785 | vixl::aarch64::Label* adrp_label = NewBootImageIntrinsicPatch(boot_image_reference); |
| 4786 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4787 | // Add ADD with its PC-relative type patch. |
| 4788 | vixl::aarch64::Label* add_label = NewBootImageIntrinsicPatch(boot_image_reference, adrp_label); |
| 4789 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 4790 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4791 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4792 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4793 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4794 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4795 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_reference, adrp_label); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4796 | EmitLdrOffsetPlaceholder(ldr_label, reg.W(), reg.X()); |
| 4797 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 4798 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4799 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 4800 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4801 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4802 | __ Ldr(reg.W(), DeduplicateBootImageAddressLiteral(reinterpret_cast<uintptr_t>(address))); |
| 4803 | } |
| 4804 | } |
| 4805 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4806 | void CodeGeneratorARM64::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 4807 | uint32_t boot_image_offset) { |
| 4808 | DCHECK(invoke->IsStatic()); |
| 4809 | InvokeRuntimeCallingConvention calling_convention; |
| 4810 | Register argument = calling_convention.GetRegisterAt(0); |
| 4811 | if (GetCompilerOptions().IsBootImage()) { |
| 4812 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 4813 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame^] | 4814 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4815 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 4816 | // Add ADRP with its PC-relative type patch. |
| 4817 | vixl::aarch64::Label* adrp_label = NewBootImageTypePatch(*target_method.dex_file, type_idx); |
| 4818 | EmitAdrpPlaceholder(adrp_label, argument.X()); |
| 4819 | // Add ADD with its PC-relative type patch. |
| 4820 | vixl::aarch64::Label* add_label = |
| 4821 | NewBootImageTypePatch(*target_method.dex_file, type_idx, adrp_label); |
| 4822 | EmitAddPlaceholder(add_label, argument.X(), argument.X()); |
| 4823 | } else { |
| 4824 | LoadBootImageAddress(argument, boot_image_offset); |
| 4825 | } |
| 4826 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 4827 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4828 | } |
| 4829 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4830 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4831 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4832 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4833 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4834 | for (const PcRelativePatchInfo& info : infos) { |
| 4835 | linker_patches->push_back(Factory(info.label.GetLocation(), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4836 | info.target_dex_file, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4837 | info.pc_insn_label->GetLocation(), |
| 4838 | info.offset_or_index)); |
| 4839 | } |
| 4840 | } |
| 4841 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4842 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 4843 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 4844 | const DexFile* target_dex_file, |
| 4845 | uint32_t pc_insn_offset, |
| 4846 | uint32_t boot_image_offset) { |
| 4847 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 4848 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4849 | } |
| 4850 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4851 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4852 | DCHECK(linker_patches->empty()); |
| 4853 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4854 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4855 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4856 | boot_image_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4857 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4858 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4859 | string_bss_entry_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4860 | boot_image_other_patches_.size() + |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4861 | call_entrypoint_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4862 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4863 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4864 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4865 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4866 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4867 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4868 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4869 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4870 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4871 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4872 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4873 | DCHECK(boot_image_type_patches_.empty()); |
| 4874 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4875 | } |
| 4876 | if (GetCompilerOptions().IsBootImage()) { |
| 4877 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 4878 | boot_image_other_patches_, linker_patches); |
| 4879 | } else { |
| 4880 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 4881 | boot_image_other_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4882 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4883 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4884 | method_bss_entry_patches_, linker_patches); |
| 4885 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4886 | type_bss_entry_patches_, linker_patches); |
| 4887 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4888 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4889 | for (const PatchInfo<vixl::aarch64::Label>& info : call_entrypoint_patches_) { |
| 4890 | DCHECK(info.target_dex_file == nullptr); |
| 4891 | linker_patches->push_back(linker::LinkerPatch::CallEntrypointPatch( |
| 4892 | info.label.GetLocation(), info.offset_or_index)); |
| 4893 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4894 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4895 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 4896 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4897 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4898 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4899 | } |
| 4900 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4901 | bool CodeGeneratorARM64::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4902 | return patch.GetType() == linker::LinkerPatch::Type::kCallEntrypoint || |
| 4903 | patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4904 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 4905 | } |
| 4906 | |
| 4907 | void CodeGeneratorARM64::EmitThunkCode(const linker::LinkerPatch& patch, |
| 4908 | /*out*/ ArenaVector<uint8_t>* code, |
| 4909 | /*out*/ std::string* debug_name) { |
| 4910 | Arm64Assembler assembler(GetGraph()->GetAllocator()); |
| 4911 | switch (patch.GetType()) { |
| 4912 | case linker::LinkerPatch::Type::kCallRelative: { |
| 4913 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 4914 | // to the generic JNI and interpreter trampolines. |
| 4915 | Offset offset(ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4916 | kArm64PointerSize).Int32Value()); |
| 4917 | assembler.JumpTo(ManagedRegister(arm64::X0), offset, ManagedRegister(arm64::IP0)); |
| 4918 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 4919 | *debug_name = "MethodCallThunk"; |
| 4920 | } |
| 4921 | break; |
| 4922 | } |
Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4923 | case linker::LinkerPatch::Type::kCallEntrypoint: { |
| 4924 | Offset offset(patch.EntrypointOffset()); |
| 4925 | assembler.JumpTo(ManagedRegister(arm64::TR), offset, ManagedRegister(arm64::IP0)); |
| 4926 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 4927 | *debug_name = "EntrypointCallThunk_" + std::to_string(offset.Uint32Value()); |
| 4928 | } |
| 4929 | break; |
| 4930 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4931 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| 4932 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 4933 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 4934 | break; |
| 4935 | } |
| 4936 | default: |
| 4937 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 4938 | UNREACHABLE(); |
| 4939 | } |
| 4940 | |
| 4941 | // Ensure we emit the literal pool if any. |
| 4942 | assembler.FinalizeCode(); |
| 4943 | code->resize(assembler.CodeSize()); |
| 4944 | MemoryRegion code_region(code->data(), code->size()); |
| 4945 | assembler.FinalizeInstructions(code_region); |
| 4946 | } |
| 4947 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4948 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4949 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4950 | value, |
| 4951 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4952 | } |
| 4953 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4954 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4955 | return uint64_literals_.GetOrCreate( |
| 4956 | value, |
| 4957 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4958 | } |
| 4959 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4960 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4961 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4962 | // art::PrepareForRegisterAllocation. |
| 4963 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4964 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4965 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4966 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4967 | return; |
| 4968 | } |
| 4969 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 4970 | LocationSummary* locations = invoke->GetLocations(); |
| 4971 | codegen_->GenerateStaticOrDirectCall( |
| 4972 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4973 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4974 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4975 | } |
| 4976 | |
| 4977 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4978 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4979 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4980 | return; |
| 4981 | } |
| 4982 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4983 | { |
| 4984 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4985 | // are no pools emitted. |
| 4986 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4987 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 4988 | DCHECK(!codegen_->IsLeafMethod()); |
| 4989 | } |
| 4990 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4991 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4992 | } |
| 4993 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4994 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4995 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4996 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4997 | case HLoadClass::LoadKind::kInvalid: |
| 4998 | LOG(FATAL) << "UNREACHABLE"; |
| 4999 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5000 | case HLoadClass::LoadKind::kReferrersClass: |
| 5001 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5002 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5003 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5004 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5005 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5006 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5007 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5008 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5009 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5010 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5011 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5012 | break; |
| 5013 | } |
| 5014 | return desired_class_load_kind; |
| 5015 | } |
| 5016 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5017 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5018 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5019 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5020 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5021 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5022 | cls, |
| 5023 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5024 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5025 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5026 | return; |
| 5027 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5028 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5029 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5030 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5031 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5032 | ? LocationSummary::kCallOnSlowPath |
| 5033 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5034 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5035 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5036 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5037 | } |
| 5038 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5039 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5040 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5041 | } |
| 5042 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5043 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 5044 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5045 | // 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] | 5046 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5047 | } else { |
| 5048 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5049 | } |
| 5050 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5051 | } |
| 5052 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5053 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5054 | // move. |
| 5055 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5056 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5057 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5058 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5059 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5060 | return; |
| 5061 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5062 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5063 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5064 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5065 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5066 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5067 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5068 | ? kWithoutReadBarrier |
| 5069 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5070 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5071 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5072 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5073 | DCHECK(!cls->CanCallRuntime()); |
| 5074 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5075 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5076 | Register current_method = InputRegisterAt(cls, 0); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5077 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5078 | out_loc, |
| 5079 | current_method, |
| 5080 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5081 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5082 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5083 | break; |
| 5084 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5085 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5086 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 5087 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5088 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5089 | // Add ADRP with its PC-relative type patch. |
| 5090 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5091 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5092 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5093 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5094 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5095 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5096 | codegen_->NewBootImageTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5097 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5098 | break; |
| 5099 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5100 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5101 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5102 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls); |
| 5103 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5104 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5105 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5106 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5107 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5108 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5109 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5110 | break; |
| 5111 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5112 | case HLoadClass::LoadKind::kBssEntry: { |
| 5113 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 5114 | const DexFile& dex_file = cls->GetDexFile(); |
| 5115 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5116 | vixl::aarch64::Register temp = XRegisterFrom(out_loc); |
| 5117 | vixl::aarch64::Label* adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 5118 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5119 | // Add LDR with its PC-relative Class .bss entry patch. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5120 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5121 | codegen_->NewBssEntryTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5122 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5123 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5124 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5125 | out_loc, |
| 5126 | temp, |
| 5127 | /* offset placeholder */ 0u, |
| 5128 | ldr_label, |
| 5129 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5130 | generate_null_check = true; |
| 5131 | break; |
| 5132 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5133 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 5134 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 5135 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 5136 | DCHECK_NE(address, 0u); |
| 5137 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5138 | break; |
| 5139 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5140 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5141 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5142 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5143 | cls->GetClass())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5144 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5145 | out_loc, |
| 5146 | out.X(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5147 | /* offset= */ 0, |
| 5148 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5149 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5150 | break; |
| 5151 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5152 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5153 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5154 | LOG(FATAL) << "UNREACHABLE"; |
| 5155 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5156 | } |
| 5157 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5158 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5159 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5160 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 5161 | SlowPathCodeARM64* slow_path = |
| 5162 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5163 | codegen_->AddSlowPath(slow_path); |
| 5164 | if (generate_null_check) { |
| 5165 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5166 | } |
| 5167 | if (cls->MustGenerateClinitCheck()) { |
| 5168 | GenerateClassInitializationCheck(slow_path, out); |
| 5169 | } else { |
| 5170 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5171 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5172 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5173 | } |
| 5174 | } |
| 5175 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 5176 | void LocationsBuilderARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5177 | InvokeRuntimeCallingConvention calling_convention; |
| 5178 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5179 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 5180 | } |
| 5181 | |
| 5182 | void InstructionCodeGeneratorARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5183 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 5184 | } |
| 5185 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 5186 | void LocationsBuilderARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5187 | InvokeRuntimeCallingConvention calling_convention; |
| 5188 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5189 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 5190 | } |
| 5191 | |
| 5192 | void InstructionCodeGeneratorARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5193 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 5194 | } |
| 5195 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5196 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5197 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5198 | } |
| 5199 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5200 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5201 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5202 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5203 | locations->SetOut(Location::RequiresRegister()); |
| 5204 | } |
| 5205 | |
| 5206 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5207 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5208 | } |
| 5209 | |
| 5210 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5211 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5212 | } |
| 5213 | |
| 5214 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5215 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5216 | } |
| 5217 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5218 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5219 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5220 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5221 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5222 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5223 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5224 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5225 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5226 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5227 | case HLoadString::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 5228 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5229 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5230 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5231 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5232 | } |
| 5233 | return desired_string_load_kind; |
| 5234 | } |
| 5235 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5236 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5237 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5238 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5239 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5240 | InvokeRuntimeCallingConvention calling_convention; |
| 5241 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5242 | } else { |
| 5243 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5244 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5245 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5246 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 5247 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5248 | } else { |
| 5249 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5250 | } |
| 5251 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5252 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5253 | } |
| 5254 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5255 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5256 | // move. |
| 5257 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5258 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5259 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5260 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5261 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5262 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5263 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 5264 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5265 | // Add ADRP with its PC-relative String patch. |
| 5266 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5267 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5268 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5269 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5270 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5271 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5272 | codegen_->NewBootImageStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5273 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5274 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5275 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5276 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5277 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5278 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5279 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(load); |
| 5280 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5281 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5282 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5283 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5284 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5285 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 5286 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5287 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5288 | case HLoadString::LoadKind::kBssEntry: { |
| 5289 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5290 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5291 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5292 | Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5293 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5294 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5295 | // Add LDR with its PC-relative String .bss entry patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5296 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5297 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5298 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5299 | // All aligned loads are implicitly atomic consume operations on ARM64. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5300 | codegen_->GenerateGcRootFieldLoad(load, |
| 5301 | out_loc, |
| 5302 | temp, |
| 5303 | /* offset placeholder */ 0u, |
| 5304 | ldr_label, |
| 5305 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5306 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5307 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5308 | codegen_->AddSlowPath(slow_path); |
| 5309 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5310 | __ Bind(slow_path->GetExitLabel()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5311 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5312 | return; |
| 5313 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5314 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 5315 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 5316 | DCHECK_NE(address, 0u); |
| 5317 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5318 | return; |
| 5319 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5320 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5321 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5322 | load->GetStringIndex(), |
| 5323 | load->GetString())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5324 | codegen_->GenerateGcRootFieldLoad(load, |
| 5325 | out_loc, |
| 5326 | out.X(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5327 | /* offset= */ 0, |
| 5328 | /* fixup_label= */ nullptr, |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5329 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5330 | return; |
| 5331 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5332 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5333 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5334 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5335 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5336 | // 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] | 5337 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5338 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5339 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5340 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5341 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5342 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5343 | } |
| 5344 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5345 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5346 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5347 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5348 | } |
| 5349 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5350 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5351 | // Will be generated at use site. |
| 5352 | } |
| 5353 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5354 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5355 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5356 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5357 | InvokeRuntimeCallingConvention calling_convention; |
| 5358 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5359 | } |
| 5360 | |
| 5361 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5362 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5363 | instruction, |
| 5364 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5365 | if (instruction->IsEnter()) { |
| 5366 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5367 | } else { |
| 5368 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5369 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5370 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5371 | } |
| 5372 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5373 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5374 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5375 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5376 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5377 | case DataType::Type::kInt32: |
| 5378 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5379 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5380 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5381 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5382 | break; |
| 5383 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5384 | case DataType::Type::kFloat32: |
| 5385 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5386 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5387 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5388 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5389 | break; |
| 5390 | |
| 5391 | default: |
| 5392 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5393 | } |
| 5394 | } |
| 5395 | |
| 5396 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5397 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5398 | case DataType::Type::kInt32: |
| 5399 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5400 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5401 | break; |
| 5402 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5403 | case DataType::Type::kFloat32: |
| 5404 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5405 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5406 | break; |
| 5407 | |
| 5408 | default: |
| 5409 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5410 | } |
| 5411 | } |
| 5412 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5413 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5414 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5415 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5416 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5417 | case DataType::Type::kInt32: |
| 5418 | case DataType::Type::kInt64: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5419 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5420 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5421 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5422 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5423 | case DataType::Type::kFloat32: |
| 5424 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5425 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5426 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5427 | break; |
| 5428 | |
| 5429 | default: |
| 5430 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5431 | } |
| 5432 | } |
| 5433 | |
| 5434 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5435 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5436 | case DataType::Type::kInt32: |
| 5437 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5438 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5439 | break; |
| 5440 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5441 | case DataType::Type::kFloat32: |
| 5442 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5443 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5444 | break; |
| 5445 | |
| 5446 | default: |
| 5447 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5448 | } |
| 5449 | } |
| 5450 | |
| 5451 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5452 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5453 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5454 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5455 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5456 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5457 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5458 | } |
| 5459 | |
| 5460 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5461 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5462 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5463 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5464 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5465 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5466 | } |
| 5467 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5468 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5469 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5470 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5471 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5472 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5473 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5474 | } |
| 5475 | |
| 5476 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5477 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5478 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5479 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5480 | } |
| 5481 | |
| 5482 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5483 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5484 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5485 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5486 | } |
| 5487 | |
| 5488 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5489 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5490 | case DataType::Type::kInt32: |
| 5491 | case DataType::Type::kInt64: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5492 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5493 | break; |
| 5494 | |
| 5495 | default: |
| 5496 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5497 | } |
| 5498 | } |
| 5499 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5500 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5501 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5502 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5503 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5504 | } |
| 5505 | |
| 5506 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5507 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5508 | } |
| 5509 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5510 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5511 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5512 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5513 | } |
| 5514 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5515 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5516 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5517 | return; |
| 5518 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5519 | { |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 5520 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5521 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5522 | Location obj = instruction->GetLocations()->InAt(0); |
| 5523 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5524 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5525 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5526 | } |
| 5527 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5528 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5529 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5530 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5531 | |
| 5532 | LocationSummary* locations = instruction->GetLocations(); |
| 5533 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5534 | |
| 5535 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5536 | } |
| 5537 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5538 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5539 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5540 | } |
| 5541 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5542 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5543 | HandleBinaryOp(instruction); |
| 5544 | } |
| 5545 | |
| 5546 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5547 | HandleBinaryOp(instruction); |
| 5548 | } |
| 5549 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5550 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5551 | LOG(FATAL) << "Unreachable"; |
| 5552 | } |
| 5553 | |
| 5554 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5555 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5556 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5557 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5558 | // The back edge will generate the suspend check. |
| 5559 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5560 | } |
| 5561 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5562 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5563 | } |
| 5564 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5565 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5566 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5567 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5568 | if (location.IsStackSlot()) { |
| 5569 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5570 | } else if (location.IsDoubleStackSlot()) { |
| 5571 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5572 | } |
| 5573 | locations->SetOut(location); |
| 5574 | } |
| 5575 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5576 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5577 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5578 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5579 | } |
| 5580 | |
| 5581 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5582 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5583 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5584 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5585 | } |
| 5586 | |
| 5587 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5588 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5589 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5590 | } |
| 5591 | |
| 5592 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5593 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5594 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5595 | locations->SetInAt(i, Location::Any()); |
| 5596 | } |
| 5597 | locations->SetOut(Location::Any()); |
| 5598 | } |
| 5599 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5600 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5601 | LOG(FATAL) << "Unreachable"; |
| 5602 | } |
| 5603 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5604 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5605 | DataType::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5606 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5607 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5608 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5609 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5610 | |
| 5611 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5612 | case DataType::Type::kInt32: |
| 5613 | case DataType::Type::kInt64: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5614 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5615 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5616 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5617 | break; |
| 5618 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5619 | case DataType::Type::kFloat32: |
| 5620 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5621 | InvokeRuntimeCallingConvention calling_convention; |
| 5622 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5623 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5624 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5625 | |
| 5626 | break; |
| 5627 | } |
| 5628 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5629 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5630 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5631 | } |
| 5632 | } |
| 5633 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5634 | void InstructionCodeGeneratorARM64::GenerateIntRemForPower2Denom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5635 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5636 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 5637 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 5638 | |
| 5639 | Register out = OutputRegister(instruction); |
| 5640 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5641 | |
Evgeny Astigeevich | 0f3d7ac | 2020-08-06 16:28:37 +0100 | [diff] [blame] | 5642 | if (HasNonNegativeOrMinIntInputAt(instruction, 0)) { |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 5643 | // No need to adjust the result for non-negative dividends or the INT32_MIN/INT64_MIN dividends. |
| 5644 | // NOTE: The generated code for HRem correctly works for the INT32_MIN/INT64_MIN dividends. |
| 5645 | // INT*_MIN % imm must be 0 for any imm of power 2. 'and' works only with bits |
| 5646 | // 0..30 (Int32 case)/0..62 (Int64 case) of a dividend. For INT32_MIN/INT64_MIN they are zeros. |
| 5647 | // So 'and' always produces zero. |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5648 | __ And(out, dividend, abs_imm - 1); |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 5649 | } else { |
| 5650 | if (abs_imm == 2) { |
| 5651 | __ Cmp(dividend, 0); |
| 5652 | __ And(out, dividend, 1); |
| 5653 | __ Csneg(out, out, out, ge); |
| 5654 | } else { |
| 5655 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5656 | Register temp = temps.AcquireSameSizeAs(out); |
| 5657 | |
| 5658 | __ Negs(temp, dividend); |
| 5659 | __ And(out, dividend, abs_imm - 1); |
| 5660 | __ And(temp, temp, abs_imm - 1); |
| 5661 | __ Csneg(out, out, temp, mi); |
| 5662 | } |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5663 | } |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5664 | } |
| 5665 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5666 | void InstructionCodeGeneratorARM64::GenerateIntRemForConstDenom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5667 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5668 | |
| 5669 | if (imm == 0) { |
| 5670 | // Do not generate anything. |
| 5671 | // DivZeroCheck would prevent any code to be executed. |
| 5672 | return; |
| 5673 | } |
| 5674 | |
Evgeny Astigeevich | f58dc65 | 2018-06-25 17:54:07 +0100 | [diff] [blame] | 5675 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 5676 | // Cases imm == -1 or imm == 1 are handled in constant folding by |
| 5677 | // InstructionWithAbsorbingInputSimplifier. |
| 5678 | // If the cases have survided till code generation they are handled in |
| 5679 | // GenerateIntRemForPower2Denom becauses -1 and 1 are the power of 2 (2^0). |
| 5680 | // The correct code is generated for them, just more instructions. |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5681 | GenerateIntRemForPower2Denom(instruction); |
| 5682 | } else { |
| 5683 | DCHECK(imm < -2 || imm > 2) << imm; |
| 5684 | GenerateDivRemWithAnyConstant(instruction); |
| 5685 | } |
| 5686 | } |
| 5687 | |
| 5688 | void InstructionCodeGeneratorARM64::GenerateIntRem(HRem* instruction) { |
| 5689 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 5690 | << instruction->GetResultType(); |
| 5691 | |
| 5692 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 5693 | GenerateIntRemForConstDenom(instruction); |
| 5694 | } else { |
| 5695 | Register out = OutputRegister(instruction); |
| 5696 | Register dividend = InputRegisterAt(instruction, 0); |
| 5697 | Register divisor = InputRegisterAt(instruction, 1); |
| 5698 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5699 | Register temp = temps.AcquireSameSizeAs(out); |
| 5700 | __ Sdiv(temp, dividend, divisor); |
| 5701 | __ Msub(out, temp, divisor, dividend); |
| 5702 | } |
| 5703 | } |
| 5704 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5705 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5706 | DataType::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5707 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5708 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5709 | case DataType::Type::kInt32: |
| 5710 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5711 | GenerateIntRem(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5712 | break; |
| 5713 | } |
| 5714 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5715 | case DataType::Type::kFloat32: |
| 5716 | case DataType::Type::kFloat64: { |
| 5717 | QuickEntrypointEnum entrypoint = |
| 5718 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5719 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5720 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5721 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5722 | } else { |
| 5723 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5724 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5725 | break; |
| 5726 | } |
| 5727 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5728 | default: |
| 5729 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5730 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5731 | } |
| 5732 | } |
| 5733 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5734 | void LocationsBuilderARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5735 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5736 | } |
| 5737 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5738 | void InstructionCodeGeneratorARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5739 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5740 | } |
| 5741 | |
| 5742 | void LocationsBuilderARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5743 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5744 | } |
| 5745 | |
| 5746 | void InstructionCodeGeneratorARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5747 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5748 | } |
| 5749 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5750 | void LocationsBuilderARM64::VisitAbs(HAbs* abs) { |
| 5751 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 5752 | switch (abs->GetResultType()) { |
| 5753 | case DataType::Type::kInt32: |
| 5754 | case DataType::Type::kInt64: |
| 5755 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5756 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5757 | break; |
| 5758 | case DataType::Type::kFloat32: |
| 5759 | case DataType::Type::kFloat64: |
| 5760 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5761 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5762 | break; |
| 5763 | default: |
| 5764 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5765 | } |
| 5766 | } |
| 5767 | |
| 5768 | void InstructionCodeGeneratorARM64::VisitAbs(HAbs* abs) { |
| 5769 | switch (abs->GetResultType()) { |
| 5770 | case DataType::Type::kInt32: |
| 5771 | case DataType::Type::kInt64: { |
| 5772 | Register in_reg = InputRegisterAt(abs, 0); |
| 5773 | Register out_reg = OutputRegister(abs); |
| 5774 | __ Cmp(in_reg, Operand(0)); |
| 5775 | __ Cneg(out_reg, in_reg, lt); |
| 5776 | break; |
| 5777 | } |
| 5778 | case DataType::Type::kFloat32: |
| 5779 | case DataType::Type::kFloat64: { |
Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 5780 | VRegister in_reg = InputFPRegisterAt(abs, 0); |
| 5781 | VRegister out_reg = OutputFPRegister(abs); |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5782 | __ Fabs(out_reg, in_reg); |
| 5783 | break; |
| 5784 | } |
| 5785 | default: |
| 5786 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5787 | } |
| 5788 | } |
| 5789 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5790 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5791 | constructor_fence->SetLocations(nullptr); |
| 5792 | } |
| 5793 | |
| 5794 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5795 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5796 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5797 | } |
| 5798 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5799 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5800 | memory_barrier->SetLocations(nullptr); |
| 5801 | } |
| 5802 | |
| 5803 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5804 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5805 | } |
| 5806 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5807 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5808 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5809 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5810 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5811 | } |
| 5812 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 5813 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* ret) { |
| 5814 | if (GetGraph()->IsCompilingOsr()) { |
| 5815 | // To simplify callers of an OSR method, we put the return value in both |
| 5816 | // floating point and core register. |
| 5817 | switch (ret->InputAt(0)->GetType()) { |
| 5818 | case DataType::Type::kFloat32: |
| 5819 | __ Fmov(w0, s0); |
| 5820 | break; |
| 5821 | case DataType::Type::kFloat64: |
| 5822 | __ Fmov(x0, d0); |
| 5823 | break; |
| 5824 | default: |
| 5825 | break; |
| 5826 | } |
| 5827 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5828 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5829 | } |
| 5830 | |
| 5831 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5832 | instruction->SetLocations(nullptr); |
| 5833 | } |
| 5834 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5835 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5836 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5837 | } |
| 5838 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5839 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5840 | HandleBinaryOp(ror); |
| 5841 | } |
| 5842 | |
| 5843 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5844 | HandleBinaryOp(ror); |
| 5845 | } |
| 5846 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5847 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5848 | HandleShift(shl); |
| 5849 | } |
| 5850 | |
| 5851 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5852 | HandleShift(shl); |
| 5853 | } |
| 5854 | |
| 5855 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5856 | HandleShift(shr); |
| 5857 | } |
| 5858 | |
| 5859 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5860 | HandleShift(shr); |
| 5861 | } |
| 5862 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5863 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5864 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5865 | } |
| 5866 | |
| 5867 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5868 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5869 | } |
| 5870 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5871 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5872 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5873 | } |
| 5874 | |
| 5875 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5876 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5877 | } |
| 5878 | |
| 5879 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5880 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5881 | } |
| 5882 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5883 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5884 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5885 | } |
| 5886 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 5887 | void LocationsBuilderARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5888 | codegen_->CreateStringBuilderAppendLocations(instruction, LocationFrom(x0)); |
| 5889 | } |
| 5890 | |
| 5891 | void InstructionCodeGeneratorARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5892 | __ Mov(w0, instruction->GetFormat()->GetValue()); |
| 5893 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 5894 | } |
| 5895 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5896 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5897 | HUnresolvedInstanceFieldGet* instruction) { |
| 5898 | FieldAccessCallingConventionARM64 calling_convention; |
| 5899 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5900 | instruction, instruction->GetFieldType(), calling_convention); |
| 5901 | } |
| 5902 | |
| 5903 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5904 | HUnresolvedInstanceFieldGet* instruction) { |
| 5905 | FieldAccessCallingConventionARM64 calling_convention; |
| 5906 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5907 | instruction->GetFieldType(), |
| 5908 | instruction->GetFieldIndex(), |
| 5909 | instruction->GetDexPc(), |
| 5910 | calling_convention); |
| 5911 | } |
| 5912 | |
| 5913 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5914 | HUnresolvedInstanceFieldSet* instruction) { |
| 5915 | FieldAccessCallingConventionARM64 calling_convention; |
| 5916 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5917 | instruction, instruction->GetFieldType(), calling_convention); |
| 5918 | } |
| 5919 | |
| 5920 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5921 | HUnresolvedInstanceFieldSet* instruction) { |
| 5922 | FieldAccessCallingConventionARM64 calling_convention; |
| 5923 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5924 | instruction->GetFieldType(), |
| 5925 | instruction->GetFieldIndex(), |
| 5926 | instruction->GetDexPc(), |
| 5927 | calling_convention); |
| 5928 | } |
| 5929 | |
| 5930 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5931 | HUnresolvedStaticFieldGet* instruction) { |
| 5932 | FieldAccessCallingConventionARM64 calling_convention; |
| 5933 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5934 | instruction, instruction->GetFieldType(), calling_convention); |
| 5935 | } |
| 5936 | |
| 5937 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5938 | HUnresolvedStaticFieldGet* instruction) { |
| 5939 | FieldAccessCallingConventionARM64 calling_convention; |
| 5940 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5941 | instruction->GetFieldType(), |
| 5942 | instruction->GetFieldIndex(), |
| 5943 | instruction->GetDexPc(), |
| 5944 | calling_convention); |
| 5945 | } |
| 5946 | |
| 5947 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5948 | HUnresolvedStaticFieldSet* instruction) { |
| 5949 | FieldAccessCallingConventionARM64 calling_convention; |
| 5950 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5951 | instruction, instruction->GetFieldType(), calling_convention); |
| 5952 | } |
| 5953 | |
| 5954 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5955 | HUnresolvedStaticFieldSet* instruction) { |
| 5956 | FieldAccessCallingConventionARM64 calling_convention; |
| 5957 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5958 | instruction->GetFieldType(), |
| 5959 | instruction->GetFieldIndex(), |
| 5960 | instruction->GetDexPc(), |
| 5961 | calling_convention); |
| 5962 | } |
| 5963 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5964 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5965 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5966 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5967 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5968 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5969 | // registers in full width (since the runtime only saves/restores lower part). |
| 5970 | locations->SetCustomSlowPathCallerSaves( |
| 5971 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5972 | } |
| 5973 | |
| 5974 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5975 | HBasicBlock* block = instruction->GetBlock(); |
| 5976 | if (block->GetLoopInformation() != nullptr) { |
| 5977 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5978 | // The back edge will generate the suspend check. |
| 5979 | return; |
| 5980 | } |
| 5981 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5982 | // The goto will generate the suspend check. |
| 5983 | return; |
| 5984 | } |
| 5985 | GenerateSuspendCheck(instruction, nullptr); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5986 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5987 | } |
| 5988 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5989 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5990 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5991 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5992 | InvokeRuntimeCallingConvention calling_convention; |
| 5993 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5994 | } |
| 5995 | |
| 5996 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5997 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5998 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5999 | } |
| 6000 | |
| 6001 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 6002 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6003 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6004 | DataType::Type input_type = conversion->GetInputType(); |
| 6005 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6006 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6007 | << input_type << " -> " << result_type; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6008 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 6009 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6010 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 6011 | } |
| 6012 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6013 | if (DataType::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6014 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 6015 | } else { |
| 6016 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6017 | } |
| 6018 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6019 | if (DataType::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6020 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6021 | } else { |
| 6022 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6023 | } |
| 6024 | } |
| 6025 | |
| 6026 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6027 | DataType::Type result_type = conversion->GetResultType(); |
| 6028 | DataType::Type input_type = conversion->GetInputType(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6029 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6030 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6031 | << input_type << " -> " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6032 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6033 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 6034 | int result_size = DataType::Size(result_type); |
| 6035 | int input_size = DataType::Size(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6036 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6037 | Register output = OutputRegister(conversion); |
| 6038 | Register source = InputRegisterAt(conversion, 0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6039 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 6040 | // 'int' values are used directly as W registers, discarding the top |
| 6041 | // bits, so we don't need to sign-extend and can just perform a move. |
| 6042 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 6043 | // top 32 bits of the target register. We theoretically could leave those |
| 6044 | // bits unchanged, but we would have to make sure that no code uses a |
| 6045 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 6046 | // zero. |
| 6047 | __ Mov(output.W(), source.W()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6048 | } else if (DataType::IsUnsignedType(result_type) || |
| 6049 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 6050 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6051 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6052 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6053 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6054 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6055 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6056 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 6057 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6058 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6059 | } else if (DataType::IsFloatingPointType(result_type) && |
| 6060 | DataType::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6061 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 6062 | } else { |
| 6063 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6064 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6065 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6066 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6067 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6068 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 6069 | HandleShift(ushr); |
| 6070 | } |
| 6071 | |
| 6072 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 6073 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6074 | } |
| 6075 | |
| 6076 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 6077 | HandleBinaryOp(instruction); |
| 6078 | } |
| 6079 | |
| 6080 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 6081 | HandleBinaryOp(instruction); |
| 6082 | } |
| 6083 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6084 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6085 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6086 | LOG(FATAL) << "Unreachable"; |
| 6087 | } |
| 6088 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6089 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6090 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6091 | LOG(FATAL) << "Unreachable"; |
| 6092 | } |
| 6093 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6094 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6095 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6096 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6097 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6098 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6099 | } |
| 6100 | |
| 6101 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6102 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6103 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6104 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 6105 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6106 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6107 | // 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] | 6108 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6109 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 6110 | // make sure we don't emit it if the target may run out of range. |
| 6111 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 6112 | // ranges and emit the tables only as required. |
| 6113 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6114 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6115 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6116 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 6117 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 6118 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6119 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6120 | Register temp = temps.AcquireW(); |
| 6121 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 6122 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6123 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6124 | // Jump to successors[0] if value == lower_bound. |
| 6125 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 6126 | int32_t last_index = 0; |
| 6127 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6128 | __ Subs(temp, temp, Operand(2)); |
| 6129 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6130 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6131 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6132 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6133 | } |
| 6134 | if (num_entries - last_index == 2) { |
| 6135 | // The last missing case_value. |
| 6136 | __ Cmp(temp, Operand(1)); |
| 6137 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6138 | } |
| 6139 | |
| 6140 | // And the default for any other value. |
| 6141 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6142 | __ B(codegen_->GetLabelOf(default_block)); |
| 6143 | } |
| 6144 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 6145 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6146 | |
| 6147 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6148 | |
| 6149 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 6150 | // registers, we are free to block one. |
| 6151 | Register temp_w = temps.AcquireW(); |
| 6152 | Register index; |
| 6153 | // Remove the bias. |
| 6154 | if (lower_bound != 0) { |
| 6155 | index = temp_w; |
| 6156 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 6157 | } else { |
| 6158 | index = value_reg; |
| 6159 | } |
| 6160 | |
| 6161 | // Jump to default block if index is out of the range. |
| 6162 | __ Cmp(index, Operand(num_entries)); |
| 6163 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 6164 | |
| 6165 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 6166 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 6167 | // register pressure. |
| 6168 | Register table_base = temps.AcquireX(); |
| 6169 | // Load jump offset from the table. |
| 6170 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 6171 | Register jump_offset = temp_w; |
| 6172 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 6173 | |
| 6174 | // Jump to target block by branching to table_base(pc related) + offset. |
| 6175 | Register target_address = table_base; |
| 6176 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 6177 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6178 | } |
| 6179 | } |
| 6180 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6181 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 6182 | HInstruction* instruction, |
| 6183 | Location out, |
| 6184 | uint32_t offset, |
| 6185 | Location maybe_temp, |
| 6186 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6187 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6188 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6189 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6190 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6191 | if (kUseBakerReadBarrier) { |
| 6192 | // Load with fast path based Baker's read barrier. |
| 6193 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6194 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6195 | out, |
| 6196 | out_reg, |
| 6197 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6198 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6199 | /* needs_null_check= */ false, |
| 6200 | /* use_load_acquire= */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6201 | } else { |
| 6202 | // Load with slow path based read barrier. |
| 6203 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6204 | // in the following move operation, as we will need it for the |
| 6205 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6206 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6207 | __ Mov(temp_reg, out_reg); |
| 6208 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6209 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6210 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6211 | } |
| 6212 | } else { |
| 6213 | // Plain load with no read barrier. |
| 6214 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6215 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6216 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6217 | } |
| 6218 | } |
| 6219 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6220 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 6221 | HInstruction* instruction, |
| 6222 | Location out, |
| 6223 | Location obj, |
| 6224 | uint32_t offset, |
| 6225 | Location maybe_temp, |
| 6226 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6227 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6228 | Register out_reg = RegisterFrom(out, type); |
| 6229 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6230 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6231 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6232 | if (kUseBakerReadBarrier) { |
| 6233 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6234 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6235 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6236 | out, |
| 6237 | obj_reg, |
| 6238 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6239 | maybe_temp, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6240 | /* needs_null_check= */ false, |
| 6241 | /* use_load_acquire= */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6242 | } else { |
| 6243 | // Load with slow path based read barrier. |
| 6244 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6245 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6246 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6247 | } |
| 6248 | } else { |
| 6249 | // Plain load with no read barrier. |
| 6250 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6251 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6252 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6253 | } |
| 6254 | } |
| 6255 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6256 | void CodeGeneratorARM64::GenerateGcRootFieldLoad( |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6257 | HInstruction* instruction, |
| 6258 | Location root, |
| 6259 | Register obj, |
| 6260 | uint32_t offset, |
| 6261 | vixl::aarch64::Label* fixup_label, |
| 6262 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6263 | DCHECK(fixup_label == nullptr || offset == 0u); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6264 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6265 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6266 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6267 | if (kUseBakerReadBarrier) { |
| 6268 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6269 | // Baker's read barrier are used. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6270 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6271 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6272 | // the Marking Register) to decide whether we need to enter |
| 6273 | // the slow path to mark the GC root. |
| 6274 | // |
| 6275 | // We use shared thunks for the slow path; shared within the method |
| 6276 | // for JIT, across methods for AOT. That thunk checks the reference |
| 6277 | // and jumps to the entrypoint if needed. |
| 6278 | // |
| 6279 | // lr = &return_address; |
| 6280 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6281 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6282 | // goto gc_root_thunk<root_reg>(lr) |
| 6283 | // } |
| 6284 | // return_address: |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6285 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6286 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6287 | DCHECK(temps.IsAvailable(ip0)); |
| 6288 | DCHECK(temps.IsAvailable(ip1)); |
| 6289 | temps.Exclude(ip0, ip1); |
| 6290 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6291 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6292 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6293 | vixl::aarch64::Label return_address; |
| 6294 | __ adr(lr, &return_address); |
| 6295 | if (fixup_label != nullptr) { |
| 6296 | __ bind(fixup_label); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6297 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6298 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6299 | "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] | 6300 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6301 | EmitBakerReadBarrierCbnz(custom_data); |
| 6302 | __ bind(&return_address); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6303 | } else { |
| 6304 | // GC root loaded through a slow path for read barriers other |
| 6305 | // than Baker's. |
| 6306 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6307 | if (fixup_label == nullptr) { |
| 6308 | __ Add(root_reg.X(), obj.X(), offset); |
| 6309 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6310 | EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6311 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6312 | // /* mirror::Object* */ root = root->Read() |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6313 | GenerateReadBarrierForRootSlow(instruction, root, root); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6314 | } |
| 6315 | } else { |
| 6316 | // Plain GC root load with no read barrier. |
| 6317 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6318 | if (fixup_label == nullptr) { |
| 6319 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6320 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6321 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6322 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6323 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6324 | // do not have to unpoison `root_reg` here. |
| 6325 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6326 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6327 | } |
| 6328 | |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6329 | void CodeGeneratorARM64::GenerateUnsafeCasOldValueMovWithBakerReadBarrier( |
| 6330 | vixl::aarch64::Register marked, |
| 6331 | vixl::aarch64::Register old_value) { |
| 6332 | DCHECK(kEmitCompilerReadBarrier); |
| 6333 | DCHECK(kUseBakerReadBarrier); |
| 6334 | |
| 6335 | // Similar to the Baker RB path in GenerateGcRootFieldLoad(), with a MOV instead of LDR. |
| 6336 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(marked.GetCode()); |
| 6337 | |
| 6338 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6339 | vixl::aarch64::Label return_address; |
| 6340 | __ adr(lr, &return_address); |
| 6341 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6342 | "GC root LDR must be 2 instructions (8B) before the return address label."); |
| 6343 | __ mov(marked, old_value); |
| 6344 | EmitBakerReadBarrierCbnz(custom_data); |
| 6345 | __ bind(&return_address); |
| 6346 | } |
| 6347 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6348 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6349 | Location ref, |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6350 | vixl::aarch64::Register obj, |
| 6351 | const vixl::aarch64::MemOperand& src, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6352 | bool needs_null_check, |
| 6353 | bool use_load_acquire) { |
| 6354 | DCHECK(kEmitCompilerReadBarrier); |
| 6355 | DCHECK(kUseBakerReadBarrier); |
| 6356 | |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6357 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6358 | // Marking Register) to decide whether we need to enter the slow |
| 6359 | // path to mark the reference. Then, in the slow path, check the |
| 6360 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6361 | // decide whether to mark `ref` or not. |
| 6362 | // |
| 6363 | // We use shared thunks for the slow path; shared within the method |
| 6364 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6365 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6366 | // it creates a fake dependency and returns to the LDR instruction. |
| 6367 | // |
| 6368 | // lr = &gray_return_address; |
| 6369 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6370 | // goto field_thunk<holder_reg, base_reg, use_load_acquire>(lr) |
| 6371 | // } |
| 6372 | // not_gray_return_address: |
| 6373 | // // Original reference load. If the offset is too large to fit |
| 6374 | // // into LDR, we use an adjusted base register here. |
| 6375 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 6376 | // gray_return_address: |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6377 | |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6378 | DCHECK(src.GetAddrMode() == vixl::aarch64::Offset); |
| 6379 | DCHECK_ALIGNED(src.GetOffset(), sizeof(mirror::HeapReference<mirror::Object>)); |
| 6380 | |
| 6381 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6382 | DCHECK(temps.IsAvailable(ip0)); |
| 6383 | DCHECK(temps.IsAvailable(ip1)); |
| 6384 | temps.Exclude(ip0, ip1); |
| 6385 | uint32_t custom_data = use_load_acquire |
| 6386 | ? EncodeBakerReadBarrierAcquireData(src.GetBaseRegister().GetCode(), obj.GetCode()) |
| 6387 | : EncodeBakerReadBarrierFieldData(src.GetBaseRegister().GetCode(), obj.GetCode()); |
| 6388 | |
| 6389 | { |
| 6390 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6391 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6392 | vixl::aarch64::Label return_address; |
| 6393 | __ adr(lr, &return_address); |
| 6394 | EmitBakerReadBarrierCbnz(custom_data); |
| 6395 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6396 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6397 | " 2 instructions (8B) for heap poisoning."); |
| 6398 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 6399 | if (use_load_acquire) { |
| 6400 | DCHECK_EQ(src.GetOffset(), 0); |
| 6401 | __ ldar(ref_reg, src); |
| 6402 | } else { |
| 6403 | __ ldr(ref_reg, src); |
| 6404 | } |
| 6405 | if (needs_null_check) { |
| 6406 | MaybeRecordImplicitNullCheck(instruction); |
| 6407 | } |
| 6408 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6409 | // macro instructions disallowed in ExactAssemblyScope. |
| 6410 | if (kPoisonHeapReferences) { |
| 6411 | __ neg(ref_reg, Operand(ref_reg)); |
| 6412 | } |
| 6413 | __ bind(&return_address); |
| 6414 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6415 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6416 | } |
| 6417 | |
| 6418 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6419 | Location ref, |
| 6420 | Register obj, |
| 6421 | uint32_t offset, |
| 6422 | Location maybe_temp, |
| 6423 | bool needs_null_check, |
| 6424 | bool use_load_acquire) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6425 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6426 | Register base = obj; |
| 6427 | if (use_load_acquire) { |
| 6428 | DCHECK(maybe_temp.IsRegister()); |
| 6429 | base = WRegisterFrom(maybe_temp); |
| 6430 | __ Add(base, obj, offset); |
| 6431 | offset = 0u; |
| 6432 | } else if (offset >= kReferenceLoadMinFarOffset) { |
| 6433 | DCHECK(maybe_temp.IsRegister()); |
| 6434 | base = WRegisterFrom(maybe_temp); |
| 6435 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6436 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6437 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6438 | } |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6439 | MemOperand src(base.X(), offset); |
| 6440 | GenerateFieldLoadWithBakerReadBarrier( |
| 6441 | instruction, ref, obj, src, needs_null_check, use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6442 | } |
| 6443 | |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6444 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HArrayGet* instruction, |
| 6445 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6446 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6447 | uint32_t data_offset, |
| 6448 | Location index, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6449 | bool needs_null_check) { |
| 6450 | DCHECK(kEmitCompilerReadBarrier); |
| 6451 | DCHECK(kUseBakerReadBarrier); |
| 6452 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6453 | static_assert( |
| 6454 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6455 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6456 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6457 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6458 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6459 | // Marking Register) to decide whether we need to enter the slow |
| 6460 | // path to mark the reference. Then, in the slow path, check the |
| 6461 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6462 | // decide whether to mark `ref` or not. |
| 6463 | // |
| 6464 | // We use shared thunks for the slow path; shared within the method |
| 6465 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6466 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6467 | // it creates a fake dependency and returns to the LDR instruction. |
| 6468 | // |
| 6469 | // lr = &gray_return_address; |
| 6470 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6471 | // goto array_thunk<base_reg>(lr) |
| 6472 | // } |
| 6473 | // not_gray_return_address: |
| 6474 | // // Original reference load. If the offset is too large to fit |
| 6475 | // // into LDR, we use an adjusted base register here. |
| 6476 | // HeapReference<mirror::Object> reference = data[index]; |
| 6477 | // gray_return_address: |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6478 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6479 | DCHECK(index.IsValid()); |
| 6480 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 6481 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6482 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6483 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6484 | DCHECK(temps.IsAvailable(ip0)); |
| 6485 | DCHECK(temps.IsAvailable(ip1)); |
| 6486 | temps.Exclude(ip0, ip1); |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6487 | |
| 6488 | Register temp; |
| 6489 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 6490 | // We do not need to compute the intermediate address from the array: the |
| 6491 | // input instruction has done it already. See the comment in |
| 6492 | // `TryExtractArrayAccessAddress()`. |
| 6493 | if (kIsDebugBuild) { |
| 6494 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 6495 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 6496 | } |
| 6497 | temp = obj; |
| 6498 | } else { |
| 6499 | temp = WRegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 6500 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
| 6501 | } |
| 6502 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6503 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(temp.GetCode()); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6504 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6505 | { |
| 6506 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6507 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6508 | vixl::aarch64::Label return_address; |
| 6509 | __ adr(lr, &return_address); |
| 6510 | EmitBakerReadBarrierCbnz(custom_data); |
| 6511 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6512 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6513 | " 2 instructions (8B) for heap poisoning."); |
| 6514 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6515 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6516 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6517 | // macro instructions disallowed in ExactAssemblyScope. |
| 6518 | if (kPoisonHeapReferences) { |
| 6519 | __ neg(ref_reg, Operand(ref_reg)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6520 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6521 | __ bind(&return_address); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6522 | } |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6523 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6524 | } |
| 6525 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6526 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6527 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6528 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6529 | // The following condition is a run-time one; it is executed after the |
| 6530 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6531 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6532 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6533 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6534 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6535 | } |
| 6536 | } |
| 6537 | } |
| 6538 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6539 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6540 | Location out, |
| 6541 | Location ref, |
| 6542 | Location obj, |
| 6543 | uint32_t offset, |
| 6544 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6545 | DCHECK(kEmitCompilerReadBarrier); |
| 6546 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6547 | // Insert a slow path based read barrier *after* the reference load. |
| 6548 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6549 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6550 | // reference will be carried out by the runtime within the slow |
| 6551 | // path. |
| 6552 | // |
| 6553 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6554 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6555 | // not used by the artReadBarrierSlow entry point. |
| 6556 | // |
| 6557 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6558 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6559 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6560 | AddSlowPath(slow_path); |
| 6561 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6562 | __ B(slow_path->GetEntryLabel()); |
| 6563 | __ Bind(slow_path->GetExitLabel()); |
| 6564 | } |
| 6565 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6566 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6567 | Location out, |
| 6568 | Location ref, |
| 6569 | Location obj, |
| 6570 | uint32_t offset, |
| 6571 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6572 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6573 | // Baker's read barriers shall be handled by the fast path |
| 6574 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6575 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6576 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6577 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6578 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6579 | } else if (kPoisonHeapReferences) { |
| 6580 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6581 | } |
| 6582 | } |
| 6583 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6584 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6585 | Location out, |
| 6586 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6587 | DCHECK(kEmitCompilerReadBarrier); |
| 6588 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6589 | // Insert a slow path based read barrier *after* the GC root load. |
| 6590 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6591 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6592 | // not need to do anything special for this here. |
| 6593 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6594 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6595 | AddSlowPath(slow_path); |
| 6596 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6597 | __ B(slow_path->GetEntryLabel()); |
| 6598 | __ Bind(slow_path->GetExitLabel()); |
| 6599 | } |
| 6600 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6601 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6602 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6603 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6604 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6605 | locations->SetOut(Location::RequiresRegister()); |
| 6606 | } |
| 6607 | |
| 6608 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6609 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6610 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6611 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6612 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6613 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6614 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6615 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6616 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6617 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6618 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6619 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6620 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6621 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6622 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6623 | } |
| 6624 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6625 | static void PatchJitRootUse(uint8_t* code, |
| 6626 | const uint8_t* roots_data, |
| 6627 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6628 | uint64_t index_in_table) { |
| 6629 | uint32_t literal_offset = literal->GetOffset(); |
| 6630 | uintptr_t address = |
| 6631 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6632 | uint8_t* data = code + literal_offset; |
| 6633 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6634 | } |
| 6635 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6636 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6637 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6638 | const StringReference& string_reference = entry.first; |
| 6639 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6640 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6641 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6642 | } |
| 6643 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6644 | const TypeReference& type_reference = entry.first; |
| 6645 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6646 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6647 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6648 | } |
| 6649 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6650 | |
Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 6651 | MemOperand InstructionCodeGeneratorARM64::VecNeonAddress( |
| 6652 | HVecMemoryOperation* instruction, |
| 6653 | UseScratchRegisterScope* temps_scope, |
| 6654 | size_t size, |
| 6655 | bool is_string_char_at, |
| 6656 | /*out*/ Register* scratch) { |
| 6657 | LocationSummary* locations = instruction->GetLocations(); |
| 6658 | Register base = InputRegisterAt(instruction, 0); |
| 6659 | |
| 6660 | if (instruction->InputAt(1)->IsIntermediateAddressIndex()) { |
| 6661 | DCHECK(!is_string_char_at); |
| 6662 | return MemOperand(base.X(), InputRegisterAt(instruction, 1).X()); |
| 6663 | } |
| 6664 | |
| 6665 | Location index = locations->InAt(1); |
| 6666 | uint32_t offset = is_string_char_at |
| 6667 | ? mirror::String::ValueOffset().Uint32Value() |
| 6668 | : mirror::Array::DataOffset(size).Uint32Value(); |
| 6669 | size_t shift = ComponentSizeShiftWidth(size); |
| 6670 | |
| 6671 | // HIntermediateAddress optimization is only applied for scalar ArrayGet and ArraySet. |
| 6672 | DCHECK(!instruction->InputAt(0)->IsIntermediateAddress()); |
| 6673 | |
| 6674 | if (index.IsConstant()) { |
| 6675 | offset += Int64FromLocation(index) << shift; |
| 6676 | return HeapOperand(base, offset); |
| 6677 | } else { |
| 6678 | *scratch = temps_scope->AcquireSameSizeAs(base); |
| 6679 | __ Add(*scratch, base, Operand(WRegisterFrom(index), LSL, shift)); |
| 6680 | return HeapOperand(*scratch, offset); |
| 6681 | } |
| 6682 | } |
| 6683 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6684 | #undef __ |
| 6685 | #undef QUICK_ENTRY_POINT |
| 6686 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6687 | #define __ assembler.GetVIXLAssembler()-> |
| 6688 | |
| 6689 | static void EmitGrayCheckAndFastPath(arm64::Arm64Assembler& assembler, |
| 6690 | vixl::aarch64::Register base_reg, |
| 6691 | vixl::aarch64::MemOperand& lock_word, |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6692 | vixl::aarch64::Label* slow_path, |
| 6693 | vixl::aarch64::Label* throw_npe = nullptr) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6694 | // Load the lock word containing the rb_state. |
| 6695 | __ Ldr(ip0.W(), lock_word); |
| 6696 | // 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] | 6697 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6698 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 6699 | __ Tbnz(ip0.W(), LockWord::kReadBarrierStateShift, slow_path); |
| 6700 | static_assert( |
| 6701 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET, |
| 6702 | "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] | 6703 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 6704 | if (throw_npe != nullptr) { |
| 6705 | __ Bind(throw_npe); |
| 6706 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6707 | // Adjust the return address back to the LDR (1 instruction; 2 for heap poisoning). |
| 6708 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6709 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6710 | " 2 instructions (8B) for heap poisoning."); |
| 6711 | __ Add(lr, lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6712 | // Introduce a dependency on the lock_word including rb_state, |
| 6713 | // to prevent load-load reordering, and without using |
| 6714 | // a memory barrier (which would be more expensive). |
| 6715 | __ Add(base_reg, base_reg, Operand(ip0, LSR, 32)); |
| 6716 | __ Br(lr); // And return back to the function. |
| 6717 | // Note: The fake dependency is unnecessary for the slow path. |
| 6718 | } |
| 6719 | |
| 6720 | // Load the read barrier introspection entrypoint in register `entrypoint`. |
| 6721 | static void LoadReadBarrierMarkIntrospectionEntrypoint(arm64::Arm64Assembler& assembler, |
| 6722 | vixl::aarch64::Register entrypoint) { |
| 6723 | // entrypoint = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6724 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6725 | const int32_t entry_point_offset = |
| 6726 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6727 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| 6728 | } |
| 6729 | |
| 6730 | void CodeGeneratorARM64::CompileBakerReadBarrierThunk(Arm64Assembler& assembler, |
| 6731 | uint32_t encoded_data, |
| 6732 | /*out*/ std::string* debug_name) { |
| 6733 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 6734 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6735 | case BakerReadBarrierKind::kField: |
| 6736 | case BakerReadBarrierKind::kAcquire: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6737 | auto base_reg = |
| 6738 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6739 | CheckValidReg(base_reg.GetCode()); |
| 6740 | auto holder_reg = |
| 6741 | Register::GetXRegFromCode(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6742 | CheckValidReg(holder_reg.GetCode()); |
| 6743 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6744 | temps.Exclude(ip0, ip1); |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 6745 | // In the case of a field load (with relaxed semantic), if `base_reg` differs from |
| 6746 | // `holder_reg`, the offset was too large and we must have emitted (during the construction |
| 6747 | // of the HIR graph, see `art::HInstructionBuilder::BuildInstanceFieldAccess`) and preserved |
| 6748 | // (see `art::PrepareForRegisterAllocation::VisitNullCheck`) an explicit null check before |
| 6749 | // the load. Otherwise, for implicit null checks, we need to null-check the holder as we do |
| 6750 | // not necessarily do that check before going to the thunk. |
| 6751 | // |
| 6752 | // In the case of a field load with load-acquire semantics (where `base_reg` always differs |
| 6753 | // from `holder_reg`), we also need an explicit null check when implicit null checks are |
| 6754 | // allowed, as we do not emit one before going to the thunk. |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6755 | vixl::aarch64::Label throw_npe_label; |
| 6756 | vixl::aarch64::Label* throw_npe = nullptr; |
Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 6757 | if (GetCompilerOptions().GetImplicitNullChecks() && |
| 6758 | (holder_reg.Is(base_reg) || (kind == BakerReadBarrierKind::kAcquire))) { |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6759 | throw_npe = &throw_npe_label; |
| 6760 | __ Cbz(holder_reg.W(), throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6761 | } |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6762 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 6763 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 6764 | // to load the reference and call the entrypoint that performs further checks on the |
| 6765 | // reference and marks it if needed. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6766 | vixl::aarch64::Label slow_path; |
| 6767 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6768 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6769 | __ Bind(&slow_path); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6770 | if (kind == BakerReadBarrierKind::kField) { |
| 6771 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6772 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (immediate) unsigned offset. |
| 6773 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6774 | __ Ubfx(ip0.W(), ip0.W(), 10, 12); // Extract the offset. |
| 6775 | __ Ldr(ip0.W(), MemOperand(base_reg, ip0, LSL, 2)); // Load the reference. |
| 6776 | } else { |
| 6777 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 6778 | DCHECK(!base_reg.Is(holder_reg)); |
| 6779 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6780 | __ Ldar(ip0.W(), MemOperand(base_reg)); |
| 6781 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6782 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 6783 | __ Br(ip1); // Jump to the entrypoint. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6784 | break; |
| 6785 | } |
| 6786 | case BakerReadBarrierKind::kArray: { |
| 6787 | auto base_reg = |
| 6788 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6789 | CheckValidReg(base_reg.GetCode()); |
| 6790 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6791 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6792 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6793 | temps.Exclude(ip0, ip1); |
| 6794 | vixl::aarch64::Label slow_path; |
| 6795 | int32_t data_offset = |
| 6796 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 6797 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 6798 | DCHECK_LT(lock_word.GetOffset(), 0); |
| 6799 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path); |
| 6800 | __ Bind(&slow_path); |
| 6801 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| 6802 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (register) unsigned offset. |
| 6803 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6804 | __ Ubfx(ip0, ip0, 16, 6); // Extract the index register, plus 32 (bit 21 is set). |
| 6805 | __ Bfi(ip1, ip0, 3, 6); // Insert ip0 to the entrypoint address to create |
| 6806 | // a switch case target based on the index register. |
| 6807 | __ Mov(ip0, base_reg); // Move the base register to ip0. |
| 6808 | __ Br(ip1); // Jump to the entrypoint's array switch case. |
| 6809 | break; |
| 6810 | } |
| 6811 | case BakerReadBarrierKind::kGcRoot: { |
| 6812 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 6813 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 6814 | // otherwise return the reference (or the extracted forwarding address). |
| 6815 | // There is no gray bit check for GC roots. |
| 6816 | auto root_reg = |
| 6817 | Register::GetWRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6818 | CheckValidReg(root_reg.GetCode()); |
| 6819 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6820 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6821 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6822 | temps.Exclude(ip0, ip1); |
| 6823 | vixl::aarch64::Label return_label, not_marked, forwarding_address; |
| 6824 | __ Cbz(root_reg, &return_label); |
| 6825 | MemOperand lock_word(root_reg.X(), mirror::Object::MonitorOffset().Int32Value()); |
| 6826 | __ Ldr(ip0.W(), lock_word); |
| 6827 | __ Tbz(ip0.W(), LockWord::kMarkBitStateShift, ¬_marked); |
| 6828 | __ Bind(&return_label); |
| 6829 | __ Br(lr); |
| 6830 | __ Bind(¬_marked); |
| 6831 | __ Tst(ip0.W(), Operand(ip0.W(), LSL, 1)); |
| 6832 | __ B(&forwarding_address, mi); |
| 6833 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6834 | // Adjust the art_quick_read_barrier_mark_introspection address in IP1 to |
| 6835 | // art_quick_read_barrier_mark_introspection_gc_roots. |
| 6836 | __ Add(ip1, ip1, Operand(BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET)); |
| 6837 | __ Mov(ip0.W(), root_reg); |
| 6838 | __ Br(ip1); |
| 6839 | __ Bind(&forwarding_address); |
| 6840 | __ Lsl(root_reg, ip0.W(), LockWord::kForwardingAddressShift); |
| 6841 | __ Br(lr); |
| 6842 | break; |
| 6843 | } |
| 6844 | default: |
| 6845 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 6846 | UNREACHABLE(); |
| 6847 | } |
| 6848 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6849 | // For JIT, the slow path is considered part of the compiled method, |
Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 6850 | // so JIT should pass null as `debug_name`. |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 6851 | DCHECK(!GetCompilerOptions().IsJitCompiler() || debug_name == nullptr); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6852 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6853 | std::ostringstream oss; |
| 6854 | oss << "BakerReadBarrierThunk"; |
| 6855 | switch (kind) { |
| 6856 | case BakerReadBarrierKind::kField: |
| 6857 | oss << "Field_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 6858 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 6859 | break; |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6860 | case BakerReadBarrierKind::kAcquire: |
| 6861 | oss << "Acquire_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 6862 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 6863 | break; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6864 | case BakerReadBarrierKind::kArray: |
| 6865 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6866 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6867 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6868 | break; |
| 6869 | case BakerReadBarrierKind::kGcRoot: |
| 6870 | oss << "GcRoot_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6871 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6872 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6873 | break; |
| 6874 | } |
| 6875 | *debug_name = oss.str(); |
| 6876 | } |
| 6877 | } |
| 6878 | |
| 6879 | #undef __ |
| 6880 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6881 | } // namespace arm64 |
| 6882 | } // namespace art |