| 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" |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 21 | #include "art_method-inl.h" |
| Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 22 | #include "base/bit_utils.h" |
| 23 | #include "base/bit_utils_iterator.h" |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 24 | #include "class_table.h" |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 25 | #include "code_generator_utils.h" |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 26 | #include "compiled_method.h" |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 27 | #include "entrypoints/quick/quick_entrypoints.h" |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 28 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 29 | #include "gc/accounting/card_table.h" |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 30 | #include "gc/space/image_space.h" |
| Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 31 | #include "heap_poisoning.h" |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 32 | #include "intrinsics.h" |
| 33 | #include "intrinsics_arm64.h" |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 34 | #include "linker/linker_patch.h" |
| Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 35 | #include "lock_word.h" |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 36 | #include "mirror/array-inl.h" |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 37 | #include "mirror/class-inl.h" |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 38 | #include "offsets.h" |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 39 | #include "thread.h" |
| 40 | #include "utils/arm64/assembler_arm64.h" |
| 41 | #include "utils/assembler.h" |
| 42 | #include "utils/stack_checks.h" |
| 43 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 44 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 45 | using vixl::ExactAssemblyScope; |
| 46 | using vixl::CodeBufferCheckScope; |
| 47 | using vixl::EmissionCheckScope; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 48 | |
| 49 | #ifdef __ |
| 50 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 51 | #endif |
| 52 | |
| Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 53 | namespace art { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 54 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 55 | template<class MirrorType> |
| 56 | class GcRoot; |
| 57 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 58 | namespace arm64 { |
| 59 | |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 60 | using helpers::ARM64EncodableConstantOrRegister; |
| 61 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 62 | using helpers::CPURegisterFrom; |
| 63 | using helpers::DRegisterFrom; |
| 64 | using helpers::FPRegisterFrom; |
| 65 | using helpers::HeapOperand; |
| 66 | using helpers::HeapOperandFrom; |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 67 | using helpers::InputCPURegisterOrZeroRegAt; |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 68 | using helpers::InputFPRegisterAt; |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 | using helpers::InputOperandAt; |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 70 | using helpers::InputRegisterAt; |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 71 | using helpers::Int64FromLocation; |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 72 | using helpers::IsConstantZeroBitPattern; |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 73 | using helpers::LocationFrom; |
| 74 | using helpers::OperandFromMemOperand; |
| 75 | using helpers::OutputCPURegister; |
| 76 | using helpers::OutputFPRegister; |
| 77 | using helpers::OutputRegister; |
| 78 | using helpers::RegisterFrom; |
| 79 | using helpers::StackOperandFrom; |
| 80 | using helpers::VIXLRegCodeFromART; |
| 81 | using helpers::WRegisterFrom; |
| 82 | using helpers::XRegisterFrom; |
| 83 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 84 | // 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] | 85 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 86 | // generates less code/data with a small num_entries. |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 87 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 88 | |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 89 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 90 | // 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] | 91 | // 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] | 92 | // the offset explicitly. |
| 93 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 94 | |
| Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 95 | ALWAYS_INLINE static inline bool UseJitCompilation() { |
| 96 | Runtime* runtime = Runtime::Current(); |
| 97 | // Note: There may be no Runtime for gtests; gtests use debug builds. |
| 98 | return (!kIsDebugBuild || runtime != nullptr) && runtime->UseJitCompilation(); |
| 99 | } |
| 100 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 101 | inline Condition ARM64Condition(IfCondition cond) { |
| 102 | switch (cond) { |
| 103 | case kCondEQ: return eq; |
| 104 | case kCondNE: return ne; |
| 105 | case kCondLT: return lt; |
| 106 | case kCondLE: return le; |
| 107 | case kCondGT: return gt; |
| 108 | case kCondGE: return ge; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 109 | case kCondB: return lo; |
| 110 | case kCondBE: return ls; |
| 111 | case kCondA: return hi; |
| 112 | case kCondAE: return hs; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 113 | } |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 114 | LOG(FATAL) << "Unreachable"; |
| 115 | UNREACHABLE(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 118 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 119 | // The ARM64 condition codes can express all the necessary branches, see the |
| 120 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 121 | // There is no dex instruction or HIR that would need the missing conditions |
| 122 | // "equal or unordered" or "not equal". |
| 123 | switch (cond) { |
| 124 | case kCondEQ: return eq; |
| 125 | case kCondNE: return ne /* unordered */; |
| 126 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 127 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 128 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 129 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 130 | default: |
| 131 | LOG(FATAL) << "UNREACHABLE"; |
| 132 | UNREACHABLE(); |
| 133 | } |
| 134 | } |
| 135 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 136 | Location ARM64ReturnLocation(DataType::Type return_type) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 137 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 138 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 139 | // but we use the exact registers for clarity. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 140 | if (return_type == DataType::Type::kFloat32) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 141 | return LocationFrom(s0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 142 | } else if (return_type == DataType::Type::kFloat64) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 143 | return LocationFrom(d0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 144 | } else if (return_type == DataType::Type::kInt64) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 145 | return LocationFrom(x0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 146 | } else if (return_type == DataType::Type::kVoid) { |
| Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 147 | return Location::NoLocation(); |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 148 | } else { |
| 149 | return LocationFrom(w0); |
| 150 | } |
| 151 | } |
| 152 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 153 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type return_type) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 154 | return ARM64ReturnLocation(return_type); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 155 | } |
| 156 | |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 157 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 158 | InvokeRuntimeCallingConvention calling_convention; |
| 159 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 160 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 161 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 162 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 163 | DataType::Type::kReference).GetCode()); |
| 164 | return caller_saves; |
| 165 | } |
| 166 | |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 167 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 168 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 169 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 170 | |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 171 | // Calculate memory accessing operand for save/restore live registers. |
| 172 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 173 | LocationSummary* locations, |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 174 | int64_t spill_offset, |
| 175 | bool is_save) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 176 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
| 177 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 178 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 179 | codegen->GetNumberOfCoreRegisters(), |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 180 | fp_spills, |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 181 | codegen->GetNumberOfFloatingPointRegisters())); |
| 182 | |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 183 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
| Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 184 | const unsigned v_reg_size_in_bits = codegen->GetSlowPathFPWidth() * 8; |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 185 | DCHECK_LE(codegen->GetSIMDRegisterWidth(), kQRegSizeInBytes); |
| Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 186 | 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] | 187 | |
| 188 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 189 | UseScratchRegisterScope temps(masm); |
| 190 | |
| 191 | Register base = masm->StackPointer(); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 192 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 193 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 194 | int64_t reg_size = kXRegSizeInBytes; |
| 195 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 196 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 197 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 198 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 199 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 200 | // to compute the base address(float point registers spill base address). |
| 201 | Register new_base = temps.AcquireSameSizeAs(base); |
| 202 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 203 | base = new_base; |
| 204 | spill_offset = -core_spill_size; |
| 205 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 206 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 207 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 208 | } |
| 209 | |
| 210 | if (is_save) { |
| 211 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 212 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 213 | } else { |
| 214 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 215 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 220 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 221 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 222 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 223 | // If the register holds an object, update the stack mask. |
| 224 | if (locations->RegisterContainsObject(i)) { |
| 225 | locations->SetStackBit(stack_offset / kVRegSize); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 226 | } |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 227 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 228 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 229 | saved_core_stack_offsets_[i] = stack_offset; |
| 230 | stack_offset += kXRegSizeInBytes; |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 231 | } |
| 232 | |
| Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 233 | const size_t fp_reg_size = codegen->GetSlowPathFPWidth(); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 234 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 235 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 236 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 237 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 238 | saved_fpu_stack_offsets_[i] = stack_offset; |
| Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 239 | stack_offset += fp_reg_size; |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 240 | } |
| 241 | |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 242 | SaveRestoreLiveRegistersHelper(codegen, |
| 243 | locations, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 244 | codegen->GetFirstRegisterSlotInSlowPath(), /* is_save= */ true); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 248 | SaveRestoreLiveRegistersHelper(codegen, |
| 249 | locations, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 250 | codegen->GetFirstRegisterSlotInSlowPath(), /* is_save= */ false); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 251 | } |
| 252 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 253 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 254 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 255 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 256 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 257 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 258 | LocationSummary* locations = instruction_->GetLocations(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 259 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 260 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 261 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 262 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 263 | // Live registers will be restored in the catch block if caught. |
| 264 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 265 | } |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 266 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 267 | // move resolver. |
| 268 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 269 | codegen->EmitParallelMoves(locations->InAt(0), |
| 270 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 271 | DataType::Type::kInt32, |
| 272 | locations->InAt(1), |
| 273 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 274 | DataType::Type::kInt32); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 275 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 276 | ? kQuickThrowStringBounds |
| 277 | : kQuickThrowArrayBounds; |
| 278 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 279 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 280 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 281 | } |
| 282 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 283 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 284 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 285 | const char* GetDescription() const override { return "BoundsCheckSlowPathARM64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 286 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 287 | private: |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 288 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 289 | }; |
| 290 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 291 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 292 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 293 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 294 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 295 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 296 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 297 | __ Bind(GetEntryLabel()); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 298 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 299 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 302 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 303 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 304 | const char* GetDescription() const override { return "DivZeroCheckSlowPathARM64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 305 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 306 | private: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 307 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 308 | }; |
| 309 | |
| 310 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 311 | public: |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 312 | LoadClassSlowPathARM64(HLoadClass* cls, HInstruction* at) |
| 313 | : SlowPathCodeARM64(at), cls_(cls) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 314 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 315 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 318 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 319 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 320 | Location out = locations->Out(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 321 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 322 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 323 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 324 | |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 325 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 326 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 327 | SaveLiveRegisters(codegen, locations); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 328 | |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 329 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 330 | if (must_resolve_type) { |
| 331 | DCHECK(IsSameDexFile(cls_->GetDexFile(), arm64_codegen->GetGraph()->GetDexFile())); |
| 332 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 333 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
| Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 334 | arm64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 335 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 336 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 337 | } else { |
| 338 | DCHECK(must_do_clinit); |
| 339 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 340 | arm64_codegen->MoveLocation(LocationFrom(calling_convention.GetRegisterAt(0)), |
| 341 | source, |
| 342 | cls_->GetType()); |
| 343 | } |
| 344 | if (must_do_clinit) { |
| 345 | arm64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 346 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 347 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 348 | |
| 349 | // Move the class to the desired location. |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 350 | if (out.IsValid()) { |
| 351 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 352 | DataType::Type type = instruction_->GetType(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 353 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 354 | } |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 355 | RestoreLiveRegisters(codegen, locations); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 356 | __ B(GetExitLabel()); |
| 357 | } |
| 358 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 359 | const char* GetDescription() const override { return "LoadClassSlowPathARM64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 360 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 361 | private: |
| 362 | // The class this slow path will load. |
| 363 | HLoadClass* const cls_; |
| 364 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 365 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 366 | }; |
| 367 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 368 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 369 | public: |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 370 | explicit LoadStringSlowPathARM64(HLoadString* instruction) |
| 371 | : SlowPathCodeARM64(instruction) {} |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 372 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 373 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 374 | LocationSummary* locations = instruction_->GetLocations(); |
| 375 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 376 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 377 | |
| 378 | __ Bind(GetEntryLabel()); |
| 379 | SaveLiveRegisters(codegen, locations); |
| 380 | |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 381 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 382 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 383 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 384 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 385 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 386 | DataType::Type type = instruction_->GetType(); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 387 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 388 | |
| 389 | RestoreLiveRegisters(codegen, locations); |
| 390 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 391 | __ B(GetExitLabel()); |
| 392 | } |
| 393 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 394 | const char* GetDescription() const override { return "LoadStringSlowPathARM64"; } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 395 | |
| 396 | private: |
| 397 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 398 | }; |
| 399 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 400 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 401 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 402 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 403 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 404 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 405 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 406 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 407 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 408 | // Live registers will be restored in the catch block if caught. |
| 409 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 410 | } |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 411 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 412 | instruction_, |
| 413 | instruction_->GetDexPc(), |
| 414 | this); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 415 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 416 | } |
| 417 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 418 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 419 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 420 | const char* GetDescription() const override { return "NullCheckSlowPathARM64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 421 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 422 | private: |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 423 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 424 | }; |
| 425 | |
| 426 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 427 | public: |
| Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 428 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 429 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 430 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 431 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 432 | LocationSummary* locations = instruction_->GetLocations(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 433 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 434 | __ Bind(GetEntryLabel()); |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 435 | SaveLiveRegisters(codegen, locations); // Only saves live vector regs for SIMD. |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 436 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 437 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 438 | RestoreLiveRegisters(codegen, locations); // Only restores live vector regs for SIMD. |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 439 | if (successor_ == nullptr) { |
| 440 | __ B(GetReturnLabel()); |
| 441 | } else { |
| 442 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 443 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 444 | } |
| 445 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 446 | vixl::aarch64::Label* GetReturnLabel() { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 447 | DCHECK(successor_ == nullptr); |
| 448 | return &return_label_; |
| 449 | } |
| 450 | |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 451 | HBasicBlock* GetSuccessor() const { |
| 452 | return successor_; |
| 453 | } |
| 454 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 455 | const char* GetDescription() const override { return "SuspendCheckSlowPathARM64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 456 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 457 | private: |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 458 | // If not null, the block to branch to after the suspend check. |
| 459 | HBasicBlock* const successor_; |
| 460 | |
| 461 | // 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] | 462 | vixl::aarch64::Label return_label_; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 463 | |
| 464 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 465 | }; |
| 466 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 467 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 468 | public: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 469 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 470 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 471 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 472 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 473 | LocationSummary* locations = instruction_->GetLocations(); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 474 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 475 | DCHECK(instruction_->IsCheckCast() |
| 476 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 477 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 478 | uint32_t dex_pc = instruction_->GetDexPc(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 479 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 480 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 481 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 482 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 483 | SaveLiveRegisters(codegen, locations); |
| 484 | } |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 485 | |
| 486 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 487 | // move resolver. |
| 488 | InvokeRuntimeCallingConvention calling_convention; |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 489 | codegen->EmitParallelMoves(locations->InAt(0), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 490 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 491 | DataType::Type::kReference, |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 492 | locations->InAt(1), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 493 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 494 | DataType::Type::kReference); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 495 | if (instruction_->IsInstanceOf()) { |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 496 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 497 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 498 | DataType::Type ret_type = instruction_->GetType(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 499 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 500 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 501 | } else { |
| 502 | DCHECK(instruction_->IsCheckCast()); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 503 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 504 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 505 | } |
| 506 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 507 | if (!is_fatal_) { |
| 508 | RestoreLiveRegisters(codegen, locations); |
| 509 | __ B(GetExitLabel()); |
| 510 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 513 | const char* GetDescription() const override { return "TypeCheckSlowPathARM64"; } |
| 514 | bool IsFatal() const override { return is_fatal_; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 515 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 516 | private: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 517 | const bool is_fatal_; |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 518 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 519 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 520 | }; |
| 521 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 522 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 523 | public: |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 524 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 525 | : SlowPathCodeARM64(instruction) {} |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 526 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 527 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 528 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 529 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 530 | LocationSummary* locations = instruction_->GetLocations(); |
| 531 | SaveLiveRegisters(codegen, locations); |
| 532 | InvokeRuntimeCallingConvention calling_convention; |
| 533 | __ Mov(calling_convention.GetRegisterAt(0), |
| 534 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 535 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 536 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 539 | const char* GetDescription() const override { return "DeoptimizationSlowPathARM64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 540 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 541 | private: |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 542 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 543 | }; |
| 544 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 545 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 546 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 547 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 548 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 549 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 550 | LocationSummary* locations = instruction_->GetLocations(); |
| 551 | __ Bind(GetEntryLabel()); |
| 552 | SaveLiveRegisters(codegen, locations); |
| 553 | |
| 554 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 555 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 556 | parallel_move.AddMove( |
| 557 | locations->InAt(0), |
| 558 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 559 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 560 | nullptr); |
| 561 | parallel_move.AddMove( |
| 562 | locations->InAt(1), |
| 563 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 564 | DataType::Type::kInt32, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 565 | nullptr); |
| 566 | parallel_move.AddMove( |
| 567 | locations->InAt(2), |
| 568 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 569 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 570 | nullptr); |
| 571 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 572 | |
| 573 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 574 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 575 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 576 | RestoreLiveRegisters(codegen, locations); |
| 577 | __ B(GetExitLabel()); |
| 578 | } |
| 579 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 580 | const char* GetDescription() const override { return "ArraySetSlowPathARM64"; } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 581 | |
| 582 | private: |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 583 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 584 | }; |
| 585 | |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 586 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 587 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 588 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 589 | |
| 590 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 591 | // 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] | 592 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 593 | num_entries * sizeof(int32_t), |
| 594 | CodeBufferCheckScope::kExactSize); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 595 | |
| 596 | __ Bind(&table_start_); |
| 597 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 598 | for (uint32_t i = 0; i < num_entries; i++) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 599 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 600 | DCHECK(target_label->IsBound()); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 601 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 602 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 603 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 604 | Literal<int32_t> literal(jump_offset); |
| 605 | __ place(&literal); |
| 606 | } |
| 607 | } |
| 608 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 609 | // Slow path generating a read barrier for a heap reference. |
| 610 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 611 | public: |
| 612 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 613 | Location out, |
| 614 | Location ref, |
| 615 | Location obj, |
| 616 | uint32_t offset, |
| 617 | Location index) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 618 | : SlowPathCodeARM64(instruction), |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 619 | out_(out), |
| 620 | ref_(ref), |
| 621 | obj_(obj), |
| 622 | offset_(offset), |
| 623 | index_(index) { |
| 624 | DCHECK(kEmitCompilerReadBarrier); |
| 625 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 626 | // has been overwritten by (or after) the heap object reference load |
| 627 | // to be instrumented, e.g.: |
| 628 | // |
| 629 | // __ Ldr(out, HeapOperand(out, class_offset); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 630 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 631 | // |
| 632 | // In that case, we have lost the information about the original |
| 633 | // object, and the emitted read barrier cannot work properly. |
| 634 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 635 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 636 | } |
| 637 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 638 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 639 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 640 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 641 | DataType::Type type = DataType::Type::kReference; |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 642 | DCHECK(locations->CanCall()); |
| 643 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 644 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 645 | instruction_->IsStaticFieldGet() || |
| 646 | instruction_->IsArrayGet() || |
| 647 | instruction_->IsInstanceOf() || |
| 648 | instruction_->IsCheckCast() || |
| Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 649 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 650 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 651 | << instruction_->DebugName(); |
| Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 652 | // The read barrier instrumentation of object ArrayGet |
| 653 | // instructions does not support the HIntermediateAddress |
| 654 | // instruction. |
| Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 655 | DCHECK(!(instruction_->IsArrayGet() && |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 656 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 657 | |
| 658 | __ Bind(GetEntryLabel()); |
| 659 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 660 | SaveLiveRegisters(codegen, locations); |
| 661 | |
| 662 | // We may have to change the index's value, but as `index_` is a |
| 663 | // constant member (like other "inputs" of this slow path), |
| 664 | // introduce a copy of it, `index`. |
| 665 | Location index = index_; |
| 666 | if (index_.IsValid()) { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 667 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 668 | if (instruction_->IsArrayGet()) { |
| 669 | // Compute the actual memory offset and store it in `index`. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 670 | Register index_reg = RegisterFrom(index_, DataType::Type::kInt32); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 671 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 672 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 673 | // We are about to change the value of `index_reg` (see the |
| 674 | // calls to vixl::MacroAssembler::Lsl and |
| 675 | // vixl::MacroAssembler::Mov below), but it has |
| 676 | // not been saved by the previous call to |
| 677 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 678 | // callee-save register -- |
| 679 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 680 | // callee-save registers, as it has been designed with the |
| 681 | // assumption that callee-save registers are supposed to be |
| 682 | // handled by the called function. So, as a callee-save |
| 683 | // register, `index_reg` _would_ eventually be saved onto |
| 684 | // the stack, but it would be too late: we would have |
| 685 | // changed its value earlier. Therefore, we manually save |
| 686 | // it here into another freely available register, |
| 687 | // `free_reg`, chosen of course among the caller-save |
| 688 | // registers (as a callee-save `free_reg` register would |
| 689 | // exhibit the same problem). |
| 690 | // |
| 691 | // Note we could have requested a temporary register from |
| 692 | // the register allocator instead; but we prefer not to, as |
| 693 | // this is a slow path, and we know we can find a |
| 694 | // caller-save register that is available. |
| 695 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 696 | __ Mov(free_reg.W(), index_reg); |
| 697 | index_reg = free_reg; |
| 698 | index = LocationFrom(index_reg); |
| 699 | } else { |
| 700 | // The initial register stored in `index_` has already been |
| 701 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 702 | // (as it is not a callee-save register), so we can freely |
| 703 | // use it. |
| 704 | } |
| 705 | // Shifting the index value contained in `index_reg` by the scale |
| 706 | // factor (2) cannot overflow in practice, as the runtime is |
| 707 | // unable to allocate object arrays with a size larger than |
| 708 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 709 | __ Lsl(index_reg, index_reg, DataType::SizeShift(type)); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 710 | static_assert( |
| 711 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 712 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 713 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 714 | } else { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 715 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 716 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 717 | // (as in the case of ArrayGet), as it is actually an offset |
| 718 | // to an object field within an object. |
| 719 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 720 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 721 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 722 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 723 | << instruction_->AsInvoke()->GetIntrinsic(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 724 | DCHECK_EQ(offset_, 0u); |
| Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 725 | DCHECK(index_.IsRegister()); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | |
| 729 | // We're moving two or three locations to locations that could |
| 730 | // overlap, so we need a parallel move resolver. |
| 731 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 732 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 733 | parallel_move.AddMove(ref_, |
| 734 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 735 | type, |
| 736 | nullptr); |
| 737 | parallel_move.AddMove(obj_, |
| 738 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 739 | type, |
| 740 | nullptr); |
| 741 | if (index.IsValid()) { |
| 742 | parallel_move.AddMove(index, |
| 743 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 744 | DataType::Type::kInt32, |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 745 | nullptr); |
| 746 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 747 | } else { |
| 748 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 749 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 750 | } |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 751 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 752 | instruction_, |
| 753 | instruction_->GetDexPc(), |
| 754 | this); |
| 755 | CheckEntrypointTypes< |
| 756 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 757 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 758 | |
| 759 | RestoreLiveRegisters(codegen, locations); |
| 760 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 761 | __ B(GetExitLabel()); |
| 762 | } |
| 763 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 764 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 765 | |
| 766 | private: |
| 767 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 768 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 769 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 770 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 771 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 772 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 773 | } |
| 774 | } |
| 775 | // We shall never fail to find a free caller-save register, as |
| 776 | // there are more than two core caller-save registers on ARM64 |
| 777 | // (meaning it is possible to find one which is different from |
| 778 | // `ref` and `obj`). |
| 779 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 780 | LOG(FATAL) << "Could not find a free register"; |
| 781 | UNREACHABLE(); |
| 782 | } |
| 783 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 784 | const Location out_; |
| 785 | const Location ref_; |
| 786 | const Location obj_; |
| 787 | const uint32_t offset_; |
| 788 | // An additional location containing an index to an array. |
| 789 | // Only used for HArrayGet and the UnsafeGetObject & |
| 790 | // UnsafeGetObjectVolatile intrinsics. |
| 791 | const Location index_; |
| 792 | |
| 793 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 794 | }; |
| 795 | |
| 796 | // Slow path generating a read barrier for a GC root. |
| 797 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 798 | public: |
| 799 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 800 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 801 | DCHECK(kEmitCompilerReadBarrier); |
| 802 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 803 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 804 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 805 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 806 | DataType::Type type = DataType::Type::kReference; |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 807 | DCHECK(locations->CanCall()); |
| 808 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 809 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 810 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 811 | << instruction_->DebugName(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 812 | |
| 813 | __ Bind(GetEntryLabel()); |
| 814 | SaveLiveRegisters(codegen, locations); |
| 815 | |
| 816 | InvokeRuntimeCallingConvention calling_convention; |
| 817 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 818 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 819 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 820 | // thus we need a 64-bit move here, and we cannot use |
| 821 | // |
| 822 | // arm64_codegen->MoveLocation( |
| 823 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 824 | // root_, |
| 825 | // type); |
| 826 | // |
| 827 | // 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] | 828 | // reference type (`DataType::Type::kReference`). |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 829 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 830 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 831 | instruction_, |
| 832 | instruction_->GetDexPc(), |
| 833 | this); |
| 834 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 835 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 836 | |
| 837 | RestoreLiveRegisters(codegen, locations); |
| 838 | __ B(GetExitLabel()); |
| 839 | } |
| 840 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 841 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathARM64"; } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 842 | |
| 843 | private: |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 844 | const Location out_; |
| 845 | const Location root_; |
| 846 | |
| 847 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 848 | }; |
| 849 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 850 | #undef __ |
| 851 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 852 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 853 | Location next_location; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 854 | if (type == DataType::Type::kVoid) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 855 | LOG(FATAL) << "Unreachable type " << type; |
| 856 | } |
| 857 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 858 | if (DataType::IsFloatingPointType(type) && |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 859 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 860 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 861 | } else if (!DataType::IsFloatingPointType(type) && |
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 862 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 863 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 864 | } else { |
| 865 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 866 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 867 | : Location::StackSlot(stack_offset); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 868 | } |
| 869 | |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 870 | // Space on the stack is reserved for all arguments. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 871 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 872 | return next_location; |
| 873 | } |
| 874 | |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 875 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 876 | return LocationFrom(kArtMethodRegister); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 877 | } |
| 878 | |
| Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 879 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 880 | const CompilerOptions& compiler_options, |
| 881 | OptimizingCompilerStats* stats) |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 882 | : CodeGenerator(graph, |
| 883 | kNumberOfAllocatableRegisters, |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 884 | kNumberOfAllocatableFPRegisters, |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 885 | kNumberOfAllocatableRegisterPairs, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 886 | callee_saved_core_registers.GetList(), |
| 887 | callee_saved_fp_registers.GetList(), |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 888 | compiler_options, |
| 889 | stats), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 890 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 891 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 892 | location_builder_neon_(graph, this), |
| 893 | instruction_visitor_neon_(graph, this), |
| 894 | location_builder_sve_(graph, this), |
| 895 | instruction_visitor_sve_(graph, this), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 896 | move_resolver_(graph->GetAllocator(), this), |
| Artem Serov | aa6f483 | 2018-11-21 18:57:54 +0000 | [diff] [blame] | 897 | assembler_(graph->GetAllocator(), |
| 898 | compiler_options.GetInstructionSetFeatures()->AsArm64InstructionSetFeatures()), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 899 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 900 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 901 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 902 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 903 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 904 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 905 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 906 | call_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 907 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 908 | uint32_literals_(std::less<uint32_t>(), |
| 909 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 910 | uint64_literals_(std::less<uint64_t>(), |
| 911 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 912 | jit_string_patches_(StringReferenceValueComparator(), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 913 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 914 | jit_class_patches_(TypeReferenceValueComparator(), |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 915 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 916 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 917 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 918 | // Save the link register (containing the return address) to mimic Quick. |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 919 | AddAllocatedRegister(LocationFrom(lr)); |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 920 | |
| 921 | bool use_sve = ShouldUseSVE(); |
| 922 | if (use_sve) { |
| 923 | location_builder_ = &location_builder_sve_; |
| 924 | instruction_visitor_ = &instruction_visitor_sve_; |
| 925 | } else { |
| 926 | location_builder_ = &location_builder_neon_; |
| 927 | instruction_visitor_ = &instruction_visitor_neon_; |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | bool CodeGeneratorARM64::ShouldUseSVE() const { |
| 932 | return kArm64AllowSVE && GetInstructionSetFeatures().HasSVE(); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 933 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 934 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 935 | #define __ GetVIXLAssembler()-> |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 936 | |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 937 | void CodeGeneratorARM64::EmitJumpTables() { |
| Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 938 | for (auto&& jump_table : jump_tables_) { |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 939 | jump_table->EmitTable(this); |
| 940 | } |
| 941 | } |
| 942 | |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 943 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 944 | EmitJumpTables(); |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 945 | |
| 946 | // Emit JIT baker read barrier slow paths. |
| Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 947 | DCHECK(UseJitCompilation() || jit_baker_read_barrier_slow_paths_.empty()); |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 948 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 949 | uint32_t encoded_data = entry.first; |
| 950 | vixl::aarch64::Label* slow_path_entry = &entry.second.label; |
| 951 | __ Bind(slow_path_entry); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 952 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name= */ nullptr); |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 955 | // Ensure we emit the literal pool. |
| 956 | __ FinalizeCode(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 957 | |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 958 | CodeGenerator::Finalize(allocator); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 959 | |
| 960 | // Verify Baker read barrier linker patches. |
| 961 | if (kIsDebugBuild) { |
| 962 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 963 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 964 | DCHECK(info.label.IsBound()); |
| 965 | uint32_t literal_offset = info.label.GetLocation(); |
| 966 | DCHECK_ALIGNED(literal_offset, 4u); |
| 967 | |
| 968 | auto GetInsn = [&code](uint32_t offset) { |
| 969 | DCHECK_ALIGNED(offset, 4u); |
| 970 | return |
| 971 | (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 972 | (static_cast<uint32_t>(code[offset + 1]) << 8) + |
| 973 | (static_cast<uint32_t>(code[offset + 2]) << 16)+ |
| 974 | (static_cast<uint32_t>(code[offset + 3]) << 24); |
| 975 | }; |
| 976 | |
| 977 | const uint32_t encoded_data = info.custom_data; |
| 978 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 979 | // Check that the next instruction matches the expected LDR. |
| 980 | switch (kind) { |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 981 | case BakerReadBarrierKind::kField: |
| 982 | case BakerReadBarrierKind::kAcquire: { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 983 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 984 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 985 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 986 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 987 | if (kind == BakerReadBarrierKind::kField) { |
| 988 | // LDR (immediate) with correct base_reg. |
| 989 | CHECK_EQ(next_insn & 0xffc003e0u, 0xb9400000u | (base_reg << 5)); |
| 990 | } else { |
| 991 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 992 | // LDAR with correct base_reg. |
| 993 | CHECK_EQ(next_insn & 0xffffffe0u, 0x88dffc00u | (base_reg << 5)); |
| 994 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 995 | break; |
| 996 | } |
| 997 | case BakerReadBarrierKind::kArray: { |
| 998 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 999 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 1000 | // LDR (register) with the correct base_reg, size=10 (32-bit), option=011 (extend = LSL), |
| 1001 | // and S=1 (shift amount = 2 for 32-bit version), i.e. LDR Wt, [Xn, Xm, LSL #2]. |
| 1002 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1003 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1004 | CHECK_EQ(next_insn & 0xffe0ffe0u, 0xb8607800u | (base_reg << 5)); |
| 1005 | CheckValidReg((next_insn >> 16) & 0x1f); // Check index register |
| 1006 | break; |
| 1007 | } |
| 1008 | case BakerReadBarrierKind::kGcRoot: { |
| 1009 | DCHECK_GE(literal_offset, 4u); |
| 1010 | uint32_t prev_insn = GetInsn(literal_offset - 4u); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1011 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 1012 | // Usually LDR (immediate) with correct root_reg but |
| 1013 | // we may have a "MOV marked, old_value" for UnsafeCASObject. |
| 1014 | if ((prev_insn & 0xffe0ffff) != (0x2a0003e0 | root_reg)) { // MOV? |
| 1015 | CHECK_EQ(prev_insn & 0xffc0001fu, 0xb9400000u | root_reg); // LDR? |
| 1016 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1017 | break; |
| 1018 | } |
| 1019 | default: |
| 1020 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 1021 | UNREACHABLE(); |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1027 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1028 | // Note: There are 6 kinds of moves: |
| 1029 | // 1. constant -> GPR/FPR (non-cycle) |
| 1030 | // 2. constant -> stack (non-cycle) |
| 1031 | // 3. GPR/FPR -> GPR/FPR |
| 1032 | // 4. GPR/FPR -> stack |
| 1033 | // 5. stack -> GPR/FPR |
| 1034 | // 6. stack -> stack (non-cycle) |
| 1035 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1036 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1037 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1038 | // dependency. |
| 1039 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1040 | } |
| 1041 | |
| 1042 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1043 | vixl_temps_.Close(); |
| 1044 | } |
| 1045 | |
| 1046 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1047 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1048 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1049 | || kind == Location::kSIMDStackSlot); |
| 1050 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1051 | ? Location::kFpuRegister |
| 1052 | : Location::kRegister; |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1053 | Location scratch = GetScratchLocation(kind); |
| 1054 | if (!scratch.Equals(Location::NoLocation())) { |
| 1055 | return scratch; |
| 1056 | } |
| 1057 | // Allocate from VIXL temp registers. |
| 1058 | if (kind == Location::kRegister) { |
| 1059 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1060 | } else { |
| Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1061 | DCHECK_EQ(kind, Location::kFpuRegister); |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1062 | scratch = codegen_->GetGraph()->HasSIMD() |
| 1063 | ? codegen_->GetInstructionCodeGeneratorArm64()->AllocateSIMDScratchLocation(&vixl_temps_) |
| 1064 | : LocationFrom(vixl_temps_.AcquireD()); |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1065 | } |
| 1066 | AddScratchLocation(scratch); |
| 1067 | return scratch; |
| 1068 | } |
| 1069 | |
| 1070 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1071 | if (loc.IsRegister()) { |
| 1072 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1073 | } else { |
| 1074 | DCHECK(loc.IsFpuRegister()); |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1075 | if (codegen_->GetGraph()->HasSIMD()) { |
| 1076 | codegen_->GetInstructionCodeGeneratorArm64()->FreeSIMDScratchLocation(loc, &vixl_temps_); |
| 1077 | } else { |
| 1078 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1079 | } |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1080 | } |
| 1081 | RemoveScratchLocation(loc); |
| 1082 | } |
| 1083 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1084 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1085 | MoveOperands* move = moves_[index]; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1086 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1087 | } |
| 1088 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1089 | void CodeGeneratorARM64::MaybeIncrementHotness(bool is_frame_entry) { |
| 1090 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1091 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1092 | UseScratchRegisterScope temps(masm); |
| 1093 | Register counter = temps.AcquireX(); |
| 1094 | Register method = is_frame_entry ? kArtMethodRegister : temps.AcquireX(); |
| 1095 | if (!is_frame_entry) { |
| 1096 | __ Ldr(method, MemOperand(sp, 0)); |
| 1097 | } |
| 1098 | __ Ldrh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1099 | __ Add(counter, counter, 1); |
| 1100 | // Subtract one if the counter would overflow. |
| 1101 | __ Sub(counter, counter, Operand(counter, LSR, 16)); |
| 1102 | __ Strh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1103 | } |
| 1104 | |
| 1105 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| 1106 | ScopedObjectAccess soa(Thread::Current()); |
| 1107 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1108 | if (info != nullptr) { |
| Nicolas Geoffray | c1cd133 | 2020-01-25 13:08:24 +0000 | [diff] [blame] | 1109 | uint64_t address = reinterpret_cast64<uint64_t>(info); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1110 | vixl::aarch64::Label done; |
| 1111 | UseScratchRegisterScope temps(masm); |
| 1112 | Register temp = temps.AcquireX(); |
| 1113 | Register counter = temps.AcquireW(); |
| 1114 | __ Mov(temp, address); |
| 1115 | __ Ldrh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 1116 | __ Add(counter, counter, 1); |
| 1117 | __ Strh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 1118 | __ Tst(counter, 0xffff); |
| 1119 | __ B(ne, &done); |
| 1120 | if (is_frame_entry) { |
| 1121 | if (HasEmptyFrame()) { |
| 1122 | // The entyrpoint expects the method at the bottom of the stack. We |
| 1123 | // claim stack space necessary for alignment. |
| 1124 | __ Claim(kStackAlignment); |
| 1125 | __ Stp(kArtMethodRegister, lr, MemOperand(sp, 0)); |
| 1126 | } else if (!RequiresCurrentMethod()) { |
| 1127 | __ Str(kArtMethodRegister, MemOperand(sp, 0)); |
| 1128 | } |
| 1129 | } else { |
| 1130 | CHECK(RequiresCurrentMethod()); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1131 | } |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1132 | uint32_t entrypoint_offset = |
| 1133 | GetThreadOffset<kArm64PointerSize>(kQuickCompileOptimized).Int32Value(); |
| 1134 | __ Ldr(lr, MemOperand(tr, entrypoint_offset)); |
| 1135 | // Note: we don't record the call here (and therefore don't generate a stack |
| 1136 | // map), as the entrypoint should never be suspended. |
| 1137 | __ Blr(lr); |
| 1138 | if (HasEmptyFrame()) { |
| 1139 | CHECK(is_frame_entry); |
| 1140 | __ Ldr(lr, MemOperand(sp, 8)); |
| 1141 | __ Drop(kStackAlignment); |
| 1142 | } |
| 1143 | __ Bind(&done); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1144 | } |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1145 | } |
| 1146 | } |
| 1147 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1148 | void CodeGeneratorARM64::GenerateFrameEntry() { |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1149 | MacroAssembler* masm = GetVIXLAssembler(); |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1150 | __ Bind(&frame_entry_label_); |
| 1151 | |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1152 | bool do_overflow_check = |
| 1153 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1154 | if (do_overflow_check) { |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1155 | UseScratchRegisterScope temps(masm); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1156 | Register temp = temps.AcquireX(); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1157 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1158 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1159 | { |
| 1160 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1161 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1162 | kInstructionSize, |
| 1163 | CodeBufferCheckScope::kExactSize); |
| 1164 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1165 | RecordPcInfo(nullptr, 0); |
| 1166 | } |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1167 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1168 | |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1169 | if (!HasEmptyFrame()) { |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1170 | // Stack layout: |
| 1171 | // sp[frame_size - 8] : lr. |
| 1172 | // ... : other preserved core registers. |
| 1173 | // ... : other preserved fp registers. |
| 1174 | // ... : reserved frame space. |
| 1175 | // sp[0] : current method. |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1176 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1177 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1178 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1179 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1180 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1181 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1182 | |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1183 | // Save the current method if we need it, or if using STP reduces code |
| 1184 | // size. Note that we do not do this in HCurrentMethod, as the |
| 1185 | // instruction might have been removed in the SSA graph. |
| 1186 | CPURegister lowest_spill; |
| 1187 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1188 | // If there is no gap between the method and the lowest core spill, use |
| 1189 | // aligned STP pre-index to store both. Max difference is 512. We do |
| 1190 | // that to reduce code size even if we do not have to save the method. |
| 1191 | DCHECK_LE(frame_size, 512); // 32 core registers are only 256 bytes. |
| 1192 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1193 | __ Stp(kArtMethodRegister, lowest_spill, MemOperand(sp, -frame_size, PreIndex)); |
| 1194 | } else if (RequiresCurrentMethod()) { |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1195 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
| Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1196 | } else { |
| 1197 | __ Claim(frame_size); |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1198 | } |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1199 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1200 | if (lowest_spill.IsValid()) { |
| 1201 | GetAssembler()->cfi().RelOffset(DWARFReg(lowest_spill), core_spills_offset); |
| 1202 | core_spills_offset += kXRegSizeInBytes; |
| 1203 | } |
| 1204 | GetAssembler()->SpillRegisters(preserved_core_registers, core_spills_offset); |
| 1205 | GetAssembler()->SpillRegisters(preserved_fp_registers, fp_spills_offset); |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1206 | |
| 1207 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1208 | // Initialize should_deoptimize flag to 0. |
| 1209 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1210 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1211 | } |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1212 | } |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1213 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1214 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | void CodeGeneratorARM64::GenerateFrameExit() { |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1218 | GetAssembler()->cfi().RememberState(); |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1219 | if (!HasEmptyFrame()) { |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1220 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1221 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1222 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1223 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1224 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1225 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
| 1226 | |
| 1227 | CPURegister lowest_spill; |
| 1228 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1229 | // If there is no gap between the method and the lowest core spill, use |
| 1230 | // aligned LDP pre-index to pop both. Max difference is 504. We do |
| 1231 | // that to reduce code size even though the loaded method is unused. |
| 1232 | DCHECK_LE(frame_size, 504); // 32 core registers are only 256 bytes. |
| 1233 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1234 | core_spills_offset += kXRegSizeInBytes; |
| 1235 | } |
| 1236 | GetAssembler()->UnspillRegisters(preserved_fp_registers, fp_spills_offset); |
| 1237 | GetAssembler()->UnspillRegisters(preserved_core_registers, core_spills_offset); |
| 1238 | if (lowest_spill.IsValid()) { |
| 1239 | __ Ldp(xzr, lowest_spill, MemOperand(sp, frame_size, PostIndex)); |
| 1240 | GetAssembler()->cfi().Restore(DWARFReg(lowest_spill)); |
| 1241 | } else { |
| 1242 | __ Drop(frame_size); |
| 1243 | } |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1244 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1245 | } |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1246 | __ Ret(); |
| 1247 | GetAssembler()->cfi().RestoreState(); |
| 1248 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1249 | } |
| 1250 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1251 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1252 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1253 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1254 | core_spill_mask_); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1255 | } |
| 1256 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1257 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1258 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1259 | GetNumberOfFloatingPointRegisters())); |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1260 | return CPURegList(CPURegister::kVRegister, kDRegSize, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1261 | fpu_spill_mask_); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1262 | } |
| 1263 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1264 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1265 | __ Bind(GetLabelOf(block)); |
| 1266 | } |
| 1267 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1268 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1269 | DCHECK(location.IsRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1270 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1271 | } |
| 1272 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1273 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1274 | if (location.IsRegister()) { |
| 1275 | locations->AddTemp(location); |
| 1276 | } else { |
| 1277 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1278 | } |
| 1279 | } |
| 1280 | |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1281 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1282 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1283 | Register card = temps.AcquireX(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1284 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1285 | vixl::aarch64::Label done; |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1286 | if (value_can_be_null) { |
| 1287 | __ Cbz(value, &done); |
| 1288 | } |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1289 | // Load the address of the card table into `card`. |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1290 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1291 | // Calculate the offset (in the card table) of the card corresponding to |
| 1292 | // `object`. |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1293 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1294 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 1295 | // `object`'s card. |
| 1296 | // |
| 1297 | // Register `card` contains the address of the card table. Note that the card |
| 1298 | // table's base is biased during its creation so that it always starts at an |
| 1299 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 1300 | // art::gc::accounting::CardTable::Create). Therefore the STRB instruction |
| 1301 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 1302 | // (located at `card + object >> kCardShift`). |
| 1303 | // |
| 1304 | // This dual use of the value in register `card` (1. to calculate the location |
| 1305 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 1306 | // (no need to explicitly load `kCardDirty` as an immediate value). |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1307 | __ Strb(card, MemOperand(card, temp.X())); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1308 | if (value_can_be_null) { |
| 1309 | __ Bind(&done); |
| 1310 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1311 | } |
| 1312 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1313 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1314 | // Blocked core registers: |
| 1315 | // lr : Runtime reserved. |
| 1316 | // tr : Runtime reserved. |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1317 | // mr : Runtime reserved. |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1318 | // ip1 : VIXL core temp. |
| 1319 | // ip0 : VIXL core temp. |
| Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1320 | // x18 : Platform register. |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1321 | // |
| 1322 | // Blocked fp registers: |
| 1323 | // d31 : VIXL fp temp. |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1324 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1325 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1326 | while (!reserved_core_registers.IsEmpty()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1327 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1328 | } |
| Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1329 | blocked_core_registers_[X18] = true; |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1330 | |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1331 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
| Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1332 | while (!reserved_fp_registers.IsEmpty()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1333 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1334 | } |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1335 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1336 | if (GetGraph()->IsDebuggable()) { |
| Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1337 | // Stubs do not save callee-save floating point registers. If the graph |
| 1338 | // is debuggable, we need to deal with these registers differently. For |
| 1339 | // now, just block them. |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1340 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1341 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1342 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1343 | } |
| 1344 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1345 | } |
| 1346 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1347 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1348 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1349 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1350 | return kArm64WordSize; |
| 1351 | } |
| 1352 | |
| 1353 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1354 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1355 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1356 | return kArm64WordSize; |
| 1357 | } |
| 1358 | |
| Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1359 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1360 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1361 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1362 | << "use SaveRestoreLiveRegistersHelper"; |
| 1363 | UNREACHABLE(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
| Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1366 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1367 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1368 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1369 | << "use SaveRestoreLiveRegistersHelper"; |
| 1370 | UNREACHABLE(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1373 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1374 | stream << XRegister(reg); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1378 | stream << DRegister(reg); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1379 | } |
| 1380 | |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1381 | const Arm64InstructionSetFeatures& CodeGeneratorARM64::GetInstructionSetFeatures() const { |
| 1382 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArm64InstructionSetFeatures(); |
| 1383 | } |
| 1384 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1385 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1386 | if (constant->IsIntConstant()) { |
| 1387 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1388 | } else if (constant->IsLongConstant()) { |
| 1389 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1390 | } else if (constant->IsNullConstant()) { |
| 1391 | __ Mov(Register(destination), 0); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1392 | } else if (constant->IsFloatConstant()) { |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1393 | __ Fmov(VRegister(destination), constant->AsFloatConstant()->GetValue()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1394 | } else { |
| 1395 | DCHECK(constant->IsDoubleConstant()); |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1396 | __ Fmov(VRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1397 | } |
| 1398 | } |
| 1399 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1400 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1401 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1402 | DCHECK(constant.IsConstant()); |
| 1403 | HConstant* cst = constant.GetConstant(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1404 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1405 | // 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] | 1406 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1407 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1408 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1409 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
| Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1412 | // Allocate a scratch register from the VIXL pool, querying first |
| 1413 | // the floating-point register pool, and then the core register |
| 1414 | // pool. This is essentially a reimplementation of |
| Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1415 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1416 | // using a different allocation strategy. |
| 1417 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1418 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1419 | int size_in_bits) { |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1420 | return masm->GetScratchVRegisterList()->IsEmpty() |
| Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1421 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1422 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1423 | } |
| 1424 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1425 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1426 | Location source, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1427 | DataType::Type dst_type) { |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1428 | if (source.Equals(destination)) { |
| 1429 | return; |
| 1430 | } |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1431 | |
| 1432 | // A valid move can always be inferred from the destination and source |
| 1433 | // locations. When moving from and to a register, the argument type can be |
| 1434 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1435 | // checks the coherency of the locations and the type. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1436 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1437 | |
| 1438 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1439 | if (unspecified_type) { |
| 1440 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1441 | if (source.IsStackSlot() || |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1442 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1443 | || src_cst->IsFloatConstant() |
| 1444 | || src_cst->IsNullConstant()))) { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1445 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1446 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1447 | } else { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1448 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1449 | // type is appropriate. Else the source is a register, and since the |
| 1450 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1451 | // move. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1452 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1453 | } |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1454 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1455 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1456 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1457 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1458 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1459 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1460 | __ Ldr(dst, StackOperandFrom(source)); |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1461 | } else if (source.IsSIMDStackSlot()) { |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1462 | GetInstructionCodeGeneratorArm64()->LoadSIMDRegFromStack(destination, source); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1463 | } else if (source.IsConstant()) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1464 | DCHECK(CoherentConstantAndType(source, dst_type)); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1465 | MoveConstant(dst, source.GetConstant()); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1466 | } else if (source.IsRegister()) { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1467 | if (destination.IsRegister()) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1468 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1469 | } else { |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1470 | DCHECK(destination.IsFpuRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1471 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1472 | ? DataType::Type::kInt64 |
| 1473 | : DataType::Type::kInt32; |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1474 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1475 | } |
| 1476 | } else { |
| 1477 | DCHECK(source.IsFpuRegister()); |
| 1478 | if (destination.IsRegister()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1479 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1480 | ? DataType::Type::kFloat64 |
| 1481 | : DataType::Type::kFloat32; |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1482 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1483 | } else { |
| 1484 | DCHECK(destination.IsFpuRegister()); |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1485 | if (GetGraph()->HasSIMD()) { |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1486 | GetInstructionCodeGeneratorArm64()->MoveSIMDRegToSIMDReg(destination, source); |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1487 | } else { |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1488 | __ Fmov(VRegister(dst), FPRegisterFrom(source, dst_type)); |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1489 | } |
| 1490 | } |
| 1491 | } |
| 1492 | } else if (destination.IsSIMDStackSlot()) { |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1493 | GetInstructionCodeGeneratorArm64()->MoveToSIMDStackSlot(destination, source); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1494 | } else { // The destination is not a register. It must be a stack slot. |
| 1495 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1496 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1497 | if (unspecified_type) { |
| 1498 | if (source.IsRegister()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1499 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1500 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1501 | dst_type = |
| 1502 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1503 | } |
| 1504 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1505 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1506 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1507 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1508 | } else if (source.IsConstant()) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1509 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1510 | << source << " " << dst_type; |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1511 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1512 | HConstant* src_cst = source.GetConstant(); |
| 1513 | CPURegister temp; |
| Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1514 | if (src_cst->IsZeroBitPattern()) { |
| Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1515 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1516 | ? Register(xzr) |
| 1517 | : Register(wzr); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1518 | } else { |
| Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1519 | if (src_cst->IsIntConstant()) { |
| 1520 | temp = temps.AcquireW(); |
| 1521 | } else if (src_cst->IsLongConstant()) { |
| 1522 | temp = temps.AcquireX(); |
| 1523 | } else if (src_cst->IsFloatConstant()) { |
| 1524 | temp = temps.AcquireS(); |
| 1525 | } else { |
| 1526 | DCHECK(src_cst->IsDoubleConstant()); |
| 1527 | temp = temps.AcquireD(); |
| 1528 | } |
| 1529 | MoveConstant(temp, src_cst); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1530 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1531 | __ Str(temp, StackOperandFrom(destination)); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1532 | } else { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1533 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1534 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1535 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1536 | // Use any scratch register (a core or a floating-point one) |
| 1537 | // from VIXL scratch register pools as a temporary. |
| 1538 | // |
| 1539 | // We used to only use the FP scratch register pool, but in some |
| 1540 | // rare cases the only register from this pool (D31) would |
| 1541 | // already be used (e.g. within a ParallelMove instruction, when |
| 1542 | // a move is blocked by a another move requiring a scratch FP |
| 1543 | // register, which would reserve D31). To prevent this issue, we |
| 1544 | // ask for a scratch register of any type (core or FP). |
| Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1545 | // |
| 1546 | // 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] | 1547 | // demand of scratch core registers is higher. This is why we |
| Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1548 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1549 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1550 | // allocates core scratch registers first. |
| 1551 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1552 | GetVIXLAssembler(), |
| 1553 | &temps, |
| 1554 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1555 | __ Ldr(temp, StackOperandFrom(source)); |
| 1556 | __ Str(temp, StackOperandFrom(destination)); |
| 1557 | } |
| 1558 | } |
| 1559 | } |
| 1560 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1561 | void CodeGeneratorARM64::Load(DataType::Type type, |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1562 | CPURegister dst, |
| 1563 | const MemOperand& src) { |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1564 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1565 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1566 | case DataType::Type::kUint8: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1567 | __ Ldrb(Register(dst), src); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1568 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1569 | case DataType::Type::kInt8: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1570 | __ Ldrsb(Register(dst), src); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1571 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1572 | case DataType::Type::kUint16: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1573 | __ Ldrh(Register(dst), src); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1574 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1575 | case DataType::Type::kInt16: |
| 1576 | __ Ldrsh(Register(dst), src); |
| 1577 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1578 | case DataType::Type::kInt32: |
| 1579 | case DataType::Type::kReference: |
| 1580 | case DataType::Type::kInt64: |
| 1581 | case DataType::Type::kFloat32: |
| 1582 | case DataType::Type::kFloat64: |
| 1583 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1584 | __ Ldr(dst, src); |
| 1585 | break; |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1586 | case DataType::Type::kUint32: |
| 1587 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1588 | case DataType::Type::kVoid: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1589 | LOG(FATAL) << "Unreachable type " << type; |
| 1590 | } |
| 1591 | } |
| 1592 | |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1593 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1594 | CPURegister dst, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1595 | const MemOperand& src, |
| 1596 | bool needs_null_check) { |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1597 | MacroAssembler* masm = GetVIXLAssembler(); |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1598 | UseScratchRegisterScope temps(masm); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1599 | Register temp_base = temps.AcquireX(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1600 | DataType::Type type = instruction->GetType(); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1601 | |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1602 | DCHECK(!src.IsPreIndex()); |
| 1603 | DCHECK(!src.IsPostIndex()); |
| 1604 | |
| 1605 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1606 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1607 | { |
| 1608 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1609 | MemOperand base = MemOperand(temp_base); |
| 1610 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1611 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1612 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1613 | case DataType::Type::kInt8: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1614 | { |
| 1615 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1616 | __ ldarb(Register(dst), base); |
| 1617 | if (needs_null_check) { |
| 1618 | MaybeRecordImplicitNullCheck(instruction); |
| 1619 | } |
| 1620 | } |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1621 | if (type == DataType::Type::kInt8) { |
| 1622 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1623 | } |
| 1624 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1625 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1626 | case DataType::Type::kInt16: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1627 | { |
| 1628 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1629 | __ ldarh(Register(dst), base); |
| 1630 | if (needs_null_check) { |
| 1631 | MaybeRecordImplicitNullCheck(instruction); |
| 1632 | } |
| 1633 | } |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1634 | if (type == DataType::Type::kInt16) { |
| 1635 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 1636 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1637 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1638 | case DataType::Type::kInt32: |
| 1639 | case DataType::Type::kReference: |
| 1640 | case DataType::Type::kInt64: |
| 1641 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1642 | { |
| 1643 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1644 | __ ldar(Register(dst), base); |
| 1645 | if (needs_null_check) { |
| 1646 | MaybeRecordImplicitNullCheck(instruction); |
| 1647 | } |
| 1648 | } |
| 1649 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1650 | case DataType::Type::kFloat32: |
| 1651 | case DataType::Type::kFloat64: { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1652 | DCHECK(dst.IsFPRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1653 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1654 | |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1655 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1656 | { |
| 1657 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1658 | __ ldar(temp, base); |
| 1659 | if (needs_null_check) { |
| 1660 | MaybeRecordImplicitNullCheck(instruction); |
| 1661 | } |
| 1662 | } |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1663 | __ Fmov(VRegister(dst), temp); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1664 | break; |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1665 | } |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1666 | case DataType::Type::kUint32: |
| 1667 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1668 | case DataType::Type::kVoid: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1669 | LOG(FATAL) << "Unreachable type " << type; |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1670 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1671 | } |
| 1672 | } |
| 1673 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1674 | void CodeGeneratorARM64::Store(DataType::Type type, |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1675 | CPURegister src, |
| 1676 | const MemOperand& dst) { |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1677 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1678 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1679 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1680 | case DataType::Type::kInt8: |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1681 | __ Strb(Register(src), dst); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1682 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1683 | case DataType::Type::kUint16: |
| 1684 | case DataType::Type::kInt16: |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1685 | __ Strh(Register(src), dst); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1686 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1687 | case DataType::Type::kInt32: |
| 1688 | case DataType::Type::kReference: |
| 1689 | case DataType::Type::kInt64: |
| 1690 | case DataType::Type::kFloat32: |
| 1691 | case DataType::Type::kFloat64: |
| 1692 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1693 | __ Str(src, dst); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1694 | break; |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1695 | case DataType::Type::kUint32: |
| 1696 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1697 | case DataType::Type::kVoid: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1698 | LOG(FATAL) << "Unreachable type " << type; |
| 1699 | } |
| 1700 | } |
| 1701 | |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1702 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1703 | DataType::Type type, |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1704 | CPURegister src, |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1705 | const MemOperand& dst, |
| 1706 | bool needs_null_check) { |
| 1707 | MacroAssembler* masm = GetVIXLAssembler(); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1708 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1709 | Register temp_base = temps.AcquireX(); |
| 1710 | |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1711 | DCHECK(!dst.IsPreIndex()); |
| 1712 | DCHECK(!dst.IsPostIndex()); |
| 1713 | |
| 1714 | // TODO(vixl): Let the MacroAssembler handle this. |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1715 | Operand op = OperandFromMemOperand(dst); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1716 | __ Add(temp_base, dst.GetBaseRegister(), op); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1717 | MemOperand base = MemOperand(temp_base); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1718 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1719 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1720 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1721 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1722 | case DataType::Type::kInt8: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1723 | { |
| 1724 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1725 | __ stlrb(Register(src), base); |
| 1726 | if (needs_null_check) { |
| 1727 | MaybeRecordImplicitNullCheck(instruction); |
| 1728 | } |
| 1729 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1730 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1731 | case DataType::Type::kUint16: |
| 1732 | case DataType::Type::kInt16: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1733 | { |
| 1734 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1735 | __ stlrh(Register(src), base); |
| 1736 | if (needs_null_check) { |
| 1737 | MaybeRecordImplicitNullCheck(instruction); |
| 1738 | } |
| 1739 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1740 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1741 | case DataType::Type::kInt32: |
| 1742 | case DataType::Type::kReference: |
| 1743 | case DataType::Type::kInt64: |
| 1744 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1745 | { |
| 1746 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1747 | __ stlr(Register(src), base); |
| 1748 | if (needs_null_check) { |
| 1749 | MaybeRecordImplicitNullCheck(instruction); |
| 1750 | } |
| 1751 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1752 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1753 | case DataType::Type::kFloat32: |
| 1754 | case DataType::Type::kFloat64: { |
| 1755 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1756 | Register temp_src; |
| 1757 | if (src.IsZero()) { |
| 1758 | // The zero register is used to avoid synthesizing zero constants. |
| 1759 | temp_src = Register(src); |
| 1760 | } else { |
| 1761 | DCHECK(src.IsFPRegister()); |
| 1762 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1763 | __ Fmov(temp_src, VRegister(src)); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1764 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1765 | { |
| 1766 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1767 | __ stlr(temp_src, base); |
| 1768 | if (needs_null_check) { |
| 1769 | MaybeRecordImplicitNullCheck(instruction); |
| 1770 | } |
| 1771 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1772 | break; |
| 1773 | } |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1774 | case DataType::Type::kUint32: |
| 1775 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1776 | case DataType::Type::kVoid: |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1777 | LOG(FATAL) << "Unreachable type " << type; |
| 1778 | } |
| 1779 | } |
| 1780 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1781 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1782 | HInstruction* instruction, |
| 1783 | uint32_t dex_pc, |
| 1784 | SlowPathCode* slow_path) { |
| Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1785 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1786 | |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1787 | ThreadOffset64 entrypoint_offset = GetThreadOffset<kArm64PointerSize>(entrypoint); |
| 1788 | // Reduce code size for AOT by using shared trampolines for slow path runtime calls across the |
| 1789 | // entire oat file. This adds an extra branch and we do not want to slow down the main path. |
| 1790 | // For JIT, thunk sharing is per-method, so the gains would be smaller or even negative. |
| Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 1791 | if (slow_path == nullptr || UseJitCompilation()) { |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1792 | __ Ldr(lr, MemOperand(tr, entrypoint_offset.Int32Value())); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1793 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 1794 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1795 | __ blr(lr); |
| 1796 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1797 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1798 | } |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1799 | } else { |
| 1800 | // Ensure the pc position is recorded immediately after the `bl` instruction. |
| 1801 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1802 | EmitEntrypointThunkCall(entrypoint_offset); |
| 1803 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1804 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1805 | } |
| Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1806 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1807 | } |
| 1808 | |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1809 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1810 | HInstruction* instruction, |
| 1811 | SlowPathCode* slow_path) { |
| 1812 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1813 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1814 | __ Blr(lr); |
| 1815 | } |
| 1816 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1817 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1818 | Register class_reg) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1819 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1820 | Register temp = temps.AcquireW(); |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1821 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| Vladimir Marko | 2bb44fe | 2019-10-04 12:28:14 +0100 | [diff] [blame] | 1822 | const size_t status_byte_offset = |
| 1823 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 1824 | constexpr uint32_t shifted_visibly_initialized_value = |
| 1825 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1826 | |
| Vladimir Marko | 2bb44fe | 2019-10-04 12:28:14 +0100 | [diff] [blame] | 1827 | // CMP (immediate) is limited to imm12 or imm12<<12, so we would need to materialize |
| 1828 | // the constant 0xf0000000 for comparison with the full 32-bit field. To reduce the code |
| 1829 | // size, load only the high byte of the field and compare with 0xf0. |
| 1830 | // Note: The same code size could be achieved with LDR+MNV(asr #24)+CBNZ but benchmarks |
| 1831 | // show that this pattern is slower (tested on little cores). |
| 1832 | __ Ldrb(temp, HeapOperand(class_reg, status_byte_offset)); |
| 1833 | __ Cmp(temp, shifted_visibly_initialized_value); |
| 1834 | __ B(lo, slow_path->GetEntryLabel()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1835 | __ Bind(slow_path->GetExitLabel()); |
| 1836 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1837 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 1838 | void InstructionCodeGeneratorARM64::GenerateBitstringTypeCheckCompare( |
| 1839 | HTypeCheckInstruction* check, vixl::aarch64::Register temp) { |
| 1840 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 1841 | uint32_t mask = check->GetBitstringMask(); |
| 1842 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 1843 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 1844 | |
| 1845 | if (mask_bits == 16u) { |
| 1846 | // Load only the bitstring part of the status word. |
| 1847 | __ Ldrh(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1848 | } else { |
| 1849 | // /* uint32_t */ temp = temp->status_ |
| 1850 | __ Ldr(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1851 | // Extract the bitstring bits. |
| 1852 | __ Ubfx(temp, temp, 0, mask_bits); |
| 1853 | } |
| 1854 | // Compare the bitstring bits to `path_to_root`. |
| 1855 | __ Cmp(temp, path_to_root); |
| 1856 | } |
| 1857 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1858 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1859 | BarrierType type = BarrierAll; |
| 1860 | |
| 1861 | switch (kind) { |
| 1862 | case MemBarrierKind::kAnyAny: |
| 1863 | case MemBarrierKind::kAnyStore: { |
| 1864 | type = BarrierAll; |
| 1865 | break; |
| 1866 | } |
| 1867 | case MemBarrierKind::kLoadAny: { |
| 1868 | type = BarrierReads; |
| 1869 | break; |
| 1870 | } |
| 1871 | case MemBarrierKind::kStoreStore: { |
| 1872 | type = BarrierWrites; |
| 1873 | break; |
| 1874 | } |
| 1875 | default: |
| 1876 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1877 | } |
| 1878 | __ Dmb(InnerShareable, type); |
| 1879 | } |
| 1880 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1881 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1882 | HBasicBlock* successor) { |
| 1883 | SuspendCheckSlowPathARM64* slow_path = |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1884 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1885 | if (slow_path == nullptr) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1886 | slow_path = |
| 1887 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1888 | instruction->SetSlowPath(slow_path); |
| 1889 | codegen_->AddSlowPath(slow_path); |
| 1890 | if (successor != nullptr) { |
| 1891 | DCHECK(successor->IsLoopHeader()); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1892 | } |
| 1893 | } else { |
| 1894 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1895 | } |
| 1896 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1897 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1898 | Register temp = temps.AcquireW(); |
| 1899 | |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1900 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1901 | if (successor == nullptr) { |
| 1902 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1903 | __ Bind(slow_path->GetReturnLabel()); |
| 1904 | } else { |
| 1905 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1906 | __ B(slow_path->GetEntryLabel()); |
| 1907 | // slow_path will return to GetLabelOf(successor). |
| 1908 | } |
| 1909 | } |
| 1910 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1911 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1912 | CodeGeneratorARM64* codegen) |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1913 | : InstructionCodeGenerator(graph, codegen), |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1914 | assembler_(codegen->GetAssembler()), |
| 1915 | codegen_(codegen) {} |
| 1916 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1917 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1918 | DCHECK_EQ(instr->InputCount(), 2U); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1919 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1920 | DataType::Type type = instr->GetResultType(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1921 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1922 | case DataType::Type::kInt32: |
| 1923 | case DataType::Type::kInt64: |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1924 | locations->SetInAt(0, Location::RequiresRegister()); |
| Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1925 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1926 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1927 | break; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1928 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1929 | case DataType::Type::kFloat32: |
| 1930 | case DataType::Type::kFloat64: |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1931 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1932 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1933 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1934 | break; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1935 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1936 | default: |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1937 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1938 | } |
| 1939 | } |
| 1940 | |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1941 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 1942 | const FieldInfo& field_info) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1943 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1944 | |
| 1945 | bool object_field_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1946 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1947 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1948 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 1949 | object_field_get_with_read_barrier |
| 1950 | ? LocationSummary::kCallOnSlowPath |
| 1951 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1952 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1953 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1954 | // We need a temporary register for the read barrier load in |
| 1955 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 1956 | // only if the field is volatile or the offset is too big. |
| 1957 | if (field_info.IsVolatile() || |
| 1958 | field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 1959 | locations->AddTemp(FixedTempLocation()); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1960 | } |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1961 | } |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1962 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1963 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1964 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1965 | } else { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1966 | // The output overlaps for an object field get when read barriers |
| 1967 | // are enabled: we do not want the load to overwrite the object's |
| 1968 | // location, as we need it to emit the read barrier. |
| 1969 | locations->SetOut( |
| 1970 | Location::RequiresRegister(), |
| 1971 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 1976 | const FieldInfo& field_info) { |
| 1977 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1978 | LocationSummary* locations = instruction->GetLocations(); |
| 1979 | Location base_loc = locations->InAt(0); |
| 1980 | Location out = locations->Out(); |
| 1981 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 1982 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 1983 | DataType::Type load_type = instruction->GetType(); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1984 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1985 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1986 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 1987 | load_type == DataType::Type::kReference) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1988 | // Object FieldGet with Baker's read barrier case. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1989 | // /* HeapReference<Object> */ out = *(base + offset) |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1990 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1991 | Location maybe_temp = |
| 1992 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1993 | // Note that potential implicit null checks are handled in this |
| 1994 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 1995 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1996 | instruction, |
| 1997 | out, |
| 1998 | base, |
| 1999 | offset, |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2000 | maybe_temp, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2001 | /* needs_null_check= */ true, |
| Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2002 | field_info.IsVolatile()); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2003 | } else { |
| 2004 | // General case. |
| 2005 | if (field_info.IsVolatile()) { |
| Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2006 | // Note that a potential implicit null check is handled in this |
| 2007 | // CodeGeneratorARM64::LoadAcquire call. |
| 2008 | // NB: LoadAcquire will record the pc info if needed. |
| 2009 | codegen_->LoadAcquire( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2010 | instruction, OutputCPURegister(instruction), field, /* needs_null_check= */ true); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2011 | } else { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2012 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2013 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2014 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2015 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2016 | } |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2017 | if (load_type == DataType::Type::kReference) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2018 | // If read barriers are enabled, emit read barriers other than |
| 2019 | // Baker's using a slow path (and also unpoison the loaded |
| 2020 | // reference, if heap poisoning is enabled). |
| 2021 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2022 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2023 | } |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2027 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2028 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2029 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2030 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2031 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2032 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2033 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2034 | } else { |
| 2035 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2040 | const FieldInfo& field_info, |
| 2041 | bool value_can_be_null) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2042 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2043 | |
| 2044 | Register obj = InputRegisterAt(instruction, 0); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2045 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2046 | CPURegister source = value; |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2047 | Offset offset = field_info.GetFieldOffset(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2048 | DataType::Type field_type = field_info.GetFieldType(); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2049 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2050 | { |
| 2051 | // We use a block to end the scratch scope before the write barrier, thus |
| 2052 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2053 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2054 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2055 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2056 | DCHECK(value.IsW()); |
| 2057 | Register temp = temps.AcquireW(); |
| 2058 | __ Mov(temp, value.W()); |
| 2059 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2060 | source = temp; |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2061 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2062 | |
| 2063 | if (field_info.IsVolatile()) { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2064 | codegen_->StoreRelease( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2065 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check= */ true); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2066 | } else { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2067 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2068 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2069 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2070 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2071 | } |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2075 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2076 | } |
| 2077 | } |
| 2078 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2079 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2080 | DataType::Type type = instr->GetType(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2081 | |
| 2082 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2083 | case DataType::Type::kInt32: |
| 2084 | case DataType::Type::kInt64: { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2085 | Register dst = OutputRegister(instr); |
| 2086 | Register lhs = InputRegisterAt(instr, 0); |
| 2087 | Operand rhs = InputOperandAt(instr, 1); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2088 | if (instr->IsAdd()) { |
| 2089 | __ Add(dst, lhs, rhs); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2090 | } else if (instr->IsAnd()) { |
| 2091 | __ And(dst, lhs, rhs); |
| 2092 | } else if (instr->IsOr()) { |
| 2093 | __ Orr(dst, lhs, rhs); |
| 2094 | } else if (instr->IsSub()) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2095 | __ Sub(dst, lhs, rhs); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2096 | } else if (instr->IsRor()) { |
| 2097 | if (rhs.IsImmediate()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2098 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2099 | __ Ror(dst, lhs, shift); |
| 2100 | } else { |
| 2101 | // Ensure shift distance is in the same size register as the result. If |
| 2102 | // we are rotating a long and the shift comes in a w register originally, |
| 2103 | // we don't need to sxtw for use as an x since the shift distances are |
| 2104 | // all & reg_bits - 1. |
| 2105 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2106 | } |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2107 | } else if (instr->IsMin() || instr->IsMax()) { |
| 2108 | __ Cmp(lhs, rhs); |
| 2109 | __ Csel(dst, lhs, rhs, instr->IsMin() ? lt : gt); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2110 | } else { |
| 2111 | DCHECK(instr->IsXor()); |
| 2112 | __ Eor(dst, lhs, rhs); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2113 | } |
| 2114 | break; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2115 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2116 | case DataType::Type::kFloat32: |
| 2117 | case DataType::Type::kFloat64: { |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 2118 | VRegister dst = OutputFPRegister(instr); |
| 2119 | VRegister lhs = InputFPRegisterAt(instr, 0); |
| 2120 | VRegister rhs = InputFPRegisterAt(instr, 1); |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2121 | if (instr->IsAdd()) { |
| 2122 | __ Fadd(dst, lhs, rhs); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2123 | } else if (instr->IsSub()) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2124 | __ Fsub(dst, lhs, rhs); |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2125 | } else if (instr->IsMin()) { |
| 2126 | __ Fmin(dst, lhs, rhs); |
| 2127 | } else if (instr->IsMax()) { |
| 2128 | __ Fmax(dst, lhs, rhs); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2129 | } else { |
| 2130 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2131 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2132 | break; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2133 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2134 | default: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2135 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2136 | } |
| 2137 | } |
| 2138 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2139 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2140 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2141 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2142 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2143 | DataType::Type type = instr->GetResultType(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2144 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2145 | case DataType::Type::kInt32: |
| 2146 | case DataType::Type::kInt64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2147 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2148 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2149 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2150 | break; |
| 2151 | } |
| 2152 | default: |
| 2153 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2154 | } |
| 2155 | } |
| 2156 | |
| 2157 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2158 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2159 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2160 | DataType::Type type = instr->GetType(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2161 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2162 | case DataType::Type::kInt32: |
| 2163 | case DataType::Type::kInt64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2164 | Register dst = OutputRegister(instr); |
| 2165 | Register lhs = InputRegisterAt(instr, 0); |
| 2166 | Operand rhs = InputOperandAt(instr, 1); |
| 2167 | if (rhs.IsImmediate()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2168 | uint32_t shift_value = rhs.GetImmediate() & |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2169 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2170 | if (instr->IsShl()) { |
| 2171 | __ Lsl(dst, lhs, shift_value); |
| 2172 | } else if (instr->IsShr()) { |
| 2173 | __ Asr(dst, lhs, shift_value); |
| 2174 | } else { |
| 2175 | __ Lsr(dst, lhs, shift_value); |
| 2176 | } |
| 2177 | } else { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2178 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2179 | |
| 2180 | if (instr->IsShl()) { |
| 2181 | __ Lsl(dst, lhs, rhs_reg); |
| 2182 | } else if (instr->IsShr()) { |
| 2183 | __ Asr(dst, lhs, rhs_reg); |
| 2184 | } else { |
| 2185 | __ Lsr(dst, lhs, rhs_reg); |
| 2186 | } |
| 2187 | } |
| 2188 | break; |
| 2189 | } |
| 2190 | default: |
| 2191 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2192 | } |
| 2193 | } |
| 2194 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2195 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2196 | HandleBinaryOp(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2200 | HandleBinaryOp(instruction); |
| 2201 | } |
| 2202 | |
| 2203 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2204 | HandleBinaryOp(instruction); |
| 2205 | } |
| 2206 | |
| 2207 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2208 | HandleBinaryOp(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2209 | } |
| 2210 | |
| Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2211 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2212 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2213 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
| Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2214 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2215 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2216 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2217 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2218 | } |
| 2219 | |
| Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2220 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
| Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2221 | Register dst = OutputRegister(instr); |
| 2222 | Register lhs = InputRegisterAt(instr, 0); |
| 2223 | Register rhs = InputRegisterAt(instr, 1); |
| 2224 | |
| 2225 | switch (instr->GetOpKind()) { |
| 2226 | case HInstruction::kAnd: |
| 2227 | __ Bic(dst, lhs, rhs); |
| 2228 | break; |
| 2229 | case HInstruction::kOr: |
| 2230 | __ Orn(dst, lhs, rhs); |
| 2231 | break; |
| 2232 | case HInstruction::kXor: |
| 2233 | __ Eon(dst, lhs, rhs); |
| 2234 | break; |
| 2235 | default: |
| 2236 | LOG(FATAL) << "Unreachable"; |
| 2237 | } |
| 2238 | } |
| 2239 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2240 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2241 | HDataProcWithShifterOp* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2242 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2243 | instruction->GetType() == DataType::Type::kInt64); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2244 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2245 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2246 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2247 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2248 | } else { |
| 2249 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2250 | } |
| 2251 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2252 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2253 | } |
| 2254 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2255 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2256 | HDataProcWithShifterOp* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2257 | DataType::Type type = instruction->GetType(); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2258 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2259 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2260 | Register out = OutputRegister(instruction); |
| 2261 | Register left; |
| 2262 | if (kind != HInstruction::kNeg) { |
| 2263 | left = InputRegisterAt(instruction, 0); |
| 2264 | } |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2265 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2266 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2267 | // conversion) can have a different type from the current instruction's type, |
| 2268 | // so we manually indicate the type. |
| 2269 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2270 | Operand right_operand(0); |
| 2271 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2272 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2273 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2274 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2275 | } else { |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2276 | right_operand = Operand(right_reg, |
| 2277 | helpers::ShiftFromOpKind(op_kind), |
| 2278 | instruction->GetShiftAmount()); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | // Logical binary operations do not support extension operations in the |
| 2282 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2283 | // the extension as a separate instruction. |
| 2284 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2285 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2286 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2287 | kind != HInstruction::kNeg)); |
| 2288 | switch (kind) { |
| 2289 | case HInstruction::kAdd: |
| 2290 | __ Add(out, left, right_operand); |
| 2291 | break; |
| 2292 | case HInstruction::kAnd: |
| 2293 | __ And(out, left, right_operand); |
| 2294 | break; |
| 2295 | case HInstruction::kNeg: |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2296 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2297 | __ Neg(out, right_operand); |
| 2298 | break; |
| 2299 | case HInstruction::kOr: |
| 2300 | __ Orr(out, left, right_operand); |
| 2301 | break; |
| 2302 | case HInstruction::kSub: |
| 2303 | __ Sub(out, left, right_operand); |
| 2304 | break; |
| 2305 | case HInstruction::kXor: |
| 2306 | __ Eor(out, left, right_operand); |
| 2307 | break; |
| 2308 | default: |
| 2309 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2310 | UNREACHABLE(); |
| 2311 | } |
| 2312 | } |
| 2313 | |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2314 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2315 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2316 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2317 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2318 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
| Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2319 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2320 | } |
| 2321 | |
| Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2322 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2323 | __ Add(OutputRegister(instruction), |
| 2324 | InputRegisterAt(instruction, 0), |
| 2325 | Operand(InputOperandAt(instruction, 1))); |
| 2326 | } |
| 2327 | |
| Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2328 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2329 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2330 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2331 | |
| 2332 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2333 | |
| 2334 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2335 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2336 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2337 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2338 | // loop. |
| 2339 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2340 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2341 | : Location::RequiresRegister()); |
| 2342 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2343 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2344 | } |
| 2345 | |
| 2346 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2347 | HIntermediateAddressIndex* instruction) { |
| 2348 | Register index_reg = InputRegisterAt(instruction, 0); |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2349 | uint32_t shift = Int64FromLocation(instruction->GetLocations()->InAt(2)); |
| Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2350 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2351 | |
| 2352 | if (shift == 0) { |
| 2353 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2354 | } else { |
| 2355 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2356 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2357 | } |
| 2358 | } |
| 2359 | |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2360 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2361 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2362 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2363 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2364 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2365 | accumulator->IsConstant() && |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2366 | accumulator->AsConstant()->IsArithmeticZero()) { |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2367 | // Don't allocate register for Mneg instruction. |
| 2368 | } else { |
| 2369 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2370 | Location::RequiresRegister()); |
| 2371 | } |
| 2372 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2373 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2374 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2375 | } |
| 2376 | |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2377 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2378 | Register res = OutputRegister(instr); |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2379 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2380 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2381 | |
| 2382 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2383 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2384 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2385 | if (instr->GetType() == DataType::Type::kInt64 && |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2386 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2387 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2388 | vixl::aarch64::Instruction* prev = |
| 2389 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2390 | if (prev->IsLoadOrStore()) { |
| 2391 | // Make sure we emit only exactly one nop. |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2392 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2393 | __ nop(); |
| 2394 | } |
| 2395 | } |
| 2396 | |
| 2397 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2398 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2399 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2400 | } else { |
| 2401 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2402 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2403 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2404 | __ Mneg(res, mul_left, mul_right); |
| 2405 | } else { |
| 2406 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2407 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2408 | } |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2409 | } |
| 2410 | } |
| 2411 | |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2412 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2413 | bool object_array_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2414 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2415 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2416 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2417 | object_array_get_with_read_barrier |
| 2418 | ? LocationSummary::kCallOnSlowPath |
| 2419 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2420 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2421 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2422 | if (instruction->GetIndex()->IsConstant()) { |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2423 | // Array loads with constant index are treated as field loads. |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2424 | // We need a temporary register for the read barrier load in |
| 2425 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2426 | // only if the offset is too big. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2427 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2428 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2429 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2430 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2431 | locations->AddTemp(FixedTempLocation()); |
| 2432 | } |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2433 | } else if (!instruction->GetArray()->IsIntermediateAddress()) { |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2434 | // We need a non-scratch temporary for the array data pointer in |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2435 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier() for the case with no |
| 2436 | // intermediate address. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2437 | locations->AddTemp(Location::RequiresRegister()); |
| 2438 | } |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2439 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2440 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2441 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2442 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2443 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2444 | } else { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2445 | // The output overlaps in the case of an object array get with |
| 2446 | // read barriers enabled: we do not want the move to overwrite the |
| 2447 | // array's location, as we need it to emit the read barrier. |
| 2448 | locations->SetOut( |
| 2449 | Location::RequiresRegister(), |
| 2450 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2451 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2455 | DataType::Type type = instruction->GetType(); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2456 | Register obj = InputRegisterAt(instruction, 0); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2457 | LocationSummary* locations = instruction->GetLocations(); |
| 2458 | Location index = locations->InAt(1); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2459 | Location out = locations->Out(); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2460 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2461 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2462 | instruction->IsStringCharAt(); |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2463 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2464 | UseScratchRegisterScope temps(masm); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2465 | |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2466 | // The non-Baker read barrier instrumentation of object ArrayGet instructions |
| Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2467 | // does not support the HIntermediateAddress instruction. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2468 | DCHECK(!((type == DataType::Type::kReference) && |
| Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2469 | instruction->GetArray()->IsIntermediateAddress() && |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2470 | kEmitCompilerReadBarrier && |
| 2471 | !kUseBakerReadBarrier)); |
| Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2472 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2473 | if (type == DataType::Type::kReference && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2474 | // Object ArrayGet with Baker's read barrier case. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2475 | // Note that a potential implicit null check is handled in the |
| 2476 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2477 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2478 | if (index.IsConstant()) { |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2479 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2480 | // 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] | 2481 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2482 | Location maybe_temp = |
| 2483 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2484 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2485 | out, |
| 2486 | obj.W(), |
| 2487 | offset, |
| 2488 | maybe_temp, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2489 | /* needs_null_check= */ false, |
| 2490 | /* use_load_acquire= */ false); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2491 | } else { |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2492 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2493 | instruction, out, obj.W(), offset, index, /* needs_null_check= */ false); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2494 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2495 | } else { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2496 | // General case. |
| 2497 | MemOperand source = HeapOperand(obj); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2498 | Register length; |
| 2499 | if (maybe_compressed_char_at) { |
| 2500 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2501 | length = temps.AcquireW(); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2502 | { |
| 2503 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2504 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2505 | |
| 2506 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2507 | DCHECK_LT(count_offset, offset); |
| 2508 | int64_t adjusted_offset = |
| 2509 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2510 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2511 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2512 | } else { |
| 2513 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2514 | } |
| 2515 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2516 | } |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2517 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2518 | if (index.IsConstant()) { |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2519 | if (maybe_compressed_char_at) { |
| 2520 | vixl::aarch64::Label uncompressed_load, done; |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2521 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2522 | "Expecting 0=compressed, 1=uncompressed"); |
| 2523 | __ Tbnz(length.W(), 0, &uncompressed_load); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2524 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2525 | HeapOperand(obj, offset + Int64FromLocation(index))); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2526 | __ B(&done); |
| 2527 | __ Bind(&uncompressed_load); |
| 2528 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2529 | HeapOperand(obj, offset + (Int64FromLocation(index) << 1))); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2530 | __ Bind(&done); |
| 2531 | } else { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2532 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2533 | source = HeapOperand(obj, offset); |
| 2534 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2535 | } else { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2536 | Register temp = temps.AcquireSameSizeAs(obj); |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2537 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2538 | // We do not need to compute the intermediate address from the array: the |
| 2539 | // input instruction has done it already. See the comment in |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2540 | // `TryExtractArrayAccessAddress()`. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2541 | if (kIsDebugBuild) { |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2542 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2543 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2544 | } |
| 2545 | temp = obj; |
| 2546 | } else { |
| 2547 | __ Add(temp, obj, offset); |
| 2548 | } |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2549 | if (maybe_compressed_char_at) { |
| 2550 | vixl::aarch64::Label uncompressed_load, done; |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2551 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2552 | "Expecting 0=compressed, 1=uncompressed"); |
| 2553 | __ Tbnz(length.W(), 0, &uncompressed_load); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2554 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2555 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2556 | __ B(&done); |
| 2557 | __ Bind(&uncompressed_load); |
| 2558 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2559 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2560 | __ Bind(&done); |
| 2561 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2562 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2563 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2564 | } |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2565 | if (!maybe_compressed_char_at) { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2566 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2567 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2568 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2569 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2570 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2571 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2572 | if (type == DataType::Type::kReference) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2573 | static_assert( |
| 2574 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2575 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2576 | Location obj_loc = locations->InAt(0); |
| 2577 | if (index.IsConstant()) { |
| 2578 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2579 | } else { |
| 2580 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2581 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2582 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2583 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2584 | } |
| 2585 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2586 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2587 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2588 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2589 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2593 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2594 | vixl::aarch64::Register out = OutputRegister(instruction); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2595 | { |
| 2596 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2597 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2598 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2599 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2600 | } |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2601 | // Mask out compression flag from String's array length. |
| 2602 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2603 | __ Lsr(out.W(), out.W(), 1u); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2604 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2605 | } |
| 2606 | |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2607 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2608 | DataType::Type value_type = instruction->GetComponentType(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2609 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2610 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2611 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2612 | instruction, |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2613 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2614 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2615 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2616 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2617 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2618 | } else if (DataType::IsFloatingPointType(value_type)) { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2619 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2620 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2621 | locations->SetInAt(2, Location::RequiresRegister()); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2622 | } |
| 2623 | } |
| 2624 | |
| 2625 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2626 | DataType::Type value_type = instruction->GetComponentType(); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2627 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2628 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2629 | bool needs_write_barrier = |
| 2630 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2631 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2632 | Register array = InputRegisterAt(instruction, 0); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2633 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2634 | CPURegister source = value; |
| 2635 | Location index = locations->InAt(1); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2636 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2637 | MemOperand destination = HeapOperand(array); |
| 2638 | MacroAssembler* masm = GetVIXLAssembler(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2639 | |
| 2640 | if (!needs_write_barrier) { |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2641 | DCHECK(!needs_type_check); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2642 | if (index.IsConstant()) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2643 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2644 | destination = HeapOperand(array, offset); |
| 2645 | } else { |
| 2646 | UseScratchRegisterScope temps(masm); |
| 2647 | Register temp = temps.AcquireSameSizeAs(array); |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2648 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2649 | // We do not need to compute the intermediate address from the array: the |
| 2650 | // input instruction has done it already. See the comment in |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2651 | // `TryExtractArrayAccessAddress()`. |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2652 | if (kIsDebugBuild) { |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2653 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2654 | DCHECK(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2655 | } |
| 2656 | temp = array; |
| 2657 | } else { |
| 2658 | __ Add(temp, array, offset); |
| 2659 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2660 | destination = HeapOperand(temp, |
| 2661 | XRegisterFrom(index), |
| 2662 | LSL, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2663 | DataType::SizeShift(value_type)); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2664 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2665 | { |
| 2666 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2667 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2668 | codegen_->Store(value_type, value, destination); |
| 2669 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2670 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2671 | } else { |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2672 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2673 | |
| 2674 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 2675 | vixl::aarch64::Label do_store; |
| 2676 | if (can_value_be_null) { |
| 2677 | __ Cbz(Register(value), &do_store); |
| 2678 | } |
| 2679 | |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2680 | SlowPathCodeARM64* slow_path = nullptr; |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2681 | if (needs_type_check) { |
| 2682 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
| 2683 | codegen_->AddSlowPath(slow_path); |
| 2684 | |
| 2685 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2686 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2687 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2688 | |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2689 | UseScratchRegisterScope temps(masm); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2690 | Register temp = temps.AcquireSameSizeAs(array); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2691 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2692 | |
| 2693 | // Note that when Baker read barriers are enabled, the type |
| 2694 | // checks are performed without read barriers. This is fine, |
| 2695 | // even in the case where a class object is in the from-space |
| 2696 | // after the flip, as a comparison involving such a type would |
| 2697 | // not produce a false positive; it may of course produce a |
| 2698 | // false negative, in which case we would take the ArraySet |
| 2699 | // slow path. |
| 2700 | |
| 2701 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2702 | { |
| 2703 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2704 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2705 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2706 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2707 | } |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2708 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2709 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2710 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2711 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2712 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2713 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2714 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2715 | // nor `temp2`, as we are comparing two poisoned references. |
| 2716 | __ Cmp(temp, temp2); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2717 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2718 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2719 | vixl::aarch64::Label do_put; |
| 2720 | __ B(eq, &do_put); |
| 2721 | // If heap poisoning is enabled, the `temp` reference has |
| 2722 | // not been unpoisoned yet; unpoison it now. |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2723 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2724 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2725 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2726 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2727 | // If heap poisoning is enabled, no need to unpoison |
| 2728 | // `temp`, as we are comparing against null below. |
| 2729 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2730 | __ Bind(&do_put); |
| Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 2731 | } else { |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2732 | __ B(ne, slow_path->GetEntryLabel()); |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2733 | } |
| 2734 | } |
| 2735 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2736 | codegen_->MarkGCCard(array, value.W(), /* value_can_be_null= */ false); |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2737 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2738 | if (can_value_be_null) { |
| 2739 | DCHECK(do_store.IsLinked()); |
| 2740 | __ Bind(&do_store); |
| 2741 | } |
| 2742 | |
| 2743 | UseScratchRegisterScope temps(masm); |
| 2744 | if (kPoisonHeapReferences) { |
| 2745 | Register temp_source = temps.AcquireSameSizeAs(array); |
| 2746 | DCHECK(value.IsW()); |
| 2747 | __ Mov(temp_source, value.W()); |
| 2748 | GetAssembler()->PoisonHeapReference(temp_source); |
| 2749 | source = temp_source; |
| 2750 | } |
| 2751 | |
| 2752 | if (index.IsConstant()) { |
| 2753 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
| 2754 | destination = HeapOperand(array, offset); |
| 2755 | } else { |
| 2756 | Register temp_base = temps.AcquireSameSizeAs(array); |
| 2757 | __ Add(temp_base, array, offset); |
| 2758 | destination = HeapOperand(temp_base, |
| 2759 | XRegisterFrom(index), |
| 2760 | LSL, |
| 2761 | DataType::SizeShift(value_type)); |
| 2762 | } |
| 2763 | |
| 2764 | { |
| 2765 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2766 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2767 | __ Str(source, destination); |
| 2768 | |
| 2769 | if (can_value_be_null || !needs_type_check) { |
| 2770 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2771 | } |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | if (slow_path != nullptr) { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2775 | __ Bind(slow_path->GetExitLabel()); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2776 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2777 | } |
| 2778 | } |
| 2779 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2780 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2781 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2782 | InvokeRuntimeCallingConvention calling_convention; |
| 2783 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 2784 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 2785 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2786 | |
| 2787 | // If both index and length are constant, we can check the bounds statically and |
| 2788 | // generate code accordingly. We want to make sure we generate constant locations |
| 2789 | // in that case, regardless of whether they are encodable in the comparison or not. |
| 2790 | HInstruction* index = instruction->InputAt(0); |
| 2791 | HInstruction* length = instruction->InputAt(1); |
| 2792 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 2793 | locations->SetInAt(0, both_const |
| 2794 | ? Location::ConstantLocation(index->AsConstant()) |
| 2795 | : ARM64EncodableConstantOrRegister(index, instruction)); |
| 2796 | locations->SetInAt(1, both_const |
| 2797 | ? Location::ConstantLocation(length->AsConstant()) |
| 2798 | : ARM64EncodableConstantOrRegister(length, instruction)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2799 | } |
| 2800 | |
| 2801 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2802 | LocationSummary* locations = instruction->GetLocations(); |
| 2803 | Location index_loc = locations->InAt(0); |
| 2804 | Location length_loc = locations->InAt(1); |
| 2805 | |
| 2806 | int cmp_first_input = 0; |
| 2807 | int cmp_second_input = 1; |
| 2808 | Condition cond = hs; |
| 2809 | |
| 2810 | if (index_loc.IsConstant()) { |
| 2811 | int64_t index = Int64FromLocation(index_loc); |
| 2812 | if (length_loc.IsConstant()) { |
| 2813 | int64_t length = Int64FromLocation(length_loc); |
| 2814 | if (index < 0 || index >= length) { |
| 2815 | BoundsCheckSlowPathARM64* slow_path = |
| 2816 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
| 2817 | codegen_->AddSlowPath(slow_path); |
| 2818 | __ B(slow_path->GetEntryLabel()); |
| 2819 | } else { |
| 2820 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 2821 | // However, some optimization after BCE may have generated this, and we should not |
| 2822 | // generate a bounds check if it is a valid range. |
| 2823 | } |
| 2824 | return; |
| 2825 | } |
| 2826 | // Only the index is constant: change the order of the operands and commute the condition |
| 2827 | // so we can use an immediate constant for the index (only the second input to a cmp |
| 2828 | // instruction can be an immediate). |
| 2829 | cmp_first_input = 1; |
| 2830 | cmp_second_input = 0; |
| 2831 | cond = ls; |
| 2832 | } |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2833 | BoundsCheckSlowPathARM64* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2834 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
| Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2835 | __ Cmp(InputRegisterAt(instruction, cmp_first_input), |
| 2836 | InputOperandAt(instruction, cmp_second_input)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2837 | codegen_->AddSlowPath(slow_path); |
| Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2838 | __ B(slow_path->GetEntryLabel(), cond); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2839 | } |
| 2840 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2841 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2842 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2843 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2844 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2845 | if (check->HasUses()) { |
| 2846 | locations->SetOut(Location::SameAsFirstInput()); |
| 2847 | } |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 2848 | // Rely on the type initialization to save everything we need. |
| 2849 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2850 | } |
| 2851 | |
| 2852 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2853 | // We assume the class is not null. |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 2854 | SlowPathCodeARM64* slow_path = |
| 2855 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(check->GetLoadClass(), check); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2856 | codegen_->AddSlowPath(slow_path); |
| 2857 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2858 | } |
| 2859 | |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2860 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2861 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2862 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2863 | } |
| 2864 | |
| 2865 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 2866 | VRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2867 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2868 | if (rhs_loc.IsConstant()) { |
| 2869 | // 0.0 is the only immediate that can be encoded directly in |
| 2870 | // an FCMP instruction. |
| 2871 | // |
| 2872 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2873 | // specify that in a floating-point comparison, positive zero |
| 2874 | // and negative zero are considered equal, so we can use the |
| 2875 | // literal 0.0 for both cases here. |
| 2876 | // |
| 2877 | // Note however that some methods (Float.equal, Float.compare, |
| 2878 | // Float.compareTo, Double.equal, Double.compare, |
| 2879 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2880 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2881 | // -0.0. So if we ever translate calls to these methods into a |
| 2882 | // HCompare instruction, we must handle the -0.0 case with |
| 2883 | // care here. |
| 2884 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2885 | __ Fcmp(lhs_reg, 0.0); |
| 2886 | } else { |
| 2887 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2888 | } |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2889 | } |
| 2890 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2891 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2892 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2893 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2894 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2895 | switch (in_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2896 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2897 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2898 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2899 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2900 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2901 | case DataType::Type::kInt32: |
| 2902 | case DataType::Type::kInt64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2903 | locations->SetInAt(0, Location::RequiresRegister()); |
| Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2904 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2905 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2906 | break; |
| 2907 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2908 | case DataType::Type::kFloat32: |
| 2909 | case DataType::Type::kFloat64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2910 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2911 | locations->SetInAt(1, |
| 2912 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2913 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2914 | : Location::RequiresFpuRegister()); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2915 | locations->SetOut(Location::RequiresRegister()); |
| 2916 | break; |
| 2917 | } |
| 2918 | default: |
| 2919 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2924 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2925 | |
| 2926 | // 0 if: left == right |
| 2927 | // 1 if: left > right |
| 2928 | // -1 if: left < right |
| 2929 | switch (in_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2930 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2931 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2932 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2933 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2934 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2935 | case DataType::Type::kInt32: |
| 2936 | case DataType::Type::kInt64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2937 | Register result = OutputRegister(compare); |
| 2938 | Register left = InputRegisterAt(compare, 0); |
| 2939 | Operand right = InputOperandAt(compare, 1); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2940 | __ Cmp(left, right); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2941 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 2942 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2943 | break; |
| 2944 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2945 | case DataType::Type::kFloat32: |
| 2946 | case DataType::Type::kFloat64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2947 | Register result = OutputRegister(compare); |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2948 | GenerateFcmp(compare); |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2949 | __ Cset(result, ne); |
| 2950 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2951 | break; |
| 2952 | } |
| 2953 | default: |
| 2954 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2955 | } |
| 2956 | } |
| 2957 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2958 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2959 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2960 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2961 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2962 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2963 | locations->SetInAt(1, |
| 2964 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 2965 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 2966 | : Location::RequiresFpuRegister()); |
| 2967 | } else { |
| 2968 | // Integer cases. |
| 2969 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2970 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 2971 | } |
| 2972 | |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2973 | if (!instruction->IsEmittedAtUseSite()) { |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2974 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2975 | } |
| 2976 | } |
| 2977 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2978 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2979 | if (instruction->IsEmittedAtUseSite()) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2980 | return; |
| 2981 | } |
| 2982 | |
| 2983 | LocationSummary* locations = instruction->GetLocations(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2984 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2985 | IfCondition if_cond = instruction->GetCondition(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2986 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2987 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2988 | GenerateFcmp(instruction); |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2989 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2990 | } else { |
| 2991 | // Integer cases. |
| 2992 | Register lhs = InputRegisterAt(instruction, 0); |
| 2993 | Operand rhs = InputOperandAt(instruction, 1); |
| 2994 | __ Cmp(lhs, rhs); |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2995 | __ Cset(res, ARM64Condition(if_cond)); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2996 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2997 | } |
| 2998 | |
| 2999 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3000 | M(Equal) \ |
| 3001 | M(NotEqual) \ |
| 3002 | M(LessThan) \ |
| 3003 | M(LessThanOrEqual) \ |
| 3004 | M(GreaterThan) \ |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3005 | M(GreaterThanOrEqual) \ |
| 3006 | M(Below) \ |
| 3007 | M(BelowOrEqual) \ |
| 3008 | M(Above) \ |
| 3009 | M(AboveOrEqual) |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3010 | #define DEFINE_CONDITION_VISITORS(Name) \ |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3011 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3012 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3013 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3014 | #undef DEFINE_CONDITION_VISITORS |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3015 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3016 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3017 | void InstructionCodeGeneratorARM64::GenerateIntDivForPower2Denom(HDiv* instruction) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3018 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3019 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3020 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 3021 | |
| 3022 | Register out = OutputRegister(instruction); |
| 3023 | Register dividend = InputRegisterAt(instruction, 0); |
| Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3024 | |
| 3025 | if (abs_imm == 2) { |
| 3026 | int bits = DataType::Size(instruction->GetResultType()) * kBitsPerByte; |
| 3027 | __ Add(out, dividend, Operand(dividend, LSR, bits - 1)); |
| 3028 | } else { |
| 3029 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3030 | Register temp = temps.AcquireSameSizeAs(out); |
| 3031 | __ Add(temp, dividend, abs_imm - 1); |
| 3032 | __ Cmp(dividend, 0); |
| 3033 | __ Csel(out, temp, dividend, lt); |
| 3034 | } |
| 3035 | |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3036 | int ctz_imm = CTZ(abs_imm); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3037 | if (imm > 0) { |
| 3038 | __ Asr(out, out, ctz_imm); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3039 | } else { |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3040 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3041 | } |
| 3042 | } |
| 3043 | |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3044 | // Return true if the magic number was modified by subtracting 2^32. So dividend needs to be added. |
| 3045 | static inline bool NeedToAddDividend(int64_t magic_number, int64_t divisor) { |
| 3046 | return divisor > 0 && magic_number < 0; |
| 3047 | } |
| 3048 | |
| 3049 | // Return true if the magic number was modified by adding 2^32. So dividend needs to be subtracted. |
| 3050 | static inline bool NeedToSubDividend(int64_t magic_number, int64_t divisor) { |
| 3051 | return divisor < 0 && magic_number > 0; |
| 3052 | } |
| 3053 | |
| Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3054 | // Return true if the result of multiplication of the dividend by a sort of reciprocal |
| 3055 | // of the divisor (magic_number) needs to be corrected. This means additional operations will |
| 3056 | // be generated. |
| 3057 | static inline bool NeedToCorrectMulResult(int64_t magic_number, int64_t divisor) { |
| 3058 | return NeedToAddDividend(magic_number, divisor) || NeedToSubDividend(magic_number, divisor); |
| 3059 | } |
| 3060 | |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3061 | void InstructionCodeGeneratorARM64::GenerateResultDivRemWithAnyConstant( |
| 3062 | bool is_rem, |
| 3063 | int final_right_shift, |
| 3064 | int64_t magic_number, |
| 3065 | int64_t divisor, |
| 3066 | Register dividend, |
| 3067 | Register temp_result, |
| 3068 | Register out, |
| 3069 | UseScratchRegisterScope* temps_scope) { |
| Evgeny Astigeevich | 1439e57 | 2020-05-12 12:43:09 +0100 | [diff] [blame^] | 3070 | // The multiplication result might need some corrections to be finalized. |
| 3071 | // The last correction is to increment by 1, if the result is negative. |
| 3072 | // Currently it is done with 'add result, temp_result, temp_result, lsr #31 or #63'. |
| 3073 | // Such ADD usually has latency 2, e.g. on Cortex-A55. |
| 3074 | // However if one of the corrections is ADD or SUB, the sign can be detected |
| 3075 | // with ADDS/SUBS. They set the N flag if the result is negative. |
| 3076 | // This allows to use CINC MI which has latency 1. |
| 3077 | bool use_cond_inc = false; |
| 3078 | |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3079 | // As magic_number can be modified to fit into 32 bits, check whether the correction is needed. |
| 3080 | if (NeedToAddDividend(magic_number, divisor)) { |
| Evgeny Astigeevich | 1439e57 | 2020-05-12 12:43:09 +0100 | [diff] [blame^] | 3081 | __ Adds(temp_result, temp_result, dividend); |
| 3082 | use_cond_inc = true; |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3083 | } else if (NeedToSubDividend(magic_number, divisor)) { |
| Evgeny Astigeevich | 1439e57 | 2020-05-12 12:43:09 +0100 | [diff] [blame^] | 3084 | __ Subs(temp_result, temp_result, dividend); |
| 3085 | use_cond_inc = true; |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | if (final_right_shift != 0) { |
| 3089 | __ Asr(temp_result, temp_result, final_right_shift); |
| 3090 | } |
| 3091 | |
| 3092 | Register& result = (is_rem) ? temp_result : out; |
| Evgeny Astigeevich | 1439e57 | 2020-05-12 12:43:09 +0100 | [diff] [blame^] | 3093 | if (use_cond_inc) { |
| 3094 | __ Cinc(result, temp_result, mi); |
| 3095 | } else { |
| 3096 | __ Add(result, temp_result, Operand(temp_result, LSR, temp_result.GetSizeInBits() - 1)); |
| 3097 | } |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3098 | if (is_rem) { |
| 3099 | // TODO: Strength reduction for msub. |
| 3100 | Register temp_imm = temps_scope->AcquireSameSizeAs(out); |
| 3101 | __ Mov(temp_imm, divisor); |
| 3102 | __ Msub(out, temp_result, temp_imm, dividend); |
| 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | void InstructionCodeGeneratorARM64::GenerateInt64DivRemWithAnyConstant( |
| 3107 | HBinaryOperation* instruction) { |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3108 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3109 | DCHECK(instruction->GetResultType() == DataType::Type::kInt64); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3110 | |
| 3111 | LocationSummary* locations = instruction->GetLocations(); |
| 3112 | Location second = locations->InAt(1); |
| 3113 | DCHECK(second.IsConstant()); |
| 3114 | |
| 3115 | Register out = OutputRegister(instruction); |
| 3116 | Register dividend = InputRegisterAt(instruction, 0); |
| 3117 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3118 | |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3119 | int64_t magic; |
| 3120 | int shift; |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3121 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ true, &magic, &shift); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3122 | |
| 3123 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3124 | Register temp = temps.AcquireSameSizeAs(out); |
| 3125 | |
| 3126 | // temp = get_high(dividend * magic) |
| 3127 | __ Mov(temp, magic); |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3128 | __ Smulh(temp, dividend, temp); |
| 3129 | |
| 3130 | GenerateResultDivRemWithAnyConstant(/* is_rem= */ instruction->IsRem(), |
| 3131 | /* final_right_shift= */ shift, |
| 3132 | magic, |
| 3133 | imm, |
| 3134 | dividend, |
| 3135 | temp, |
| 3136 | out, |
| 3137 | &temps); |
| 3138 | } |
| 3139 | |
| 3140 | void InstructionCodeGeneratorARM64::GenerateInt32DivRemWithAnyConstant( |
| 3141 | HBinaryOperation* instruction) { |
| 3142 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3143 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 3144 | |
| 3145 | LocationSummary* locations = instruction->GetLocations(); |
| 3146 | Location second = locations->InAt(1); |
| 3147 | DCHECK(second.IsConstant()); |
| 3148 | |
| 3149 | Register out = OutputRegister(instruction); |
| 3150 | Register dividend = InputRegisterAt(instruction, 0); |
| 3151 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3152 | |
| 3153 | int64_t magic; |
| 3154 | int shift; |
| 3155 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| 3156 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3157 | Register temp = temps.AcquireSameSizeAs(out); |
| 3158 | |
| 3159 | // temp = get_high(dividend * magic) |
| 3160 | __ Mov(temp, magic); |
| 3161 | __ Smull(temp.X(), dividend, temp); |
| Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame] | 3162 | |
| 3163 | if (NeedToCorrectMulResult(magic, imm)) { |
| 3164 | __ Lsr(temp.X(), temp.X(), 32); |
| 3165 | } else { |
| 3166 | // As between 'lsr temp.X(), temp.X(), #32' and 'asr temp, temp, #shift' there are |
| 3167 | // no other instructions modifying 'temp', they can be combined into one |
| 3168 | // 'asr temp.X(), temp.X(), #32 + shift'. |
| 3169 | DCHECK_LT(shift, 32); |
| 3170 | __ Asr(temp.X(), temp.X(), 32 + shift); |
| 3171 | shift = 0; |
| 3172 | } |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3173 | |
| 3174 | GenerateResultDivRemWithAnyConstant(/* is_rem= */ instruction->IsRem(), |
| 3175 | /* final_right_shift= */ shift, |
| 3176 | magic, |
| 3177 | imm, |
| 3178 | dividend, |
| 3179 | temp, |
| 3180 | out, |
| 3181 | &temps); |
| 3182 | } |
| 3183 | |
| 3184 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3185 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3186 | if (instruction->GetResultType() == DataType::Type::kInt64) { |
| 3187 | GenerateInt64DivRemWithAnyConstant(instruction); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3188 | } else { |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3189 | GenerateInt32DivRemWithAnyConstant(instruction); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3190 | } |
| 3191 | } |
| 3192 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3193 | void InstructionCodeGeneratorARM64::GenerateIntDivForConstDenom(HDiv *instruction) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3194 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3195 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3196 | if (imm == 0) { |
| 3197 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3198 | return; |
| 3199 | } |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3200 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3201 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3202 | GenerateIntDivForPower2Denom(instruction); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3203 | } else { |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3204 | // Cases imm == -1 or imm == 1 are handled by InstructionSimplifier. |
| 3205 | DCHECK(imm < -2 || imm > 2) << imm; |
| 3206 | GenerateDivRemWithAnyConstant(instruction); |
| 3207 | } |
| 3208 | } |
| 3209 | |
| 3210 | void InstructionCodeGeneratorARM64::GenerateIntDiv(HDiv *instruction) { |
| 3211 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 3212 | << instruction->GetResultType(); |
| 3213 | |
| 3214 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 3215 | GenerateIntDivForConstDenom(instruction); |
| 3216 | } else { |
| 3217 | Register out = OutputRegister(instruction); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3218 | Register dividend = InputRegisterAt(instruction, 0); |
| 3219 | Register divisor = InputRegisterAt(instruction, 1); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3220 | __ Sdiv(out, dividend, divisor); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3221 | } |
| 3222 | } |
| 3223 | |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3224 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3225 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3226 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3227 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3228 | case DataType::Type::kInt32: |
| 3229 | case DataType::Type::kInt64: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3230 | locations->SetInAt(0, Location::RequiresRegister()); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3231 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3232 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3233 | break; |
| 3234 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3235 | case DataType::Type::kFloat32: |
| 3236 | case DataType::Type::kFloat64: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3237 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3238 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3239 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3240 | break; |
| 3241 | |
| 3242 | default: |
| 3243 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3244 | } |
| 3245 | } |
| 3246 | |
| 3247 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3248 | DataType::Type type = div->GetResultType(); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3249 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3250 | case DataType::Type::kInt32: |
| 3251 | case DataType::Type::kInt64: |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3252 | GenerateIntDiv(div); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3253 | break; |
| 3254 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3255 | case DataType::Type::kFloat32: |
| 3256 | case DataType::Type::kFloat64: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3257 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3258 | break; |
| 3259 | |
| 3260 | default: |
| 3261 | LOG(FATAL) << "Unexpected div type " << type; |
| 3262 | } |
| 3263 | } |
| 3264 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3265 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3266 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3267 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3271 | SlowPathCodeARM64* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3272 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3273 | codegen_->AddSlowPath(slow_path); |
| 3274 | Location value = instruction->GetLocations()->InAt(0); |
| 3275 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3276 | DataType::Type type = instruction->GetType(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3277 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3278 | if (!DataType::IsIntegralType(type)) { |
| Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3279 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3280 | UNREACHABLE(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3281 | } |
| 3282 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3283 | if (value.IsConstant()) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3284 | int64_t divisor = Int64FromLocation(value); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3285 | if (divisor == 0) { |
| 3286 | __ B(slow_path->GetEntryLabel()); |
| 3287 | } else { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3288 | // A division by a non-null constant is valid. We don't need to perform |
| 3289 | // any check, so simply fall through. |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3290 | } |
| 3291 | } else { |
| 3292 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3293 | } |
| 3294 | } |
| 3295 | |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3296 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3297 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3298 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3299 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3300 | } |
| 3301 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3302 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3303 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3304 | // Will be generated at use site. |
| 3305 | } |
| 3306 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3307 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3308 | exit->SetLocations(nullptr); |
| 3309 | } |
| 3310 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3311 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3312 | } |
| 3313 | |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3314 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3315 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3316 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3317 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3318 | } |
| 3319 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3320 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3321 | // Will be generated at use site. |
| 3322 | } |
| 3323 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3324 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3325 | if (successor->IsExitBlock()) { |
| 3326 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3327 | return; // no code needed |
| 3328 | } |
| 3329 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3330 | HBasicBlock* block = got->GetBlock(); |
| 3331 | HInstruction* previous = got->GetPrevious(); |
| 3332 | HLoopInformation* info = block->GetLoopInformation(); |
| 3333 | |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3334 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 3335 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3336 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3337 | return; |
| 3338 | } |
| 3339 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3340 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3341 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3342 | } |
| 3343 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3344 | __ B(codegen_->GetLabelOf(successor)); |
| 3345 | } |
| 3346 | } |
| 3347 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3348 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3349 | got->SetLocations(nullptr); |
| 3350 | } |
| 3351 | |
| 3352 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3353 | HandleGoto(got, got->GetSuccessor()); |
| 3354 | } |
| 3355 | |
| 3356 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3357 | try_boundary->SetLocations(nullptr); |
| 3358 | } |
| 3359 | |
| 3360 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3361 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3362 | if (!successor->IsExitBlock()) { |
| 3363 | HandleGoto(try_boundary, successor); |
| 3364 | } |
| 3365 | } |
| 3366 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3367 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3368 | size_t condition_input_index, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3369 | vixl::aarch64::Label* true_target, |
| 3370 | vixl::aarch64::Label* false_target) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3371 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3372 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3373 | if (true_target == nullptr && false_target == nullptr) { |
| 3374 | // Nothing to do. The code always falls through. |
| 3375 | return; |
| 3376 | } else if (cond->IsIntConstant()) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3377 | // Constant condition, statically compared against "true" (integer value 1). |
| 3378 | if (cond->AsIntConstant()->IsTrue()) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3379 | if (true_target != nullptr) { |
| 3380 | __ B(true_target); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3381 | } |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3382 | } else { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3383 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3384 | if (false_target != nullptr) { |
| 3385 | __ B(false_target); |
| 3386 | } |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3387 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3388 | return; |
| 3389 | } |
| 3390 | |
| 3391 | // The following code generates these patterns: |
| 3392 | // (1) true_target == nullptr && false_target != nullptr |
| 3393 | // - opposite condition true => branch to false_target |
| 3394 | // (2) true_target != nullptr && false_target == nullptr |
| 3395 | // - condition true => branch to true_target |
| 3396 | // (3) true_target != nullptr && false_target != nullptr |
| 3397 | // - condition true => branch to true_target |
| 3398 | // - branch to false_target |
| 3399 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3400 | // The condition instruction has been materialized, compare the output to 0. |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3401 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3402 | DCHECK(cond_val.IsRegister()); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3403 | if (true_target == nullptr) { |
| 3404 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3405 | } else { |
| 3406 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3407 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3408 | } else { |
| 3409 | // The condition instruction has not been materialized, use its inputs as |
| 3410 | // the comparison and its condition as the branch condition. |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3411 | HCondition* condition = cond->AsCondition(); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3412 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3413 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3414 | if (DataType::IsFloatingPointType(type)) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3415 | GenerateFcmp(condition); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3416 | if (true_target == nullptr) { |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3417 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3418 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3419 | } else { |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3420 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3421 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3422 | } else { |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3423 | // Integer cases. |
| 3424 | Register lhs = InputRegisterAt(condition, 0); |
| 3425 | Operand rhs = InputOperandAt(condition, 1); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3426 | |
| 3427 | Condition arm64_cond; |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3428 | vixl::aarch64::Label* non_fallthrough_target; |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3429 | if (true_target == nullptr) { |
| 3430 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3431 | non_fallthrough_target = false_target; |
| 3432 | } else { |
| 3433 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3434 | non_fallthrough_target = true_target; |
| 3435 | } |
| 3436 | |
| Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3437 | 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] | 3438 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3439 | switch (arm64_cond) { |
| 3440 | case eq: |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3441 | __ Cbz(lhs, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3442 | break; |
| 3443 | case ne: |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3444 | __ Cbnz(lhs, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3445 | break; |
| 3446 | case lt: |
| 3447 | // Test the sign bit and branch accordingly. |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3448 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3449 | break; |
| 3450 | case ge: |
| 3451 | // Test the sign bit and branch accordingly. |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3452 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3453 | break; |
| 3454 | default: |
| 3455 | // Without the `static_cast` the compiler throws an error for |
| 3456 | // `-Werror=sign-promo`. |
| 3457 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3458 | } |
| 3459 | } else { |
| 3460 | __ Cmp(lhs, rhs); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3461 | __ B(arm64_cond, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3462 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3463 | } |
| 3464 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3465 | |
| 3466 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3467 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3468 | if (true_target != nullptr && false_target != nullptr) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3469 | __ B(false_target); |
| 3470 | } |
| 3471 | } |
| 3472 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3473 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3474 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3475 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3476 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3477 | } |
| 3478 | } |
| 3479 | |
| 3480 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3481 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3482 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3483 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3484 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3485 | true_target = nullptr; |
| 3486 | } |
| 3487 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3488 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3489 | false_target = nullptr; |
| 3490 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3491 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3492 | } |
| 3493 | |
| 3494 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3495 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3496 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3497 | InvokeRuntimeCallingConvention calling_convention; |
| 3498 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3499 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3500 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3501 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3502 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3503 | } |
| 3504 | } |
| 3505 | |
| 3506 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3507 | SlowPathCodeARM64* slow_path = |
| 3508 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3509 | GenerateTestAndBranch(deoptimize, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3510 | /* condition_input_index= */ 0, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3511 | slow_path->GetEntryLabel(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3512 | /* false_target= */ nullptr); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3513 | } |
| 3514 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3515 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3516 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3517 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3518 | locations->SetOut(Location::RequiresRegister()); |
| 3519 | } |
| 3520 | |
| 3521 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3522 | __ Ldr(OutputRegister(flag), |
| 3523 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3524 | } |
| 3525 | |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3526 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3527 | return condition->IsCondition() && |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3528 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3529 | } |
| 3530 | |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3531 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3532 | IfCondition cond = condition->AsCondition()->GetCondition(); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3533 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3534 | : ARM64Condition(cond); |
| 3535 | } |
| 3536 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3537 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3538 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3539 | if (DataType::IsFloatingPointType(select->GetType())) { |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3540 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3541 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3542 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3543 | } else { |
| 3544 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3545 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3546 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3547 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3548 | // Ask VIXL whether we should synthesize constants in registers. |
| 3549 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3550 | Operand true_op = is_true_value_constant ? |
| 3551 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3552 | Operand false_op = is_false_value_constant ? |
| 3553 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3554 | bool true_value_in_register = false; |
| 3555 | bool false_value_in_register = false; |
| 3556 | MacroAssembler::GetCselSynthesisInformation( |
| 3557 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3558 | true_value_in_register |= !is_true_value_constant; |
| 3559 | false_value_in_register |= !is_false_value_constant; |
| 3560 | |
| 3561 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3562 | : Location::ConstantLocation(cst_true_value)); |
| 3563 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3564 | : Location::ConstantLocation(cst_false_value)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3565 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3566 | } |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3567 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3568 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3569 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3570 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3571 | } |
| 3572 | |
| 3573 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3574 | HInstruction* cond = select->GetCondition(); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3575 | Condition csel_cond; |
| 3576 | |
| 3577 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3578 | if (cond->IsCondition() && cond->GetNext() == select) { |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3579 | // Use the condition flags set by the previous instruction. |
| 3580 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3581 | } else { |
| 3582 | __ Cmp(InputRegisterAt(select, 2), 0); |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3583 | csel_cond = ne; |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3584 | } |
| 3585 | } else if (IsConditionOnFloatingPointValues(cond)) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3586 | GenerateFcmp(cond); |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3587 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3588 | } else { |
| 3589 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3590 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3591 | } |
| 3592 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3593 | if (DataType::IsFloatingPointType(select->GetType())) { |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3594 | __ Fcsel(OutputFPRegister(select), |
| 3595 | InputFPRegisterAt(select, 1), |
| 3596 | InputFPRegisterAt(select, 0), |
| 3597 | csel_cond); |
| 3598 | } else { |
| 3599 | __ Csel(OutputRegister(select), |
| 3600 | InputOperandAt(select, 1), |
| 3601 | InputOperandAt(select, 0), |
| 3602 | csel_cond); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3603 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3604 | } |
| 3605 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3606 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3607 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3608 | } |
| 3609 | |
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3610 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3611 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | void CodeGeneratorARM64::GenerateNop() { |
| 3615 | __ Nop(); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3616 | } |
| 3617 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3618 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3619 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3623 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3627 | HandleFieldSet(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3628 | } |
| 3629 | |
| 3630 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3631 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3632 | } |
| 3633 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3634 | // Temp is used for read barrier. |
| 3635 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3636 | if (kEmitCompilerReadBarrier && |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3637 | (kUseBakerReadBarrier || |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3638 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3639 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3640 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3641 | return 1; |
| 3642 | } |
| 3643 | return 0; |
| 3644 | } |
| 3645 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3646 | // 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] | 3647 | // interface pointer, one for loading the current interface. |
| 3648 | // The other checks have one temp for loading the object's class. |
| 3649 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3650 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3651 | return 3; |
| 3652 | } |
| 3653 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3654 | } |
| 3655 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3656 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3657 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3658 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3659 | bool baker_read_barrier_slow_path = false; |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3660 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3661 | case TypeCheckKind::kExactCheck: |
| 3662 | case TypeCheckKind::kAbstractClassCheck: |
| 3663 | case TypeCheckKind::kClassHierarchyCheck: |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3664 | case TypeCheckKind::kArrayObjectCheck: { |
| 3665 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 3666 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 3667 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3668 | break; |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3669 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3670 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3671 | case TypeCheckKind::kUnresolvedCheck: |
| 3672 | case TypeCheckKind::kInterfaceCheck: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3673 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3674 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3675 | case TypeCheckKind::kBitstringCheck: |
| 3676 | break; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3677 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3678 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3679 | LocationSummary* locations = |
| 3680 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3681 | if (baker_read_barrier_slow_path) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3682 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3683 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3684 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3685 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3686 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3687 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3688 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3689 | } else { |
| 3690 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3691 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3692 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3693 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3694 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3695 | // Add temps if necessary for read barriers. |
| 3696 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3697 | } |
| 3698 | |
| 3699 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3700 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3701 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3702 | Location obj_loc = locations->InAt(0); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3703 | Register obj = InputRegisterAt(instruction, 0); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3704 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 3705 | ? Register() |
| 3706 | : InputRegisterAt(instruction, 1); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3707 | Location out_loc = locations->Out(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3708 | Register out = OutputRegister(instruction); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3709 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3710 | DCHECK_LE(num_temps, 1u); |
| 3711 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3712 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3713 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3714 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3715 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3716 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3717 | vixl::aarch64::Label done, zero; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3718 | SlowPathCodeARM64* slow_path = nullptr; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3719 | |
| 3720 | // Return 0 if `obj` is null. |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3721 | // Avoid null check if we know `obj` is not null. |
| 3722 | if (instruction->MustDoNullCheck()) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3723 | __ Cbz(obj, &zero); |
| 3724 | } |
| 3725 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3726 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3727 | case TypeCheckKind::kExactCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3728 | ReadBarrierOption read_barrier_option = |
| 3729 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3730 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3731 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3732 | out_loc, |
| 3733 | obj_loc, |
| 3734 | class_offset, |
| 3735 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3736 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3737 | __ Cmp(out, cls); |
| 3738 | __ Cset(out, eq); |
| 3739 | if (zero.IsLinked()) { |
| 3740 | __ B(&done); |
| 3741 | } |
| 3742 | break; |
| 3743 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3744 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3745 | case TypeCheckKind::kAbstractClassCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3746 | ReadBarrierOption read_barrier_option = |
| 3747 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3748 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3749 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3750 | out_loc, |
| 3751 | obj_loc, |
| 3752 | class_offset, |
| 3753 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3754 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3755 | // If the class is abstract, we eagerly fetch the super class of the |
| 3756 | // object to avoid doing a comparison we know will fail. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3757 | vixl::aarch64::Label loop, success; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3758 | __ Bind(&loop); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3759 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3760 | GenerateReferenceLoadOneRegister(instruction, |
| 3761 | out_loc, |
| 3762 | super_offset, |
| 3763 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3764 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3765 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3766 | __ Cbz(out, &done); |
| 3767 | __ Cmp(out, cls); |
| 3768 | __ B(ne, &loop); |
| 3769 | __ Mov(out, 1); |
| 3770 | if (zero.IsLinked()) { |
| 3771 | __ B(&done); |
| 3772 | } |
| 3773 | break; |
| 3774 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3775 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3776 | case TypeCheckKind::kClassHierarchyCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3777 | ReadBarrierOption read_barrier_option = |
| 3778 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3779 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3780 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3781 | out_loc, |
| 3782 | obj_loc, |
| 3783 | class_offset, |
| 3784 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3785 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3786 | // Walk over the class hierarchy to find a match. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3787 | vixl::aarch64::Label loop, success; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3788 | __ Bind(&loop); |
| 3789 | __ Cmp(out, cls); |
| 3790 | __ B(eq, &success); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3791 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3792 | GenerateReferenceLoadOneRegister(instruction, |
| 3793 | out_loc, |
| 3794 | super_offset, |
| 3795 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3796 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3797 | __ Cbnz(out, &loop); |
| 3798 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3799 | __ B(&done); |
| 3800 | __ Bind(&success); |
| 3801 | __ Mov(out, 1); |
| 3802 | if (zero.IsLinked()) { |
| 3803 | __ B(&done); |
| 3804 | } |
| 3805 | break; |
| 3806 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3807 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3808 | case TypeCheckKind::kArrayObjectCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3809 | ReadBarrierOption read_barrier_option = |
| 3810 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3811 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3812 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3813 | out_loc, |
| 3814 | obj_loc, |
| 3815 | class_offset, |
| 3816 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3817 | read_barrier_option); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3818 | // Do an exact check. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3819 | vixl::aarch64::Label exact_check; |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3820 | __ Cmp(out, cls); |
| 3821 | __ B(eq, &exact_check); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3822 | // 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] | 3823 | // /* HeapReference<Class> */ out = out->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3824 | GenerateReferenceLoadOneRegister(instruction, |
| 3825 | out_loc, |
| 3826 | component_offset, |
| 3827 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3828 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3829 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3830 | __ Cbz(out, &done); |
| 3831 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3832 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3833 | __ Cbnz(out, &zero); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3834 | __ Bind(&exact_check); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3835 | __ Mov(out, 1); |
| 3836 | __ B(&done); |
| 3837 | break; |
| 3838 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3839 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3840 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3841 | // No read barrier since the slow path will retry upon failure. |
| 3842 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3843 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3844 | out_loc, |
| 3845 | obj_loc, |
| 3846 | class_offset, |
| 3847 | maybe_temp_loc, |
| 3848 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3849 | __ Cmp(out, cls); |
| 3850 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3851 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3852 | instruction, /* is_fatal= */ false); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3853 | codegen_->AddSlowPath(slow_path); |
| 3854 | __ B(ne, slow_path->GetEntryLabel()); |
| 3855 | __ Mov(out, 1); |
| 3856 | if (zero.IsLinked()) { |
| 3857 | __ B(&done); |
| 3858 | } |
| 3859 | break; |
| 3860 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3861 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3862 | case TypeCheckKind::kUnresolvedCheck: |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3863 | case TypeCheckKind::kInterfaceCheck: { |
| 3864 | // Note that we indeed only call on slow path, but we always go |
| 3865 | // into the slow path for the unresolved and interface check |
| 3866 | // cases. |
| 3867 | // |
| 3868 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3869 | // entry point without resorting to a type checking slow path |
| 3870 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3871 | // require to assign fixed registers for the inputs of this |
| 3872 | // HInstanceOf instruction (following the runtime calling |
| 3873 | // convention), which might be cluttered by the potential first |
| 3874 | // read barrier emission at the beginning of this method. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3875 | // |
| 3876 | // TODO: Introduce a new runtime entry point taking the object |
| 3877 | // to test (instead of its class) as argument, and let it deal |
| 3878 | // with the read barrier issues. This will let us refactor this |
| 3879 | // case of the `switch` code as it was previously (with a direct |
| 3880 | // call to the runtime not using a type checking slow path). |
| 3881 | // This should also be beneficial for the other cases above. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3882 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3883 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3884 | instruction, /* is_fatal= */ false); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3885 | codegen_->AddSlowPath(slow_path); |
| 3886 | __ B(slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3887 | if (zero.IsLinked()) { |
| 3888 | __ B(&done); |
| 3889 | } |
| 3890 | break; |
| 3891 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3892 | |
| 3893 | case TypeCheckKind::kBitstringCheck: { |
| 3894 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3895 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3896 | out_loc, |
| 3897 | obj_loc, |
| 3898 | class_offset, |
| 3899 | maybe_temp_loc, |
| 3900 | kWithoutReadBarrier); |
| 3901 | |
| 3902 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 3903 | __ Cset(out, eq); |
| 3904 | if (zero.IsLinked()) { |
| 3905 | __ B(&done); |
| 3906 | } |
| 3907 | break; |
| 3908 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3909 | } |
| 3910 | |
| 3911 | if (zero.IsLinked()) { |
| 3912 | __ Bind(&zero); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3913 | __ Mov(out, 0); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | if (done.IsLinked()) { |
| 3917 | __ Bind(&done); |
| 3918 | } |
| 3919 | |
| 3920 | if (slow_path != nullptr) { |
| 3921 | __ Bind(slow_path->GetExitLabel()); |
| 3922 | } |
| 3923 | } |
| 3924 | |
| 3925 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3926 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3927 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3928 | LocationSummary* locations = |
| 3929 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3930 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3931 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3932 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3933 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3934 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3935 | } else { |
| 3936 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3937 | } |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3938 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 3939 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3940 | } |
| 3941 | |
| 3942 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3943 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3944 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3945 | Location obj_loc = locations->InAt(0); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3946 | Register obj = InputRegisterAt(instruction, 0); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3947 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 3948 | ? Register() |
| 3949 | : InputRegisterAt(instruction, 1); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3950 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3951 | DCHECK_GE(num_temps, 1u); |
| 3952 | DCHECK_LE(num_temps, 3u); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3953 | Location temp_loc = locations->GetTemp(0); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3954 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 3955 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3956 | Register temp = WRegisterFrom(temp_loc); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3957 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3958 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3959 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3960 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3961 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3962 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3963 | const uint32_t object_array_data_offset = |
| 3964 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3965 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3966 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3967 | SlowPathCodeARM64* type_check_slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3968 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 3969 | instruction, is_type_check_slow_path_fatal); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3970 | codegen_->AddSlowPath(type_check_slow_path); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3971 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3972 | vixl::aarch64::Label done; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3973 | // Avoid null check if we know obj is not null. |
| 3974 | if (instruction->MustDoNullCheck()) { |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3975 | __ Cbz(obj, &done); |
| 3976 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3977 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3978 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3979 | case TypeCheckKind::kExactCheck: |
| 3980 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3981 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3982 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3983 | temp_loc, |
| 3984 | obj_loc, |
| 3985 | class_offset, |
| 3986 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3987 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3988 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3989 | __ Cmp(temp, cls); |
| 3990 | // Jump to slow path for throwing the exception or doing a |
| 3991 | // more involved array check. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3992 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3993 | break; |
| 3994 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3995 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3996 | case TypeCheckKind::kAbstractClassCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3997 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3998 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3999 | temp_loc, |
| 4000 | obj_loc, |
| 4001 | class_offset, |
| 4002 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4003 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4004 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4005 | // If the class is abstract, we eagerly fetch the super class of the |
| 4006 | // object to avoid doing a comparison we know will fail. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4007 | vixl::aarch64::Label loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4008 | __ Bind(&loop); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4009 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4010 | GenerateReferenceLoadOneRegister(instruction, |
| 4011 | temp_loc, |
| 4012 | super_offset, |
| 4013 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4014 | kWithoutReadBarrier); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4015 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4016 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4017 | // exception. |
| 4018 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4019 | // Otherwise, compare classes. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4020 | __ Cmp(temp, cls); |
| 4021 | __ B(ne, &loop); |
| 4022 | break; |
| 4023 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4024 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4025 | case TypeCheckKind::kClassHierarchyCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4026 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4027 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4028 | temp_loc, |
| 4029 | obj_loc, |
| 4030 | class_offset, |
| 4031 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4032 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4033 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4034 | // Walk over the class hierarchy to find a match. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4035 | vixl::aarch64::Label loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4036 | __ Bind(&loop); |
| 4037 | __ Cmp(temp, cls); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4038 | __ B(eq, &done); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4039 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4040 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4041 | GenerateReferenceLoadOneRegister(instruction, |
| 4042 | temp_loc, |
| 4043 | super_offset, |
| 4044 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4045 | kWithoutReadBarrier); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4046 | |
| 4047 | // If the class reference currently in `temp` is not null, jump |
| 4048 | // back at the beginning of the loop. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4049 | __ Cbnz(temp, &loop); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4050 | // Otherwise, jump to the slow path to throw the exception. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4051 | __ B(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4052 | break; |
| 4053 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4054 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4055 | case TypeCheckKind::kArrayObjectCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4056 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4057 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4058 | temp_loc, |
| 4059 | obj_loc, |
| 4060 | class_offset, |
| 4061 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4062 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4063 | |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4064 | // Do an exact check. |
| 4065 | __ Cmp(temp, cls); |
| 4066 | __ B(eq, &done); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4067 | |
| 4068 | // 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] | 4069 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4070 | GenerateReferenceLoadOneRegister(instruction, |
| 4071 | temp_loc, |
| 4072 | component_offset, |
| 4073 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4074 | kWithoutReadBarrier); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4075 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4076 | // If the component type is null, jump to the slow path to throw the exception. |
| 4077 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4078 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4079 | // primitive type. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4080 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4081 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4082 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4083 | break; |
| 4084 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4085 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4086 | case TypeCheckKind::kUnresolvedCheck: |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4087 | // 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] | 4088 | // |
| 4089 | // We cannot directly call the CheckCast runtime entry point |
| 4090 | // without resorting to a type checking slow path here (i.e. by |
| 4091 | // calling InvokeRuntime directly), as it would require to |
| 4092 | // assign fixed registers for the inputs of this HInstanceOf |
| 4093 | // instruction (following the runtime calling convention), which |
| 4094 | // might be cluttered by the potential first read barrier |
| 4095 | // emission at the beginning of this method. |
| 4096 | __ B(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4097 | break; |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4098 | case TypeCheckKind::kInterfaceCheck: { |
| 4099 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4100 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4101 | temp_loc, |
| 4102 | obj_loc, |
| 4103 | class_offset, |
| 4104 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4105 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4106 | |
| 4107 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4108 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4109 | temp_loc, |
| 4110 | temp_loc, |
| 4111 | iftable_offset, |
| 4112 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4113 | kWithoutReadBarrier); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4114 | // Iftable is never null. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4115 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4116 | // Loop through the iftable and check if any class matches. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4117 | vixl::aarch64::Label start_loop; |
| 4118 | __ Bind(&start_loop); |
| Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4119 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4120 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4121 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4122 | // Go to next interface. |
| 4123 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4124 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
| Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4125 | // Compare the classes and continue the loop if they do not match. |
| 4126 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4127 | __ B(ne, &start_loop); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4128 | break; |
| 4129 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4130 | |
| 4131 | case TypeCheckKind::kBitstringCheck: { |
| 4132 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4133 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4134 | temp_loc, |
| 4135 | obj_loc, |
| 4136 | class_offset, |
| 4137 | maybe_temp2_loc, |
| 4138 | kWithoutReadBarrier); |
| 4139 | |
| 4140 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 4141 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 4142 | break; |
| 4143 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4144 | } |
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4145 | __ Bind(&done); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4146 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4147 | __ Bind(type_check_slow_path->GetExitLabel()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4148 | } |
| 4149 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4150 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4151 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4152 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4153 | } |
| 4154 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4155 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4156 | // Will be generated at use site. |
| 4157 | } |
| 4158 | |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4159 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4160 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4161 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4162 | } |
| 4163 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4164 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4165 | // Will be generated at use site. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4166 | } |
| 4167 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4168 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4169 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4170 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4171 | // the method_idx. |
| 4172 | HandleInvoke(invoke); |
| 4173 | } |
| 4174 | |
| 4175 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4176 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4177 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4178 | } |
| 4179 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4180 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4181 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4182 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4183 | } |
| 4184 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4185 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4186 | HandleInvoke(invoke); |
| 4187 | } |
| 4188 | |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4189 | void CodeGeneratorARM64::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 4190 | Register klass) { |
| 4191 | DCHECK_EQ(klass.GetCode(), 0u); |
| Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4192 | // We know the destination of an intrinsic, so no need to record inline |
| 4193 | // caches. |
| 4194 | if (!instruction->GetLocations()->Intrinsified() && |
| Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 4195 | GetGraph()->IsCompilingBaseline() && |
| Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4196 | !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4197 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
| 4198 | ScopedObjectAccess soa(Thread::Current()); |
| 4199 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 4200 | if (info != nullptr) { |
| 4201 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 4202 | uint64_t address = reinterpret_cast64<uint64_t>(cache); |
| 4203 | vixl::aarch64::Label done; |
| 4204 | __ Mov(x8, address); |
| 4205 | __ Ldr(x9, MemOperand(x8, InlineCache::ClassesOffset().Int32Value())); |
| 4206 | // Fast path for a monomorphic cache. |
| 4207 | __ Cmp(klass, x9); |
| 4208 | __ B(eq, &done); |
| 4209 | InvokeRuntime(kQuickUpdateInlineCache, instruction, instruction->GetDexPc()); |
| 4210 | __ Bind(&done); |
| 4211 | } |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4212 | } |
| 4213 | } |
| 4214 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4215 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4216 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4217 | LocationSummary* locations = invoke->GetLocations(); |
| 4218 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4219 | Location receiver = locations->InAt(0); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4220 | Offset class_offset = mirror::Object::ClassOffset(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4221 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4222 | |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4223 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4224 | if (receiver.IsStackSlot()) { |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4225 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4226 | { |
| 4227 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4228 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4229 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4230 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4231 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4232 | } else { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4233 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4234 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4235 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4236 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4237 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4238 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4239 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4240 | // emit a read barrier for the previous class reference load. |
| 4241 | // However this is not required in practice, as this is an |
| 4242 | // intermediate/temporary reference and because the current |
| 4243 | // concurrent copying collector keeps the from-space memory |
| 4244 | // intact/accessible until the end of the marking phase (the |
| 4245 | // concurrent copying collector may not in the future). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4246 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4247 | |
| 4248 | // If we're compiling baseline, update the inline cache. |
| 4249 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4250 | |
| 4251 | // The register ip1 is required to be used for the hidden argument in |
| 4252 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
| 4253 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4254 | UseScratchRegisterScope scratch_scope(masm); |
| 4255 | scratch_scope.Exclude(ip1); |
| 4256 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4257 | |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4258 | __ Ldr(temp, |
| 4259 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4260 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4261 | invoke->GetImtIndex(), kArm64PointerSize)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4262 | // temp = temp->GetImtEntryAt(method_offset); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4263 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4264 | // lr = temp->GetEntryPoint(); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4265 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4266 | |
| 4267 | { |
| 4268 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4269 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4270 | |
| 4271 | // lr(); |
| 4272 | __ blr(lr); |
| 4273 | DCHECK(!codegen_->IsLeafMethod()); |
| 4274 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4275 | } |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4276 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4277 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4281 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4282 | if (intrinsic.TryDispatch(invoke)) { |
| 4283 | return; |
| 4284 | } |
| 4285 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4286 | HandleInvoke(invoke); |
| 4287 | } |
| 4288 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4289 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4290 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4291 | // art::PrepareForRegisterAllocation. |
| 4292 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4293 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4294 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4295 | if (intrinsic.TryDispatch(invoke)) { |
| 4296 | return; |
| 4297 | } |
| 4298 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4299 | HandleInvoke(invoke); |
| 4300 | } |
| 4301 | |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4302 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4303 | if (invoke->GetLocations()->Intrinsified()) { |
| 4304 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4305 | intrinsic.Dispatch(invoke); |
| 4306 | return true; |
| 4307 | } |
| 4308 | return false; |
| 4309 | } |
| 4310 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4311 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4312 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4313 | ArtMethod* method ATTRIBUTE_UNUSED) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4314 | // On ARM64 we support all dispatch types. |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4315 | return desired_dispatch_info; |
| 4316 | } |
| 4317 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4318 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4319 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4320 | // 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] | 4321 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4322 | switch (invoke->GetMethodLoadKind()) { |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4323 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4324 | uint32_t offset = |
| 4325 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4326 | // temp = thread->string_init_entrypoint |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4327 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4328 | break; |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4329 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4330 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4331 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4332 | break; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4333 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4334 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4335 | // Add ADRP with its PC-relative method patch. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4336 | vixl::aarch64::Label* adrp_label = NewBootImageMethodPatch(invoke->GetTargetMethod()); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4337 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4338 | // Add ADD with its PC-relative method patch. |
| 4339 | vixl::aarch64::Label* add_label = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4340 | NewBootImageMethodPatch(invoke->GetTargetMethod(), adrp_label); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4341 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4342 | break; |
| 4343 | } |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4344 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4345 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4346 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4347 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_offset); |
| 4348 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4349 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| 4350 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| 4351 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 4352 | EmitLdrOffsetPlaceholder(ldr_label, WRegisterFrom(temp), XRegisterFrom(temp)); |
| 4353 | break; |
| 4354 | } |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4355 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4356 | // Add ADRP with its PC-relative .bss entry patch. |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4357 | MethodReference target_method(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4358 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(target_method); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4359 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4360 | // Add LDR with its PC-relative .bss entry patch. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4361 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4362 | NewMethodBssEntryPatch(target_method, adrp_label); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 4363 | // All aligned loads are implicitly atomic consume operations on ARM64. |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4364 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4365 | break; |
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4366 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4367 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 4368 | // Load method address from literal pool. |
| 4369 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
| 4370 | break; |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4371 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4372 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4373 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4374 | } |
| 4375 | } |
| 4376 | |
| 4377 | switch (invoke->GetCodePtrLocation()) { |
| 4378 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4379 | { |
| 4380 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4381 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4382 | kInstructionSize, |
| 4383 | CodeBufferCheckScope::kExactSize); |
| 4384 | __ bl(&frame_entry_label_); |
| 4385 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4386 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4387 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4388 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4389 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4390 | __ Ldr(lr, MemOperand( |
| Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4391 | XRegisterFrom(callee_method), |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4392 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4393 | { |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4394 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4395 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4396 | kInstructionSize, |
| 4397 | CodeBufferCheckScope::kExactSize); |
| 4398 | // lr() |
| 4399 | __ blr(lr); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4400 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4401 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4402 | break; |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4403 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4404 | |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4405 | DCHECK(!IsLeafMethod()); |
| 4406 | } |
| 4407 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4408 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4409 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4410 | // Use the calling convention instead of the location of the receiver, as |
| 4411 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4412 | // slow path, the arguments have been moved to the right place, so here we are |
| 4413 | // guaranteed that the receiver is the first register of the calling convention. |
| 4414 | InvokeDexCallingConvention calling_convention; |
| 4415 | Register receiver = calling_convention.GetRegisterAt(0); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4416 | Register temp = XRegisterFrom(temp_in); |
| 4417 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4418 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4419 | Offset class_offset = mirror::Object::ClassOffset(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4420 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4421 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4422 | DCHECK(receiver.IsRegister()); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4423 | |
| 4424 | { |
| 4425 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4426 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4427 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4428 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4429 | MaybeRecordImplicitNullCheck(invoke); |
| 4430 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4431 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4432 | // emit a read barrier for the previous class reference load. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4433 | // intermediate/temporary reference and because the current |
| 4434 | // concurrent copying collector keeps the from-space memory |
| 4435 | // intact/accessible until the end of the marking phase (the |
| 4436 | // concurrent copying collector may not in the future). |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4437 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4438 | |
| 4439 | // If we're compiling baseline, update the inline cache. |
| 4440 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4441 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4442 | // temp = temp->GetMethodAt(method_offset); |
| 4443 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4444 | // lr = temp->GetEntryPoint(); |
| 4445 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4446 | { |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4447 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4448 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4449 | // lr(); |
| 4450 | __ blr(lr); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4451 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4452 | } |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4453 | } |
| 4454 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4455 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4456 | HandleInvoke(invoke); |
| 4457 | } |
| 4458 | |
| 4459 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4460 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4461 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4464 | void LocationsBuilderARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4465 | HandleInvoke(invoke); |
| 4466 | } |
| 4467 | |
| 4468 | void InstructionCodeGeneratorARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4469 | codegen_->GenerateInvokeCustomCall(invoke); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4470 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4471 | } |
| 4472 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4473 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageIntrinsicPatch( |
| 4474 | uint32_t intrinsic_data, |
| 4475 | vixl::aarch64::Label* adrp_label) { |
| 4476 | return NewPcRelativePatch( |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4477 | /* dex_file= */ nullptr, intrinsic_data, adrp_label, &boot_image_other_patches_); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4478 | } |
| 4479 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4480 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageRelRoPatch( |
| 4481 | uint32_t boot_image_offset, |
| 4482 | vixl::aarch64::Label* adrp_label) { |
| 4483 | return NewPcRelativePatch( |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4484 | /* dex_file= */ nullptr, boot_image_offset, adrp_label, &boot_image_other_patches_); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4485 | } |
| 4486 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4487 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageMethodPatch( |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4488 | MethodReference target_method, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4489 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4490 | return NewPcRelativePatch( |
| 4491 | 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] | 4492 | } |
| 4493 | |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4494 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4495 | MethodReference target_method, |
| 4496 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4497 | return NewPcRelativePatch( |
| 4498 | 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] | 4499 | } |
| 4500 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4501 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageTypePatch( |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4502 | const DexFile& dex_file, |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4503 | dex::TypeIndex type_index, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4504 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4505 | 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] | 4506 | } |
| 4507 | |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4508 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4509 | const DexFile& dex_file, |
| 4510 | dex::TypeIndex type_index, |
| 4511 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4512 | 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] | 4513 | } |
| 4514 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4515 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageStringPatch( |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4516 | const DexFile& dex_file, |
| 4517 | dex::StringIndex string_index, |
| 4518 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4519 | return NewPcRelativePatch( |
| 4520 | &dex_file, string_index.index_, adrp_label, &boot_image_string_patches_); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4521 | } |
| 4522 | |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4523 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4524 | const DexFile& dex_file, |
| 4525 | dex::StringIndex string_index, |
| 4526 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4527 | 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] | 4528 | } |
| 4529 | |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4530 | void CodeGeneratorARM64::EmitEntrypointThunkCall(ThreadOffset64 entrypoint_offset) { |
| 4531 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
| Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 4532 | DCHECK(!UseJitCompilation()); |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4533 | call_entrypoint_patches_.emplace_back(/*dex_file*/ nullptr, entrypoint_offset.Uint32Value()); |
| 4534 | vixl::aarch64::Label* bl_label = &call_entrypoint_patches_.back().label; |
| 4535 | __ bind(bl_label); |
| 4536 | __ bl(static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 4537 | } |
| 4538 | |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 4539 | void CodeGeneratorARM64::EmitBakerReadBarrierCbnz(uint32_t custom_data) { |
| Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 4540 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
| Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 4541 | if (UseJitCompilation()) { |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 4542 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 4543 | vixl::aarch64::Label* slow_path_entry = &it->second.label; |
| 4544 | __ cbnz(mr, slow_path_entry); |
| 4545 | } else { |
| 4546 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4547 | vixl::aarch64::Label* cbnz_label = &baker_read_barrier_patches_.back().label; |
| 4548 | __ bind(cbnz_label); |
| 4549 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 4550 | } |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4551 | } |
| 4552 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4553 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4554 | const DexFile* dex_file, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4555 | uint32_t offset_or_index, |
| 4556 | vixl::aarch64::Label* adrp_label, |
| 4557 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4558 | // Add a patch entry and return the label. |
| 4559 | patches->emplace_back(dex_file, offset_or_index); |
| 4560 | PcRelativePatchInfo* info = &patches->back(); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4561 | vixl::aarch64::Label* label = &info->label; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4562 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4563 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4564 | return label; |
| 4565 | } |
| 4566 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4567 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4568 | uint64_t address) { |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4569 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4570 | } |
| 4571 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4572 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4573 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4574 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4575 | return jit_string_patches_.GetOrCreate( |
| 4576 | StringReference(&dex_file, string_index), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4577 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4578 | } |
| 4579 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4580 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4581 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4582 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4583 | return jit_class_patches_.GetOrCreate( |
| 4584 | TypeReference(&dex_file, type_index), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4585 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4586 | } |
| 4587 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4588 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4589 | vixl::aarch64::Register reg) { |
| 4590 | DCHECK(reg.IsX()); |
| 4591 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4592 | __ Bind(fixup_label); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4593 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4594 | } |
| 4595 | |
| 4596 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4597 | vixl::aarch64::Register out, |
| 4598 | vixl::aarch64::Register base) { |
| 4599 | DCHECK(out.IsX()); |
| 4600 | DCHECK(base.IsX()); |
| 4601 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4602 | __ Bind(fixup_label); |
| 4603 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4604 | } |
| 4605 | |
| 4606 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4607 | vixl::aarch64::Register out, |
| 4608 | vixl::aarch64::Register base) { |
| 4609 | DCHECK(base.IsX()); |
| 4610 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4611 | __ Bind(fixup_label); |
| 4612 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4613 | } |
| 4614 | |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4615 | void CodeGeneratorARM64::LoadBootImageAddress(vixl::aarch64::Register reg, |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4616 | uint32_t boot_image_reference) { |
| 4617 | if (GetCompilerOptions().IsBootImage()) { |
| 4618 | // Add ADRP with its PC-relative type patch. |
| 4619 | vixl::aarch64::Label* adrp_label = NewBootImageIntrinsicPatch(boot_image_reference); |
| 4620 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4621 | // Add ADD with its PC-relative type patch. |
| 4622 | vixl::aarch64::Label* add_label = NewBootImageIntrinsicPatch(boot_image_reference, adrp_label); |
| 4623 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
| Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 4624 | } else if (GetCompilerOptions().GetCompilePic()) { |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4625 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4626 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_reference); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4627 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4628 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4629 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_reference, adrp_label); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4630 | EmitLdrOffsetPlaceholder(ldr_label, reg.W(), reg.X()); |
| 4631 | } else { |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4632 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4633 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 4634 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4635 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4636 | __ Ldr(reg.W(), DeduplicateBootImageAddressLiteral(reinterpret_cast<uintptr_t>(address))); |
| 4637 | } |
| 4638 | } |
| 4639 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4640 | void CodeGeneratorARM64::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 4641 | uint32_t boot_image_offset) { |
| 4642 | DCHECK(invoke->IsStatic()); |
| 4643 | InvokeRuntimeCallingConvention calling_convention; |
| 4644 | Register argument = calling_convention.GetRegisterAt(0); |
| 4645 | if (GetCompilerOptions().IsBootImage()) { |
| 4646 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 4647 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 4648 | MethodReference target_method = invoke->GetTargetMethod(); |
| 4649 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 4650 | // Add ADRP with its PC-relative type patch. |
| 4651 | vixl::aarch64::Label* adrp_label = NewBootImageTypePatch(*target_method.dex_file, type_idx); |
| 4652 | EmitAdrpPlaceholder(adrp_label, argument.X()); |
| 4653 | // Add ADD with its PC-relative type patch. |
| 4654 | vixl::aarch64::Label* add_label = |
| 4655 | NewBootImageTypePatch(*target_method.dex_file, type_idx, adrp_label); |
| 4656 | EmitAddPlaceholder(add_label, argument.X(), argument.X()); |
| 4657 | } else { |
| 4658 | LoadBootImageAddress(argument, boot_image_offset); |
| 4659 | } |
| 4660 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 4661 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4662 | } |
| 4663 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4664 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4665 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4666 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4667 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4668 | for (const PcRelativePatchInfo& info : infos) { |
| 4669 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4670 | info.target_dex_file, |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4671 | info.pc_insn_label->GetLocation(), |
| 4672 | info.offset_or_index)); |
| 4673 | } |
| 4674 | } |
| 4675 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4676 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 4677 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 4678 | const DexFile* target_dex_file, |
| 4679 | uint32_t pc_insn_offset, |
| 4680 | uint32_t boot_image_offset) { |
| 4681 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 4682 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4683 | } |
| 4684 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4685 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4686 | DCHECK(linker_patches->empty()); |
| 4687 | size_t size = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4688 | boot_image_method_patches_.size() + |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4689 | method_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4690 | boot_image_type_patches_.size() + |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4691 | type_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4692 | boot_image_string_patches_.size() + |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4693 | string_bss_entry_patches_.size() + |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4694 | boot_image_other_patches_.size() + |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4695 | call_entrypoint_patches_.size() + |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4696 | baker_read_barrier_patches_.size(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4697 | linker_patches->reserve(size); |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4698 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4699 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4700 | boot_image_method_patches_, linker_patches); |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4701 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4702 | boot_image_type_patches_, linker_patches); |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4703 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4704 | boot_image_string_patches_, linker_patches); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4705 | } else { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4706 | DCHECK(boot_image_method_patches_.empty()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4707 | DCHECK(boot_image_type_patches_.empty()); |
| 4708 | DCHECK(boot_image_string_patches_.empty()); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4709 | } |
| 4710 | if (GetCompilerOptions().IsBootImage()) { |
| 4711 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 4712 | boot_image_other_patches_, linker_patches); |
| 4713 | } else { |
| 4714 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 4715 | boot_image_other_patches_, linker_patches); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4716 | } |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4717 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4718 | method_bss_entry_patches_, linker_patches); |
| 4719 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4720 | type_bss_entry_patches_, linker_patches); |
| 4721 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4722 | string_bss_entry_patches_, linker_patches); |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4723 | for (const PatchInfo<vixl::aarch64::Label>& info : call_entrypoint_patches_) { |
| 4724 | DCHECK(info.target_dex_file == nullptr); |
| 4725 | linker_patches->push_back(linker::LinkerPatch::CallEntrypointPatch( |
| 4726 | info.label.GetLocation(), info.offset_or_index)); |
| 4727 | } |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4728 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4729 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 4730 | info.label.GetLocation(), info.custom_data)); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4731 | } |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4732 | DCHECK_EQ(size, linker_patches->size()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4733 | } |
| 4734 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4735 | bool CodeGeneratorARM64::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4736 | return patch.GetType() == linker::LinkerPatch::Type::kCallEntrypoint || |
| 4737 | patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4738 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 4739 | } |
| 4740 | |
| 4741 | void CodeGeneratorARM64::EmitThunkCode(const linker::LinkerPatch& patch, |
| 4742 | /*out*/ ArenaVector<uint8_t>* code, |
| 4743 | /*out*/ std::string* debug_name) { |
| 4744 | Arm64Assembler assembler(GetGraph()->GetAllocator()); |
| 4745 | switch (patch.GetType()) { |
| 4746 | case linker::LinkerPatch::Type::kCallRelative: { |
| 4747 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 4748 | // to the generic JNI and interpreter trampolines. |
| 4749 | Offset offset(ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4750 | kArm64PointerSize).Int32Value()); |
| 4751 | assembler.JumpTo(ManagedRegister(arm64::X0), offset, ManagedRegister(arm64::IP0)); |
| 4752 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 4753 | *debug_name = "MethodCallThunk"; |
| 4754 | } |
| 4755 | break; |
| 4756 | } |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4757 | case linker::LinkerPatch::Type::kCallEntrypoint: { |
| 4758 | Offset offset(patch.EntrypointOffset()); |
| 4759 | assembler.JumpTo(ManagedRegister(arm64::TR), offset, ManagedRegister(arm64::IP0)); |
| 4760 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 4761 | *debug_name = "EntrypointCallThunk_" + std::to_string(offset.Uint32Value()); |
| 4762 | } |
| 4763 | break; |
| 4764 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4765 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| 4766 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 4767 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 4768 | break; |
| 4769 | } |
| 4770 | default: |
| 4771 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 4772 | UNREACHABLE(); |
| 4773 | } |
| 4774 | |
| 4775 | // Ensure we emit the literal pool if any. |
| 4776 | assembler.FinalizeCode(); |
| 4777 | code->resize(assembler.CodeSize()); |
| 4778 | MemoryRegion code_region(code->data(), code->size()); |
| 4779 | assembler.FinalizeInstructions(code_region); |
| 4780 | } |
| 4781 | |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4782 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4783 | return uint32_literals_.GetOrCreate( |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4784 | value, |
| 4785 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4786 | } |
| 4787 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4788 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4789 | return uint64_literals_.GetOrCreate( |
| 4790 | value, |
| 4791 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4792 | } |
| 4793 | |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4794 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4795 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4796 | // art::PrepareForRegisterAllocation. |
| 4797 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4798 | |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4799 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4800 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4801 | return; |
| 4802 | } |
| 4803 | |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4804 | { |
| 4805 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4806 | // are no pools emitted. |
| 4807 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4808 | LocationSummary* locations = invoke->GetLocations(); |
| 4809 | codegen_->GenerateStaticOrDirectCall( |
| 4810 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| 4811 | } |
| 4812 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4813 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4814 | } |
| 4815 | |
| 4816 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4817 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4818 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4819 | return; |
| 4820 | } |
| 4821 | |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4822 | { |
| 4823 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4824 | // are no pools emitted. |
| 4825 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4826 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 4827 | DCHECK(!codegen_->IsLeafMethod()); |
| 4828 | } |
| 4829 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4830 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4831 | } |
| 4832 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4833 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4834 | HLoadClass::LoadKind desired_class_load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4835 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4836 | case HLoadClass::LoadKind::kInvalid: |
| 4837 | LOG(FATAL) << "UNREACHABLE"; |
| 4838 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4839 | case HLoadClass::LoadKind::kReferrersClass: |
| 4840 | break; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4841 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4842 | case HLoadClass::LoadKind::kBootImageRelRo: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4843 | case HLoadClass::LoadKind::kBssEntry: |
| 4844 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4845 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4846 | case HLoadClass::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4847 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4848 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4849 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4850 | case HLoadClass::LoadKind::kRuntimeCall: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4851 | break; |
| 4852 | } |
| 4853 | return desired_class_load_kind; |
| 4854 | } |
| 4855 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4856 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4857 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4858 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4859 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4860 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4861 | cls, |
| 4862 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4863 | LocationFrom(vixl::aarch64::x0)); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4864 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4865 | return; |
| 4866 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4867 | DCHECK(!cls->NeedsAccessCheck()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4868 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4869 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4870 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4871 | ? LocationSummary::kCallOnSlowPath |
| 4872 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4873 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4874 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4875 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4876 | } |
| 4877 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4878 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4879 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4880 | } |
| 4881 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4882 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 4883 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4884 | // 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] | 4885 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4886 | } else { |
| 4887 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4888 | } |
| 4889 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4890 | } |
| 4891 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4892 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4893 | // move. |
| 4894 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4895 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4896 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4897 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4898 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4899 | return; |
| 4900 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4901 | DCHECK(!cls->NeedsAccessCheck()); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4902 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4903 | Location out_loc = cls->GetLocations()->Out(); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4904 | Register out = OutputRegister(cls); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4905 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4906 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4907 | ? kWithoutReadBarrier |
| 4908 | : kCompilerReadBarrierOption; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4909 | bool generate_null_check = false; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4910 | switch (load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4911 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4912 | DCHECK(!cls->CanCallRuntime()); |
| 4913 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4914 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4915 | Register current_method = InputRegisterAt(cls, 0); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4916 | codegen_->GenerateGcRootFieldLoad(cls, |
| 4917 | out_loc, |
| 4918 | current_method, |
| 4919 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4920 | /* fixup_label= */ nullptr, |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4921 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4922 | break; |
| 4923 | } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4924 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4925 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 4926 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4927 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4928 | // Add ADRP with its PC-relative type patch. |
| 4929 | const DexFile& dex_file = cls->GetDexFile(); |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4930 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4931 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageTypePatch(dex_file, type_index); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4932 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4933 | // Add ADD with its PC-relative type patch. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4934 | vixl::aarch64::Label* add_label = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4935 | codegen_->NewBootImageTypePatch(dex_file, type_index, adrp_label); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4936 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4937 | break; |
| 4938 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4939 | case HLoadClass::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4940 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4941 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls); |
| 4942 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 4943 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4944 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4945 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4946 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4947 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4948 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4949 | break; |
| 4950 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4951 | case HLoadClass::LoadKind::kBssEntry: { |
| 4952 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 4953 | const DexFile& dex_file = cls->GetDexFile(); |
| 4954 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 4955 | vixl::aarch64::Register temp = XRegisterFrom(out_loc); |
| 4956 | vixl::aarch64::Label* adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 4957 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4958 | // Add LDR with its PC-relative Class .bss entry patch. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4959 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 4960 | codegen_->NewBssEntryTypePatch(dex_file, type_index, adrp_label); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4961 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 4962 | // All aligned loads are implicitly atomic consume operations on ARM64. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4963 | codegen_->GenerateGcRootFieldLoad(cls, |
| 4964 | out_loc, |
| 4965 | temp, |
| 4966 | /* offset placeholder */ 0u, |
| 4967 | ldr_label, |
| 4968 | read_barrier_option); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4969 | generate_null_check = true; |
| 4970 | break; |
| 4971 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4972 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 4973 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 4974 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 4975 | DCHECK_NE(address, 0u); |
| 4976 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 4977 | break; |
| 4978 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4979 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 4980 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 4981 | cls->GetTypeIndex(), |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4982 | cls->GetClass())); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4983 | codegen_->GenerateGcRootFieldLoad(cls, |
| 4984 | out_loc, |
| 4985 | out.X(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4986 | /* offset= */ 0, |
| 4987 | /* fixup_label= */ nullptr, |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4988 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4989 | break; |
| 4990 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4991 | case HLoadClass::LoadKind::kRuntimeCall: |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4992 | case HLoadClass::LoadKind::kInvalid: |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4993 | LOG(FATAL) << "UNREACHABLE"; |
| 4994 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4995 | } |
| 4996 | |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4997 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 4998 | if (generate_null_check || do_clinit) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4999 | DCHECK(cls->CanCallRuntime()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 5000 | SlowPathCodeARM64* slow_path = |
| 5001 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(cls, cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5002 | codegen_->AddSlowPath(slow_path); |
| 5003 | if (generate_null_check) { |
| 5004 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5005 | } |
| 5006 | if (cls->MustGenerateClinitCheck()) { |
| 5007 | GenerateClassInitializationCheck(slow_path, out); |
| 5008 | } else { |
| 5009 | __ Bind(slow_path->GetExitLabel()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5010 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5011 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5012 | } |
| 5013 | } |
| 5014 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 5015 | void LocationsBuilderARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5016 | InvokeRuntimeCallingConvention calling_convention; |
| 5017 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5018 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 5019 | } |
| 5020 | |
| 5021 | void InstructionCodeGeneratorARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5022 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 5023 | } |
| 5024 | |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 5025 | void LocationsBuilderARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5026 | InvokeRuntimeCallingConvention calling_convention; |
| 5027 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5028 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 5029 | } |
| 5030 | |
| 5031 | void InstructionCodeGeneratorARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5032 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 5033 | } |
| 5034 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5035 | static MemOperand GetExceptionTlsAddress() { |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5036 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5037 | } |
| 5038 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5039 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5040 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5041 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5042 | locations->SetOut(Location::RequiresRegister()); |
| 5043 | } |
| 5044 | |
| 5045 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5046 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5047 | } |
| 5048 | |
| 5049 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5050 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5054 | __ Str(wzr, GetExceptionTlsAddress()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5055 | } |
| 5056 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5057 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5058 | HLoadString::LoadKind desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5059 | switch (desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5060 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5061 | case HLoadString::LoadKind::kBootImageRelRo: |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5062 | case HLoadString::LoadKind::kBssEntry: |
| Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5063 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5064 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5065 | case HLoadString::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5066 | case HLoadString::LoadKind::kJitTableAddress: |
| 5067 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5068 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5069 | case HLoadString::LoadKind::kRuntimeCall: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5070 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5071 | } |
| 5072 | return desired_string_load_kind; |
| 5073 | } |
| 5074 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5075 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5076 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5077 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5078 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
| Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5079 | InvokeRuntimeCallingConvention calling_convention; |
| 5080 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5081 | } else { |
| 5082 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5083 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5084 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5085 | // Rely on the pResolveString and marking to save everything we need. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 5086 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5087 | } else { |
| 5088 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5089 | } |
| 5090 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5091 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5092 | } |
| 5093 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5094 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5095 | // move. |
| 5096 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5097 | Register out = OutputRegister(load); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5098 | Location out_loc = load->GetLocations()->Out(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5099 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5100 | switch (load->GetLoadKind()) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5101 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5102 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 5103 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5104 | // Add ADRP with its PC-relative String patch. |
| 5105 | const DexFile& dex_file = load->GetDexFile(); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5106 | const dex::StringIndex string_index = load->GetStringIndex(); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5107 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageStringPatch(dex_file, string_index); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5108 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5109 | // Add ADD with its PC-relative String patch. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5110 | vixl::aarch64::Label* add_label = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5111 | codegen_->NewBootImageStringPatch(dex_file, string_index, adrp_label); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5112 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5113 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5114 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5115 | case HLoadString::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5116 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5117 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5118 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(load); |
| 5119 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5120 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5121 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5122 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5123 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5124 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 5125 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5126 | } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5127 | case HLoadString::LoadKind::kBssEntry: { |
| 5128 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5129 | const DexFile& dex_file = load->GetDexFile(); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5130 | const dex::StringIndex string_index = load->GetStringIndex(); |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5131 | Register temp = XRegisterFrom(out_loc); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5132 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5133 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5134 | // Add LDR with its PC-relative String .bss entry patch. |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5135 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5136 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5137 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5138 | // All aligned loads are implicitly atomic consume operations on ARM64. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5139 | codegen_->GenerateGcRootFieldLoad(load, |
| 5140 | out_loc, |
| 5141 | temp, |
| 5142 | /* offset placeholder */ 0u, |
| 5143 | ldr_label, |
| 5144 | kCompilerReadBarrierOption); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5145 | SlowPathCodeARM64* slow_path = |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5146 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5147 | codegen_->AddSlowPath(slow_path); |
| 5148 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5149 | __ Bind(slow_path->GetExitLabel()); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5150 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5151 | return; |
| 5152 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5153 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 5154 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 5155 | DCHECK_NE(address, 0u); |
| 5156 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5157 | return; |
| 5158 | } |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5159 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5160 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5161 | load->GetStringIndex(), |
| 5162 | load->GetString())); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5163 | codegen_->GenerateGcRootFieldLoad(load, |
| 5164 | out_loc, |
| 5165 | out.X(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5166 | /* offset= */ 0, |
| 5167 | /* fixup_label= */ nullptr, |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5168 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5169 | return; |
| 5170 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5171 | default: |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5172 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5173 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5174 | |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5175 | // 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] | 5176 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5177 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5178 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
| Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5179 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5180 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5181 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5182 | } |
| 5183 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5184 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5185 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5186 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5187 | } |
| 5188 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5189 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5190 | // Will be generated at use site. |
| 5191 | } |
| 5192 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5193 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5194 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5195 | instruction, LocationSummary::kCallOnMainOnly); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5196 | InvokeRuntimeCallingConvention calling_convention; |
| 5197 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5198 | } |
| 5199 | |
| 5200 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5201 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5202 | instruction, |
| 5203 | instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5204 | if (instruction->IsEnter()) { |
| 5205 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5206 | } else { |
| 5207 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5208 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5209 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5210 | } |
| 5211 | |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5212 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5213 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5214 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5215 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5216 | case DataType::Type::kInt32: |
| 5217 | case DataType::Type::kInt64: |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5218 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5219 | locations->SetInAt(1, Location::RequiresRegister()); |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5220 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5221 | break; |
| 5222 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5223 | case DataType::Type::kFloat32: |
| 5224 | case DataType::Type::kFloat64: |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5225 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5226 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5227 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5228 | break; |
| 5229 | |
| 5230 | default: |
| 5231 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5232 | } |
| 5233 | } |
| 5234 | |
| 5235 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5236 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5237 | case DataType::Type::kInt32: |
| 5238 | case DataType::Type::kInt64: |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5239 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5240 | break; |
| 5241 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5242 | case DataType::Type::kFloat32: |
| 5243 | case DataType::Type::kFloat64: |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5244 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5245 | break; |
| 5246 | |
| 5247 | default: |
| 5248 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5249 | } |
| 5250 | } |
| 5251 | |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5252 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5253 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5254 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5255 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5256 | case DataType::Type::kInt32: |
| 5257 | case DataType::Type::kInt64: |
| Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5258 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5259 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5260 | break; |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5261 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5262 | case DataType::Type::kFloat32: |
| 5263 | case DataType::Type::kFloat64: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5264 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5265 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5266 | break; |
| 5267 | |
| 5268 | default: |
| 5269 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5270 | } |
| 5271 | } |
| 5272 | |
| 5273 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5274 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5275 | case DataType::Type::kInt32: |
| 5276 | case DataType::Type::kInt64: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5277 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5278 | break; |
| 5279 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5280 | case DataType::Type::kFloat32: |
| 5281 | case DataType::Type::kFloat64: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5282 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5283 | break; |
| 5284 | |
| 5285 | default: |
| 5286 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5287 | } |
| 5288 | } |
| 5289 | |
| 5290 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5291 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5292 | instruction, LocationSummary::kCallOnMainOnly); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5293 | InvokeRuntimeCallingConvention calling_convention; |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5294 | locations->SetOut(LocationFrom(x0)); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5295 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5296 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5297 | } |
| 5298 | |
| 5299 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5300 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5301 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
| Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5302 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5303 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5304 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5305 | } |
| 5306 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5307 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5308 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5309 | instruction, LocationSummary::kCallOnMainOnly); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5310 | InvokeRuntimeCallingConvention calling_convention; |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5311 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5312 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5316 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5317 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5318 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5322 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5323 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5324 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5328 | switch (instruction->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5329 | case DataType::Type::kInt32: |
| 5330 | case DataType::Type::kInt64: |
| Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5331 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5332 | break; |
| 5333 | |
| 5334 | default: |
| 5335 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5336 | } |
| 5337 | } |
| 5338 | |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5339 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5340 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5341 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5342 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5343 | } |
| 5344 | |
| 5345 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5346 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5347 | } |
| 5348 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5349 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5350 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5351 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5352 | } |
| 5353 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5354 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5355 | if (CanMoveNullCheckToUser(instruction)) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5356 | return; |
| 5357 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5358 | { |
| Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 5359 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5360 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5361 | Location obj = instruction->GetLocations()->InAt(0); |
| 5362 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5363 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5364 | } |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5365 | } |
| 5366 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5367 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5368 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5369 | AddSlowPath(slow_path); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5370 | |
| 5371 | LocationSummary* locations = instruction->GetLocations(); |
| 5372 | Location obj = locations->InAt(0); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5373 | |
| 5374 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5375 | } |
| 5376 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5377 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5378 | codegen_->GenerateNullCheck(instruction); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5379 | } |
| 5380 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5381 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5382 | HandleBinaryOp(instruction); |
| 5383 | } |
| 5384 | |
| 5385 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5386 | HandleBinaryOp(instruction); |
| 5387 | } |
| 5388 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5389 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5390 | LOG(FATAL) << "Unreachable"; |
| 5391 | } |
| 5392 | |
| 5393 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5394 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5395 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5396 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5397 | // The back edge will generate the suspend check. |
| 5398 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5399 | } |
| 5400 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5401 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5402 | } |
| 5403 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5404 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5405 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5406 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5407 | if (location.IsStackSlot()) { |
| 5408 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5409 | } else if (location.IsDoubleStackSlot()) { |
| 5410 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5411 | } |
| 5412 | locations->SetOut(location); |
| 5413 | } |
| 5414 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5415 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5416 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5417 | // Nothing to do, the parameter is already at its location. |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5418 | } |
| 5419 | |
| 5420 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5421 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5422 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5423 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5424 | } |
| 5425 | |
| 5426 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5427 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5428 | // Nothing to do, the method is already at its location. |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5432 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5433 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5434 | locations->SetInAt(i, Location::Any()); |
| 5435 | } |
| 5436 | locations->SetOut(Location::Any()); |
| 5437 | } |
| 5438 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5439 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5440 | LOG(FATAL) << "Unreachable"; |
| 5441 | } |
| 5442 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5443 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5444 | DataType::Type type = rem->GetResultType(); |
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5445 | LocationSummary::CallKind call_kind = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5446 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5447 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5448 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5449 | |
| 5450 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5451 | case DataType::Type::kInt32: |
| 5452 | case DataType::Type::kInt64: |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5453 | locations->SetInAt(0, Location::RequiresRegister()); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5454 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5455 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5456 | break; |
| 5457 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5458 | case DataType::Type::kFloat32: |
| 5459 | case DataType::Type::kFloat64: { |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5460 | InvokeRuntimeCallingConvention calling_convention; |
| 5461 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5462 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5463 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5464 | |
| 5465 | break; |
| 5466 | } |
| 5467 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5468 | default: |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5469 | LOG(FATAL) << "Unexpected rem type " << type; |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5470 | } |
| 5471 | } |
| 5472 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5473 | void InstructionCodeGeneratorARM64::GenerateIntRemForPower2Denom(HRem *instruction) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5474 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5475 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 5476 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 5477 | |
| 5478 | Register out = OutputRegister(instruction); |
| 5479 | Register dividend = InputRegisterAt(instruction, 0); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5480 | |
| Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5481 | if (abs_imm == 2) { |
| 5482 | __ Cmp(dividend, 0); |
| 5483 | __ And(out, dividend, 1); |
| 5484 | __ Csneg(out, out, out, ge); |
| 5485 | } else { |
| 5486 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5487 | Register temp = temps.AcquireSameSizeAs(out); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5488 | |
| Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5489 | __ Negs(temp, dividend); |
| 5490 | __ And(out, dividend, abs_imm - 1); |
| 5491 | __ And(temp, temp, abs_imm - 1); |
| 5492 | __ Csneg(out, out, temp, mi); |
| 5493 | } |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5494 | } |
| 5495 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5496 | void InstructionCodeGeneratorARM64::GenerateIntRemForConstDenom(HRem *instruction) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5497 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5498 | |
| 5499 | if (imm == 0) { |
| 5500 | // Do not generate anything. |
| 5501 | // DivZeroCheck would prevent any code to be executed. |
| 5502 | return; |
| 5503 | } |
| 5504 | |
| Evgeny Astigeevich | f58dc65 | 2018-06-25 17:54:07 +0100 | [diff] [blame] | 5505 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 5506 | // Cases imm == -1 or imm == 1 are handled in constant folding by |
| 5507 | // InstructionWithAbsorbingInputSimplifier. |
| 5508 | // If the cases have survided till code generation they are handled in |
| 5509 | // GenerateIntRemForPower2Denom becauses -1 and 1 are the power of 2 (2^0). |
| 5510 | // The correct code is generated for them, just more instructions. |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5511 | GenerateIntRemForPower2Denom(instruction); |
| 5512 | } else { |
| 5513 | DCHECK(imm < -2 || imm > 2) << imm; |
| 5514 | GenerateDivRemWithAnyConstant(instruction); |
| 5515 | } |
| 5516 | } |
| 5517 | |
| 5518 | void InstructionCodeGeneratorARM64::GenerateIntRem(HRem* instruction) { |
| 5519 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 5520 | << instruction->GetResultType(); |
| 5521 | |
| 5522 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 5523 | GenerateIntRemForConstDenom(instruction); |
| 5524 | } else { |
| 5525 | Register out = OutputRegister(instruction); |
| 5526 | Register dividend = InputRegisterAt(instruction, 0); |
| 5527 | Register divisor = InputRegisterAt(instruction, 1); |
| 5528 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5529 | Register temp = temps.AcquireSameSizeAs(out); |
| 5530 | __ Sdiv(temp, dividend, divisor); |
| 5531 | __ Msub(out, temp, divisor, dividend); |
| 5532 | } |
| 5533 | } |
| 5534 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5535 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5536 | DataType::Type type = rem->GetResultType(); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5537 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5538 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5539 | case DataType::Type::kInt32: |
| 5540 | case DataType::Type::kInt64: { |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5541 | GenerateIntRem(rem); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5542 | break; |
| 5543 | } |
| 5544 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5545 | case DataType::Type::kFloat32: |
| 5546 | case DataType::Type::kFloat64: { |
| 5547 | QuickEntrypointEnum entrypoint = |
| 5548 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5549 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5550 | if (type == DataType::Type::kFloat32) { |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5551 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5552 | } else { |
| 5553 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5554 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5555 | break; |
| 5556 | } |
| 5557 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5558 | default: |
| 5559 | LOG(FATAL) << "Unexpected rem type " << type; |
| Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5560 | UNREACHABLE(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5561 | } |
| 5562 | } |
| 5563 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5564 | void LocationsBuilderARM64::VisitMin(HMin* min) { |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5565 | HandleBinaryOp(min); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5566 | } |
| 5567 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5568 | void InstructionCodeGeneratorARM64::VisitMin(HMin* min) { |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5569 | HandleBinaryOp(min); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5570 | } |
| 5571 | |
| 5572 | void LocationsBuilderARM64::VisitMax(HMax* max) { |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5573 | HandleBinaryOp(max); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5574 | } |
| 5575 | |
| 5576 | void InstructionCodeGeneratorARM64::VisitMax(HMax* max) { |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5577 | HandleBinaryOp(max); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5578 | } |
| 5579 | |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5580 | void LocationsBuilderARM64::VisitAbs(HAbs* abs) { |
| 5581 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 5582 | switch (abs->GetResultType()) { |
| 5583 | case DataType::Type::kInt32: |
| 5584 | case DataType::Type::kInt64: |
| 5585 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5586 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5587 | break; |
| 5588 | case DataType::Type::kFloat32: |
| 5589 | case DataType::Type::kFloat64: |
| 5590 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5591 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5592 | break; |
| 5593 | default: |
| 5594 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5595 | } |
| 5596 | } |
| 5597 | |
| 5598 | void InstructionCodeGeneratorARM64::VisitAbs(HAbs* abs) { |
| 5599 | switch (abs->GetResultType()) { |
| 5600 | case DataType::Type::kInt32: |
| 5601 | case DataType::Type::kInt64: { |
| 5602 | Register in_reg = InputRegisterAt(abs, 0); |
| 5603 | Register out_reg = OutputRegister(abs); |
| 5604 | __ Cmp(in_reg, Operand(0)); |
| 5605 | __ Cneg(out_reg, in_reg, lt); |
| 5606 | break; |
| 5607 | } |
| 5608 | case DataType::Type::kFloat32: |
| 5609 | case DataType::Type::kFloat64: { |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 5610 | VRegister in_reg = InputFPRegisterAt(abs, 0); |
| 5611 | VRegister out_reg = OutputFPRegister(abs); |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5612 | __ Fabs(out_reg, in_reg); |
| 5613 | break; |
| 5614 | } |
| 5615 | default: |
| 5616 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5617 | } |
| 5618 | } |
| 5619 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5620 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5621 | constructor_fence->SetLocations(nullptr); |
| 5622 | } |
| 5623 | |
| 5624 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5625 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5626 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5627 | } |
| 5628 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5629 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5630 | memory_barrier->SetLocations(nullptr); |
| 5631 | } |
| 5632 | |
| 5633 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5634 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5635 | } |
| 5636 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5637 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5638 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5639 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5640 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5641 | } |
| 5642 | |
| Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 5643 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* ret) { |
| 5644 | if (GetGraph()->IsCompilingOsr()) { |
| 5645 | // To simplify callers of an OSR method, we put the return value in both |
| 5646 | // floating point and core register. |
| 5647 | switch (ret->InputAt(0)->GetType()) { |
| 5648 | case DataType::Type::kFloat32: |
| 5649 | __ Fmov(w0, s0); |
| 5650 | break; |
| 5651 | case DataType::Type::kFloat64: |
| 5652 | __ Fmov(x0, d0); |
| 5653 | break; |
| 5654 | default: |
| 5655 | break; |
| 5656 | } |
| 5657 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5658 | codegen_->GenerateFrameExit(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5662 | instruction->SetLocations(nullptr); |
| 5663 | } |
| 5664 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5665 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5666 | codegen_->GenerateFrameExit(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5667 | } |
| 5668 | |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5669 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5670 | HandleBinaryOp(ror); |
| 5671 | } |
| 5672 | |
| 5673 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5674 | HandleBinaryOp(ror); |
| 5675 | } |
| 5676 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5677 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5678 | HandleShift(shl); |
| 5679 | } |
| 5680 | |
| 5681 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5682 | HandleShift(shl); |
| 5683 | } |
| 5684 | |
| 5685 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5686 | HandleShift(shr); |
| 5687 | } |
| 5688 | |
| 5689 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5690 | HandleShift(shr); |
| 5691 | } |
| 5692 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5693 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5694 | HandleBinaryOp(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5695 | } |
| 5696 | |
| 5697 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5698 | HandleBinaryOp(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5699 | } |
| 5700 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5701 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5702 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5703 | } |
| 5704 | |
| 5705 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5706 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5707 | } |
| 5708 | |
| 5709 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5710 | HandleFieldSet(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5711 | } |
| 5712 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5713 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5714 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5715 | } |
| 5716 | |
| Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 5717 | void LocationsBuilderARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5718 | codegen_->CreateStringBuilderAppendLocations(instruction, LocationFrom(x0)); |
| 5719 | } |
| 5720 | |
| 5721 | void InstructionCodeGeneratorARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5722 | __ Mov(w0, instruction->GetFormat()->GetValue()); |
| 5723 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 5724 | } |
| 5725 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5726 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5727 | HUnresolvedInstanceFieldGet* instruction) { |
| 5728 | FieldAccessCallingConventionARM64 calling_convention; |
| 5729 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5730 | instruction, instruction->GetFieldType(), calling_convention); |
| 5731 | } |
| 5732 | |
| 5733 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5734 | HUnresolvedInstanceFieldGet* instruction) { |
| 5735 | FieldAccessCallingConventionARM64 calling_convention; |
| 5736 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5737 | instruction->GetFieldType(), |
| 5738 | instruction->GetFieldIndex(), |
| 5739 | instruction->GetDexPc(), |
| 5740 | calling_convention); |
| 5741 | } |
| 5742 | |
| 5743 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5744 | HUnresolvedInstanceFieldSet* instruction) { |
| 5745 | FieldAccessCallingConventionARM64 calling_convention; |
| 5746 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5747 | instruction, instruction->GetFieldType(), calling_convention); |
| 5748 | } |
| 5749 | |
| 5750 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5751 | HUnresolvedInstanceFieldSet* instruction) { |
| 5752 | FieldAccessCallingConventionARM64 calling_convention; |
| 5753 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5754 | instruction->GetFieldType(), |
| 5755 | instruction->GetFieldIndex(), |
| 5756 | instruction->GetDexPc(), |
| 5757 | calling_convention); |
| 5758 | } |
| 5759 | |
| 5760 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5761 | HUnresolvedStaticFieldGet* instruction) { |
| 5762 | FieldAccessCallingConventionARM64 calling_convention; |
| 5763 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5764 | instruction, instruction->GetFieldType(), calling_convention); |
| 5765 | } |
| 5766 | |
| 5767 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5768 | HUnresolvedStaticFieldGet* instruction) { |
| 5769 | FieldAccessCallingConventionARM64 calling_convention; |
| 5770 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5771 | instruction->GetFieldType(), |
| 5772 | instruction->GetFieldIndex(), |
| 5773 | instruction->GetDexPc(), |
| 5774 | calling_convention); |
| 5775 | } |
| 5776 | |
| 5777 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5778 | HUnresolvedStaticFieldSet* instruction) { |
| 5779 | FieldAccessCallingConventionARM64 calling_convention; |
| 5780 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5781 | instruction, instruction->GetFieldType(), calling_convention); |
| 5782 | } |
| 5783 | |
| 5784 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5785 | HUnresolvedStaticFieldSet* instruction) { |
| 5786 | FieldAccessCallingConventionARM64 calling_convention; |
| 5787 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5788 | instruction->GetFieldType(), |
| 5789 | instruction->GetFieldIndex(), |
| 5790 | instruction->GetDexPc(), |
| 5791 | calling_convention); |
| 5792 | } |
| 5793 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5794 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5795 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5796 | instruction, LocationSummary::kCallOnSlowPath); |
| Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5797 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5798 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5799 | // registers in full width (since the runtime only saves/restores lower part). |
| 5800 | locations->SetCustomSlowPathCallerSaves( |
| 5801 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5802 | } |
| 5803 | |
| 5804 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5805 | HBasicBlock* block = instruction->GetBlock(); |
| 5806 | if (block->GetLoopInformation() != nullptr) { |
| 5807 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5808 | // The back edge will generate the suspend check. |
| 5809 | return; |
| 5810 | } |
| 5811 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5812 | // The goto will generate the suspend check. |
| 5813 | return; |
| 5814 | } |
| 5815 | GenerateSuspendCheck(instruction, nullptr); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5816 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5817 | } |
| 5818 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5819 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5820 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5821 | instruction, LocationSummary::kCallOnMainOnly); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5822 | InvokeRuntimeCallingConvention calling_convention; |
| 5823 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5824 | } |
| 5825 | |
| 5826 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5827 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5828 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5829 | } |
| 5830 | |
| 5831 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5832 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5833 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5834 | DataType::Type input_type = conversion->GetInputType(); |
| 5835 | DataType::Type result_type = conversion->GetResultType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5836 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5837 | << input_type << " -> " << result_type; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5838 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 5839 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5840 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5841 | } |
| 5842 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5843 | if (DataType::IsFloatingPointType(input_type)) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5844 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5845 | } else { |
| 5846 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5847 | } |
| 5848 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5849 | if (DataType::IsFloatingPointType(result_type)) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5850 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5851 | } else { |
| 5852 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5853 | } |
| 5854 | } |
| 5855 | |
| 5856 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5857 | DataType::Type result_type = conversion->GetResultType(); |
| 5858 | DataType::Type input_type = conversion->GetInputType(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5859 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5860 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5861 | << input_type << " -> " << result_type; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5862 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5863 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 5864 | int result_size = DataType::Size(result_type); |
| 5865 | int input_size = DataType::Size(input_type); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5866 | int min_size = std::min(result_size, input_size); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5867 | Register output = OutputRegister(conversion); |
| 5868 | Register source = InputRegisterAt(conversion, 0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5869 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
| Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5870 | // 'int' values are used directly as W registers, discarding the top |
| 5871 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5872 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5873 | // top 32 bits of the target register. We theoretically could leave those |
| 5874 | // bits unchanged, but we would have to make sure that no code uses a |
| 5875 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5876 | // zero. |
| 5877 | __ Mov(output.W(), source.W()); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5878 | } else if (DataType::IsUnsignedType(result_type) || |
| 5879 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 5880 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5881 | } else { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5882 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5883 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5884 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5885 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5886 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 5887 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5888 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5889 | } else if (DataType::IsFloatingPointType(result_type) && |
| 5890 | DataType::IsFloatingPointType(input_type)) { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5891 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5892 | } else { |
| 5893 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5894 | << " to " << result_type; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5895 | } |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5896 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5897 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5898 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5899 | HandleShift(ushr); |
| 5900 | } |
| 5901 | |
| 5902 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5903 | HandleShift(ushr); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5904 | } |
| 5905 | |
| 5906 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5907 | HandleBinaryOp(instruction); |
| 5908 | } |
| 5909 | |
| 5910 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5911 | HandleBinaryOp(instruction); |
| 5912 | } |
| 5913 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5914 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5915 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5916 | LOG(FATAL) << "Unreachable"; |
| 5917 | } |
| 5918 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5919 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5920 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5921 | LOG(FATAL) << "Unreachable"; |
| 5922 | } |
| 5923 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5924 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5925 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5926 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5927 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5928 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5929 | } |
| 5930 | |
| 5931 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5932 | int32_t lower_bound = switch_instr->GetStartValue(); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5933 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5934 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5935 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5936 | |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5937 | // 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] | 5938 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5939 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5940 | // make sure we don't emit it if the target may run out of range. |
| 5941 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5942 | // ranges and emit the tables only as required. |
| 5943 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5944 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5945 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5946 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5947 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5948 | // Create a series of compare/jumps. |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5949 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5950 | Register temp = temps.AcquireW(); |
| 5951 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5952 | |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5953 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5954 | // Jump to successors[0] if value == lower_bound. |
| 5955 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5956 | int32_t last_index = 0; |
| 5957 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5958 | __ Subs(temp, temp, Operand(2)); |
| 5959 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5960 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5961 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5962 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5963 | } |
| 5964 | if (num_entries - last_index == 2) { |
| 5965 | // The last missing case_value. |
| 5966 | __ Cmp(temp, Operand(1)); |
| 5967 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5968 | } |
| 5969 | |
| 5970 | // And the default for any other value. |
| 5971 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5972 | __ B(codegen_->GetLabelOf(default_block)); |
| 5973 | } |
| 5974 | } else { |
| Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5975 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5976 | |
| 5977 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5978 | |
| 5979 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5980 | // registers, we are free to block one. |
| 5981 | Register temp_w = temps.AcquireW(); |
| 5982 | Register index; |
| 5983 | // Remove the bias. |
| 5984 | if (lower_bound != 0) { |
| 5985 | index = temp_w; |
| 5986 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5987 | } else { |
| 5988 | index = value_reg; |
| 5989 | } |
| 5990 | |
| 5991 | // Jump to default block if index is out of the range. |
| 5992 | __ Cmp(index, Operand(num_entries)); |
| 5993 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5994 | |
| 5995 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5996 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5997 | // register pressure. |
| 5998 | Register table_base = temps.AcquireX(); |
| 5999 | // Load jump offset from the table. |
| 6000 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 6001 | Register jump_offset = temp_w; |
| 6002 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 6003 | |
| 6004 | // Jump to target block by branching to table_base(pc related) + offset. |
| 6005 | Register target_address = table_base; |
| 6006 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 6007 | __ Br(target_address); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6008 | } |
| 6009 | } |
| 6010 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6011 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 6012 | HInstruction* instruction, |
| 6013 | Location out, |
| 6014 | uint32_t offset, |
| 6015 | Location maybe_temp, |
| 6016 | ReadBarrierOption read_barrier_option) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6017 | DataType::Type type = DataType::Type::kReference; |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6018 | Register out_reg = RegisterFrom(out, type); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6019 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6020 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6021 | if (kUseBakerReadBarrier) { |
| 6022 | // Load with fast path based Baker's read barrier. |
| 6023 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6024 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6025 | out, |
| 6026 | out_reg, |
| 6027 | offset, |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6028 | maybe_temp, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6029 | /* needs_null_check= */ false, |
| 6030 | /* use_load_acquire= */ false); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6031 | } else { |
| 6032 | // Load with slow path based read barrier. |
| 6033 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6034 | // in the following move operation, as we will need it for the |
| 6035 | // read barrier below. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6036 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6037 | __ Mov(temp_reg, out_reg); |
| 6038 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6039 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6040 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6041 | } |
| 6042 | } else { |
| 6043 | // Plain load with no read barrier. |
| 6044 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6045 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6046 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6047 | } |
| 6048 | } |
| 6049 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6050 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 6051 | HInstruction* instruction, |
| 6052 | Location out, |
| 6053 | Location obj, |
| 6054 | uint32_t offset, |
| 6055 | Location maybe_temp, |
| 6056 | ReadBarrierOption read_barrier_option) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6057 | DataType::Type type = DataType::Type::kReference; |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6058 | Register out_reg = RegisterFrom(out, type); |
| 6059 | Register obj_reg = RegisterFrom(obj, type); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6060 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6061 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6062 | if (kUseBakerReadBarrier) { |
| 6063 | // Load with fast path based Baker's read barrier. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6064 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6065 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6066 | out, |
| 6067 | obj_reg, |
| 6068 | offset, |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6069 | maybe_temp, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6070 | /* needs_null_check= */ false, |
| 6071 | /* use_load_acquire= */ false); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6072 | } else { |
| 6073 | // Load with slow path based read barrier. |
| 6074 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6075 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6076 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6077 | } |
| 6078 | } else { |
| 6079 | // Plain load with no read barrier. |
| 6080 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6081 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6082 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6083 | } |
| 6084 | } |
| 6085 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6086 | void CodeGeneratorARM64::GenerateGcRootFieldLoad( |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6087 | HInstruction* instruction, |
| 6088 | Location root, |
| 6089 | Register obj, |
| 6090 | uint32_t offset, |
| 6091 | vixl::aarch64::Label* fixup_label, |
| 6092 | ReadBarrierOption read_barrier_option) { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6093 | DCHECK(fixup_label == nullptr || offset == 0u); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6094 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6095 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6096 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6097 | if (kUseBakerReadBarrier) { |
| 6098 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6099 | // Baker's read barrier are used. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6100 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6101 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6102 | // the Marking Register) to decide whether we need to enter |
| 6103 | // the slow path to mark the GC root. |
| 6104 | // |
| 6105 | // We use shared thunks for the slow path; shared within the method |
| 6106 | // for JIT, across methods for AOT. That thunk checks the reference |
| 6107 | // and jumps to the entrypoint if needed. |
| 6108 | // |
| 6109 | // lr = &return_address; |
| 6110 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6111 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6112 | // goto gc_root_thunk<root_reg>(lr) |
| 6113 | // } |
| 6114 | // return_address: |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6115 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6116 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6117 | DCHECK(temps.IsAvailable(ip0)); |
| 6118 | DCHECK(temps.IsAvailable(ip1)); |
| 6119 | temps.Exclude(ip0, ip1); |
| 6120 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6121 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6122 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6123 | vixl::aarch64::Label return_address; |
| 6124 | __ adr(lr, &return_address); |
| 6125 | if (fixup_label != nullptr) { |
| 6126 | __ bind(fixup_label); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6127 | } |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6128 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6129 | "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] | 6130 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6131 | EmitBakerReadBarrierCbnz(custom_data); |
| 6132 | __ bind(&return_address); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6133 | } else { |
| 6134 | // GC root loaded through a slow path for read barriers other |
| 6135 | // than Baker's. |
| 6136 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6137 | if (fixup_label == nullptr) { |
| 6138 | __ Add(root_reg.X(), obj.X(), offset); |
| 6139 | } else { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6140 | EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6141 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6142 | // /* mirror::Object* */ root = root->Read() |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6143 | GenerateReadBarrierForRootSlow(instruction, root, root); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6144 | } |
| 6145 | } else { |
| 6146 | // Plain GC root load with no read barrier. |
| 6147 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6148 | if (fixup_label == nullptr) { |
| 6149 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6150 | } else { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6151 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6152 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6153 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6154 | // do not have to unpoison `root_reg` here. |
| 6155 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6156 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6157 | } |
| 6158 | |
| Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6159 | void CodeGeneratorARM64::GenerateUnsafeCasOldValueMovWithBakerReadBarrier( |
| 6160 | vixl::aarch64::Register marked, |
| 6161 | vixl::aarch64::Register old_value) { |
| 6162 | DCHECK(kEmitCompilerReadBarrier); |
| 6163 | DCHECK(kUseBakerReadBarrier); |
| 6164 | |
| 6165 | // Similar to the Baker RB path in GenerateGcRootFieldLoad(), with a MOV instead of LDR. |
| 6166 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(marked.GetCode()); |
| 6167 | |
| 6168 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6169 | vixl::aarch64::Label return_address; |
| 6170 | __ adr(lr, &return_address); |
| 6171 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6172 | "GC root LDR must be 2 instructions (8B) before the return address label."); |
| 6173 | __ mov(marked, old_value); |
| 6174 | EmitBakerReadBarrierCbnz(custom_data); |
| 6175 | __ bind(&return_address); |
| 6176 | } |
| 6177 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6178 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6179 | Location ref, |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6180 | vixl::aarch64::Register obj, |
| 6181 | const vixl::aarch64::MemOperand& src, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6182 | bool needs_null_check, |
| 6183 | bool use_load_acquire) { |
| 6184 | DCHECK(kEmitCompilerReadBarrier); |
| 6185 | DCHECK(kUseBakerReadBarrier); |
| 6186 | |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6187 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6188 | // Marking Register) to decide whether we need to enter the slow |
| 6189 | // path to mark the reference. Then, in the slow path, check the |
| 6190 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6191 | // decide whether to mark `ref` or not. |
| 6192 | // |
| 6193 | // We use shared thunks for the slow path; shared within the method |
| 6194 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6195 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6196 | // it creates a fake dependency and returns to the LDR instruction. |
| 6197 | // |
| 6198 | // lr = &gray_return_address; |
| 6199 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6200 | // goto field_thunk<holder_reg, base_reg, use_load_acquire>(lr) |
| 6201 | // } |
| 6202 | // not_gray_return_address: |
| 6203 | // // Original reference load. If the offset is too large to fit |
| 6204 | // // into LDR, we use an adjusted base register here. |
| 6205 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 6206 | // gray_return_address: |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6207 | |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6208 | DCHECK(src.GetAddrMode() == vixl::aarch64::Offset); |
| 6209 | DCHECK_ALIGNED(src.GetOffset(), sizeof(mirror::HeapReference<mirror::Object>)); |
| 6210 | |
| 6211 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6212 | DCHECK(temps.IsAvailable(ip0)); |
| 6213 | DCHECK(temps.IsAvailable(ip1)); |
| 6214 | temps.Exclude(ip0, ip1); |
| 6215 | uint32_t custom_data = use_load_acquire |
| 6216 | ? EncodeBakerReadBarrierAcquireData(src.GetBaseRegister().GetCode(), obj.GetCode()) |
| 6217 | : EncodeBakerReadBarrierFieldData(src.GetBaseRegister().GetCode(), obj.GetCode()); |
| 6218 | |
| 6219 | { |
| 6220 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6221 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6222 | vixl::aarch64::Label return_address; |
| 6223 | __ adr(lr, &return_address); |
| 6224 | EmitBakerReadBarrierCbnz(custom_data); |
| 6225 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6226 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6227 | " 2 instructions (8B) for heap poisoning."); |
| 6228 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 6229 | if (use_load_acquire) { |
| 6230 | DCHECK_EQ(src.GetOffset(), 0); |
| 6231 | __ ldar(ref_reg, src); |
| 6232 | } else { |
| 6233 | __ ldr(ref_reg, src); |
| 6234 | } |
| 6235 | if (needs_null_check) { |
| 6236 | MaybeRecordImplicitNullCheck(instruction); |
| 6237 | } |
| 6238 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6239 | // macro instructions disallowed in ExactAssemblyScope. |
| 6240 | if (kPoisonHeapReferences) { |
| 6241 | __ neg(ref_reg, Operand(ref_reg)); |
| 6242 | } |
| 6243 | __ bind(&return_address); |
| 6244 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6245 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6246 | } |
| 6247 | |
| 6248 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6249 | Location ref, |
| 6250 | Register obj, |
| 6251 | uint32_t offset, |
| 6252 | Location maybe_temp, |
| 6253 | bool needs_null_check, |
| 6254 | bool use_load_acquire) { |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6255 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6256 | Register base = obj; |
| 6257 | if (use_load_acquire) { |
| 6258 | DCHECK(maybe_temp.IsRegister()); |
| 6259 | base = WRegisterFrom(maybe_temp); |
| 6260 | __ Add(base, obj, offset); |
| 6261 | offset = 0u; |
| 6262 | } else if (offset >= kReferenceLoadMinFarOffset) { |
| 6263 | DCHECK(maybe_temp.IsRegister()); |
| 6264 | base = WRegisterFrom(maybe_temp); |
| 6265 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6266 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6267 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6268 | } |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6269 | MemOperand src(base.X(), offset); |
| 6270 | GenerateFieldLoadWithBakerReadBarrier( |
| 6271 | instruction, ref, obj, src, needs_null_check, use_load_acquire); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6272 | } |
| 6273 | |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6274 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HArrayGet* instruction, |
| 6275 | Location ref, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6276 | Register obj, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6277 | uint32_t data_offset, |
| 6278 | Location index, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6279 | bool needs_null_check) { |
| 6280 | DCHECK(kEmitCompilerReadBarrier); |
| 6281 | DCHECK(kUseBakerReadBarrier); |
| 6282 | |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6283 | static_assert( |
| 6284 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6285 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6286 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6287 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6288 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6289 | // Marking Register) to decide whether we need to enter the slow |
| 6290 | // path to mark the reference. Then, in the slow path, check the |
| 6291 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6292 | // decide whether to mark `ref` or not. |
| 6293 | // |
| 6294 | // We use shared thunks for the slow path; shared within the method |
| 6295 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6296 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6297 | // it creates a fake dependency and returns to the LDR instruction. |
| 6298 | // |
| 6299 | // lr = &gray_return_address; |
| 6300 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6301 | // goto array_thunk<base_reg>(lr) |
| 6302 | // } |
| 6303 | // not_gray_return_address: |
| 6304 | // // Original reference load. If the offset is too large to fit |
| 6305 | // // into LDR, we use an adjusted base register here. |
| 6306 | // HeapReference<mirror::Object> reference = data[index]; |
| 6307 | // gray_return_address: |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6308 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6309 | DCHECK(index.IsValid()); |
| 6310 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 6311 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6312 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6313 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6314 | DCHECK(temps.IsAvailable(ip0)); |
| 6315 | DCHECK(temps.IsAvailable(ip1)); |
| 6316 | temps.Exclude(ip0, ip1); |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6317 | |
| 6318 | Register temp; |
| 6319 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 6320 | // We do not need to compute the intermediate address from the array: the |
| 6321 | // input instruction has done it already. See the comment in |
| 6322 | // `TryExtractArrayAccessAddress()`. |
| 6323 | if (kIsDebugBuild) { |
| 6324 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 6325 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 6326 | } |
| 6327 | temp = obj; |
| 6328 | } else { |
| 6329 | temp = WRegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 6330 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
| 6331 | } |
| 6332 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6333 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(temp.GetCode()); |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6334 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6335 | { |
| 6336 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6337 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6338 | vixl::aarch64::Label return_address; |
| 6339 | __ adr(lr, &return_address); |
| 6340 | EmitBakerReadBarrierCbnz(custom_data); |
| 6341 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6342 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6343 | " 2 instructions (8B) for heap poisoning."); |
| 6344 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6345 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6346 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6347 | // macro instructions disallowed in ExactAssemblyScope. |
| 6348 | if (kPoisonHeapReferences) { |
| 6349 | __ neg(ref_reg, Operand(ref_reg)); |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6350 | } |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6351 | __ bind(&return_address); |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6352 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6353 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6354 | } |
| 6355 | |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6356 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6357 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6358 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6359 | // The following condition is a run-time one; it is executed after the |
| 6360 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6361 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6362 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6363 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6364 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6365 | } |
| 6366 | } |
| 6367 | } |
| 6368 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6369 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6370 | Location out, |
| 6371 | Location ref, |
| 6372 | Location obj, |
| 6373 | uint32_t offset, |
| 6374 | Location index) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6375 | DCHECK(kEmitCompilerReadBarrier); |
| 6376 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6377 | // Insert a slow path based read barrier *after* the reference load. |
| 6378 | // |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6379 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6380 | // reference will be carried out by the runtime within the slow |
| 6381 | // path. |
| 6382 | // |
| 6383 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6384 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6385 | // not used by the artReadBarrierSlow entry point. |
| 6386 | // |
| 6387 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6388 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6389 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6390 | AddSlowPath(slow_path); |
| 6391 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6392 | __ B(slow_path->GetEntryLabel()); |
| 6393 | __ Bind(slow_path->GetExitLabel()); |
| 6394 | } |
| 6395 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6396 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6397 | Location out, |
| 6398 | Location ref, |
| 6399 | Location obj, |
| 6400 | uint32_t offset, |
| 6401 | Location index) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6402 | if (kEmitCompilerReadBarrier) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6403 | // Baker's read barriers shall be handled by the fast path |
| 6404 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6405 | DCHECK(!kUseBakerReadBarrier); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6406 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6407 | // by the runtime within the slow path. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6408 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6409 | } else if (kPoisonHeapReferences) { |
| 6410 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6411 | } |
| 6412 | } |
| 6413 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6414 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6415 | Location out, |
| 6416 | Location root) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6417 | DCHECK(kEmitCompilerReadBarrier); |
| 6418 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6419 | // Insert a slow path based read barrier *after* the GC root load. |
| 6420 | // |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6421 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6422 | // not need to do anything special for this here. |
| 6423 | SlowPathCodeARM64* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6424 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6425 | AddSlowPath(slow_path); |
| 6426 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6427 | __ B(slow_path->GetEntryLabel()); |
| 6428 | __ Bind(slow_path->GetExitLabel()); |
| 6429 | } |
| 6430 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6431 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6432 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6433 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6434 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6435 | locations->SetOut(Location::RequiresRegister()); |
| 6436 | } |
| 6437 | |
| 6438 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6439 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6440 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6441 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6442 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6443 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6444 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6445 | } else { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6446 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6447 | instruction->GetIndex(), kArm64PointerSize)); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6448 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6449 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6450 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6451 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6452 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6453 | } |
| 6454 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6455 | static void PatchJitRootUse(uint8_t* code, |
| 6456 | const uint8_t* roots_data, |
| 6457 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6458 | uint64_t index_in_table) { |
| 6459 | uint32_t literal_offset = literal->GetOffset(); |
| 6460 | uintptr_t address = |
| 6461 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6462 | uint8_t* data = code + literal_offset; |
| 6463 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6464 | } |
| 6465 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6466 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6467 | for (const auto& entry : jit_string_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6468 | const StringReference& string_reference = entry.first; |
| 6469 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6470 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6471 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6472 | } |
| 6473 | for (const auto& entry : jit_class_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6474 | const TypeReference& type_reference = entry.first; |
| 6475 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6476 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6477 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6478 | } |
| 6479 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6480 | |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 6481 | MemOperand InstructionCodeGeneratorARM64::VecNeonAddress( |
| 6482 | HVecMemoryOperation* instruction, |
| 6483 | UseScratchRegisterScope* temps_scope, |
| 6484 | size_t size, |
| 6485 | bool is_string_char_at, |
| 6486 | /*out*/ Register* scratch) { |
| 6487 | LocationSummary* locations = instruction->GetLocations(); |
| 6488 | Register base = InputRegisterAt(instruction, 0); |
| 6489 | |
| 6490 | if (instruction->InputAt(1)->IsIntermediateAddressIndex()) { |
| 6491 | DCHECK(!is_string_char_at); |
| 6492 | return MemOperand(base.X(), InputRegisterAt(instruction, 1).X()); |
| 6493 | } |
| 6494 | |
| 6495 | Location index = locations->InAt(1); |
| 6496 | uint32_t offset = is_string_char_at |
| 6497 | ? mirror::String::ValueOffset().Uint32Value() |
| 6498 | : mirror::Array::DataOffset(size).Uint32Value(); |
| 6499 | size_t shift = ComponentSizeShiftWidth(size); |
| 6500 | |
| 6501 | // HIntermediateAddress optimization is only applied for scalar ArrayGet and ArraySet. |
| 6502 | DCHECK(!instruction->InputAt(0)->IsIntermediateAddress()); |
| 6503 | |
| 6504 | if (index.IsConstant()) { |
| 6505 | offset += Int64FromLocation(index) << shift; |
| 6506 | return HeapOperand(base, offset); |
| 6507 | } else { |
| 6508 | *scratch = temps_scope->AcquireSameSizeAs(base); |
| 6509 | __ Add(*scratch, base, Operand(WRegisterFrom(index), LSL, shift)); |
| 6510 | return HeapOperand(*scratch, offset); |
| 6511 | } |
| 6512 | } |
| 6513 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6514 | #undef __ |
| 6515 | #undef QUICK_ENTRY_POINT |
| 6516 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6517 | #define __ assembler.GetVIXLAssembler()-> |
| 6518 | |
| 6519 | static void EmitGrayCheckAndFastPath(arm64::Arm64Assembler& assembler, |
| 6520 | vixl::aarch64::Register base_reg, |
| 6521 | vixl::aarch64::MemOperand& lock_word, |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6522 | vixl::aarch64::Label* slow_path, |
| 6523 | vixl::aarch64::Label* throw_npe = nullptr) { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6524 | // Load the lock word containing the rb_state. |
| 6525 | __ Ldr(ip0.W(), lock_word); |
| 6526 | // 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] | 6527 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6528 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 6529 | __ Tbnz(ip0.W(), LockWord::kReadBarrierStateShift, slow_path); |
| 6530 | static_assert( |
| 6531 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET, |
| 6532 | "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] | 6533 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 6534 | if (throw_npe != nullptr) { |
| 6535 | __ Bind(throw_npe); |
| 6536 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6537 | // Adjust the return address back to the LDR (1 instruction; 2 for heap poisoning). |
| 6538 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6539 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6540 | " 2 instructions (8B) for heap poisoning."); |
| 6541 | __ Add(lr, lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6542 | // Introduce a dependency on the lock_word including rb_state, |
| 6543 | // to prevent load-load reordering, and without using |
| 6544 | // a memory barrier (which would be more expensive). |
| 6545 | __ Add(base_reg, base_reg, Operand(ip0, LSR, 32)); |
| 6546 | __ Br(lr); // And return back to the function. |
| 6547 | // Note: The fake dependency is unnecessary for the slow path. |
| 6548 | } |
| 6549 | |
| 6550 | // Load the read barrier introspection entrypoint in register `entrypoint`. |
| 6551 | static void LoadReadBarrierMarkIntrospectionEntrypoint(arm64::Arm64Assembler& assembler, |
| 6552 | vixl::aarch64::Register entrypoint) { |
| 6553 | // entrypoint = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6554 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6555 | const int32_t entry_point_offset = |
| 6556 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6557 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| 6558 | } |
| 6559 | |
| 6560 | void CodeGeneratorARM64::CompileBakerReadBarrierThunk(Arm64Assembler& assembler, |
| 6561 | uint32_t encoded_data, |
| 6562 | /*out*/ std::string* debug_name) { |
| 6563 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 6564 | switch (kind) { |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6565 | case BakerReadBarrierKind::kField: |
| 6566 | case BakerReadBarrierKind::kAcquire: { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6567 | auto base_reg = |
| 6568 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6569 | CheckValidReg(base_reg.GetCode()); |
| 6570 | auto holder_reg = |
| 6571 | Register::GetXRegFromCode(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6572 | CheckValidReg(holder_reg.GetCode()); |
| 6573 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6574 | temps.Exclude(ip0, ip1); |
| Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 6575 | // In the case of a field load (with relaxed semantic), if `base_reg` differs from |
| 6576 | // `holder_reg`, the offset was too large and we must have emitted (during the construction |
| 6577 | // of the HIR graph, see `art::HInstructionBuilder::BuildInstanceFieldAccess`) and preserved |
| 6578 | // (see `art::PrepareForRegisterAllocation::VisitNullCheck`) an explicit null check before |
| 6579 | // the load. Otherwise, for implicit null checks, we need to null-check the holder as we do |
| 6580 | // not necessarily do that check before going to the thunk. |
| 6581 | // |
| 6582 | // In the case of a field load with load-acquire semantics (where `base_reg` always differs |
| 6583 | // from `holder_reg`), we also need an explicit null check when implicit null checks are |
| 6584 | // allowed, as we do not emit one before going to the thunk. |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6585 | vixl::aarch64::Label throw_npe_label; |
| 6586 | vixl::aarch64::Label* throw_npe = nullptr; |
| Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 6587 | if (GetCompilerOptions().GetImplicitNullChecks() && |
| 6588 | (holder_reg.Is(base_reg) || (kind == BakerReadBarrierKind::kAcquire))) { |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6589 | throw_npe = &throw_npe_label; |
| 6590 | __ Cbz(holder_reg.W(), throw_npe); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6591 | } |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6592 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 6593 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 6594 | // to load the reference and call the entrypoint that performs further checks on the |
| 6595 | // reference and marks it if needed. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6596 | vixl::aarch64::Label slow_path; |
| 6597 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6598 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, throw_npe); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6599 | __ Bind(&slow_path); |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6600 | if (kind == BakerReadBarrierKind::kField) { |
| 6601 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6602 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (immediate) unsigned offset. |
| 6603 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6604 | __ Ubfx(ip0.W(), ip0.W(), 10, 12); // Extract the offset. |
| 6605 | __ Ldr(ip0.W(), MemOperand(base_reg, ip0, LSL, 2)); // Load the reference. |
| 6606 | } else { |
| 6607 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 6608 | DCHECK(!base_reg.Is(holder_reg)); |
| 6609 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6610 | __ Ldar(ip0.W(), MemOperand(base_reg)); |
| 6611 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6612 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 6613 | __ Br(ip1); // Jump to the entrypoint. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6614 | break; |
| 6615 | } |
| 6616 | case BakerReadBarrierKind::kArray: { |
| 6617 | auto base_reg = |
| 6618 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6619 | CheckValidReg(base_reg.GetCode()); |
| 6620 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6621 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6622 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6623 | temps.Exclude(ip0, ip1); |
| 6624 | vixl::aarch64::Label slow_path; |
| 6625 | int32_t data_offset = |
| 6626 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 6627 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 6628 | DCHECK_LT(lock_word.GetOffset(), 0); |
| 6629 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path); |
| 6630 | __ Bind(&slow_path); |
| 6631 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| 6632 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (register) unsigned offset. |
| 6633 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6634 | __ Ubfx(ip0, ip0, 16, 6); // Extract the index register, plus 32 (bit 21 is set). |
| 6635 | __ Bfi(ip1, ip0, 3, 6); // Insert ip0 to the entrypoint address to create |
| 6636 | // a switch case target based on the index register. |
| 6637 | __ Mov(ip0, base_reg); // Move the base register to ip0. |
| 6638 | __ Br(ip1); // Jump to the entrypoint's array switch case. |
| 6639 | break; |
| 6640 | } |
| 6641 | case BakerReadBarrierKind::kGcRoot: { |
| 6642 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 6643 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 6644 | // otherwise return the reference (or the extracted forwarding address). |
| 6645 | // There is no gray bit check for GC roots. |
| 6646 | auto root_reg = |
| 6647 | Register::GetWRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6648 | CheckValidReg(root_reg.GetCode()); |
| 6649 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6650 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6651 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6652 | temps.Exclude(ip0, ip1); |
| 6653 | vixl::aarch64::Label return_label, not_marked, forwarding_address; |
| 6654 | __ Cbz(root_reg, &return_label); |
| 6655 | MemOperand lock_word(root_reg.X(), mirror::Object::MonitorOffset().Int32Value()); |
| 6656 | __ Ldr(ip0.W(), lock_word); |
| 6657 | __ Tbz(ip0.W(), LockWord::kMarkBitStateShift, ¬_marked); |
| 6658 | __ Bind(&return_label); |
| 6659 | __ Br(lr); |
| 6660 | __ Bind(¬_marked); |
| 6661 | __ Tst(ip0.W(), Operand(ip0.W(), LSL, 1)); |
| 6662 | __ B(&forwarding_address, mi); |
| 6663 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6664 | // Adjust the art_quick_read_barrier_mark_introspection address in IP1 to |
| 6665 | // art_quick_read_barrier_mark_introspection_gc_roots. |
| 6666 | __ Add(ip1, ip1, Operand(BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET)); |
| 6667 | __ Mov(ip0.W(), root_reg); |
| 6668 | __ Br(ip1); |
| 6669 | __ Bind(&forwarding_address); |
| 6670 | __ Lsl(root_reg, ip0.W(), LockWord::kForwardingAddressShift); |
| 6671 | __ Br(lr); |
| 6672 | break; |
| 6673 | } |
| 6674 | default: |
| 6675 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 6676 | UNREACHABLE(); |
| 6677 | } |
| 6678 | |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6679 | // For JIT, the slow path is considered part of the compiled method, |
| Vladimir Marko | f91fc12 | 2020-05-13 09:21:00 +0100 | [diff] [blame] | 6680 | // so JIT should pass null as `debug_name`. |
| 6681 | DCHECK(!UseJitCompilation() || debug_name == nullptr); |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6682 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6683 | std::ostringstream oss; |
| 6684 | oss << "BakerReadBarrierThunk"; |
| 6685 | switch (kind) { |
| 6686 | case BakerReadBarrierKind::kField: |
| 6687 | oss << "Field_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 6688 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 6689 | break; |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6690 | case BakerReadBarrierKind::kAcquire: |
| 6691 | oss << "Acquire_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 6692 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 6693 | break; |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6694 | case BakerReadBarrierKind::kArray: |
| 6695 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6696 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6697 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6698 | break; |
| 6699 | case BakerReadBarrierKind::kGcRoot: |
| 6700 | oss << "GcRoot_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6701 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6702 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6703 | break; |
| 6704 | } |
| 6705 | *debug_name = oss.str(); |
| 6706 | } |
| 6707 | } |
| 6708 | |
| 6709 | #undef __ |
| 6710 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6711 | } // namespace arm64 |
| 6712 | } // namespace art |