| 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 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 95 | inline Condition ARM64Condition(IfCondition cond) { |
| 96 | switch (cond) { |
| 97 | case kCondEQ: return eq; |
| 98 | case kCondNE: return ne; |
| 99 | case kCondLT: return lt; |
| 100 | case kCondLE: return le; |
| 101 | case kCondGT: return gt; |
| 102 | case kCondGE: return ge; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 103 | case kCondB: return lo; |
| 104 | case kCondBE: return ls; |
| 105 | case kCondA: return hi; |
| 106 | case kCondAE: return hs; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 107 | } |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 108 | LOG(FATAL) << "Unreachable"; |
| 109 | UNREACHABLE(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 112 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 113 | // The ARM64 condition codes can express all the necessary branches, see the |
| 114 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 115 | // There is no dex instruction or HIR that would need the missing conditions |
| 116 | // "equal or unordered" or "not equal". |
| 117 | switch (cond) { |
| 118 | case kCondEQ: return eq; |
| 119 | case kCondNE: return ne /* unordered */; |
| 120 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 121 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 122 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 123 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 124 | default: |
| 125 | LOG(FATAL) << "UNREACHABLE"; |
| 126 | UNREACHABLE(); |
| 127 | } |
| 128 | } |
| 129 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 130 | Location ARM64ReturnLocation(DataType::Type return_type) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 131 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 132 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 133 | // but we use the exact registers for clarity. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 134 | if (return_type == DataType::Type::kFloat32) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 135 | return LocationFrom(s0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 136 | } else if (return_type == DataType::Type::kFloat64) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 137 | return LocationFrom(d0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 138 | } else if (return_type == DataType::Type::kInt64) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 139 | return LocationFrom(x0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 140 | } else if (return_type == DataType::Type::kVoid) { |
| Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 141 | return Location::NoLocation(); |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 142 | } else { |
| 143 | return LocationFrom(w0); |
| 144 | } |
| 145 | } |
| 146 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 147 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type return_type) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 148 | return ARM64ReturnLocation(return_type); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 149 | } |
| 150 | |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 151 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 152 | InvokeRuntimeCallingConvention calling_convention; |
| 153 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 154 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 155 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 156 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 157 | DataType::Type::kReference).GetCode()); |
| 158 | return caller_saves; |
| 159 | } |
| 160 | |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 161 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 162 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 163 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 164 | |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 165 | // Calculate memory accessing operand for save/restore live registers. |
| 166 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 167 | LocationSummary* locations, |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 168 | int64_t spill_offset, |
| 169 | bool is_save) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 170 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
| 171 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 172 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 173 | codegen->GetNumberOfCoreRegisters(), |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 174 | fp_spills, |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 175 | codegen->GetNumberOfFloatingPointRegisters())); |
| 176 | |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 177 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
| Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 178 | const unsigned v_reg_size_in_bits = codegen->GetSlowPathFPWidth() * 8; |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 179 | DCHECK_LE(codegen->GetSIMDRegisterWidth(), kQRegSizeInBytes); |
| Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 180 | 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] | 181 | |
| 182 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 183 | UseScratchRegisterScope temps(masm); |
| 184 | |
| 185 | Register base = masm->StackPointer(); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 186 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 187 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 188 | int64_t reg_size = kXRegSizeInBytes; |
| 189 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 190 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 191 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 192 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 193 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 194 | // to compute the base address(float point registers spill base address). |
| 195 | Register new_base = temps.AcquireSameSizeAs(base); |
| 196 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 197 | base = new_base; |
| 198 | spill_offset = -core_spill_size; |
| 199 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 200 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 201 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 202 | } |
| 203 | |
| 204 | if (is_save) { |
| 205 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 206 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 207 | } else { |
| 208 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 209 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 214 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 215 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 216 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 217 | // If the register holds an object, update the stack mask. |
| 218 | if (locations->RegisterContainsObject(i)) { |
| 219 | locations->SetStackBit(stack_offset / kVRegSize); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 220 | } |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 221 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 222 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 223 | saved_core_stack_offsets_[i] = stack_offset; |
| 224 | stack_offset += kXRegSizeInBytes; |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 225 | } |
| 226 | |
| Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 227 | const size_t fp_reg_size = codegen->GetSlowPathFPWidth(); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 228 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 229 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 230 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 231 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 232 | saved_fpu_stack_offsets_[i] = stack_offset; |
| Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 233 | stack_offset += fp_reg_size; |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 234 | } |
| 235 | |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 236 | SaveRestoreLiveRegistersHelper(codegen, |
| 237 | locations, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 238 | codegen->GetFirstRegisterSlotInSlowPath(), /* is_save= */ true); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 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= */ false); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 245 | } |
| 246 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 247 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 248 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 249 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 250 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 251 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 252 | LocationSummary* locations = instruction_->GetLocations(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 253 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 254 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 255 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 256 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 257 | // Live registers will be restored in the catch block if caught. |
| 258 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 259 | } |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 260 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 261 | // move resolver. |
| 262 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 263 | codegen->EmitParallelMoves(locations->InAt(0), |
| 264 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 265 | DataType::Type::kInt32, |
| 266 | locations->InAt(1), |
| 267 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 268 | DataType::Type::kInt32); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 269 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 270 | ? kQuickThrowStringBounds |
| 271 | : kQuickThrowArrayBounds; |
| 272 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 273 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 274 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 275 | } |
| 276 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 277 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 278 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 279 | const char* GetDescription() const override { return "BoundsCheckSlowPathARM64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 280 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 281 | private: |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 282 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 283 | }; |
| 284 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 285 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 286 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 287 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 288 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 289 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 290 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 291 | __ Bind(GetEntryLabel()); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 292 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 293 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 296 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 297 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 298 | const char* GetDescription() const override { return "DivZeroCheckSlowPathARM64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 299 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 300 | private: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 301 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 302 | }; |
| 303 | |
| 304 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 305 | public: |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 306 | LoadClassSlowPathARM64(HLoadClass* cls, HInstruction* at) |
| 307 | : SlowPathCodeARM64(at), cls_(cls) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 308 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 309 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 312 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 313 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 314 | Location out = locations->Out(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 315 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 316 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 317 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 318 | |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 319 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 320 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 321 | SaveLiveRegisters(codegen, locations); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 322 | |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 323 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 324 | if (must_resolve_type) { |
| 325 | DCHECK(IsSameDexFile(cls_->GetDexFile(), arm64_codegen->GetGraph()->GetDexFile())); |
| 326 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 327 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
| Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 328 | arm64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 329 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 330 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 331 | } else { |
| 332 | DCHECK(must_do_clinit); |
| 333 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 334 | arm64_codegen->MoveLocation(LocationFrom(calling_convention.GetRegisterAt(0)), |
| 335 | source, |
| 336 | cls_->GetType()); |
| 337 | } |
| 338 | if (must_do_clinit) { |
| 339 | arm64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 340 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 341 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 342 | |
| 343 | // Move the class to the desired location. |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 344 | if (out.IsValid()) { |
| 345 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 346 | DataType::Type type = instruction_->GetType(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 347 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 348 | } |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 349 | RestoreLiveRegisters(codegen, locations); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 350 | __ B(GetExitLabel()); |
| 351 | } |
| 352 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 353 | const char* GetDescription() const override { return "LoadClassSlowPathARM64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 354 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 355 | private: |
| 356 | // The class this slow path will load. |
| 357 | HLoadClass* const cls_; |
| 358 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 359 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 360 | }; |
| 361 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 362 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 363 | public: |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 364 | explicit LoadStringSlowPathARM64(HLoadString* instruction) |
| 365 | : SlowPathCodeARM64(instruction) {} |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 366 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 367 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 368 | LocationSummary* locations = instruction_->GetLocations(); |
| 369 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 370 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 371 | |
| 372 | __ Bind(GetEntryLabel()); |
| 373 | SaveLiveRegisters(codegen, locations); |
| 374 | |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 375 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 376 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 377 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 378 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 379 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 380 | DataType::Type type = instruction_->GetType(); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 381 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 382 | |
| 383 | RestoreLiveRegisters(codegen, locations); |
| 384 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 385 | __ B(GetExitLabel()); |
| 386 | } |
| 387 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 388 | const char* GetDescription() const override { return "LoadStringSlowPathARM64"; } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 389 | |
| 390 | private: |
| 391 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 392 | }; |
| 393 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 394 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 395 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 396 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 397 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 398 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 399 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 400 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 401 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 402 | // Live registers will be restored in the catch block if caught. |
| 403 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 404 | } |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 405 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 406 | instruction_, |
| 407 | instruction_->GetDexPc(), |
| 408 | this); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 409 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 410 | } |
| 411 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 412 | bool IsFatal() const override { return true; } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 413 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 414 | const char* GetDescription() const override { return "NullCheckSlowPathARM64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 415 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 416 | private: |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 417 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 418 | }; |
| 419 | |
| 420 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 421 | public: |
| Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 422 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 423 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 424 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 425 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 426 | LocationSummary* locations = instruction_->GetLocations(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 427 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 428 | __ Bind(GetEntryLabel()); |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 429 | SaveLiveRegisters(codegen, locations); // Only saves live vector regs for SIMD. |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 430 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 431 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 432 | RestoreLiveRegisters(codegen, locations); // Only restores live vector regs for SIMD. |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 433 | if (successor_ == nullptr) { |
| 434 | __ B(GetReturnLabel()); |
| 435 | } else { |
| 436 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 437 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 438 | } |
| 439 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 440 | vixl::aarch64::Label* GetReturnLabel() { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 441 | DCHECK(successor_ == nullptr); |
| 442 | return &return_label_; |
| 443 | } |
| 444 | |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 445 | HBasicBlock* GetSuccessor() const { |
| 446 | return successor_; |
| 447 | } |
| 448 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 449 | const char* GetDescription() const override { return "SuspendCheckSlowPathARM64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 450 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 451 | private: |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 452 | // If not null, the block to branch to after the suspend check. |
| 453 | HBasicBlock* const successor_; |
| 454 | |
| 455 | // 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] | 456 | vixl::aarch64::Label return_label_; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 457 | |
| 458 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 459 | }; |
| 460 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 461 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 462 | public: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 463 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 464 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 465 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 466 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 467 | LocationSummary* locations = instruction_->GetLocations(); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 468 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 469 | DCHECK(instruction_->IsCheckCast() |
| 470 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 471 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 472 | uint32_t dex_pc = instruction_->GetDexPc(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 473 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 474 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 475 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 476 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 477 | SaveLiveRegisters(codegen, locations); |
| 478 | } |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 479 | |
| 480 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 481 | // move resolver. |
| 482 | InvokeRuntimeCallingConvention calling_convention; |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 483 | codegen->EmitParallelMoves(locations->InAt(0), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 484 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 485 | DataType::Type::kReference, |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 486 | locations->InAt(1), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 487 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 488 | DataType::Type::kReference); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 489 | if (instruction_->IsInstanceOf()) { |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 490 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 491 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 492 | DataType::Type ret_type = instruction_->GetType(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 493 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 494 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 495 | } else { |
| 496 | DCHECK(instruction_->IsCheckCast()); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 497 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 498 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 501 | if (!is_fatal_) { |
| 502 | RestoreLiveRegisters(codegen, locations); |
| 503 | __ B(GetExitLabel()); |
| 504 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 505 | } |
| 506 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 507 | const char* GetDescription() const override { return "TypeCheckSlowPathARM64"; } |
| 508 | bool IsFatal() const override { return is_fatal_; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 509 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 510 | private: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 511 | const bool is_fatal_; |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 512 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 513 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 514 | }; |
| 515 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 516 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 517 | public: |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 518 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 519 | : SlowPathCodeARM64(instruction) {} |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 520 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 521 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 522 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 523 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 524 | LocationSummary* locations = instruction_->GetLocations(); |
| 525 | SaveLiveRegisters(codegen, locations); |
| 526 | InvokeRuntimeCallingConvention calling_convention; |
| 527 | __ Mov(calling_convention.GetRegisterAt(0), |
| 528 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 529 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 530 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 533 | const char* GetDescription() const override { return "DeoptimizationSlowPathARM64"; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 534 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 535 | private: |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 536 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 537 | }; |
| 538 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 539 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 540 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 541 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 542 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 543 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 544 | LocationSummary* locations = instruction_->GetLocations(); |
| 545 | __ Bind(GetEntryLabel()); |
| 546 | SaveLiveRegisters(codegen, locations); |
| 547 | |
| 548 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 549 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 550 | parallel_move.AddMove( |
| 551 | locations->InAt(0), |
| 552 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 553 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 554 | nullptr); |
| 555 | parallel_move.AddMove( |
| 556 | locations->InAt(1), |
| 557 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 558 | DataType::Type::kInt32, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 559 | nullptr); |
| 560 | parallel_move.AddMove( |
| 561 | locations->InAt(2), |
| 562 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 563 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 564 | nullptr); |
| 565 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 566 | |
| 567 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 568 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 569 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 570 | RestoreLiveRegisters(codegen, locations); |
| 571 | __ B(GetExitLabel()); |
| 572 | } |
| 573 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 574 | const char* GetDescription() const override { return "ArraySetSlowPathARM64"; } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 575 | |
| 576 | private: |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 577 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 578 | }; |
| 579 | |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 580 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 581 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 582 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 583 | |
| 584 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 585 | // 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] | 586 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 587 | num_entries * sizeof(int32_t), |
| 588 | CodeBufferCheckScope::kExactSize); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 589 | |
| 590 | __ Bind(&table_start_); |
| 591 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 592 | for (uint32_t i = 0; i < num_entries; i++) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 593 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 594 | DCHECK(target_label->IsBound()); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 595 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 596 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 597 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 598 | Literal<int32_t> literal(jump_offset); |
| 599 | __ place(&literal); |
| 600 | } |
| 601 | } |
| 602 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 603 | // Slow path generating a read barrier for a heap reference. |
| 604 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 605 | public: |
| 606 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 607 | Location out, |
| 608 | Location ref, |
| 609 | Location obj, |
| 610 | uint32_t offset, |
| 611 | Location index) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 612 | : SlowPathCodeARM64(instruction), |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 613 | out_(out), |
| 614 | ref_(ref), |
| 615 | obj_(obj), |
| 616 | offset_(offset), |
| 617 | index_(index) { |
| 618 | DCHECK(kEmitCompilerReadBarrier); |
| 619 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 620 | // has been overwritten by (or after) the heap object reference load |
| 621 | // to be instrumented, e.g.: |
| 622 | // |
| 623 | // __ Ldr(out, HeapOperand(out, class_offset); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 624 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 625 | // |
| 626 | // In that case, we have lost the information about the original |
| 627 | // object, and the emitted read barrier cannot work properly. |
| 628 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 629 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 630 | } |
| 631 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 632 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 633 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 634 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 635 | DataType::Type type = DataType::Type::kReference; |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 636 | DCHECK(locations->CanCall()); |
| 637 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 638 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 639 | instruction_->IsStaticFieldGet() || |
| 640 | instruction_->IsArrayGet() || |
| 641 | instruction_->IsInstanceOf() || |
| 642 | instruction_->IsCheckCast() || |
| Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 643 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 644 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 645 | << instruction_->DebugName(); |
| Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 646 | // The read barrier instrumentation of object ArrayGet |
| 647 | // instructions does not support the HIntermediateAddress |
| 648 | // instruction. |
| Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 649 | DCHECK(!(instruction_->IsArrayGet() && |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 650 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 651 | |
| 652 | __ Bind(GetEntryLabel()); |
| 653 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 654 | SaveLiveRegisters(codegen, locations); |
| 655 | |
| 656 | // We may have to change the index's value, but as `index_` is a |
| 657 | // constant member (like other "inputs" of this slow path), |
| 658 | // introduce a copy of it, `index`. |
| 659 | Location index = index_; |
| 660 | if (index_.IsValid()) { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 661 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 662 | if (instruction_->IsArrayGet()) { |
| 663 | // Compute the actual memory offset and store it in `index`. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 664 | Register index_reg = RegisterFrom(index_, DataType::Type::kInt32); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 665 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 666 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 667 | // We are about to change the value of `index_reg` (see the |
| 668 | // calls to vixl::MacroAssembler::Lsl and |
| 669 | // vixl::MacroAssembler::Mov below), but it has |
| 670 | // not been saved by the previous call to |
| 671 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 672 | // callee-save register -- |
| 673 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 674 | // callee-save registers, as it has been designed with the |
| 675 | // assumption that callee-save registers are supposed to be |
| 676 | // handled by the called function. So, as a callee-save |
| 677 | // register, `index_reg` _would_ eventually be saved onto |
| 678 | // the stack, but it would be too late: we would have |
| 679 | // changed its value earlier. Therefore, we manually save |
| 680 | // it here into another freely available register, |
| 681 | // `free_reg`, chosen of course among the caller-save |
| 682 | // registers (as a callee-save `free_reg` register would |
| 683 | // exhibit the same problem). |
| 684 | // |
| 685 | // Note we could have requested a temporary register from |
| 686 | // the register allocator instead; but we prefer not to, as |
| 687 | // this is a slow path, and we know we can find a |
| 688 | // caller-save register that is available. |
| 689 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 690 | __ Mov(free_reg.W(), index_reg); |
| 691 | index_reg = free_reg; |
| 692 | index = LocationFrom(index_reg); |
| 693 | } else { |
| 694 | // The initial register stored in `index_` has already been |
| 695 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 696 | // (as it is not a callee-save register), so we can freely |
| 697 | // use it. |
| 698 | } |
| 699 | // Shifting the index value contained in `index_reg` by the scale |
| 700 | // factor (2) cannot overflow in practice, as the runtime is |
| 701 | // unable to allocate object arrays with a size larger than |
| 702 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 703 | __ Lsl(index_reg, index_reg, DataType::SizeShift(type)); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 704 | static_assert( |
| 705 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 706 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 707 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 708 | } else { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 709 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 710 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 711 | // (as in the case of ArrayGet), as it is actually an offset |
| 712 | // to an object field within an object. |
| 713 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 714 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 715 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 716 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 717 | << instruction_->AsInvoke()->GetIntrinsic(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 718 | DCHECK_EQ(offset_, 0u); |
| Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 719 | DCHECK(index_.IsRegister()); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | |
| 723 | // We're moving two or three locations to locations that could |
| 724 | // overlap, so we need a parallel move resolver. |
| 725 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 726 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 727 | parallel_move.AddMove(ref_, |
| 728 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 729 | type, |
| 730 | nullptr); |
| 731 | parallel_move.AddMove(obj_, |
| 732 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 733 | type, |
| 734 | nullptr); |
| 735 | if (index.IsValid()) { |
| 736 | parallel_move.AddMove(index, |
| 737 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 738 | DataType::Type::kInt32, |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 739 | nullptr); |
| 740 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 741 | } else { |
| 742 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 743 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 744 | } |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 745 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 746 | instruction_, |
| 747 | instruction_->GetDexPc(), |
| 748 | this); |
| 749 | CheckEntrypointTypes< |
| 750 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 751 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 752 | |
| 753 | RestoreLiveRegisters(codegen, locations); |
| 754 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 755 | __ B(GetExitLabel()); |
| 756 | } |
| 757 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 758 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 759 | |
| 760 | private: |
| 761 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 762 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 763 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 764 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 765 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 766 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 767 | } |
| 768 | } |
| 769 | // We shall never fail to find a free caller-save register, as |
| 770 | // there are more than two core caller-save registers on ARM64 |
| 771 | // (meaning it is possible to find one which is different from |
| 772 | // `ref` and `obj`). |
| 773 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 774 | LOG(FATAL) << "Could not find a free register"; |
| 775 | UNREACHABLE(); |
| 776 | } |
| 777 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 778 | const Location out_; |
| 779 | const Location ref_; |
| 780 | const Location obj_; |
| 781 | const uint32_t offset_; |
| 782 | // An additional location containing an index to an array. |
| 783 | // Only used for HArrayGet and the UnsafeGetObject & |
| 784 | // UnsafeGetObjectVolatile intrinsics. |
| 785 | const Location index_; |
| 786 | |
| 787 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 788 | }; |
| 789 | |
| 790 | // Slow path generating a read barrier for a GC root. |
| 791 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 792 | public: |
| 793 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 794 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 795 | DCHECK(kEmitCompilerReadBarrier); |
| 796 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 797 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 798 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 799 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 800 | DataType::Type type = DataType::Type::kReference; |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 801 | DCHECK(locations->CanCall()); |
| 802 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 803 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 804 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 805 | << instruction_->DebugName(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 806 | |
| 807 | __ Bind(GetEntryLabel()); |
| 808 | SaveLiveRegisters(codegen, locations); |
| 809 | |
| 810 | InvokeRuntimeCallingConvention calling_convention; |
| 811 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 812 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 813 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 814 | // thus we need a 64-bit move here, and we cannot use |
| 815 | // |
| 816 | // arm64_codegen->MoveLocation( |
| 817 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 818 | // root_, |
| 819 | // type); |
| 820 | // |
| 821 | // 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] | 822 | // reference type (`DataType::Type::kReference`). |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 823 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 824 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 825 | instruction_, |
| 826 | instruction_->GetDexPc(), |
| 827 | this); |
| 828 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 829 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 830 | |
| 831 | RestoreLiveRegisters(codegen, locations); |
| 832 | __ B(GetExitLabel()); |
| 833 | } |
| 834 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 835 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathARM64"; } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 836 | |
| 837 | private: |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 838 | const Location out_; |
| 839 | const Location root_; |
| 840 | |
| 841 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 842 | }; |
| 843 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 844 | #undef __ |
| 845 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 846 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 847 | Location next_location; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 848 | if (type == DataType::Type::kVoid) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 849 | LOG(FATAL) << "Unreachable type " << type; |
| 850 | } |
| 851 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 852 | if (DataType::IsFloatingPointType(type) && |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 853 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 854 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 855 | } else if (!DataType::IsFloatingPointType(type) && |
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 856 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 857 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 858 | } else { |
| 859 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 860 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 861 | : Location::StackSlot(stack_offset); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 862 | } |
| 863 | |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 864 | // Space on the stack is reserved for all arguments. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 865 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 866 | return next_location; |
| 867 | } |
| 868 | |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 869 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 870 | return LocationFrom(kArtMethodRegister); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 871 | } |
| 872 | |
| Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 873 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 874 | const CompilerOptions& compiler_options, |
| 875 | OptimizingCompilerStats* stats) |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 876 | : CodeGenerator(graph, |
| 877 | kNumberOfAllocatableRegisters, |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 878 | kNumberOfAllocatableFPRegisters, |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 879 | kNumberOfAllocatableRegisterPairs, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 880 | callee_saved_core_registers.GetList(), |
| 881 | callee_saved_fp_registers.GetList(), |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 882 | compiler_options, |
| 883 | stats), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 884 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 885 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 886 | location_builder_neon_(graph, this), |
| 887 | instruction_visitor_neon_(graph, this), |
| 888 | location_builder_sve_(graph, this), |
| 889 | instruction_visitor_sve_(graph, this), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 890 | move_resolver_(graph->GetAllocator(), this), |
| Artem Serov | aa6f483 | 2018-11-21 18:57:54 +0000 | [diff] [blame] | 891 | assembler_(graph->GetAllocator(), |
| 892 | compiler_options.GetInstructionSetFeatures()->AsArm64InstructionSetFeatures()), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 893 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 894 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 895 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 896 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 897 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 898 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 899 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 900 | call_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 901 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 902 | uint32_literals_(std::less<uint32_t>(), |
| 903 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 904 | uint64_literals_(std::less<uint64_t>(), |
| 905 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 906 | jit_string_patches_(StringReferenceValueComparator(), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 907 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 908 | jit_class_patches_(TypeReferenceValueComparator(), |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 909 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 910 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 911 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 912 | // Save the link register (containing the return address) to mimic Quick. |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 913 | AddAllocatedRegister(LocationFrom(lr)); |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 914 | |
| 915 | bool use_sve = ShouldUseSVE(); |
| 916 | if (use_sve) { |
| 917 | location_builder_ = &location_builder_sve_; |
| 918 | instruction_visitor_ = &instruction_visitor_sve_; |
| 919 | } else { |
| 920 | location_builder_ = &location_builder_neon_; |
| 921 | instruction_visitor_ = &instruction_visitor_neon_; |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | bool CodeGeneratorARM64::ShouldUseSVE() const { |
| 926 | return kArm64AllowSVE && GetInstructionSetFeatures().HasSVE(); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 927 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 928 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 929 | #define __ GetVIXLAssembler()-> |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 930 | |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 931 | void CodeGeneratorARM64::EmitJumpTables() { |
| Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 932 | for (auto&& jump_table : jump_tables_) { |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 933 | jump_table->EmitTable(this); |
| 934 | } |
| 935 | } |
| 936 | |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 937 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 938 | EmitJumpTables(); |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 939 | |
| 940 | // Emit JIT baker read barrier slow paths. |
| 941 | DCHECK(Runtime::Current()->UseJitCompilation() || jit_baker_read_barrier_slow_paths_.empty()); |
| 942 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 943 | uint32_t encoded_data = entry.first; |
| 944 | vixl::aarch64::Label* slow_path_entry = &entry.second.label; |
| 945 | __ Bind(slow_path_entry); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 946 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name= */ nullptr); |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 949 | // Ensure we emit the literal pool. |
| 950 | __ FinalizeCode(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 951 | |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 952 | CodeGenerator::Finalize(allocator); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 953 | |
| 954 | // Verify Baker read barrier linker patches. |
| 955 | if (kIsDebugBuild) { |
| 956 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 957 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 958 | DCHECK(info.label.IsBound()); |
| 959 | uint32_t literal_offset = info.label.GetLocation(); |
| 960 | DCHECK_ALIGNED(literal_offset, 4u); |
| 961 | |
| 962 | auto GetInsn = [&code](uint32_t offset) { |
| 963 | DCHECK_ALIGNED(offset, 4u); |
| 964 | return |
| 965 | (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 966 | (static_cast<uint32_t>(code[offset + 1]) << 8) + |
| 967 | (static_cast<uint32_t>(code[offset + 2]) << 16)+ |
| 968 | (static_cast<uint32_t>(code[offset + 3]) << 24); |
| 969 | }; |
| 970 | |
| 971 | const uint32_t encoded_data = info.custom_data; |
| 972 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 973 | // Check that the next instruction matches the expected LDR. |
| 974 | switch (kind) { |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 975 | case BakerReadBarrierKind::kField: |
| 976 | case BakerReadBarrierKind::kAcquire: { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 977 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 978 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 979 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 980 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 981 | if (kind == BakerReadBarrierKind::kField) { |
| 982 | // LDR (immediate) with correct base_reg. |
| 983 | CHECK_EQ(next_insn & 0xffc003e0u, 0xb9400000u | (base_reg << 5)); |
| 984 | } else { |
| 985 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 986 | // LDAR with correct base_reg. |
| 987 | CHECK_EQ(next_insn & 0xffffffe0u, 0x88dffc00u | (base_reg << 5)); |
| 988 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 989 | break; |
| 990 | } |
| 991 | case BakerReadBarrierKind::kArray: { |
| 992 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 993 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 994 | // LDR (register) with the correct base_reg, size=10 (32-bit), option=011 (extend = LSL), |
| 995 | // and S=1 (shift amount = 2 for 32-bit version), i.e. LDR Wt, [Xn, Xm, LSL #2]. |
| 996 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 997 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 998 | CHECK_EQ(next_insn & 0xffe0ffe0u, 0xb8607800u | (base_reg << 5)); |
| 999 | CheckValidReg((next_insn >> 16) & 0x1f); // Check index register |
| 1000 | break; |
| 1001 | } |
| 1002 | case BakerReadBarrierKind::kGcRoot: { |
| 1003 | DCHECK_GE(literal_offset, 4u); |
| 1004 | uint32_t prev_insn = GetInsn(literal_offset - 4u); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1005 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 1006 | // Usually LDR (immediate) with correct root_reg but |
| 1007 | // we may have a "MOV marked, old_value" for UnsafeCASObject. |
| 1008 | if ((prev_insn & 0xffe0ffff) != (0x2a0003e0 | root_reg)) { // MOV? |
| 1009 | CHECK_EQ(prev_insn & 0xffc0001fu, 0xb9400000u | root_reg); // LDR? |
| 1010 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1011 | break; |
| 1012 | } |
| 1013 | default: |
| 1014 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 1015 | UNREACHABLE(); |
| 1016 | } |
| 1017 | } |
| 1018 | } |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1021 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1022 | // Note: There are 6 kinds of moves: |
| 1023 | // 1. constant -> GPR/FPR (non-cycle) |
| 1024 | // 2. constant -> stack (non-cycle) |
| 1025 | // 3. GPR/FPR -> GPR/FPR |
| 1026 | // 4. GPR/FPR -> stack |
| 1027 | // 5. stack -> GPR/FPR |
| 1028 | // 6. stack -> stack (non-cycle) |
| 1029 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1030 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1031 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1032 | // dependency. |
| 1033 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1034 | } |
| 1035 | |
| 1036 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1037 | vixl_temps_.Close(); |
| 1038 | } |
| 1039 | |
| 1040 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1041 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1042 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1043 | || kind == Location::kSIMDStackSlot); |
| 1044 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1045 | ? Location::kFpuRegister |
| 1046 | : Location::kRegister; |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1047 | Location scratch = GetScratchLocation(kind); |
| 1048 | if (!scratch.Equals(Location::NoLocation())) { |
| 1049 | return scratch; |
| 1050 | } |
| 1051 | // Allocate from VIXL temp registers. |
| 1052 | if (kind == Location::kRegister) { |
| 1053 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1054 | } else { |
| Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1055 | DCHECK_EQ(kind, Location::kFpuRegister); |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1056 | scratch = codegen_->GetGraph()->HasSIMD() |
| 1057 | ? codegen_->GetInstructionCodeGeneratorArm64()->AllocateSIMDScratchLocation(&vixl_temps_) |
| 1058 | : LocationFrom(vixl_temps_.AcquireD()); |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1059 | } |
| 1060 | AddScratchLocation(scratch); |
| 1061 | return scratch; |
| 1062 | } |
| 1063 | |
| 1064 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1065 | if (loc.IsRegister()) { |
| 1066 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1067 | } else { |
| 1068 | DCHECK(loc.IsFpuRegister()); |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1069 | if (codegen_->GetGraph()->HasSIMD()) { |
| 1070 | codegen_->GetInstructionCodeGeneratorArm64()->FreeSIMDScratchLocation(loc, &vixl_temps_); |
| 1071 | } else { |
| 1072 | vixl_temps_.Release(DRegisterFrom(loc)); |
| 1073 | } |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1074 | } |
| 1075 | RemoveScratchLocation(loc); |
| 1076 | } |
| 1077 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1078 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1079 | MoveOperands* move = moves_[index]; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1080 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1083 | void CodeGeneratorARM64::MaybeIncrementHotness(bool is_frame_entry) { |
| 1084 | MacroAssembler* masm = GetVIXLAssembler(); |
| 1085 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1086 | UseScratchRegisterScope temps(masm); |
| 1087 | Register counter = temps.AcquireX(); |
| 1088 | Register method = is_frame_entry ? kArtMethodRegister : temps.AcquireX(); |
| 1089 | if (!is_frame_entry) { |
| 1090 | __ Ldr(method, MemOperand(sp, 0)); |
| 1091 | } |
| 1092 | __ Ldrh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1093 | __ Add(counter, counter, 1); |
| 1094 | // Subtract one if the counter would overflow. |
| 1095 | __ Sub(counter, counter, Operand(counter, LSR, 16)); |
| 1096 | __ Strh(counter, MemOperand(method, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1097 | } |
| 1098 | |
| 1099 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| 1100 | ScopedObjectAccess soa(Thread::Current()); |
| 1101 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1102 | if (info != nullptr) { |
| Nicolas Geoffray | c1cd133 | 2020-01-25 13:08:24 +0000 | [diff] [blame] | 1103 | uint64_t address = reinterpret_cast64<uint64_t>(info); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1104 | vixl::aarch64::Label done; |
| 1105 | UseScratchRegisterScope temps(masm); |
| 1106 | Register temp = temps.AcquireX(); |
| 1107 | Register counter = temps.AcquireW(); |
| 1108 | __ Mov(temp, address); |
| 1109 | __ Ldrh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 1110 | __ Add(counter, counter, 1); |
| 1111 | __ Strh(counter, MemOperand(temp, ProfilingInfo::BaselineHotnessCountOffset().Int32Value())); |
| 1112 | __ Tst(counter, 0xffff); |
| 1113 | __ B(ne, &done); |
| 1114 | if (is_frame_entry) { |
| 1115 | if (HasEmptyFrame()) { |
| 1116 | // The entyrpoint expects the method at the bottom of the stack. We |
| 1117 | // claim stack space necessary for alignment. |
| 1118 | __ Claim(kStackAlignment); |
| 1119 | __ Stp(kArtMethodRegister, lr, MemOperand(sp, 0)); |
| 1120 | } else if (!RequiresCurrentMethod()) { |
| 1121 | __ Str(kArtMethodRegister, MemOperand(sp, 0)); |
| 1122 | } |
| 1123 | } else { |
| 1124 | CHECK(RequiresCurrentMethod()); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1125 | } |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1126 | uint32_t entrypoint_offset = |
| 1127 | GetThreadOffset<kArm64PointerSize>(kQuickCompileOptimized).Int32Value(); |
| 1128 | __ Ldr(lr, MemOperand(tr, entrypoint_offset)); |
| 1129 | // Note: we don't record the call here (and therefore don't generate a stack |
| 1130 | // map), as the entrypoint should never be suspended. |
| 1131 | __ Blr(lr); |
| 1132 | if (HasEmptyFrame()) { |
| 1133 | CHECK(is_frame_entry); |
| 1134 | __ Ldr(lr, MemOperand(sp, 8)); |
| 1135 | __ Drop(kStackAlignment); |
| 1136 | } |
| 1137 | __ Bind(&done); |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1138 | } |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1142 | void CodeGeneratorARM64::GenerateFrameEntry() { |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1143 | MacroAssembler* masm = GetVIXLAssembler(); |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1144 | __ Bind(&frame_entry_label_); |
| 1145 | |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1146 | bool do_overflow_check = |
| 1147 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1148 | if (do_overflow_check) { |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1149 | UseScratchRegisterScope temps(masm); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1150 | Register temp = temps.AcquireX(); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1151 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1152 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1153 | { |
| 1154 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1155 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1156 | kInstructionSize, |
| 1157 | CodeBufferCheckScope::kExactSize); |
| 1158 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1159 | RecordPcInfo(nullptr, 0); |
| 1160 | } |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1161 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1162 | |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1163 | if (!HasEmptyFrame()) { |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1164 | // Stack layout: |
| 1165 | // sp[frame_size - 8] : lr. |
| 1166 | // ... : other preserved core registers. |
| 1167 | // ... : other preserved fp registers. |
| 1168 | // ... : reserved frame space. |
| 1169 | // sp[0] : current method. |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1170 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1171 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1172 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1173 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1174 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1175 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1176 | |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1177 | // Save the current method if we need it, or if using STP reduces code |
| 1178 | // size. Note that we do not do this in HCurrentMethod, as the |
| 1179 | // instruction might have been removed in the SSA graph. |
| 1180 | CPURegister lowest_spill; |
| 1181 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1182 | // If there is no gap between the method and the lowest core spill, use |
| 1183 | // aligned STP pre-index to store both. Max difference is 512. We do |
| 1184 | // that to reduce code size even if we do not have to save the method. |
| 1185 | DCHECK_LE(frame_size, 512); // 32 core registers are only 256 bytes. |
| 1186 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1187 | __ Stp(kArtMethodRegister, lowest_spill, MemOperand(sp, -frame_size, PreIndex)); |
| 1188 | } else if (RequiresCurrentMethod()) { |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1189 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
| Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1190 | } else { |
| 1191 | __ Claim(frame_size); |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1192 | } |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1193 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1194 | if (lowest_spill.IsValid()) { |
| 1195 | GetAssembler()->cfi().RelOffset(DWARFReg(lowest_spill), core_spills_offset); |
| 1196 | core_spills_offset += kXRegSizeInBytes; |
| 1197 | } |
| 1198 | GetAssembler()->SpillRegisters(preserved_core_registers, core_spills_offset); |
| 1199 | GetAssembler()->SpillRegisters(preserved_fp_registers, fp_spills_offset); |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1200 | |
| 1201 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1202 | // Initialize should_deoptimize flag to 0. |
| 1203 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1204 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1205 | } |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1206 | } |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1207 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1208 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | void CodeGeneratorARM64::GenerateFrameExit() { |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1212 | GetAssembler()->cfi().RememberState(); |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1213 | if (!HasEmptyFrame()) { |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 1214 | int32_t frame_size = dchecked_integral_cast<int32_t>(GetFrameSize()); |
| 1215 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 1216 | CPURegList preserved_core_registers = GetFramePreservedCoreRegisters(); |
| 1217 | DCHECK(!preserved_core_registers.IsEmpty()); |
| 1218 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 1219 | CPURegList preserved_fp_registers = GetFramePreservedFPRegisters(); |
| 1220 | |
| 1221 | CPURegister lowest_spill; |
| 1222 | if (core_spills_offset == kXRegSizeInBytes) { |
| 1223 | // If there is no gap between the method and the lowest core spill, use |
| 1224 | // aligned LDP pre-index to pop both. Max difference is 504. We do |
| 1225 | // that to reduce code size even though the loaded method is unused. |
| 1226 | DCHECK_LE(frame_size, 504); // 32 core registers are only 256 bytes. |
| 1227 | lowest_spill = preserved_core_registers.PopLowestIndex(); |
| 1228 | core_spills_offset += kXRegSizeInBytes; |
| 1229 | } |
| 1230 | GetAssembler()->UnspillRegisters(preserved_fp_registers, fp_spills_offset); |
| 1231 | GetAssembler()->UnspillRegisters(preserved_core_registers, core_spills_offset); |
| 1232 | if (lowest_spill.IsValid()) { |
| 1233 | __ Ldp(xzr, lowest_spill, MemOperand(sp, frame_size, PostIndex)); |
| 1234 | GetAssembler()->cfi().Restore(DWARFReg(lowest_spill)); |
| 1235 | } else { |
| 1236 | __ Drop(frame_size); |
| 1237 | } |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1238 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1239 | } |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1240 | __ Ret(); |
| 1241 | GetAssembler()->cfi().RestoreState(); |
| 1242 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1243 | } |
| 1244 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1245 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1246 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1247 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1248 | core_spill_mask_); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1249 | } |
| 1250 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1251 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1252 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1253 | GetNumberOfFloatingPointRegisters())); |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1254 | return CPURegList(CPURegister::kVRegister, kDRegSize, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1255 | fpu_spill_mask_); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1256 | } |
| 1257 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1258 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1259 | __ Bind(GetLabelOf(block)); |
| 1260 | } |
| 1261 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1262 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1263 | DCHECK(location.IsRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1264 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1265 | } |
| 1266 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1267 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1268 | if (location.IsRegister()) { |
| 1269 | locations->AddTemp(location); |
| 1270 | } else { |
| 1271 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1272 | } |
| 1273 | } |
| 1274 | |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1275 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1276 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1277 | Register card = temps.AcquireX(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1278 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1279 | vixl::aarch64::Label done; |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1280 | if (value_can_be_null) { |
| 1281 | __ Cbz(value, &done); |
| 1282 | } |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1283 | // Load the address of the card table into `card`. |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1284 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1285 | // Calculate the offset (in the card table) of the card corresponding to |
| 1286 | // `object`. |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1287 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1288 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 1289 | // `object`'s card. |
| 1290 | // |
| 1291 | // Register `card` contains the address of the card table. Note that the card |
| 1292 | // table's base is biased during its creation so that it always starts at an |
| 1293 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 1294 | // art::gc::accounting::CardTable::Create). Therefore the STRB instruction |
| 1295 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 1296 | // (located at `card + object >> kCardShift`). |
| 1297 | // |
| 1298 | // This dual use of the value in register `card` (1. to calculate the location |
| 1299 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 1300 | // (no need to explicitly load `kCardDirty` as an immediate value). |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1301 | __ Strb(card, MemOperand(card, temp.X())); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1302 | if (value_can_be_null) { |
| 1303 | __ Bind(&done); |
| 1304 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1305 | } |
| 1306 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1307 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1308 | // Blocked core registers: |
| 1309 | // lr : Runtime reserved. |
| 1310 | // tr : Runtime reserved. |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1311 | // mr : Runtime reserved. |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1312 | // ip1 : VIXL core temp. |
| 1313 | // ip0 : VIXL core temp. |
| Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1314 | // x18 : Platform register. |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1315 | // |
| 1316 | // Blocked fp registers: |
| 1317 | // d31 : VIXL fp temp. |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1318 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1319 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1320 | while (!reserved_core_registers.IsEmpty()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1321 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1322 | } |
| Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1323 | blocked_core_registers_[X18] = true; |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1324 | |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1325 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
| Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1326 | while (!reserved_fp_registers.IsEmpty()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1327 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1328 | } |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1329 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1330 | if (GetGraph()->IsDebuggable()) { |
| Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1331 | // Stubs do not save callee-save floating point registers. If the graph |
| 1332 | // is debuggable, we need to deal with these registers differently. For |
| 1333 | // now, just block them. |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1334 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1335 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1336 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1337 | } |
| 1338 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1339 | } |
| 1340 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1341 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1342 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1343 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1344 | return kArm64WordSize; |
| 1345 | } |
| 1346 | |
| 1347 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1348 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1349 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1350 | return kArm64WordSize; |
| 1351 | } |
| 1352 | |
| Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1353 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1354 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1355 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1356 | << "use SaveRestoreLiveRegistersHelper"; |
| 1357 | UNREACHABLE(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
| Artem Serov | 9df37b9 | 2019-07-23 16:41:54 +0100 | [diff] [blame] | 1360 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1361 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1362 | LOG(FATAL) << "FP registers shouldn't be saved/restored individually, " |
| 1363 | << "use SaveRestoreLiveRegistersHelper"; |
| 1364 | UNREACHABLE(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1367 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1368 | stream << XRegister(reg); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1372 | stream << DRegister(reg); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1373 | } |
| 1374 | |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1375 | const Arm64InstructionSetFeatures& CodeGeneratorARM64::GetInstructionSetFeatures() const { |
| 1376 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArm64InstructionSetFeatures(); |
| 1377 | } |
| 1378 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1379 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1380 | if (constant->IsIntConstant()) { |
| 1381 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1382 | } else if (constant->IsLongConstant()) { |
| 1383 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1384 | } else if (constant->IsNullConstant()) { |
| 1385 | __ Mov(Register(destination), 0); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1386 | } else if (constant->IsFloatConstant()) { |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1387 | __ Fmov(VRegister(destination), constant->AsFloatConstant()->GetValue()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1388 | } else { |
| 1389 | DCHECK(constant->IsDoubleConstant()); |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1390 | __ Fmov(VRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1391 | } |
| 1392 | } |
| 1393 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1394 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1395 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1396 | DCHECK(constant.IsConstant()); |
| 1397 | HConstant* cst = constant.GetConstant(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1398 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1399 | // 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] | 1400 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1401 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1402 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1403 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
| Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1406 | // Allocate a scratch register from the VIXL pool, querying first |
| 1407 | // the floating-point register pool, and then the core register |
| 1408 | // pool. This is essentially a reimplementation of |
| Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1409 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1410 | // using a different allocation strategy. |
| 1411 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1412 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1413 | int size_in_bits) { |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1414 | return masm->GetScratchVRegisterList()->IsEmpty() |
| Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1415 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1416 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1417 | } |
| 1418 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1419 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1420 | Location source, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1421 | DataType::Type dst_type) { |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1422 | if (source.Equals(destination)) { |
| 1423 | return; |
| 1424 | } |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1425 | |
| 1426 | // A valid move can always be inferred from the destination and source |
| 1427 | // locations. When moving from and to a register, the argument type can be |
| 1428 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1429 | // checks the coherency of the locations and the type. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1430 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1431 | |
| 1432 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1433 | if (unspecified_type) { |
| 1434 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1435 | if (source.IsStackSlot() || |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1436 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1437 | || src_cst->IsFloatConstant() |
| 1438 | || src_cst->IsNullConstant()))) { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1439 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1440 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1441 | } else { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1442 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1443 | // type is appropriate. Else the source is a register, and since the |
| 1444 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1445 | // move. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1446 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1447 | } |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1448 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1449 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1450 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1451 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1452 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1453 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1454 | __ Ldr(dst, StackOperandFrom(source)); |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1455 | } else if (source.IsSIMDStackSlot()) { |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1456 | GetInstructionCodeGeneratorArm64()->LoadSIMDRegFromStack(destination, source); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1457 | } else if (source.IsConstant()) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1458 | DCHECK(CoherentConstantAndType(source, dst_type)); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1459 | MoveConstant(dst, source.GetConstant()); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1460 | } else if (source.IsRegister()) { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1461 | if (destination.IsRegister()) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1462 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1463 | } else { |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1464 | DCHECK(destination.IsFpuRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1465 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1466 | ? DataType::Type::kInt64 |
| 1467 | : DataType::Type::kInt32; |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1468 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1469 | } |
| 1470 | } else { |
| 1471 | DCHECK(source.IsFpuRegister()); |
| 1472 | if (destination.IsRegister()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1473 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1474 | ? DataType::Type::kFloat64 |
| 1475 | : DataType::Type::kFloat32; |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1476 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1477 | } else { |
| 1478 | DCHECK(destination.IsFpuRegister()); |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1479 | if (GetGraph()->HasSIMD()) { |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1480 | GetInstructionCodeGeneratorArm64()->MoveSIMDRegToSIMDReg(destination, source); |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1481 | } else { |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1482 | __ Fmov(VRegister(dst), FPRegisterFrom(source, dst_type)); |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1483 | } |
| 1484 | } |
| 1485 | } |
| 1486 | } else if (destination.IsSIMDStackSlot()) { |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 1487 | GetInstructionCodeGeneratorArm64()->MoveToSIMDStackSlot(destination, source); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1488 | } else { // The destination is not a register. It must be a stack slot. |
| 1489 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1490 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1491 | if (unspecified_type) { |
| 1492 | if (source.IsRegister()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1493 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1494 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1495 | dst_type = |
| 1496 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1497 | } |
| 1498 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1499 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1500 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1501 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1502 | } else if (source.IsConstant()) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1503 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1504 | << source << " " << dst_type; |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1505 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1506 | HConstant* src_cst = source.GetConstant(); |
| 1507 | CPURegister temp; |
| Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1508 | if (src_cst->IsZeroBitPattern()) { |
| Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1509 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1510 | ? Register(xzr) |
| 1511 | : Register(wzr); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1512 | } else { |
| Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1513 | if (src_cst->IsIntConstant()) { |
| 1514 | temp = temps.AcquireW(); |
| 1515 | } else if (src_cst->IsLongConstant()) { |
| 1516 | temp = temps.AcquireX(); |
| 1517 | } else if (src_cst->IsFloatConstant()) { |
| 1518 | temp = temps.AcquireS(); |
| 1519 | } else { |
| 1520 | DCHECK(src_cst->IsDoubleConstant()); |
| 1521 | temp = temps.AcquireD(); |
| 1522 | } |
| 1523 | MoveConstant(temp, src_cst); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1524 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1525 | __ Str(temp, StackOperandFrom(destination)); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1526 | } else { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1527 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1528 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1529 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1530 | // Use any scratch register (a core or a floating-point one) |
| 1531 | // from VIXL scratch register pools as a temporary. |
| 1532 | // |
| 1533 | // We used to only use the FP scratch register pool, but in some |
| 1534 | // rare cases the only register from this pool (D31) would |
| 1535 | // already be used (e.g. within a ParallelMove instruction, when |
| 1536 | // a move is blocked by a another move requiring a scratch FP |
| 1537 | // register, which would reserve D31). To prevent this issue, we |
| 1538 | // ask for a scratch register of any type (core or FP). |
| Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1539 | // |
| 1540 | // 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] | 1541 | // demand of scratch core registers is higher. This is why we |
| Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1542 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1543 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1544 | // allocates core scratch registers first. |
| 1545 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1546 | GetVIXLAssembler(), |
| 1547 | &temps, |
| 1548 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1549 | __ Ldr(temp, StackOperandFrom(source)); |
| 1550 | __ Str(temp, StackOperandFrom(destination)); |
| 1551 | } |
| 1552 | } |
| 1553 | } |
| 1554 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1555 | void CodeGeneratorARM64::Load(DataType::Type type, |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1556 | CPURegister dst, |
| 1557 | const MemOperand& src) { |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1558 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1559 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1560 | case DataType::Type::kUint8: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1561 | __ Ldrb(Register(dst), src); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1562 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1563 | case DataType::Type::kInt8: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1564 | __ Ldrsb(Register(dst), src); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1565 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1566 | case DataType::Type::kUint16: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1567 | __ Ldrh(Register(dst), src); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1568 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1569 | case DataType::Type::kInt16: |
| 1570 | __ Ldrsh(Register(dst), src); |
| 1571 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1572 | case DataType::Type::kInt32: |
| 1573 | case DataType::Type::kReference: |
| 1574 | case DataType::Type::kInt64: |
| 1575 | case DataType::Type::kFloat32: |
| 1576 | case DataType::Type::kFloat64: |
| 1577 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1578 | __ Ldr(dst, src); |
| 1579 | break; |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1580 | case DataType::Type::kUint32: |
| 1581 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1582 | case DataType::Type::kVoid: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1583 | LOG(FATAL) << "Unreachable type " << type; |
| 1584 | } |
| 1585 | } |
| 1586 | |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1587 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1588 | CPURegister dst, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1589 | const MemOperand& src, |
| 1590 | bool needs_null_check) { |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1591 | MacroAssembler* masm = GetVIXLAssembler(); |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1592 | UseScratchRegisterScope temps(masm); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1593 | Register temp_base = temps.AcquireX(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1594 | DataType::Type type = instruction->GetType(); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1595 | |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1596 | DCHECK(!src.IsPreIndex()); |
| 1597 | DCHECK(!src.IsPostIndex()); |
| 1598 | |
| 1599 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1600 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1601 | { |
| 1602 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1603 | MemOperand base = MemOperand(temp_base); |
| 1604 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1605 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1606 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1607 | case DataType::Type::kInt8: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1608 | { |
| 1609 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1610 | __ ldarb(Register(dst), base); |
| 1611 | if (needs_null_check) { |
| 1612 | MaybeRecordImplicitNullCheck(instruction); |
| 1613 | } |
| 1614 | } |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1615 | if (type == DataType::Type::kInt8) { |
| 1616 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1617 | } |
| 1618 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1619 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1620 | case DataType::Type::kInt16: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1621 | { |
| 1622 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1623 | __ ldarh(Register(dst), base); |
| 1624 | if (needs_null_check) { |
| 1625 | MaybeRecordImplicitNullCheck(instruction); |
| 1626 | } |
| 1627 | } |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1628 | if (type == DataType::Type::kInt16) { |
| 1629 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 1630 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1631 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1632 | case DataType::Type::kInt32: |
| 1633 | case DataType::Type::kReference: |
| 1634 | case DataType::Type::kInt64: |
| 1635 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1636 | { |
| 1637 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1638 | __ ldar(Register(dst), base); |
| 1639 | if (needs_null_check) { |
| 1640 | MaybeRecordImplicitNullCheck(instruction); |
| 1641 | } |
| 1642 | } |
| 1643 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1644 | case DataType::Type::kFloat32: |
| 1645 | case DataType::Type::kFloat64: { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1646 | DCHECK(dst.IsFPRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1647 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1648 | |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1649 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1650 | { |
| 1651 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1652 | __ ldar(temp, base); |
| 1653 | if (needs_null_check) { |
| 1654 | MaybeRecordImplicitNullCheck(instruction); |
| 1655 | } |
| 1656 | } |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1657 | __ Fmov(VRegister(dst), temp); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1658 | break; |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1659 | } |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1660 | case DataType::Type::kUint32: |
| 1661 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1662 | case DataType::Type::kVoid: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1663 | LOG(FATAL) << "Unreachable type " << type; |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1664 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1665 | } |
| 1666 | } |
| 1667 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1668 | void CodeGeneratorARM64::Store(DataType::Type type, |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1669 | CPURegister src, |
| 1670 | const MemOperand& dst) { |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1671 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1672 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1673 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1674 | case DataType::Type::kInt8: |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1675 | __ Strb(Register(src), dst); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1676 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1677 | case DataType::Type::kUint16: |
| 1678 | case DataType::Type::kInt16: |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1679 | __ Strh(Register(src), dst); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1680 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1681 | case DataType::Type::kInt32: |
| 1682 | case DataType::Type::kReference: |
| 1683 | case DataType::Type::kInt64: |
| 1684 | case DataType::Type::kFloat32: |
| 1685 | case DataType::Type::kFloat64: |
| 1686 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1687 | __ Str(src, dst); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1688 | break; |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1689 | case DataType::Type::kUint32: |
| 1690 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1691 | case DataType::Type::kVoid: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1692 | LOG(FATAL) << "Unreachable type " << type; |
| 1693 | } |
| 1694 | } |
| 1695 | |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1696 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1697 | DataType::Type type, |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1698 | CPURegister src, |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1699 | const MemOperand& dst, |
| 1700 | bool needs_null_check) { |
| 1701 | MacroAssembler* masm = GetVIXLAssembler(); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1702 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1703 | Register temp_base = temps.AcquireX(); |
| 1704 | |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1705 | DCHECK(!dst.IsPreIndex()); |
| 1706 | DCHECK(!dst.IsPostIndex()); |
| 1707 | |
| 1708 | // TODO(vixl): Let the MacroAssembler handle this. |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1709 | Operand op = OperandFromMemOperand(dst); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1710 | __ Add(temp_base, dst.GetBaseRegister(), op); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1711 | MemOperand base = MemOperand(temp_base); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1712 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1713 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1714 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1715 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1716 | case DataType::Type::kInt8: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1717 | { |
| 1718 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1719 | __ stlrb(Register(src), base); |
| 1720 | if (needs_null_check) { |
| 1721 | MaybeRecordImplicitNullCheck(instruction); |
| 1722 | } |
| 1723 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1724 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1725 | case DataType::Type::kUint16: |
| 1726 | case DataType::Type::kInt16: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1727 | { |
| 1728 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1729 | __ stlrh(Register(src), base); |
| 1730 | if (needs_null_check) { |
| 1731 | MaybeRecordImplicitNullCheck(instruction); |
| 1732 | } |
| 1733 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1734 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1735 | case DataType::Type::kInt32: |
| 1736 | case DataType::Type::kReference: |
| 1737 | case DataType::Type::kInt64: |
| 1738 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1739 | { |
| 1740 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1741 | __ stlr(Register(src), base); |
| 1742 | if (needs_null_check) { |
| 1743 | MaybeRecordImplicitNullCheck(instruction); |
| 1744 | } |
| 1745 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1746 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1747 | case DataType::Type::kFloat32: |
| 1748 | case DataType::Type::kFloat64: { |
| 1749 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1750 | Register temp_src; |
| 1751 | if (src.IsZero()) { |
| 1752 | // The zero register is used to avoid synthesizing zero constants. |
| 1753 | temp_src = Register(src); |
| 1754 | } else { |
| 1755 | DCHECK(src.IsFPRegister()); |
| 1756 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 1757 | __ Fmov(temp_src, VRegister(src)); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1758 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1759 | { |
| 1760 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1761 | __ stlr(temp_src, base); |
| 1762 | if (needs_null_check) { |
| 1763 | MaybeRecordImplicitNullCheck(instruction); |
| 1764 | } |
| 1765 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1766 | break; |
| 1767 | } |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1768 | case DataType::Type::kUint32: |
| 1769 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1770 | case DataType::Type::kVoid: |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1771 | LOG(FATAL) << "Unreachable type " << type; |
| 1772 | } |
| 1773 | } |
| 1774 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1775 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1776 | HInstruction* instruction, |
| 1777 | uint32_t dex_pc, |
| 1778 | SlowPathCode* slow_path) { |
| Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1779 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1780 | |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1781 | ThreadOffset64 entrypoint_offset = GetThreadOffset<kArm64PointerSize>(entrypoint); |
| 1782 | // Reduce code size for AOT by using shared trampolines for slow path runtime calls across the |
| 1783 | // entire oat file. This adds an extra branch and we do not want to slow down the main path. |
| 1784 | // For JIT, thunk sharing is per-method, so the gains would be smaller or even negative. |
| 1785 | if (slow_path == nullptr || Runtime::Current()->UseJitCompilation()) { |
| 1786 | __ Ldr(lr, MemOperand(tr, entrypoint_offset.Int32Value())); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1787 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 1788 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1789 | __ blr(lr); |
| 1790 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1791 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1792 | } |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1793 | } else { |
| 1794 | // Ensure the pc position is recorded immediately after the `bl` instruction. |
| 1795 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1796 | EmitEntrypointThunkCall(entrypoint_offset); |
| 1797 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1798 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1799 | } |
| Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1800 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1803 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1804 | HInstruction* instruction, |
| 1805 | SlowPathCode* slow_path) { |
| 1806 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1807 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1808 | __ Blr(lr); |
| 1809 | } |
| 1810 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1811 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1812 | Register class_reg) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1813 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1814 | Register temp = temps.AcquireW(); |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1815 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| Vladimir Marko | 2bb44fe | 2019-10-04 12:28:14 +0100 | [diff] [blame] | 1816 | const size_t status_byte_offset = |
| 1817 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 1818 | constexpr uint32_t shifted_visibly_initialized_value = |
| 1819 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1820 | |
| Vladimir Marko | 2bb44fe | 2019-10-04 12:28:14 +0100 | [diff] [blame] | 1821 | // CMP (immediate) is limited to imm12 or imm12<<12, so we would need to materialize |
| 1822 | // the constant 0xf0000000 for comparison with the full 32-bit field. To reduce the code |
| 1823 | // size, load only the high byte of the field and compare with 0xf0. |
| 1824 | // Note: The same code size could be achieved with LDR+MNV(asr #24)+CBNZ but benchmarks |
| 1825 | // show that this pattern is slower (tested on little cores). |
| 1826 | __ Ldrb(temp, HeapOperand(class_reg, status_byte_offset)); |
| 1827 | __ Cmp(temp, shifted_visibly_initialized_value); |
| 1828 | __ B(lo, slow_path->GetEntryLabel()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1829 | __ Bind(slow_path->GetExitLabel()); |
| 1830 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1831 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 1832 | void InstructionCodeGeneratorARM64::GenerateBitstringTypeCheckCompare( |
| 1833 | HTypeCheckInstruction* check, vixl::aarch64::Register temp) { |
| 1834 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 1835 | uint32_t mask = check->GetBitstringMask(); |
| 1836 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 1837 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 1838 | |
| 1839 | if (mask_bits == 16u) { |
| 1840 | // Load only the bitstring part of the status word. |
| 1841 | __ Ldrh(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1842 | } else { |
| 1843 | // /* uint32_t */ temp = temp->status_ |
| 1844 | __ Ldr(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1845 | // Extract the bitstring bits. |
| 1846 | __ Ubfx(temp, temp, 0, mask_bits); |
| 1847 | } |
| 1848 | // Compare the bitstring bits to `path_to_root`. |
| 1849 | __ Cmp(temp, path_to_root); |
| 1850 | } |
| 1851 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1852 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1853 | BarrierType type = BarrierAll; |
| 1854 | |
| 1855 | switch (kind) { |
| 1856 | case MemBarrierKind::kAnyAny: |
| 1857 | case MemBarrierKind::kAnyStore: { |
| 1858 | type = BarrierAll; |
| 1859 | break; |
| 1860 | } |
| 1861 | case MemBarrierKind::kLoadAny: { |
| 1862 | type = BarrierReads; |
| 1863 | break; |
| 1864 | } |
| 1865 | case MemBarrierKind::kStoreStore: { |
| 1866 | type = BarrierWrites; |
| 1867 | break; |
| 1868 | } |
| 1869 | default: |
| 1870 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1871 | } |
| 1872 | __ Dmb(InnerShareable, type); |
| 1873 | } |
| 1874 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1875 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1876 | HBasicBlock* successor) { |
| 1877 | SuspendCheckSlowPathARM64* slow_path = |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1878 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1879 | if (slow_path == nullptr) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1880 | slow_path = |
| 1881 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1882 | instruction->SetSlowPath(slow_path); |
| 1883 | codegen_->AddSlowPath(slow_path); |
| 1884 | if (successor != nullptr) { |
| 1885 | DCHECK(successor->IsLoopHeader()); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1886 | } |
| 1887 | } else { |
| 1888 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1889 | } |
| 1890 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1891 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1892 | Register temp = temps.AcquireW(); |
| 1893 | |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1894 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1895 | if (successor == nullptr) { |
| 1896 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1897 | __ Bind(slow_path->GetReturnLabel()); |
| 1898 | } else { |
| 1899 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1900 | __ B(slow_path->GetEntryLabel()); |
| 1901 | // slow_path will return to GetLabelOf(successor). |
| 1902 | } |
| 1903 | } |
| 1904 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1905 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1906 | CodeGeneratorARM64* codegen) |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1907 | : InstructionCodeGenerator(graph, codegen), |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1908 | assembler_(codegen->GetAssembler()), |
| 1909 | codegen_(codegen) {} |
| 1910 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1911 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1912 | DCHECK_EQ(instr->InputCount(), 2U); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1913 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1914 | DataType::Type type = instr->GetResultType(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1915 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1916 | case DataType::Type::kInt32: |
| 1917 | case DataType::Type::kInt64: |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1918 | locations->SetInAt(0, Location::RequiresRegister()); |
| Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1919 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1920 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1921 | break; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1922 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1923 | case DataType::Type::kFloat32: |
| 1924 | case DataType::Type::kFloat64: |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1925 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1926 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1927 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1928 | break; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1929 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1930 | default: |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1931 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1932 | } |
| 1933 | } |
| 1934 | |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1935 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 1936 | const FieldInfo& field_info) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1937 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1938 | |
| 1939 | bool object_field_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1940 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1941 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1942 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 1943 | object_field_get_with_read_barrier |
| 1944 | ? LocationSummary::kCallOnSlowPath |
| 1945 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1946 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1947 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1948 | // We need a temporary register for the read barrier load in |
| 1949 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 1950 | // only if the field is volatile or the offset is too big. |
| 1951 | if (field_info.IsVolatile() || |
| 1952 | field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 1953 | locations->AddTemp(FixedTempLocation()); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1954 | } |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1955 | } |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1956 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1957 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1958 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1959 | } else { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1960 | // The output overlaps for an object field get when read barriers |
| 1961 | // are enabled: we do not want the load to overwrite the object's |
| 1962 | // location, as we need it to emit the read barrier. |
| 1963 | locations->SetOut( |
| 1964 | Location::RequiresRegister(), |
| 1965 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1966 | } |
| 1967 | } |
| 1968 | |
| 1969 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 1970 | const FieldInfo& field_info) { |
| 1971 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1972 | LocationSummary* locations = instruction->GetLocations(); |
| 1973 | Location base_loc = locations->InAt(0); |
| 1974 | Location out = locations->Out(); |
| 1975 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 1976 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 1977 | DataType::Type load_type = instruction->GetType(); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1978 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1979 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1980 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 1981 | load_type == DataType::Type::kReference) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1982 | // Object FieldGet with Baker's read barrier case. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1983 | // /* HeapReference<Object> */ out = *(base + offset) |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1984 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1985 | Location maybe_temp = |
| 1986 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1987 | // Note that potential implicit null checks are handled in this |
| 1988 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 1989 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1990 | instruction, |
| 1991 | out, |
| 1992 | base, |
| 1993 | offset, |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1994 | maybe_temp, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1995 | /* needs_null_check= */ true, |
| Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1996 | field_info.IsVolatile()); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1997 | } else { |
| 1998 | // General case. |
| 1999 | if (field_info.IsVolatile()) { |
| Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2000 | // Note that a potential implicit null check is handled in this |
| 2001 | // CodeGeneratorARM64::LoadAcquire call. |
| 2002 | // NB: LoadAcquire will record the pc info if needed. |
| 2003 | codegen_->LoadAcquire( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2004 | instruction, OutputCPURegister(instruction), field, /* needs_null_check= */ true); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2005 | } else { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2006 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2007 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2008 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2009 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2010 | } |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2011 | if (load_type == DataType::Type::kReference) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2012 | // If read barriers are enabled, emit read barriers other than |
| 2013 | // Baker's using a slow path (and also unpoison the loaded |
| 2014 | // reference, if heap poisoning is enabled). |
| 2015 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2016 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2017 | } |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2021 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2022 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2023 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2024 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2025 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2026 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2027 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2028 | } else { |
| 2029 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2034 | const FieldInfo& field_info, |
| 2035 | bool value_can_be_null) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2036 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2037 | |
| 2038 | Register obj = InputRegisterAt(instruction, 0); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2039 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2040 | CPURegister source = value; |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2041 | Offset offset = field_info.GetFieldOffset(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2042 | DataType::Type field_type = field_info.GetFieldType(); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2043 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2044 | { |
| 2045 | // We use a block to end the scratch scope before the write barrier, thus |
| 2046 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2047 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2048 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2049 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2050 | DCHECK(value.IsW()); |
| 2051 | Register temp = temps.AcquireW(); |
| 2052 | __ Mov(temp, value.W()); |
| 2053 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2054 | source = temp; |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2055 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2056 | |
| 2057 | if (field_info.IsVolatile()) { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2058 | codegen_->StoreRelease( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2059 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check= */ true); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2060 | } else { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2061 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2062 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2063 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2064 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2065 | } |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2069 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2070 | } |
| 2071 | } |
| 2072 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2073 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2074 | DataType::Type type = instr->GetType(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2075 | |
| 2076 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2077 | case DataType::Type::kInt32: |
| 2078 | case DataType::Type::kInt64: { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2079 | Register dst = OutputRegister(instr); |
| 2080 | Register lhs = InputRegisterAt(instr, 0); |
| 2081 | Operand rhs = InputOperandAt(instr, 1); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2082 | if (instr->IsAdd()) { |
| 2083 | __ Add(dst, lhs, rhs); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2084 | } else if (instr->IsAnd()) { |
| 2085 | __ And(dst, lhs, rhs); |
| 2086 | } else if (instr->IsOr()) { |
| 2087 | __ Orr(dst, lhs, rhs); |
| 2088 | } else if (instr->IsSub()) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2089 | __ Sub(dst, lhs, rhs); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2090 | } else if (instr->IsRor()) { |
| 2091 | if (rhs.IsImmediate()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2092 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2093 | __ Ror(dst, lhs, shift); |
| 2094 | } else { |
| 2095 | // Ensure shift distance is in the same size register as the result. If |
| 2096 | // we are rotating a long and the shift comes in a w register originally, |
| 2097 | // we don't need to sxtw for use as an x since the shift distances are |
| 2098 | // all & reg_bits - 1. |
| 2099 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2100 | } |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2101 | } else if (instr->IsMin() || instr->IsMax()) { |
| 2102 | __ Cmp(lhs, rhs); |
| 2103 | __ Csel(dst, lhs, rhs, instr->IsMin() ? lt : gt); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2104 | } else { |
| 2105 | DCHECK(instr->IsXor()); |
| 2106 | __ Eor(dst, lhs, rhs); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2107 | } |
| 2108 | break; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2109 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2110 | case DataType::Type::kFloat32: |
| 2111 | case DataType::Type::kFloat64: { |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 2112 | VRegister dst = OutputFPRegister(instr); |
| 2113 | VRegister lhs = InputFPRegisterAt(instr, 0); |
| 2114 | VRegister rhs = InputFPRegisterAt(instr, 1); |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2115 | if (instr->IsAdd()) { |
| 2116 | __ Fadd(dst, lhs, rhs); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2117 | } else if (instr->IsSub()) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2118 | __ Fsub(dst, lhs, rhs); |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2119 | } else if (instr->IsMin()) { |
| 2120 | __ Fmin(dst, lhs, rhs); |
| 2121 | } else if (instr->IsMax()) { |
| 2122 | __ Fmax(dst, lhs, rhs); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2123 | } else { |
| 2124 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2125 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2126 | break; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2127 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2128 | default: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2129 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2130 | } |
| 2131 | } |
| 2132 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2133 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2134 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2135 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2136 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2137 | DataType::Type type = instr->GetResultType(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2138 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2139 | case DataType::Type::kInt32: |
| 2140 | case DataType::Type::kInt64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2141 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2142 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2143 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2144 | break; |
| 2145 | } |
| 2146 | default: |
| 2147 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2152 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2153 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2154 | DataType::Type type = instr->GetType(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2155 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2156 | case DataType::Type::kInt32: |
| 2157 | case DataType::Type::kInt64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2158 | Register dst = OutputRegister(instr); |
| 2159 | Register lhs = InputRegisterAt(instr, 0); |
| 2160 | Operand rhs = InputOperandAt(instr, 1); |
| 2161 | if (rhs.IsImmediate()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2162 | uint32_t shift_value = rhs.GetImmediate() & |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2163 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2164 | if (instr->IsShl()) { |
| 2165 | __ Lsl(dst, lhs, shift_value); |
| 2166 | } else if (instr->IsShr()) { |
| 2167 | __ Asr(dst, lhs, shift_value); |
| 2168 | } else { |
| 2169 | __ Lsr(dst, lhs, shift_value); |
| 2170 | } |
| 2171 | } else { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2172 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2173 | |
| 2174 | if (instr->IsShl()) { |
| 2175 | __ Lsl(dst, lhs, rhs_reg); |
| 2176 | } else if (instr->IsShr()) { |
| 2177 | __ Asr(dst, lhs, rhs_reg); |
| 2178 | } else { |
| 2179 | __ Lsr(dst, lhs, rhs_reg); |
| 2180 | } |
| 2181 | } |
| 2182 | break; |
| 2183 | } |
| 2184 | default: |
| 2185 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2186 | } |
| 2187 | } |
| 2188 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2189 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2190 | HandleBinaryOp(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2191 | } |
| 2192 | |
| 2193 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2194 | HandleBinaryOp(instruction); |
| 2195 | } |
| 2196 | |
| 2197 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2198 | HandleBinaryOp(instruction); |
| 2199 | } |
| 2200 | |
| 2201 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2202 | HandleBinaryOp(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2203 | } |
| 2204 | |
| Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2205 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2206 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2207 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
| Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2208 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2209 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2210 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2211 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2212 | } |
| 2213 | |
| Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2214 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
| Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2215 | Register dst = OutputRegister(instr); |
| 2216 | Register lhs = InputRegisterAt(instr, 0); |
| 2217 | Register rhs = InputRegisterAt(instr, 1); |
| 2218 | |
| 2219 | switch (instr->GetOpKind()) { |
| 2220 | case HInstruction::kAnd: |
| 2221 | __ Bic(dst, lhs, rhs); |
| 2222 | break; |
| 2223 | case HInstruction::kOr: |
| 2224 | __ Orn(dst, lhs, rhs); |
| 2225 | break; |
| 2226 | case HInstruction::kXor: |
| 2227 | __ Eon(dst, lhs, rhs); |
| 2228 | break; |
| 2229 | default: |
| 2230 | LOG(FATAL) << "Unreachable"; |
| 2231 | } |
| 2232 | } |
| 2233 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2234 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2235 | HDataProcWithShifterOp* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2236 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2237 | instruction->GetType() == DataType::Type::kInt64); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2238 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2239 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2240 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2241 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2242 | } else { |
| 2243 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2244 | } |
| 2245 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2246 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2247 | } |
| 2248 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2249 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2250 | HDataProcWithShifterOp* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2251 | DataType::Type type = instruction->GetType(); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2252 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2253 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2254 | Register out = OutputRegister(instruction); |
| 2255 | Register left; |
| 2256 | if (kind != HInstruction::kNeg) { |
| 2257 | left = InputRegisterAt(instruction, 0); |
| 2258 | } |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2259 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2260 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2261 | // conversion) can have a different type from the current instruction's type, |
| 2262 | // so we manually indicate the type. |
| 2263 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2264 | Operand right_operand(0); |
| 2265 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2266 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2267 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2268 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2269 | } else { |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2270 | right_operand = Operand(right_reg, |
| 2271 | helpers::ShiftFromOpKind(op_kind), |
| 2272 | instruction->GetShiftAmount()); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | // Logical binary operations do not support extension operations in the |
| 2276 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2277 | // the extension as a separate instruction. |
| 2278 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2279 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2280 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2281 | kind != HInstruction::kNeg)); |
| 2282 | switch (kind) { |
| 2283 | case HInstruction::kAdd: |
| 2284 | __ Add(out, left, right_operand); |
| 2285 | break; |
| 2286 | case HInstruction::kAnd: |
| 2287 | __ And(out, left, right_operand); |
| 2288 | break; |
| 2289 | case HInstruction::kNeg: |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2290 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2291 | __ Neg(out, right_operand); |
| 2292 | break; |
| 2293 | case HInstruction::kOr: |
| 2294 | __ Orr(out, left, right_operand); |
| 2295 | break; |
| 2296 | case HInstruction::kSub: |
| 2297 | __ Sub(out, left, right_operand); |
| 2298 | break; |
| 2299 | case HInstruction::kXor: |
| 2300 | __ Eor(out, left, right_operand); |
| 2301 | break; |
| 2302 | default: |
| 2303 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2304 | UNREACHABLE(); |
| 2305 | } |
| 2306 | } |
| 2307 | |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2308 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2309 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2310 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2311 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2312 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
| Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2313 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2314 | } |
| 2315 | |
| Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2316 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2317 | __ Add(OutputRegister(instruction), |
| 2318 | InputRegisterAt(instruction, 0), |
| 2319 | Operand(InputOperandAt(instruction, 1))); |
| 2320 | } |
| 2321 | |
| Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2322 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2323 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2324 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2325 | |
| 2326 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2327 | |
| 2328 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2329 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2330 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2331 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2332 | // loop. |
| 2333 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2334 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2335 | : Location::RequiresRegister()); |
| 2336 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2337 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2338 | } |
| 2339 | |
| 2340 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2341 | HIntermediateAddressIndex* instruction) { |
| 2342 | Register index_reg = InputRegisterAt(instruction, 0); |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2343 | uint32_t shift = Int64FromLocation(instruction->GetLocations()->InAt(2)); |
| Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2344 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2345 | |
| 2346 | if (shift == 0) { |
| 2347 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2348 | } else { |
| 2349 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2350 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2351 | } |
| 2352 | } |
| 2353 | |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2354 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2355 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2356 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2357 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2358 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2359 | accumulator->IsConstant() && |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2360 | accumulator->AsConstant()->IsArithmeticZero()) { |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2361 | // Don't allocate register for Mneg instruction. |
| 2362 | } else { |
| 2363 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2364 | Location::RequiresRegister()); |
| 2365 | } |
| 2366 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2367 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2368 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2369 | } |
| 2370 | |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2371 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2372 | Register res = OutputRegister(instr); |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2373 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2374 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2375 | |
| 2376 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2377 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2378 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2379 | if (instr->GetType() == DataType::Type::kInt64 && |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2380 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2381 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2382 | vixl::aarch64::Instruction* prev = |
| 2383 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2384 | if (prev->IsLoadOrStore()) { |
| 2385 | // Make sure we emit only exactly one nop. |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2386 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2387 | __ nop(); |
| 2388 | } |
| 2389 | } |
| 2390 | |
| 2391 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2392 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2393 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2394 | } else { |
| 2395 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2396 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2397 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2398 | __ Mneg(res, mul_left, mul_right); |
| 2399 | } else { |
| 2400 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2401 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2402 | } |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2403 | } |
| 2404 | } |
| 2405 | |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2406 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2407 | bool object_array_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2408 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2409 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2410 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2411 | object_array_get_with_read_barrier |
| 2412 | ? LocationSummary::kCallOnSlowPath |
| 2413 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2414 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2415 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2416 | if (instruction->GetIndex()->IsConstant()) { |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2417 | // Array loads with constant index are treated as field loads. |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2418 | // We need a temporary register for the read barrier load in |
| 2419 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2420 | // only if the offset is too big. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2421 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2422 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2423 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2424 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2425 | locations->AddTemp(FixedTempLocation()); |
| 2426 | } |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2427 | } else if (!instruction->GetArray()->IsIntermediateAddress()) { |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2428 | // We need a non-scratch temporary for the array data pointer in |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2429 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier() for the case with no |
| 2430 | // intermediate address. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2431 | locations->AddTemp(Location::RequiresRegister()); |
| 2432 | } |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2433 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2434 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2435 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2436 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2437 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2438 | } else { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2439 | // The output overlaps in the case of an object array get with |
| 2440 | // read barriers enabled: we do not want the move to overwrite the |
| 2441 | // array's location, as we need it to emit the read barrier. |
| 2442 | locations->SetOut( |
| 2443 | Location::RequiresRegister(), |
| 2444 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2445 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2449 | DataType::Type type = instruction->GetType(); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2450 | Register obj = InputRegisterAt(instruction, 0); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2451 | LocationSummary* locations = instruction->GetLocations(); |
| 2452 | Location index = locations->InAt(1); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2453 | Location out = locations->Out(); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2454 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2455 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2456 | instruction->IsStringCharAt(); |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2457 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2458 | UseScratchRegisterScope temps(masm); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2459 | |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2460 | // The non-Baker read barrier instrumentation of object ArrayGet instructions |
| Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2461 | // does not support the HIntermediateAddress instruction. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2462 | DCHECK(!((type == DataType::Type::kReference) && |
| Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2463 | instruction->GetArray()->IsIntermediateAddress() && |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2464 | kEmitCompilerReadBarrier && |
| 2465 | !kUseBakerReadBarrier)); |
| Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2466 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2467 | if (type == DataType::Type::kReference && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2468 | // Object ArrayGet with Baker's read barrier case. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2469 | // Note that a potential implicit null check is handled in the |
| 2470 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2471 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2472 | if (index.IsConstant()) { |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2473 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2474 | // 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] | 2475 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2476 | Location maybe_temp = |
| 2477 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2478 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2479 | out, |
| 2480 | obj.W(), |
| 2481 | offset, |
| 2482 | maybe_temp, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2483 | /* needs_null_check= */ false, |
| 2484 | /* use_load_acquire= */ false); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2485 | } else { |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2486 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2487 | instruction, out, obj.W(), offset, index, /* needs_null_check= */ false); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2488 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2489 | } else { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2490 | // General case. |
| 2491 | MemOperand source = HeapOperand(obj); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2492 | Register length; |
| 2493 | if (maybe_compressed_char_at) { |
| 2494 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2495 | length = temps.AcquireW(); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2496 | { |
| 2497 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2498 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2499 | |
| 2500 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2501 | DCHECK_LT(count_offset, offset); |
| 2502 | int64_t adjusted_offset = |
| 2503 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2504 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2505 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2506 | } else { |
| 2507 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2508 | } |
| 2509 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2510 | } |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2511 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2512 | if (index.IsConstant()) { |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2513 | if (maybe_compressed_char_at) { |
| 2514 | vixl::aarch64::Label uncompressed_load, done; |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2515 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2516 | "Expecting 0=compressed, 1=uncompressed"); |
| 2517 | __ Tbnz(length.W(), 0, &uncompressed_load); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2518 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2519 | HeapOperand(obj, offset + Int64FromLocation(index))); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2520 | __ B(&done); |
| 2521 | __ Bind(&uncompressed_load); |
| 2522 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2523 | HeapOperand(obj, offset + (Int64FromLocation(index) << 1))); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2524 | __ Bind(&done); |
| 2525 | } else { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2526 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2527 | source = HeapOperand(obj, offset); |
| 2528 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2529 | } else { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2530 | Register temp = temps.AcquireSameSizeAs(obj); |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2531 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2532 | // We do not need to compute the intermediate address from the array: the |
| 2533 | // input instruction has done it already. See the comment in |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2534 | // `TryExtractArrayAccessAddress()`. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2535 | if (kIsDebugBuild) { |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2536 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2537 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2538 | } |
| 2539 | temp = obj; |
| 2540 | } else { |
| 2541 | __ Add(temp, obj, offset); |
| 2542 | } |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2543 | if (maybe_compressed_char_at) { |
| 2544 | vixl::aarch64::Label uncompressed_load, done; |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2545 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2546 | "Expecting 0=compressed, 1=uncompressed"); |
| 2547 | __ Tbnz(length.W(), 0, &uncompressed_load); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2548 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2549 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2550 | __ B(&done); |
| 2551 | __ Bind(&uncompressed_load); |
| 2552 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2553 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2554 | __ Bind(&done); |
| 2555 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2556 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2557 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2558 | } |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2559 | if (!maybe_compressed_char_at) { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2560 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2561 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2562 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2563 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2564 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2565 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2566 | if (type == DataType::Type::kReference) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2567 | static_assert( |
| 2568 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2569 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2570 | Location obj_loc = locations->InAt(0); |
| 2571 | if (index.IsConstant()) { |
| 2572 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2573 | } else { |
| 2574 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2575 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2576 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2577 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2578 | } |
| 2579 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2580 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2581 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2582 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2583 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2587 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2588 | vixl::aarch64::Register out = OutputRegister(instruction); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2589 | { |
| 2590 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2591 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2592 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2593 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2594 | } |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2595 | // Mask out compression flag from String's array length. |
| 2596 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2597 | __ Lsr(out.W(), out.W(), 1u); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2598 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2599 | } |
| 2600 | |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2601 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2602 | DataType::Type value_type = instruction->GetComponentType(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2603 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2604 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2605 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2606 | instruction, |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2607 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2608 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2609 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2610 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2611 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2612 | } else if (DataType::IsFloatingPointType(value_type)) { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2613 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2614 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2615 | locations->SetInAt(2, Location::RequiresRegister()); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2620 | DataType::Type value_type = instruction->GetComponentType(); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2621 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2622 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2623 | bool needs_write_barrier = |
| 2624 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2625 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2626 | Register array = InputRegisterAt(instruction, 0); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2627 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2628 | CPURegister source = value; |
| 2629 | Location index = locations->InAt(1); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2630 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2631 | MemOperand destination = HeapOperand(array); |
| 2632 | MacroAssembler* masm = GetVIXLAssembler(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2633 | |
| 2634 | if (!needs_write_barrier) { |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2635 | DCHECK(!needs_type_check); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2636 | if (index.IsConstant()) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2637 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2638 | destination = HeapOperand(array, offset); |
| 2639 | } else { |
| 2640 | UseScratchRegisterScope temps(masm); |
| 2641 | Register temp = temps.AcquireSameSizeAs(array); |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2642 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2643 | // We do not need to compute the intermediate address from the array: the |
| 2644 | // input instruction has done it already. See the comment in |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2645 | // `TryExtractArrayAccessAddress()`. |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2646 | if (kIsDebugBuild) { |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2647 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2648 | DCHECK(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2649 | } |
| 2650 | temp = array; |
| 2651 | } else { |
| 2652 | __ Add(temp, array, offset); |
| 2653 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2654 | destination = HeapOperand(temp, |
| 2655 | XRegisterFrom(index), |
| 2656 | LSL, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2657 | DataType::SizeShift(value_type)); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2658 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2659 | { |
| 2660 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2661 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2662 | codegen_->Store(value_type, value, destination); |
| 2663 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2664 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2665 | } else { |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2666 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2667 | |
| 2668 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 2669 | vixl::aarch64::Label do_store; |
| 2670 | if (can_value_be_null) { |
| 2671 | __ Cbz(Register(value), &do_store); |
| 2672 | } |
| 2673 | |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2674 | SlowPathCodeARM64* slow_path = nullptr; |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2675 | if (needs_type_check) { |
| 2676 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
| 2677 | codegen_->AddSlowPath(slow_path); |
| 2678 | |
| 2679 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2680 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2681 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2682 | |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2683 | UseScratchRegisterScope temps(masm); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2684 | Register temp = temps.AcquireSameSizeAs(array); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2685 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2686 | |
| 2687 | // Note that when Baker read barriers are enabled, the type |
| 2688 | // checks are performed without read barriers. This is fine, |
| 2689 | // even in the case where a class object is in the from-space |
| 2690 | // after the flip, as a comparison involving such a type would |
| 2691 | // not produce a false positive; it may of course produce a |
| 2692 | // false negative, in which case we would take the ArraySet |
| 2693 | // slow path. |
| 2694 | |
| 2695 | // /* HeapReference<Class> */ temp = array->klass_ |
| 2696 | { |
| 2697 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2698 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2699 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2700 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2701 | } |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2702 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2703 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2704 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2705 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2706 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2707 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2708 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2709 | // nor `temp2`, as we are comparing two poisoned references. |
| 2710 | __ Cmp(temp, temp2); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2711 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2712 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2713 | vixl::aarch64::Label do_put; |
| 2714 | __ B(eq, &do_put); |
| 2715 | // If heap poisoning is enabled, the `temp` reference has |
| 2716 | // not been unpoisoned yet; unpoison it now. |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2717 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2718 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2719 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2720 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2721 | // If heap poisoning is enabled, no need to unpoison |
| 2722 | // `temp`, as we are comparing against null below. |
| 2723 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2724 | __ Bind(&do_put); |
| Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 2725 | } else { |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2726 | __ B(ne, slow_path->GetEntryLabel()); |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2727 | } |
| 2728 | } |
| 2729 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2730 | codegen_->MarkGCCard(array, value.W(), /* value_can_be_null= */ false); |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2731 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 2732 | if (can_value_be_null) { |
| 2733 | DCHECK(do_store.IsLinked()); |
| 2734 | __ Bind(&do_store); |
| 2735 | } |
| 2736 | |
| 2737 | UseScratchRegisterScope temps(masm); |
| 2738 | if (kPoisonHeapReferences) { |
| 2739 | Register temp_source = temps.AcquireSameSizeAs(array); |
| 2740 | DCHECK(value.IsW()); |
| 2741 | __ Mov(temp_source, value.W()); |
| 2742 | GetAssembler()->PoisonHeapReference(temp_source); |
| 2743 | source = temp_source; |
| 2744 | } |
| 2745 | |
| 2746 | if (index.IsConstant()) { |
| 2747 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
| 2748 | destination = HeapOperand(array, offset); |
| 2749 | } else { |
| 2750 | Register temp_base = temps.AcquireSameSizeAs(array); |
| 2751 | __ Add(temp_base, array, offset); |
| 2752 | destination = HeapOperand(temp_base, |
| 2753 | XRegisterFrom(index), |
| 2754 | LSL, |
| 2755 | DataType::SizeShift(value_type)); |
| 2756 | } |
| 2757 | |
| 2758 | { |
| 2759 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2760 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2761 | __ Str(source, destination); |
| 2762 | |
| 2763 | if (can_value_be_null || !needs_type_check) { |
| 2764 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2765 | } |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | if (slow_path != nullptr) { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2769 | __ Bind(slow_path->GetExitLabel()); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2770 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2771 | } |
| 2772 | } |
| 2773 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2774 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2775 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2776 | InvokeRuntimeCallingConvention calling_convention; |
| 2777 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 2778 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 2779 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2780 | |
| 2781 | // If both index and length are constant, we can check the bounds statically and |
| 2782 | // generate code accordingly. We want to make sure we generate constant locations |
| 2783 | // in that case, regardless of whether they are encodable in the comparison or not. |
| 2784 | HInstruction* index = instruction->InputAt(0); |
| 2785 | HInstruction* length = instruction->InputAt(1); |
| 2786 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 2787 | locations->SetInAt(0, both_const |
| 2788 | ? Location::ConstantLocation(index->AsConstant()) |
| 2789 | : ARM64EncodableConstantOrRegister(index, instruction)); |
| 2790 | locations->SetInAt(1, both_const |
| 2791 | ? Location::ConstantLocation(length->AsConstant()) |
| 2792 | : ARM64EncodableConstantOrRegister(length, instruction)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2793 | } |
| 2794 | |
| 2795 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2796 | LocationSummary* locations = instruction->GetLocations(); |
| 2797 | Location index_loc = locations->InAt(0); |
| 2798 | Location length_loc = locations->InAt(1); |
| 2799 | |
| 2800 | int cmp_first_input = 0; |
| 2801 | int cmp_second_input = 1; |
| 2802 | Condition cond = hs; |
| 2803 | |
| 2804 | if (index_loc.IsConstant()) { |
| 2805 | int64_t index = Int64FromLocation(index_loc); |
| 2806 | if (length_loc.IsConstant()) { |
| 2807 | int64_t length = Int64FromLocation(length_loc); |
| 2808 | if (index < 0 || index >= length) { |
| 2809 | BoundsCheckSlowPathARM64* slow_path = |
| 2810 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
| 2811 | codegen_->AddSlowPath(slow_path); |
| 2812 | __ B(slow_path->GetEntryLabel()); |
| 2813 | } else { |
| 2814 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 2815 | // However, some optimization after BCE may have generated this, and we should not |
| 2816 | // generate a bounds check if it is a valid range. |
| 2817 | } |
| 2818 | return; |
| 2819 | } |
| 2820 | // Only the index is constant: change the order of the operands and commute the condition |
| 2821 | // so we can use an immediate constant for the index (only the second input to a cmp |
| 2822 | // instruction can be an immediate). |
| 2823 | cmp_first_input = 1; |
| 2824 | cmp_second_input = 0; |
| 2825 | cond = ls; |
| 2826 | } |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2827 | BoundsCheckSlowPathARM64* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2828 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
| Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2829 | __ Cmp(InputRegisterAt(instruction, cmp_first_input), |
| 2830 | InputOperandAt(instruction, cmp_second_input)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2831 | codegen_->AddSlowPath(slow_path); |
| Georgia Kouveli | be53085 | 2019-01-17 10:46:41 +0000 | [diff] [blame] | 2832 | __ B(slow_path->GetEntryLabel(), cond); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2833 | } |
| 2834 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2835 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2836 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2837 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2838 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2839 | if (check->HasUses()) { |
| 2840 | locations->SetOut(Location::SameAsFirstInput()); |
| 2841 | } |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 2842 | // Rely on the type initialization to save everything we need. |
| 2843 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2847 | // We assume the class is not null. |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 2848 | SlowPathCodeARM64* slow_path = |
| 2849 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(check->GetLoadClass(), check); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2850 | codegen_->AddSlowPath(slow_path); |
| 2851 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2852 | } |
| 2853 | |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2854 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2855 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2856 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2857 | } |
| 2858 | |
| 2859 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 2860 | VRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2861 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2862 | if (rhs_loc.IsConstant()) { |
| 2863 | // 0.0 is the only immediate that can be encoded directly in |
| 2864 | // an FCMP instruction. |
| 2865 | // |
| 2866 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2867 | // specify that in a floating-point comparison, positive zero |
| 2868 | // and negative zero are considered equal, so we can use the |
| 2869 | // literal 0.0 for both cases here. |
| 2870 | // |
| 2871 | // Note however that some methods (Float.equal, Float.compare, |
| 2872 | // Float.compareTo, Double.equal, Double.compare, |
| 2873 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2874 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2875 | // -0.0. So if we ever translate calls to these methods into a |
| 2876 | // HCompare instruction, we must handle the -0.0 case with |
| 2877 | // care here. |
| 2878 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2879 | __ Fcmp(lhs_reg, 0.0); |
| 2880 | } else { |
| 2881 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2882 | } |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2885 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2886 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2887 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2888 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2889 | switch (in_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2890 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2891 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2892 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2893 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2894 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2895 | case DataType::Type::kInt32: |
| 2896 | case DataType::Type::kInt64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2897 | locations->SetInAt(0, Location::RequiresRegister()); |
| Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2898 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2899 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2900 | break; |
| 2901 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2902 | case DataType::Type::kFloat32: |
| 2903 | case DataType::Type::kFloat64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2904 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2905 | locations->SetInAt(1, |
| 2906 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2907 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2908 | : Location::RequiresFpuRegister()); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2909 | locations->SetOut(Location::RequiresRegister()); |
| 2910 | break; |
| 2911 | } |
| 2912 | default: |
| 2913 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2914 | } |
| 2915 | } |
| 2916 | |
| 2917 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2918 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2919 | |
| 2920 | // 0 if: left == right |
| 2921 | // 1 if: left > right |
| 2922 | // -1 if: left < right |
| 2923 | switch (in_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2924 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2925 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2926 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2927 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2928 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2929 | case DataType::Type::kInt32: |
| 2930 | case DataType::Type::kInt64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2931 | Register result = OutputRegister(compare); |
| 2932 | Register left = InputRegisterAt(compare, 0); |
| 2933 | Operand right = InputOperandAt(compare, 1); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2934 | __ Cmp(left, right); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2935 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 2936 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2937 | break; |
| 2938 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2939 | case DataType::Type::kFloat32: |
| 2940 | case DataType::Type::kFloat64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2941 | Register result = OutputRegister(compare); |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2942 | GenerateFcmp(compare); |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2943 | __ Cset(result, ne); |
| 2944 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2945 | break; |
| 2946 | } |
| 2947 | default: |
| 2948 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2949 | } |
| 2950 | } |
| 2951 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2952 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2953 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2954 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2955 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2956 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2957 | locations->SetInAt(1, |
| 2958 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 2959 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 2960 | : Location::RequiresFpuRegister()); |
| 2961 | } else { |
| 2962 | // Integer cases. |
| 2963 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2964 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 2965 | } |
| 2966 | |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2967 | if (!instruction->IsEmittedAtUseSite()) { |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2968 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2969 | } |
| 2970 | } |
| 2971 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2972 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2973 | if (instruction->IsEmittedAtUseSite()) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2974 | return; |
| 2975 | } |
| 2976 | |
| 2977 | LocationSummary* locations = instruction->GetLocations(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2978 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2979 | IfCondition if_cond = instruction->GetCondition(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2980 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2981 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2982 | GenerateFcmp(instruction); |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2983 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2984 | } else { |
| 2985 | // Integer cases. |
| 2986 | Register lhs = InputRegisterAt(instruction, 0); |
| 2987 | Operand rhs = InputOperandAt(instruction, 1); |
| 2988 | __ Cmp(lhs, rhs); |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2989 | __ Cset(res, ARM64Condition(if_cond)); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2990 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2991 | } |
| 2992 | |
| 2993 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 2994 | M(Equal) \ |
| 2995 | M(NotEqual) \ |
| 2996 | M(LessThan) \ |
| 2997 | M(LessThanOrEqual) \ |
| 2998 | M(GreaterThan) \ |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2999 | M(GreaterThanOrEqual) \ |
| 3000 | M(Below) \ |
| 3001 | M(BelowOrEqual) \ |
| 3002 | M(Above) \ |
| 3003 | M(AboveOrEqual) |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3004 | #define DEFINE_CONDITION_VISITORS(Name) \ |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3005 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3006 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3007 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3008 | #undef DEFINE_CONDITION_VISITORS |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3009 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3010 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3011 | void InstructionCodeGeneratorARM64::GenerateIntDivForPower2Denom(HDiv* instruction) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3012 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3013 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3014 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 3015 | |
| 3016 | Register out = OutputRegister(instruction); |
| 3017 | Register dividend = InputRegisterAt(instruction, 0); |
| Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3018 | |
| 3019 | if (abs_imm == 2) { |
| 3020 | int bits = DataType::Size(instruction->GetResultType()) * kBitsPerByte; |
| 3021 | __ Add(out, dividend, Operand(dividend, LSR, bits - 1)); |
| 3022 | } else { |
| 3023 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3024 | Register temp = temps.AcquireSameSizeAs(out); |
| 3025 | __ Add(temp, dividend, abs_imm - 1); |
| 3026 | __ Cmp(dividend, 0); |
| 3027 | __ Csel(out, temp, dividend, lt); |
| 3028 | } |
| 3029 | |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3030 | int ctz_imm = CTZ(abs_imm); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3031 | if (imm > 0) { |
| 3032 | __ Asr(out, out, ctz_imm); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3033 | } else { |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3034 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3035 | } |
| 3036 | } |
| 3037 | |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3038 | // Return true if the magic number was modified by subtracting 2^32. So dividend needs to be added. |
| 3039 | static inline bool NeedToAddDividend(int64_t magic_number, int64_t divisor) { |
| 3040 | return divisor > 0 && magic_number < 0; |
| 3041 | } |
| 3042 | |
| 3043 | // Return true if the magic number was modified by adding 2^32. So dividend needs to be subtracted. |
| 3044 | static inline bool NeedToSubDividend(int64_t magic_number, int64_t divisor) { |
| 3045 | return divisor < 0 && magic_number > 0; |
| 3046 | } |
| 3047 | |
| Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame^] | 3048 | // Return true if the result of multiplication of the dividend by a sort of reciprocal |
| 3049 | // of the divisor (magic_number) needs to be corrected. This means additional operations will |
| 3050 | // be generated. |
| 3051 | static inline bool NeedToCorrectMulResult(int64_t magic_number, int64_t divisor) { |
| 3052 | return NeedToAddDividend(magic_number, divisor) || NeedToSubDividend(magic_number, divisor); |
| 3053 | } |
| 3054 | |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3055 | void InstructionCodeGeneratorARM64::GenerateResultDivRemWithAnyConstant( |
| 3056 | bool is_rem, |
| 3057 | int final_right_shift, |
| 3058 | int64_t magic_number, |
| 3059 | int64_t divisor, |
| 3060 | Register dividend, |
| 3061 | Register temp_result, |
| 3062 | Register out, |
| 3063 | UseScratchRegisterScope* temps_scope) { |
| 3064 | // As magic_number can be modified to fit into 32 bits, check whether the correction is needed. |
| 3065 | if (NeedToAddDividend(magic_number, divisor)) { |
| 3066 | __ Add(temp_result, temp_result, dividend); |
| 3067 | } else if (NeedToSubDividend(magic_number, divisor)) { |
| 3068 | __ Sub(temp_result, temp_result, dividend); |
| 3069 | } |
| 3070 | |
| 3071 | if (final_right_shift != 0) { |
| 3072 | __ Asr(temp_result, temp_result, final_right_shift); |
| 3073 | } |
| 3074 | |
| 3075 | Register& result = (is_rem) ? temp_result : out; |
| 3076 | __ Add(result, temp_result, Operand(temp_result, LSR, temp_result.GetSizeInBits() - 1)); |
| 3077 | if (is_rem) { |
| 3078 | // TODO: Strength reduction for msub. |
| 3079 | Register temp_imm = temps_scope->AcquireSameSizeAs(out); |
| 3080 | __ Mov(temp_imm, divisor); |
| 3081 | __ Msub(out, temp_result, temp_imm, dividend); |
| 3082 | } |
| 3083 | } |
| 3084 | |
| 3085 | void InstructionCodeGeneratorARM64::GenerateInt64DivRemWithAnyConstant( |
| 3086 | HBinaryOperation* instruction) { |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3087 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3088 | DCHECK(instruction->GetResultType() == DataType::Type::kInt64); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3089 | |
| 3090 | LocationSummary* locations = instruction->GetLocations(); |
| 3091 | Location second = locations->InAt(1); |
| 3092 | DCHECK(second.IsConstant()); |
| 3093 | |
| 3094 | Register out = OutputRegister(instruction); |
| 3095 | Register dividend = InputRegisterAt(instruction, 0); |
| 3096 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3097 | |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3098 | int64_t magic; |
| 3099 | int shift; |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3100 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ true, &magic, &shift); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3101 | |
| 3102 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3103 | Register temp = temps.AcquireSameSizeAs(out); |
| 3104 | |
| 3105 | // temp = get_high(dividend * magic) |
| 3106 | __ Mov(temp, magic); |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3107 | __ Smulh(temp, dividend, temp); |
| 3108 | |
| 3109 | GenerateResultDivRemWithAnyConstant(/* is_rem= */ instruction->IsRem(), |
| 3110 | /* final_right_shift= */ shift, |
| 3111 | magic, |
| 3112 | imm, |
| 3113 | dividend, |
| 3114 | temp, |
| 3115 | out, |
| 3116 | &temps); |
| 3117 | } |
| 3118 | |
| 3119 | void InstructionCodeGeneratorARM64::GenerateInt32DivRemWithAnyConstant( |
| 3120 | HBinaryOperation* instruction) { |
| 3121 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3122 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| 3123 | |
| 3124 | LocationSummary* locations = instruction->GetLocations(); |
| 3125 | Location second = locations->InAt(1); |
| 3126 | DCHECK(second.IsConstant()); |
| 3127 | |
| 3128 | Register out = OutputRegister(instruction); |
| 3129 | Register dividend = InputRegisterAt(instruction, 0); |
| 3130 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3131 | |
| 3132 | int64_t magic; |
| 3133 | int shift; |
| 3134 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| 3135 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3136 | Register temp = temps.AcquireSameSizeAs(out); |
| 3137 | |
| 3138 | // temp = get_high(dividend * magic) |
| 3139 | __ Mov(temp, magic); |
| 3140 | __ Smull(temp.X(), dividend, temp); |
| Evgeny Astigeevich | 968db3c | 2020-05-07 12:44:10 +0100 | [diff] [blame^] | 3141 | |
| 3142 | if (NeedToCorrectMulResult(magic, imm)) { |
| 3143 | __ Lsr(temp.X(), temp.X(), 32); |
| 3144 | } else { |
| 3145 | // As between 'lsr temp.X(), temp.X(), #32' and 'asr temp, temp, #shift' there are |
| 3146 | // no other instructions modifying 'temp', they can be combined into one |
| 3147 | // 'asr temp.X(), temp.X(), #32 + shift'. |
| 3148 | DCHECK_LT(shift, 32); |
| 3149 | __ Asr(temp.X(), temp.X(), 32 + shift); |
| 3150 | shift = 0; |
| 3151 | } |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3152 | |
| 3153 | GenerateResultDivRemWithAnyConstant(/* is_rem= */ instruction->IsRem(), |
| 3154 | /* final_right_shift= */ shift, |
| 3155 | magic, |
| 3156 | imm, |
| 3157 | dividend, |
| 3158 | temp, |
| 3159 | out, |
| 3160 | &temps); |
| 3161 | } |
| 3162 | |
| 3163 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3164 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3165 | if (instruction->GetResultType() == DataType::Type::kInt64) { |
| 3166 | GenerateInt64DivRemWithAnyConstant(instruction); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3167 | } else { |
| Evgeny Astigeevich | a6653d3 | 2020-05-05 16:30:24 +0100 | [diff] [blame] | 3168 | GenerateInt32DivRemWithAnyConstant(instruction); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3169 | } |
| 3170 | } |
| 3171 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3172 | void InstructionCodeGeneratorARM64::GenerateIntDivForConstDenom(HDiv *instruction) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3173 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3174 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3175 | if (imm == 0) { |
| 3176 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3177 | return; |
| 3178 | } |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3179 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3180 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3181 | GenerateIntDivForPower2Denom(instruction); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3182 | } else { |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3183 | // Cases imm == -1 or imm == 1 are handled by InstructionSimplifier. |
| 3184 | DCHECK(imm < -2 || imm > 2) << imm; |
| 3185 | GenerateDivRemWithAnyConstant(instruction); |
| 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | void InstructionCodeGeneratorARM64::GenerateIntDiv(HDiv *instruction) { |
| 3190 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 3191 | << instruction->GetResultType(); |
| 3192 | |
| 3193 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 3194 | GenerateIntDivForConstDenom(instruction); |
| 3195 | } else { |
| 3196 | Register out = OutputRegister(instruction); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3197 | Register dividend = InputRegisterAt(instruction, 0); |
| 3198 | Register divisor = InputRegisterAt(instruction, 1); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3199 | __ Sdiv(out, dividend, divisor); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3200 | } |
| 3201 | } |
| 3202 | |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3203 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3204 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3205 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3206 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3207 | case DataType::Type::kInt32: |
| 3208 | case DataType::Type::kInt64: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3209 | locations->SetInAt(0, Location::RequiresRegister()); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3210 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3211 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3212 | break; |
| 3213 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3214 | case DataType::Type::kFloat32: |
| 3215 | case DataType::Type::kFloat64: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3216 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3217 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3218 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3219 | break; |
| 3220 | |
| 3221 | default: |
| 3222 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3223 | } |
| 3224 | } |
| 3225 | |
| 3226 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3227 | DataType::Type type = div->GetResultType(); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3228 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3229 | case DataType::Type::kInt32: |
| 3230 | case DataType::Type::kInt64: |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3231 | GenerateIntDiv(div); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3232 | break; |
| 3233 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3234 | case DataType::Type::kFloat32: |
| 3235 | case DataType::Type::kFloat64: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3236 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3237 | break; |
| 3238 | |
| 3239 | default: |
| 3240 | LOG(FATAL) << "Unexpected div type " << type; |
| 3241 | } |
| 3242 | } |
| 3243 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3244 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3245 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3246 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3247 | } |
| 3248 | |
| 3249 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3250 | SlowPathCodeARM64* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3251 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3252 | codegen_->AddSlowPath(slow_path); |
| 3253 | Location value = instruction->GetLocations()->InAt(0); |
| 3254 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3255 | DataType::Type type = instruction->GetType(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3256 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3257 | if (!DataType::IsIntegralType(type)) { |
| Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3258 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 3259 | UNREACHABLE(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3260 | } |
| 3261 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3262 | if (value.IsConstant()) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3263 | int64_t divisor = Int64FromLocation(value); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3264 | if (divisor == 0) { |
| 3265 | __ B(slow_path->GetEntryLabel()); |
| 3266 | } else { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3267 | // A division by a non-null constant is valid. We don't need to perform |
| 3268 | // any check, so simply fall through. |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3269 | } |
| 3270 | } else { |
| 3271 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3272 | } |
| 3273 | } |
| 3274 | |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3275 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3276 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3277 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3278 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3279 | } |
| 3280 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3281 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3282 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3283 | // Will be generated at use site. |
| 3284 | } |
| 3285 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3286 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3287 | exit->SetLocations(nullptr); |
| 3288 | } |
| 3289 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3290 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3291 | } |
| 3292 | |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3293 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3294 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3295 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3296 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3297 | } |
| 3298 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3299 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3300 | // Will be generated at use site. |
| 3301 | } |
| 3302 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3303 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3304 | if (successor->IsExitBlock()) { |
| 3305 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3306 | return; // no code needed |
| 3307 | } |
| 3308 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3309 | HBasicBlock* block = got->GetBlock(); |
| 3310 | HInstruction* previous = got->GetPrevious(); |
| 3311 | HLoopInformation* info = block->GetLoopInformation(); |
| 3312 | |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3313 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 3314 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3315 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3316 | return; |
| 3317 | } |
| 3318 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3319 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3320 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3321 | } |
| 3322 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3323 | __ B(codegen_->GetLabelOf(successor)); |
| 3324 | } |
| 3325 | } |
| 3326 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3327 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3328 | got->SetLocations(nullptr); |
| 3329 | } |
| 3330 | |
| 3331 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3332 | HandleGoto(got, got->GetSuccessor()); |
| 3333 | } |
| 3334 | |
| 3335 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3336 | try_boundary->SetLocations(nullptr); |
| 3337 | } |
| 3338 | |
| 3339 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3340 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3341 | if (!successor->IsExitBlock()) { |
| 3342 | HandleGoto(try_boundary, successor); |
| 3343 | } |
| 3344 | } |
| 3345 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3346 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3347 | size_t condition_input_index, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3348 | vixl::aarch64::Label* true_target, |
| 3349 | vixl::aarch64::Label* false_target) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3350 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3351 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3352 | if (true_target == nullptr && false_target == nullptr) { |
| 3353 | // Nothing to do. The code always falls through. |
| 3354 | return; |
| 3355 | } else if (cond->IsIntConstant()) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3356 | // Constant condition, statically compared against "true" (integer value 1). |
| 3357 | if (cond->AsIntConstant()->IsTrue()) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3358 | if (true_target != nullptr) { |
| 3359 | __ B(true_target); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3360 | } |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3361 | } else { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3362 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3363 | if (false_target != nullptr) { |
| 3364 | __ B(false_target); |
| 3365 | } |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3366 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3367 | return; |
| 3368 | } |
| 3369 | |
| 3370 | // The following code generates these patterns: |
| 3371 | // (1) true_target == nullptr && false_target != nullptr |
| 3372 | // - opposite condition true => branch to false_target |
| 3373 | // (2) true_target != nullptr && false_target == nullptr |
| 3374 | // - condition true => branch to true_target |
| 3375 | // (3) true_target != nullptr && false_target != nullptr |
| 3376 | // - condition true => branch to true_target |
| 3377 | // - branch to false_target |
| 3378 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3379 | // The condition instruction has been materialized, compare the output to 0. |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3380 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3381 | DCHECK(cond_val.IsRegister()); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3382 | if (true_target == nullptr) { |
| 3383 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3384 | } else { |
| 3385 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3386 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3387 | } else { |
| 3388 | // The condition instruction has not been materialized, use its inputs as |
| 3389 | // the comparison and its condition as the branch condition. |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3390 | HCondition* condition = cond->AsCondition(); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3391 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3392 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3393 | if (DataType::IsFloatingPointType(type)) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3394 | GenerateFcmp(condition); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3395 | if (true_target == nullptr) { |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3396 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3397 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3398 | } else { |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3399 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3400 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3401 | } else { |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3402 | // Integer cases. |
| 3403 | Register lhs = InputRegisterAt(condition, 0); |
| 3404 | Operand rhs = InputOperandAt(condition, 1); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3405 | |
| 3406 | Condition arm64_cond; |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3407 | vixl::aarch64::Label* non_fallthrough_target; |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3408 | if (true_target == nullptr) { |
| 3409 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3410 | non_fallthrough_target = false_target; |
| 3411 | } else { |
| 3412 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3413 | non_fallthrough_target = true_target; |
| 3414 | } |
| 3415 | |
| Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3416 | 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] | 3417 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3418 | switch (arm64_cond) { |
| 3419 | case eq: |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3420 | __ Cbz(lhs, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3421 | break; |
| 3422 | case ne: |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3423 | __ Cbnz(lhs, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3424 | break; |
| 3425 | case lt: |
| 3426 | // Test the sign bit and branch accordingly. |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3427 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3428 | break; |
| 3429 | case ge: |
| 3430 | // Test the sign bit and branch accordingly. |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3431 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3432 | break; |
| 3433 | default: |
| 3434 | // Without the `static_cast` the compiler throws an error for |
| 3435 | // `-Werror=sign-promo`. |
| 3436 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3437 | } |
| 3438 | } else { |
| 3439 | __ Cmp(lhs, rhs); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3440 | __ B(arm64_cond, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3441 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3442 | } |
| 3443 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3444 | |
| 3445 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3446 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3447 | if (true_target != nullptr && false_target != nullptr) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3448 | __ B(false_target); |
| 3449 | } |
| 3450 | } |
| 3451 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3452 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3453 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3454 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3455 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3460 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3461 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3462 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3463 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3464 | true_target = nullptr; |
| 3465 | } |
| 3466 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3467 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3468 | false_target = nullptr; |
| 3469 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3470 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3471 | } |
| 3472 | |
| 3473 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3474 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3475 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3476 | InvokeRuntimeCallingConvention calling_convention; |
| 3477 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3478 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3479 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3480 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3481 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3482 | } |
| 3483 | } |
| 3484 | |
| 3485 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3486 | SlowPathCodeARM64* slow_path = |
| 3487 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3488 | GenerateTestAndBranch(deoptimize, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3489 | /* condition_input_index= */ 0, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3490 | slow_path->GetEntryLabel(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3491 | /* false_target= */ nullptr); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3492 | } |
| 3493 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3494 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3495 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3496 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3497 | locations->SetOut(Location::RequiresRegister()); |
| 3498 | } |
| 3499 | |
| 3500 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3501 | __ Ldr(OutputRegister(flag), |
| 3502 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3503 | } |
| 3504 | |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3505 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3506 | return condition->IsCondition() && |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3507 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3508 | } |
| 3509 | |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3510 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3511 | IfCondition cond = condition->AsCondition()->GetCondition(); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3512 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3513 | : ARM64Condition(cond); |
| 3514 | } |
| 3515 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3516 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3517 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3518 | if (DataType::IsFloatingPointType(select->GetType())) { |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3519 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3520 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3521 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3522 | } else { |
| 3523 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3524 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3525 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3526 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3527 | // Ask VIXL whether we should synthesize constants in registers. |
| 3528 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3529 | Operand true_op = is_true_value_constant ? |
| 3530 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3531 | Operand false_op = is_false_value_constant ? |
| 3532 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3533 | bool true_value_in_register = false; |
| 3534 | bool false_value_in_register = false; |
| 3535 | MacroAssembler::GetCselSynthesisInformation( |
| 3536 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3537 | true_value_in_register |= !is_true_value_constant; |
| 3538 | false_value_in_register |= !is_false_value_constant; |
| 3539 | |
| 3540 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3541 | : Location::ConstantLocation(cst_true_value)); |
| 3542 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3543 | : Location::ConstantLocation(cst_false_value)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3544 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3545 | } |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3546 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3547 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3548 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3549 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3550 | } |
| 3551 | |
| 3552 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3553 | HInstruction* cond = select->GetCondition(); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3554 | Condition csel_cond; |
| 3555 | |
| 3556 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3557 | if (cond->IsCondition() && cond->GetNext() == select) { |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3558 | // Use the condition flags set by the previous instruction. |
| 3559 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3560 | } else { |
| 3561 | __ Cmp(InputRegisterAt(select, 2), 0); |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3562 | csel_cond = ne; |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3563 | } |
| 3564 | } else if (IsConditionOnFloatingPointValues(cond)) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3565 | GenerateFcmp(cond); |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3566 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3567 | } else { |
| 3568 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3569 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3570 | } |
| 3571 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3572 | if (DataType::IsFloatingPointType(select->GetType())) { |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3573 | __ Fcsel(OutputFPRegister(select), |
| 3574 | InputFPRegisterAt(select, 1), |
| 3575 | InputFPRegisterAt(select, 0), |
| 3576 | csel_cond); |
| 3577 | } else { |
| 3578 | __ Csel(OutputRegister(select), |
| 3579 | InputOperandAt(select, 1), |
| 3580 | InputOperandAt(select, 0), |
| 3581 | csel_cond); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3582 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3583 | } |
| 3584 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3585 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3586 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3587 | } |
| 3588 | |
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3589 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3590 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3591 | } |
| 3592 | |
| 3593 | void CodeGeneratorARM64::GenerateNop() { |
| 3594 | __ Nop(); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3595 | } |
| 3596 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3597 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3598 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3599 | } |
| 3600 | |
| 3601 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3602 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3603 | } |
| 3604 | |
| 3605 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3606 | HandleFieldSet(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3607 | } |
| 3608 | |
| 3609 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3610 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3611 | } |
| 3612 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3613 | // Temp is used for read barrier. |
| 3614 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3615 | if (kEmitCompilerReadBarrier && |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3616 | (kUseBakerReadBarrier || |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3617 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3618 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3619 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3620 | return 1; |
| 3621 | } |
| 3622 | return 0; |
| 3623 | } |
| 3624 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3625 | // 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] | 3626 | // interface pointer, one for loading the current interface. |
| 3627 | // The other checks have one temp for loading the object's class. |
| 3628 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3629 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3630 | return 3; |
| 3631 | } |
| 3632 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3633 | } |
| 3634 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3635 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3636 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3637 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3638 | bool baker_read_barrier_slow_path = false; |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3639 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3640 | case TypeCheckKind::kExactCheck: |
| 3641 | case TypeCheckKind::kAbstractClassCheck: |
| 3642 | case TypeCheckKind::kClassHierarchyCheck: |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3643 | case TypeCheckKind::kArrayObjectCheck: { |
| 3644 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 3645 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 3646 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3647 | break; |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3648 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3649 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3650 | case TypeCheckKind::kUnresolvedCheck: |
| 3651 | case TypeCheckKind::kInterfaceCheck: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3652 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3653 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3654 | case TypeCheckKind::kBitstringCheck: |
| 3655 | break; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3656 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3657 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3658 | LocationSummary* locations = |
| 3659 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3660 | if (baker_read_barrier_slow_path) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3661 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3662 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3663 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3664 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3665 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3666 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3667 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3668 | } else { |
| 3669 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3670 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3671 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3672 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3673 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3674 | // Add temps if necessary for read barriers. |
| 3675 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3676 | } |
| 3677 | |
| 3678 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3679 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3680 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3681 | Location obj_loc = locations->InAt(0); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3682 | Register obj = InputRegisterAt(instruction, 0); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3683 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 3684 | ? Register() |
| 3685 | : InputRegisterAt(instruction, 1); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3686 | Location out_loc = locations->Out(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3687 | Register out = OutputRegister(instruction); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3688 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3689 | DCHECK_LE(num_temps, 1u); |
| 3690 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3691 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3692 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3693 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3694 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3695 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3696 | vixl::aarch64::Label done, zero; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3697 | SlowPathCodeARM64* slow_path = nullptr; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3698 | |
| 3699 | // Return 0 if `obj` is null. |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3700 | // Avoid null check if we know `obj` is not null. |
| 3701 | if (instruction->MustDoNullCheck()) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3702 | __ Cbz(obj, &zero); |
| 3703 | } |
| 3704 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3705 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3706 | case TypeCheckKind::kExactCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3707 | ReadBarrierOption read_barrier_option = |
| 3708 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3709 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3710 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3711 | out_loc, |
| 3712 | obj_loc, |
| 3713 | class_offset, |
| 3714 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3715 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3716 | __ Cmp(out, cls); |
| 3717 | __ Cset(out, eq); |
| 3718 | if (zero.IsLinked()) { |
| 3719 | __ B(&done); |
| 3720 | } |
| 3721 | break; |
| 3722 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3723 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3724 | case TypeCheckKind::kAbstractClassCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3725 | ReadBarrierOption read_barrier_option = |
| 3726 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3727 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3728 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3729 | out_loc, |
| 3730 | obj_loc, |
| 3731 | class_offset, |
| 3732 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3733 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3734 | // If the class is abstract, we eagerly fetch the super class of the |
| 3735 | // object to avoid doing a comparison we know will fail. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3736 | vixl::aarch64::Label loop, success; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3737 | __ Bind(&loop); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3738 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3739 | GenerateReferenceLoadOneRegister(instruction, |
| 3740 | out_loc, |
| 3741 | super_offset, |
| 3742 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3743 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3744 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3745 | __ Cbz(out, &done); |
| 3746 | __ Cmp(out, cls); |
| 3747 | __ B(ne, &loop); |
| 3748 | __ Mov(out, 1); |
| 3749 | if (zero.IsLinked()) { |
| 3750 | __ B(&done); |
| 3751 | } |
| 3752 | break; |
| 3753 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3754 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3755 | case TypeCheckKind::kClassHierarchyCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3756 | ReadBarrierOption read_barrier_option = |
| 3757 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3758 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3759 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3760 | out_loc, |
| 3761 | obj_loc, |
| 3762 | class_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 | // Walk over the class hierarchy to find a match. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3766 | vixl::aarch64::Label loop, success; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3767 | __ Bind(&loop); |
| 3768 | __ Cmp(out, cls); |
| 3769 | __ B(eq, &success); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3770 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3771 | GenerateReferenceLoadOneRegister(instruction, |
| 3772 | out_loc, |
| 3773 | super_offset, |
| 3774 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3775 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3776 | __ Cbnz(out, &loop); |
| 3777 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3778 | __ B(&done); |
| 3779 | __ Bind(&success); |
| 3780 | __ Mov(out, 1); |
| 3781 | if (zero.IsLinked()) { |
| 3782 | __ B(&done); |
| 3783 | } |
| 3784 | break; |
| 3785 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3786 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3787 | case TypeCheckKind::kArrayObjectCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3788 | ReadBarrierOption read_barrier_option = |
| 3789 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3790 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3791 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3792 | out_loc, |
| 3793 | obj_loc, |
| 3794 | class_offset, |
| 3795 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3796 | read_barrier_option); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3797 | // Do an exact check. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3798 | vixl::aarch64::Label exact_check; |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3799 | __ Cmp(out, cls); |
| 3800 | __ B(eq, &exact_check); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3801 | // 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] | 3802 | // /* HeapReference<Class> */ out = out->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3803 | GenerateReferenceLoadOneRegister(instruction, |
| 3804 | out_loc, |
| 3805 | component_offset, |
| 3806 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3807 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3808 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3809 | __ Cbz(out, &done); |
| 3810 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3811 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3812 | __ Cbnz(out, &zero); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3813 | __ Bind(&exact_check); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3814 | __ Mov(out, 1); |
| 3815 | __ B(&done); |
| 3816 | break; |
| 3817 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3818 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3819 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3820 | // No read barrier since the slow path will retry upon failure. |
| 3821 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3822 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3823 | out_loc, |
| 3824 | obj_loc, |
| 3825 | class_offset, |
| 3826 | maybe_temp_loc, |
| 3827 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3828 | __ Cmp(out, cls); |
| 3829 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3830 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3831 | instruction, /* is_fatal= */ false); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3832 | codegen_->AddSlowPath(slow_path); |
| 3833 | __ B(ne, slow_path->GetEntryLabel()); |
| 3834 | __ Mov(out, 1); |
| 3835 | if (zero.IsLinked()) { |
| 3836 | __ B(&done); |
| 3837 | } |
| 3838 | break; |
| 3839 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3840 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3841 | case TypeCheckKind::kUnresolvedCheck: |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3842 | case TypeCheckKind::kInterfaceCheck: { |
| 3843 | // Note that we indeed only call on slow path, but we always go |
| 3844 | // into the slow path for the unresolved and interface check |
| 3845 | // cases. |
| 3846 | // |
| 3847 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3848 | // entry point without resorting to a type checking slow path |
| 3849 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3850 | // require to assign fixed registers for the inputs of this |
| 3851 | // HInstanceOf instruction (following the runtime calling |
| 3852 | // convention), which might be cluttered by the potential first |
| 3853 | // read barrier emission at the beginning of this method. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3854 | // |
| 3855 | // TODO: Introduce a new runtime entry point taking the object |
| 3856 | // to test (instead of its class) as argument, and let it deal |
| 3857 | // with the read barrier issues. This will let us refactor this |
| 3858 | // case of the `switch` code as it was previously (with a direct |
| 3859 | // call to the runtime not using a type checking slow path). |
| 3860 | // This should also be beneficial for the other cases above. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3861 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3862 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3863 | instruction, /* is_fatal= */ false); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3864 | codegen_->AddSlowPath(slow_path); |
| 3865 | __ B(slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3866 | if (zero.IsLinked()) { |
| 3867 | __ B(&done); |
| 3868 | } |
| 3869 | break; |
| 3870 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3871 | |
| 3872 | case TypeCheckKind::kBitstringCheck: { |
| 3873 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3874 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3875 | out_loc, |
| 3876 | obj_loc, |
| 3877 | class_offset, |
| 3878 | maybe_temp_loc, |
| 3879 | kWithoutReadBarrier); |
| 3880 | |
| 3881 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 3882 | __ Cset(out, eq); |
| 3883 | if (zero.IsLinked()) { |
| 3884 | __ B(&done); |
| 3885 | } |
| 3886 | break; |
| 3887 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3888 | } |
| 3889 | |
| 3890 | if (zero.IsLinked()) { |
| 3891 | __ Bind(&zero); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3892 | __ Mov(out, 0); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3893 | } |
| 3894 | |
| 3895 | if (done.IsLinked()) { |
| 3896 | __ Bind(&done); |
| 3897 | } |
| 3898 | |
| 3899 | if (slow_path != nullptr) { |
| 3900 | __ Bind(slow_path->GetExitLabel()); |
| 3901 | } |
| 3902 | } |
| 3903 | |
| 3904 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3905 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3906 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3907 | LocationSummary* locations = |
| 3908 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3909 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3910 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3911 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3912 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3913 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3914 | } else { |
| 3915 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3916 | } |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3917 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 3918 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3919 | } |
| 3920 | |
| 3921 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3922 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3923 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3924 | Location obj_loc = locations->InAt(0); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3925 | Register obj = InputRegisterAt(instruction, 0); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3926 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 3927 | ? Register() |
| 3928 | : InputRegisterAt(instruction, 1); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3929 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3930 | DCHECK_GE(num_temps, 1u); |
| 3931 | DCHECK_LE(num_temps, 3u); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3932 | Location temp_loc = locations->GetTemp(0); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3933 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 3934 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3935 | Register temp = WRegisterFrom(temp_loc); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3936 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3937 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3938 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3939 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3940 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3941 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3942 | const uint32_t object_array_data_offset = |
| 3943 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3944 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3945 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3946 | SlowPathCodeARM64* type_check_slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3947 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 3948 | instruction, is_type_check_slow_path_fatal); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3949 | codegen_->AddSlowPath(type_check_slow_path); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3950 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3951 | vixl::aarch64::Label done; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3952 | // Avoid null check if we know obj is not null. |
| 3953 | if (instruction->MustDoNullCheck()) { |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3954 | __ Cbz(obj, &done); |
| 3955 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3956 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3957 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3958 | case TypeCheckKind::kExactCheck: |
| 3959 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3960 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3961 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3962 | temp_loc, |
| 3963 | obj_loc, |
| 3964 | class_offset, |
| 3965 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3966 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3967 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3968 | __ Cmp(temp, cls); |
| 3969 | // Jump to slow path for throwing the exception or doing a |
| 3970 | // more involved array check. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3971 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3972 | break; |
| 3973 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3974 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3975 | case TypeCheckKind::kAbstractClassCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3976 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3977 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3978 | temp_loc, |
| 3979 | obj_loc, |
| 3980 | class_offset, |
| 3981 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3982 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3983 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3984 | // If the class is abstract, we eagerly fetch the super class of the |
| 3985 | // object to avoid doing a comparison we know will fail. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3986 | vixl::aarch64::Label loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3987 | __ Bind(&loop); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3988 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3989 | GenerateReferenceLoadOneRegister(instruction, |
| 3990 | temp_loc, |
| 3991 | super_offset, |
| 3992 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3993 | kWithoutReadBarrier); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3994 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3995 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3996 | // exception. |
| 3997 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 3998 | // Otherwise, compare classes. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3999 | __ Cmp(temp, cls); |
| 4000 | __ B(ne, &loop); |
| 4001 | break; |
| 4002 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4003 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4004 | case TypeCheckKind::kClassHierarchyCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4005 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4006 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4007 | temp_loc, |
| 4008 | obj_loc, |
| 4009 | class_offset, |
| 4010 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4011 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4012 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4013 | // Walk over the class hierarchy to find a match. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4014 | vixl::aarch64::Label loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4015 | __ Bind(&loop); |
| 4016 | __ Cmp(temp, cls); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4017 | __ B(eq, &done); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4018 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4019 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4020 | GenerateReferenceLoadOneRegister(instruction, |
| 4021 | temp_loc, |
| 4022 | super_offset, |
| 4023 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4024 | kWithoutReadBarrier); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4025 | |
| 4026 | // If the class reference currently in `temp` is not null, jump |
| 4027 | // back at the beginning of the loop. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4028 | __ Cbnz(temp, &loop); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4029 | // Otherwise, jump to the slow path to throw the exception. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4030 | __ B(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4031 | break; |
| 4032 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4033 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4034 | case TypeCheckKind::kArrayObjectCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4035 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4036 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4037 | temp_loc, |
| 4038 | obj_loc, |
| 4039 | class_offset, |
| 4040 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4041 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4042 | |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4043 | // Do an exact check. |
| 4044 | __ Cmp(temp, cls); |
| 4045 | __ B(eq, &done); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4046 | |
| 4047 | // 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] | 4048 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4049 | GenerateReferenceLoadOneRegister(instruction, |
| 4050 | temp_loc, |
| 4051 | component_offset, |
| 4052 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4053 | kWithoutReadBarrier); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4054 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4055 | // If the component type is null, jump to the slow path to throw the exception. |
| 4056 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4057 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4058 | // primitive type. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4059 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4060 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4061 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4062 | break; |
| 4063 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4064 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4065 | case TypeCheckKind::kUnresolvedCheck: |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4066 | // 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] | 4067 | // |
| 4068 | // We cannot directly call the CheckCast runtime entry point |
| 4069 | // without resorting to a type checking slow path here (i.e. by |
| 4070 | // calling InvokeRuntime directly), as it would require to |
| 4071 | // assign fixed registers for the inputs of this HInstanceOf |
| 4072 | // instruction (following the runtime calling convention), which |
| 4073 | // might be cluttered by the potential first read barrier |
| 4074 | // emission at the beginning of this method. |
| 4075 | __ B(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4076 | break; |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4077 | case TypeCheckKind::kInterfaceCheck: { |
| 4078 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4079 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4080 | temp_loc, |
| 4081 | obj_loc, |
| 4082 | class_offset, |
| 4083 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4084 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4085 | |
| 4086 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4087 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4088 | temp_loc, |
| 4089 | temp_loc, |
| 4090 | iftable_offset, |
| 4091 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4092 | kWithoutReadBarrier); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4093 | // Iftable is never null. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4094 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4095 | // Loop through the iftable and check if any class matches. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4096 | vixl::aarch64::Label start_loop; |
| 4097 | __ Bind(&start_loop); |
| Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4098 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4099 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4100 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4101 | // Go to next interface. |
| 4102 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4103 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
| Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4104 | // Compare the classes and continue the loop if they do not match. |
| 4105 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4106 | __ B(ne, &start_loop); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4107 | break; |
| 4108 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4109 | |
| 4110 | case TypeCheckKind::kBitstringCheck: { |
| 4111 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4112 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4113 | temp_loc, |
| 4114 | obj_loc, |
| 4115 | class_offset, |
| 4116 | maybe_temp2_loc, |
| 4117 | kWithoutReadBarrier); |
| 4118 | |
| 4119 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 4120 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 4121 | break; |
| 4122 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4123 | } |
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4124 | __ Bind(&done); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4125 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4126 | __ Bind(type_check_slow_path->GetExitLabel()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4127 | } |
| 4128 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4129 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4130 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4131 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4132 | } |
| 4133 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4134 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4135 | // Will be generated at use site. |
| 4136 | } |
| 4137 | |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4138 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4139 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4140 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4141 | } |
| 4142 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4143 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4144 | // Will be generated at use site. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4145 | } |
| 4146 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4147 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4148 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4149 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4150 | // the method_idx. |
| 4151 | HandleInvoke(invoke); |
| 4152 | } |
| 4153 | |
| 4154 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4155 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4156 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4157 | } |
| 4158 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4159 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4160 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4161 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4162 | } |
| 4163 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4164 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4165 | HandleInvoke(invoke); |
| 4166 | } |
| 4167 | |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4168 | void CodeGeneratorARM64::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 4169 | Register klass) { |
| 4170 | DCHECK_EQ(klass.GetCode(), 0u); |
| Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4171 | // We know the destination of an intrinsic, so no need to record inline |
| 4172 | // caches. |
| 4173 | if (!instruction->GetLocations()->Intrinsified() && |
| Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 4174 | GetGraph()->IsCompilingBaseline() && |
| Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 4175 | !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4176 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
| 4177 | ScopedObjectAccess soa(Thread::Current()); |
| 4178 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
| Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 4179 | if (info != nullptr) { |
| 4180 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 4181 | uint64_t address = reinterpret_cast64<uint64_t>(cache); |
| 4182 | vixl::aarch64::Label done; |
| 4183 | __ Mov(x8, address); |
| 4184 | __ Ldr(x9, MemOperand(x8, InlineCache::ClassesOffset().Int32Value())); |
| 4185 | // Fast path for a monomorphic cache. |
| 4186 | __ Cmp(klass, x9); |
| 4187 | __ B(eq, &done); |
| 4188 | InvokeRuntime(kQuickUpdateInlineCache, instruction, instruction->GetDexPc()); |
| 4189 | __ Bind(&done); |
| 4190 | } |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4191 | } |
| 4192 | } |
| 4193 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4194 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4195 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4196 | LocationSummary* locations = invoke->GetLocations(); |
| 4197 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4198 | Location receiver = locations->InAt(0); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4199 | Offset class_offset = mirror::Object::ClassOffset(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4200 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4201 | |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4202 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4203 | if (receiver.IsStackSlot()) { |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4204 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4205 | { |
| 4206 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4207 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4208 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4209 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4210 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4211 | } else { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4212 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4213 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4214 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4215 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4216 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4217 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4218 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4219 | // emit a read barrier for the previous class reference load. |
| 4220 | // However this is not required in practice, as this is an |
| 4221 | // intermediate/temporary reference and because the current |
| 4222 | // concurrent copying collector keeps the from-space memory |
| 4223 | // intact/accessible until the end of the marking phase (the |
| 4224 | // concurrent copying collector may not in the future). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4225 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4226 | |
| 4227 | // If we're compiling baseline, update the inline cache. |
| 4228 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4229 | |
| 4230 | // The register ip1 is required to be used for the hidden argument in |
| 4231 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
| 4232 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4233 | UseScratchRegisterScope scratch_scope(masm); |
| 4234 | scratch_scope.Exclude(ip1); |
| 4235 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4236 | |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4237 | __ Ldr(temp, |
| 4238 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4239 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4240 | invoke->GetImtIndex(), kArm64PointerSize)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4241 | // temp = temp->GetImtEntryAt(method_offset); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4242 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4243 | // lr = temp->GetEntryPoint(); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4244 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4245 | |
| 4246 | { |
| 4247 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4248 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4249 | |
| 4250 | // lr(); |
| 4251 | __ blr(lr); |
| 4252 | DCHECK(!codegen_->IsLeafMethod()); |
| 4253 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4254 | } |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4255 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4256 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4260 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4261 | if (intrinsic.TryDispatch(invoke)) { |
| 4262 | return; |
| 4263 | } |
| 4264 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4265 | HandleInvoke(invoke); |
| 4266 | } |
| 4267 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4268 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4269 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4270 | // art::PrepareForRegisterAllocation. |
| 4271 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4272 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4273 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4274 | if (intrinsic.TryDispatch(invoke)) { |
| 4275 | return; |
| 4276 | } |
| 4277 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4278 | HandleInvoke(invoke); |
| 4279 | } |
| 4280 | |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4281 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4282 | if (invoke->GetLocations()->Intrinsified()) { |
| 4283 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4284 | intrinsic.Dispatch(invoke); |
| 4285 | return true; |
| 4286 | } |
| 4287 | return false; |
| 4288 | } |
| 4289 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4290 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4291 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4292 | ArtMethod* method ATTRIBUTE_UNUSED) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4293 | // On ARM64 we support all dispatch types. |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4294 | return desired_dispatch_info; |
| 4295 | } |
| 4296 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4297 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4298 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4299 | // 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] | 4300 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4301 | switch (invoke->GetMethodLoadKind()) { |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4302 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4303 | uint32_t offset = |
| 4304 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4305 | // temp = thread->string_init_entrypoint |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4306 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4307 | break; |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4308 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4309 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4310 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4311 | break; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4312 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4313 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4314 | // Add ADRP with its PC-relative method patch. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4315 | vixl::aarch64::Label* adrp_label = NewBootImageMethodPatch(invoke->GetTargetMethod()); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4316 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4317 | // Add ADD with its PC-relative method patch. |
| 4318 | vixl::aarch64::Label* add_label = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4319 | NewBootImageMethodPatch(invoke->GetTargetMethod(), adrp_label); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4320 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4321 | break; |
| 4322 | } |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4323 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4324 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4325 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4326 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_offset); |
| 4327 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4328 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| 4329 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| 4330 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 4331 | EmitLdrOffsetPlaceholder(ldr_label, WRegisterFrom(temp), XRegisterFrom(temp)); |
| 4332 | break; |
| 4333 | } |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4334 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4335 | // Add ADRP with its PC-relative .bss entry patch. |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4336 | MethodReference target_method(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4337 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(target_method); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4338 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4339 | // Add LDR with its PC-relative .bss entry patch. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4340 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4341 | NewMethodBssEntryPatch(target_method, adrp_label); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 4342 | // All aligned loads are implicitly atomic consume operations on ARM64. |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4343 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4344 | break; |
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4345 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4346 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 4347 | // Load method address from literal pool. |
| 4348 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
| 4349 | break; |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4350 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4351 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4352 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4353 | } |
| 4354 | } |
| 4355 | |
| 4356 | switch (invoke->GetCodePtrLocation()) { |
| 4357 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4358 | { |
| 4359 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4360 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4361 | kInstructionSize, |
| 4362 | CodeBufferCheckScope::kExactSize); |
| 4363 | __ bl(&frame_entry_label_); |
| 4364 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4365 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4366 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4367 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4368 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4369 | __ Ldr(lr, MemOperand( |
| Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4370 | XRegisterFrom(callee_method), |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4371 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4372 | { |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4373 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4374 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4375 | kInstructionSize, |
| 4376 | CodeBufferCheckScope::kExactSize); |
| 4377 | // lr() |
| 4378 | __ blr(lr); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4379 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4380 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4381 | break; |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4382 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4383 | |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4384 | DCHECK(!IsLeafMethod()); |
| 4385 | } |
| 4386 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4387 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4388 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4389 | // Use the calling convention instead of the location of the receiver, as |
| 4390 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4391 | // slow path, the arguments have been moved to the right place, so here we are |
| 4392 | // guaranteed that the receiver is the first register of the calling convention. |
| 4393 | InvokeDexCallingConvention calling_convention; |
| 4394 | Register receiver = calling_convention.GetRegisterAt(0); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4395 | Register temp = XRegisterFrom(temp_in); |
| 4396 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4397 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4398 | Offset class_offset = mirror::Object::ClassOffset(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4399 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4400 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4401 | DCHECK(receiver.IsRegister()); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4402 | |
| 4403 | { |
| 4404 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4405 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4406 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4407 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4408 | MaybeRecordImplicitNullCheck(invoke); |
| 4409 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4410 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4411 | // emit a read barrier for the previous class reference load. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4412 | // intermediate/temporary reference and because the current |
| 4413 | // concurrent copying collector keeps the from-space memory |
| 4414 | // intact/accessible until the end of the marking phase (the |
| 4415 | // concurrent copying collector may not in the future). |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4416 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 4417 | |
| 4418 | // If we're compiling baseline, update the inline cache. |
| 4419 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 4420 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4421 | // temp = temp->GetMethodAt(method_offset); |
| 4422 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4423 | // lr = temp->GetEntryPoint(); |
| 4424 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4425 | { |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4426 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4427 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4428 | // lr(); |
| 4429 | __ blr(lr); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4430 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4431 | } |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4432 | } |
| 4433 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4434 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4435 | HandleInvoke(invoke); |
| 4436 | } |
| 4437 | |
| 4438 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4439 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4440 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4441 | } |
| 4442 | |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4443 | void LocationsBuilderARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4444 | HandleInvoke(invoke); |
| 4445 | } |
| 4446 | |
| 4447 | void InstructionCodeGeneratorARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4448 | codegen_->GenerateInvokeCustomCall(invoke); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4449 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4450 | } |
| 4451 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4452 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageIntrinsicPatch( |
| 4453 | uint32_t intrinsic_data, |
| 4454 | vixl::aarch64::Label* adrp_label) { |
| 4455 | return NewPcRelativePatch( |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4456 | /* dex_file= */ nullptr, intrinsic_data, adrp_label, &boot_image_other_patches_); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4457 | } |
| 4458 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4459 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageRelRoPatch( |
| 4460 | uint32_t boot_image_offset, |
| 4461 | vixl::aarch64::Label* adrp_label) { |
| 4462 | return NewPcRelativePatch( |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4463 | /* dex_file= */ nullptr, boot_image_offset, adrp_label, &boot_image_other_patches_); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4464 | } |
| 4465 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4466 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageMethodPatch( |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4467 | MethodReference target_method, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4468 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4469 | return NewPcRelativePatch( |
| 4470 | 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] | 4471 | } |
| 4472 | |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4473 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4474 | MethodReference target_method, |
| 4475 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4476 | return NewPcRelativePatch( |
| 4477 | 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] | 4478 | } |
| 4479 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4480 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageTypePatch( |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4481 | const DexFile& dex_file, |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4482 | dex::TypeIndex type_index, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4483 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4484 | 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] | 4485 | } |
| 4486 | |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4487 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4488 | const DexFile& dex_file, |
| 4489 | dex::TypeIndex type_index, |
| 4490 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4491 | 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] | 4492 | } |
| 4493 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4494 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageStringPatch( |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4495 | const DexFile& dex_file, |
| 4496 | dex::StringIndex string_index, |
| 4497 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4498 | return NewPcRelativePatch( |
| 4499 | &dex_file, string_index.index_, adrp_label, &boot_image_string_patches_); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4500 | } |
| 4501 | |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4502 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4503 | const DexFile& dex_file, |
| 4504 | dex::StringIndex string_index, |
| 4505 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4506 | 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] | 4507 | } |
| 4508 | |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4509 | void CodeGeneratorARM64::EmitEntrypointThunkCall(ThreadOffset64 entrypoint_offset) { |
| 4510 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
| 4511 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4512 | call_entrypoint_patches_.emplace_back(/*dex_file*/ nullptr, entrypoint_offset.Uint32Value()); |
| 4513 | vixl::aarch64::Label* bl_label = &call_entrypoint_patches_.back().label; |
| 4514 | __ bind(bl_label); |
| 4515 | __ bl(static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 4516 | } |
| 4517 | |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 4518 | void CodeGeneratorARM64::EmitBakerReadBarrierCbnz(uint32_t custom_data) { |
| Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 4519 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 4520 | if (Runtime::Current()->UseJitCompilation()) { |
| 4521 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 4522 | vixl::aarch64::Label* slow_path_entry = &it->second.label; |
| 4523 | __ cbnz(mr, slow_path_entry); |
| 4524 | } else { |
| 4525 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4526 | vixl::aarch64::Label* cbnz_label = &baker_read_barrier_patches_.back().label; |
| 4527 | __ bind(cbnz_label); |
| 4528 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 4529 | } |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4530 | } |
| 4531 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4532 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4533 | const DexFile* dex_file, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4534 | uint32_t offset_or_index, |
| 4535 | vixl::aarch64::Label* adrp_label, |
| 4536 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4537 | // Add a patch entry and return the label. |
| 4538 | patches->emplace_back(dex_file, offset_or_index); |
| 4539 | PcRelativePatchInfo* info = &patches->back(); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4540 | vixl::aarch64::Label* label = &info->label; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4541 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4542 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4543 | return label; |
| 4544 | } |
| 4545 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4546 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4547 | uint64_t address) { |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4548 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4549 | } |
| 4550 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4551 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4552 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4553 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4554 | return jit_string_patches_.GetOrCreate( |
| 4555 | StringReference(&dex_file, string_index), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4556 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4557 | } |
| 4558 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4559 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4560 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4561 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4562 | return jit_class_patches_.GetOrCreate( |
| 4563 | TypeReference(&dex_file, type_index), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4564 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); }); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4565 | } |
| 4566 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4567 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4568 | vixl::aarch64::Register reg) { |
| 4569 | DCHECK(reg.IsX()); |
| 4570 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4571 | __ Bind(fixup_label); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4572 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4573 | } |
| 4574 | |
| 4575 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4576 | vixl::aarch64::Register out, |
| 4577 | vixl::aarch64::Register base) { |
| 4578 | DCHECK(out.IsX()); |
| 4579 | DCHECK(base.IsX()); |
| 4580 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4581 | __ Bind(fixup_label); |
| 4582 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4583 | } |
| 4584 | |
| 4585 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4586 | vixl::aarch64::Register out, |
| 4587 | vixl::aarch64::Register base) { |
| 4588 | DCHECK(base.IsX()); |
| 4589 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4590 | __ Bind(fixup_label); |
| 4591 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4592 | } |
| 4593 | |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4594 | void CodeGeneratorARM64::LoadBootImageAddress(vixl::aarch64::Register reg, |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4595 | uint32_t boot_image_reference) { |
| 4596 | if (GetCompilerOptions().IsBootImage()) { |
| 4597 | // Add ADRP with its PC-relative type patch. |
| 4598 | vixl::aarch64::Label* adrp_label = NewBootImageIntrinsicPatch(boot_image_reference); |
| 4599 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4600 | // Add ADD with its PC-relative type patch. |
| 4601 | vixl::aarch64::Label* add_label = NewBootImageIntrinsicPatch(boot_image_reference, adrp_label); |
| 4602 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
| Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 4603 | } else if (GetCompilerOptions().GetCompilePic()) { |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4604 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4605 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_reference); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4606 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4607 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4608 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_reference, adrp_label); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4609 | EmitLdrOffsetPlaceholder(ldr_label, reg.W(), reg.X()); |
| 4610 | } else { |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4611 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4612 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 4613 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4614 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4615 | __ Ldr(reg.W(), DeduplicateBootImageAddressLiteral(reinterpret_cast<uintptr_t>(address))); |
| 4616 | } |
| 4617 | } |
| 4618 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4619 | void CodeGeneratorARM64::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 4620 | uint32_t boot_image_offset) { |
| 4621 | DCHECK(invoke->IsStatic()); |
| 4622 | InvokeRuntimeCallingConvention calling_convention; |
| 4623 | Register argument = calling_convention.GetRegisterAt(0); |
| 4624 | if (GetCompilerOptions().IsBootImage()) { |
| 4625 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 4626 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 4627 | MethodReference target_method = invoke->GetTargetMethod(); |
| 4628 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 4629 | // Add ADRP with its PC-relative type patch. |
| 4630 | vixl::aarch64::Label* adrp_label = NewBootImageTypePatch(*target_method.dex_file, type_idx); |
| 4631 | EmitAdrpPlaceholder(adrp_label, argument.X()); |
| 4632 | // Add ADD with its PC-relative type patch. |
| 4633 | vixl::aarch64::Label* add_label = |
| 4634 | NewBootImageTypePatch(*target_method.dex_file, type_idx, adrp_label); |
| 4635 | EmitAddPlaceholder(add_label, argument.X(), argument.X()); |
| 4636 | } else { |
| 4637 | LoadBootImageAddress(argument, boot_image_offset); |
| 4638 | } |
| 4639 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 4640 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4641 | } |
| 4642 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4643 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4644 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4645 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4646 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4647 | for (const PcRelativePatchInfo& info : infos) { |
| 4648 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4649 | info.target_dex_file, |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4650 | info.pc_insn_label->GetLocation(), |
| 4651 | info.offset_or_index)); |
| 4652 | } |
| 4653 | } |
| 4654 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4655 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 4656 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 4657 | const DexFile* target_dex_file, |
| 4658 | uint32_t pc_insn_offset, |
| 4659 | uint32_t boot_image_offset) { |
| 4660 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 4661 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4662 | } |
| 4663 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4664 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4665 | DCHECK(linker_patches->empty()); |
| 4666 | size_t size = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4667 | boot_image_method_patches_.size() + |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4668 | method_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4669 | boot_image_type_patches_.size() + |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4670 | type_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4671 | boot_image_string_patches_.size() + |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4672 | string_bss_entry_patches_.size() + |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4673 | boot_image_other_patches_.size() + |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4674 | call_entrypoint_patches_.size() + |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4675 | baker_read_barrier_patches_.size(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4676 | linker_patches->reserve(size); |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4677 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4678 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4679 | boot_image_method_patches_, linker_patches); |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4680 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4681 | boot_image_type_patches_, linker_patches); |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4682 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4683 | boot_image_string_patches_, linker_patches); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4684 | } else { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4685 | DCHECK(boot_image_method_patches_.empty()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4686 | DCHECK(boot_image_type_patches_.empty()); |
| 4687 | DCHECK(boot_image_string_patches_.empty()); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 4688 | } |
| 4689 | if (GetCompilerOptions().IsBootImage()) { |
| 4690 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 4691 | boot_image_other_patches_, linker_patches); |
| 4692 | } else { |
| 4693 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 4694 | boot_image_other_patches_, linker_patches); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4695 | } |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4696 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4697 | method_bss_entry_patches_, linker_patches); |
| 4698 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4699 | type_bss_entry_patches_, linker_patches); |
| 4700 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4701 | string_bss_entry_patches_, linker_patches); |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4702 | for (const PatchInfo<vixl::aarch64::Label>& info : call_entrypoint_patches_) { |
| 4703 | DCHECK(info.target_dex_file == nullptr); |
| 4704 | linker_patches->push_back(linker::LinkerPatch::CallEntrypointPatch( |
| 4705 | info.label.GetLocation(), info.offset_or_index)); |
| 4706 | } |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4707 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4708 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 4709 | info.label.GetLocation(), info.custom_data)); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4710 | } |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4711 | DCHECK_EQ(size, linker_patches->size()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4712 | } |
| 4713 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4714 | bool CodeGeneratorARM64::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4715 | return patch.GetType() == linker::LinkerPatch::Type::kCallEntrypoint || |
| 4716 | patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4717 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 4718 | } |
| 4719 | |
| 4720 | void CodeGeneratorARM64::EmitThunkCode(const linker::LinkerPatch& patch, |
| 4721 | /*out*/ ArenaVector<uint8_t>* code, |
| 4722 | /*out*/ std::string* debug_name) { |
| 4723 | Arm64Assembler assembler(GetGraph()->GetAllocator()); |
| 4724 | switch (patch.GetType()) { |
| 4725 | case linker::LinkerPatch::Type::kCallRelative: { |
| 4726 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 4727 | // to the generic JNI and interpreter trampolines. |
| 4728 | Offset offset(ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4729 | kArm64PointerSize).Int32Value()); |
| 4730 | assembler.JumpTo(ManagedRegister(arm64::X0), offset, ManagedRegister(arm64::IP0)); |
| 4731 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 4732 | *debug_name = "MethodCallThunk"; |
| 4733 | } |
| 4734 | break; |
| 4735 | } |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 4736 | case linker::LinkerPatch::Type::kCallEntrypoint: { |
| 4737 | Offset offset(patch.EntrypointOffset()); |
| 4738 | assembler.JumpTo(ManagedRegister(arm64::TR), offset, ManagedRegister(arm64::IP0)); |
| 4739 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 4740 | *debug_name = "EntrypointCallThunk_" + std::to_string(offset.Uint32Value()); |
| 4741 | } |
| 4742 | break; |
| 4743 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4744 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| 4745 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 4746 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 4747 | break; |
| 4748 | } |
| 4749 | default: |
| 4750 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 4751 | UNREACHABLE(); |
| 4752 | } |
| 4753 | |
| 4754 | // Ensure we emit the literal pool if any. |
| 4755 | assembler.FinalizeCode(); |
| 4756 | code->resize(assembler.CodeSize()); |
| 4757 | MemoryRegion code_region(code->data(), code->size()); |
| 4758 | assembler.FinalizeInstructions(code_region); |
| 4759 | } |
| 4760 | |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4761 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4762 | return uint32_literals_.GetOrCreate( |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4763 | value, |
| 4764 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4765 | } |
| 4766 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4767 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4768 | return uint64_literals_.GetOrCreate( |
| 4769 | value, |
| 4770 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4771 | } |
| 4772 | |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4773 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4774 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4775 | // art::PrepareForRegisterAllocation. |
| 4776 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4777 | |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4778 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4779 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4780 | return; |
| 4781 | } |
| 4782 | |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4783 | { |
| 4784 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4785 | // are no pools emitted. |
| 4786 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4787 | LocationSummary* locations = invoke->GetLocations(); |
| 4788 | codegen_->GenerateStaticOrDirectCall( |
| 4789 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| 4790 | } |
| 4791 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4792 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4793 | } |
| 4794 | |
| 4795 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4796 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4797 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4798 | return; |
| 4799 | } |
| 4800 | |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4801 | { |
| 4802 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4803 | // are no pools emitted. |
| 4804 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4805 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 4806 | DCHECK(!codegen_->IsLeafMethod()); |
| 4807 | } |
| 4808 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4809 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4810 | } |
| 4811 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4812 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4813 | HLoadClass::LoadKind desired_class_load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4814 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4815 | case HLoadClass::LoadKind::kInvalid: |
| 4816 | LOG(FATAL) << "UNREACHABLE"; |
| 4817 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4818 | case HLoadClass::LoadKind::kReferrersClass: |
| 4819 | break; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4820 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4821 | case HLoadClass::LoadKind::kBootImageRelRo: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4822 | case HLoadClass::LoadKind::kBssEntry: |
| 4823 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4824 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4825 | case HLoadClass::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4826 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4827 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4828 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4829 | case HLoadClass::LoadKind::kRuntimeCall: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4830 | break; |
| 4831 | } |
| 4832 | return desired_class_load_kind; |
| 4833 | } |
| 4834 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4835 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4836 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4837 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4838 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4839 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4840 | cls, |
| 4841 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4842 | LocationFrom(vixl::aarch64::x0)); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4843 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4844 | return; |
| 4845 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4846 | DCHECK(!cls->NeedsAccessCheck()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4847 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4848 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4849 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4850 | ? LocationSummary::kCallOnSlowPath |
| 4851 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4852 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4853 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4854 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4855 | } |
| 4856 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4857 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4858 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4859 | } |
| 4860 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4861 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 4862 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4863 | // 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] | 4864 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4865 | } else { |
| 4866 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4867 | } |
| 4868 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4869 | } |
| 4870 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4871 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4872 | // move. |
| 4873 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4874 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4875 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4876 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4877 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4878 | return; |
| 4879 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4880 | DCHECK(!cls->NeedsAccessCheck()); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4881 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4882 | Location out_loc = cls->GetLocations()->Out(); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4883 | Register out = OutputRegister(cls); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4884 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4885 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4886 | ? kWithoutReadBarrier |
| 4887 | : kCompilerReadBarrierOption; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4888 | bool generate_null_check = false; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4889 | switch (load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4890 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4891 | DCHECK(!cls->CanCallRuntime()); |
| 4892 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4893 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4894 | Register current_method = InputRegisterAt(cls, 0); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4895 | codegen_->GenerateGcRootFieldLoad(cls, |
| 4896 | out_loc, |
| 4897 | current_method, |
| 4898 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4899 | /* fixup_label= */ nullptr, |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4900 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4901 | break; |
| 4902 | } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4903 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 4904 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 4905 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4906 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4907 | // Add ADRP with its PC-relative type patch. |
| 4908 | const DexFile& dex_file = cls->GetDexFile(); |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4909 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4910 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageTypePatch(dex_file, type_index); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4911 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4912 | // Add ADD with its PC-relative type patch. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4913 | vixl::aarch64::Label* add_label = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4914 | codegen_->NewBootImageTypePatch(dex_file, type_index, adrp_label); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4915 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4916 | break; |
| 4917 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4918 | case HLoadClass::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4919 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4920 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls); |
| 4921 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 4922 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4923 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4924 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4925 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4926 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4927 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4928 | break; |
| 4929 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4930 | case HLoadClass::LoadKind::kBssEntry: { |
| 4931 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 4932 | const DexFile& dex_file = cls->GetDexFile(); |
| 4933 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 4934 | vixl::aarch64::Register temp = XRegisterFrom(out_loc); |
| 4935 | vixl::aarch64::Label* adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 4936 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4937 | // Add LDR with its PC-relative Class .bss entry patch. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4938 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 4939 | codegen_->NewBssEntryTypePatch(dex_file, type_index, adrp_label); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4940 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 4941 | // All aligned loads are implicitly atomic consume operations on ARM64. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4942 | codegen_->GenerateGcRootFieldLoad(cls, |
| 4943 | out_loc, |
| 4944 | temp, |
| 4945 | /* offset placeholder */ 0u, |
| 4946 | ldr_label, |
| 4947 | read_barrier_option); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4948 | generate_null_check = true; |
| 4949 | break; |
| 4950 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4951 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 4952 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 4953 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 4954 | DCHECK_NE(address, 0u); |
| 4955 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 4956 | break; |
| 4957 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4958 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 4959 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 4960 | cls->GetTypeIndex(), |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4961 | cls->GetClass())); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4962 | codegen_->GenerateGcRootFieldLoad(cls, |
| 4963 | out_loc, |
| 4964 | out.X(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4965 | /* offset= */ 0, |
| 4966 | /* fixup_label= */ nullptr, |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4967 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4968 | break; |
| 4969 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4970 | case HLoadClass::LoadKind::kRuntimeCall: |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4971 | case HLoadClass::LoadKind::kInvalid: |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4972 | LOG(FATAL) << "UNREACHABLE"; |
| 4973 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4974 | } |
| 4975 | |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4976 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 4977 | if (generate_null_check || do_clinit) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4978 | DCHECK(cls->CanCallRuntime()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 4979 | SlowPathCodeARM64* slow_path = |
| 4980 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(cls, cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4981 | codegen_->AddSlowPath(slow_path); |
| 4982 | if (generate_null_check) { |
| 4983 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4984 | } |
| 4985 | if (cls->MustGenerateClinitCheck()) { |
| 4986 | GenerateClassInitializationCheck(slow_path, out); |
| 4987 | } else { |
| 4988 | __ Bind(slow_path->GetExitLabel()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4989 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4990 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4991 | } |
| 4992 | } |
| 4993 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 4994 | void LocationsBuilderARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 4995 | InvokeRuntimeCallingConvention calling_convention; |
| 4996 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 4997 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 4998 | } |
| 4999 | |
| 5000 | void InstructionCodeGeneratorARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5001 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 5002 | } |
| 5003 | |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 5004 | void LocationsBuilderARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5005 | InvokeRuntimeCallingConvention calling_convention; |
| 5006 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5007 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 5008 | } |
| 5009 | |
| 5010 | void InstructionCodeGeneratorARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5011 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 5012 | } |
| 5013 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5014 | static MemOperand GetExceptionTlsAddress() { |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5015 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5016 | } |
| 5017 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5018 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5019 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5020 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5021 | locations->SetOut(Location::RequiresRegister()); |
| 5022 | } |
| 5023 | |
| 5024 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5025 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5026 | } |
| 5027 | |
| 5028 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5029 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5030 | } |
| 5031 | |
| 5032 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5033 | __ Str(wzr, GetExceptionTlsAddress()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5034 | } |
| 5035 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5036 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5037 | HLoadString::LoadKind desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5038 | switch (desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5039 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5040 | case HLoadString::LoadKind::kBootImageRelRo: |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5041 | case HLoadString::LoadKind::kBssEntry: |
| Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5042 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5043 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5044 | case HLoadString::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5045 | case HLoadString::LoadKind::kJitTableAddress: |
| 5046 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5047 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5048 | case HLoadString::LoadKind::kRuntimeCall: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5049 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5050 | } |
| 5051 | return desired_string_load_kind; |
| 5052 | } |
| 5053 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5054 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5055 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5056 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5057 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
| Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5058 | InvokeRuntimeCallingConvention calling_convention; |
| 5059 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5060 | } else { |
| 5061 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5062 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5063 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5064 | // Rely on the pResolveString and marking to save everything we need. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 5065 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5066 | } else { |
| 5067 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5068 | } |
| 5069 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5070 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5071 | } |
| 5072 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5073 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5074 | // move. |
| 5075 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5076 | Register out = OutputRegister(load); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5077 | Location out_loc = load->GetLocations()->Out(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5078 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5079 | switch (load->GetLoadKind()) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5080 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 5081 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 5082 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5083 | // Add ADRP with its PC-relative String patch. |
| 5084 | const DexFile& dex_file = load->GetDexFile(); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5085 | const dex::StringIndex string_index = load->GetStringIndex(); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5086 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageStringPatch(dex_file, string_index); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5087 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5088 | // Add ADD with its PC-relative String patch. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5089 | vixl::aarch64::Label* add_label = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5090 | codegen_->NewBootImageStringPatch(dex_file, string_index, adrp_label); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5091 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5092 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5093 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5094 | case HLoadString::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5095 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5096 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5097 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(load); |
| 5098 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5099 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5100 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5101 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5102 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5103 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 5104 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5105 | } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5106 | case HLoadString::LoadKind::kBssEntry: { |
| 5107 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5108 | const DexFile& dex_file = load->GetDexFile(); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5109 | const dex::StringIndex string_index = load->GetStringIndex(); |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5110 | Register temp = XRegisterFrom(out_loc); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5111 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5112 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5113 | // Add LDR with its PC-relative String .bss entry patch. |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5114 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5115 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5116 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 5117 | // All aligned loads are implicitly atomic consume operations on ARM64. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5118 | codegen_->GenerateGcRootFieldLoad(load, |
| 5119 | out_loc, |
| 5120 | temp, |
| 5121 | /* offset placeholder */ 0u, |
| 5122 | ldr_label, |
| 5123 | kCompilerReadBarrierOption); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5124 | SlowPathCodeARM64* slow_path = |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5125 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5126 | codegen_->AddSlowPath(slow_path); |
| 5127 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5128 | __ Bind(slow_path->GetExitLabel()); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5129 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5130 | return; |
| 5131 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5132 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 5133 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 5134 | DCHECK_NE(address, 0u); |
| 5135 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5136 | return; |
| 5137 | } |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5138 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5139 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5140 | load->GetStringIndex(), |
| 5141 | load->GetString())); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5142 | codegen_->GenerateGcRootFieldLoad(load, |
| 5143 | out_loc, |
| 5144 | out.X(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5145 | /* offset= */ 0, |
| 5146 | /* fixup_label= */ nullptr, |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5147 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5148 | return; |
| 5149 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5150 | default: |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5151 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5152 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5153 | |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5154 | // 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] | 5155 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5156 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5157 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
| Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5158 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5159 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5160 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5161 | } |
| 5162 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5163 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5164 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5165 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5166 | } |
| 5167 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5168 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5169 | // Will be generated at use site. |
| 5170 | } |
| 5171 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5172 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5173 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5174 | instruction, LocationSummary::kCallOnMainOnly); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5175 | InvokeRuntimeCallingConvention calling_convention; |
| 5176 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5177 | } |
| 5178 | |
| 5179 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5180 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5181 | instruction, |
| 5182 | instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5183 | if (instruction->IsEnter()) { |
| 5184 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5185 | } else { |
| 5186 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5187 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5188 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5189 | } |
| 5190 | |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5191 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5192 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5193 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5194 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5195 | case DataType::Type::kInt32: |
| 5196 | case DataType::Type::kInt64: |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5197 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5198 | locations->SetInAt(1, Location::RequiresRegister()); |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5199 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5200 | break; |
| 5201 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5202 | case DataType::Type::kFloat32: |
| 5203 | case DataType::Type::kFloat64: |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5204 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5205 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5206 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5207 | break; |
| 5208 | |
| 5209 | default: |
| 5210 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5211 | } |
| 5212 | } |
| 5213 | |
| 5214 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 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 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5219 | break; |
| 5220 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5221 | case DataType::Type::kFloat32: |
| 5222 | case DataType::Type::kFloat64: |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5223 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5224 | break; |
| 5225 | |
| 5226 | default: |
| 5227 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5228 | } |
| 5229 | } |
| 5230 | |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5231 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5232 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5233 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5234 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5235 | case DataType::Type::kInt32: |
| 5236 | case DataType::Type::kInt64: |
| Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5237 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5238 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5239 | break; |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5240 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5241 | case DataType::Type::kFloat32: |
| 5242 | case DataType::Type::kFloat64: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5243 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5244 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5245 | break; |
| 5246 | |
| 5247 | default: |
| 5248 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5249 | } |
| 5250 | } |
| 5251 | |
| 5252 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5253 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5254 | case DataType::Type::kInt32: |
| 5255 | case DataType::Type::kInt64: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5256 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5257 | break; |
| 5258 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5259 | case DataType::Type::kFloat32: |
| 5260 | case DataType::Type::kFloat64: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5261 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5262 | break; |
| 5263 | |
| 5264 | default: |
| 5265 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5266 | } |
| 5267 | } |
| 5268 | |
| 5269 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5270 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5271 | instruction, LocationSummary::kCallOnMainOnly); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5272 | InvokeRuntimeCallingConvention calling_convention; |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5273 | locations->SetOut(LocationFrom(x0)); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5274 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5275 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5276 | } |
| 5277 | |
| 5278 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5279 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5280 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
| Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5281 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5282 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5283 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5284 | } |
| 5285 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5286 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5287 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5288 | instruction, LocationSummary::kCallOnMainOnly); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5289 | InvokeRuntimeCallingConvention calling_convention; |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5290 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5291 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5292 | } |
| 5293 | |
| 5294 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5295 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5296 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5297 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5298 | } |
| 5299 | |
| 5300 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5301 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5302 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5303 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5304 | } |
| 5305 | |
| 5306 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5307 | switch (instruction->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5308 | case DataType::Type::kInt32: |
| 5309 | case DataType::Type::kInt64: |
| Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5310 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5311 | break; |
| 5312 | |
| 5313 | default: |
| 5314 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5315 | } |
| 5316 | } |
| 5317 | |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5318 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5319 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5320 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5321 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5322 | } |
| 5323 | |
| 5324 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5325 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5326 | } |
| 5327 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5328 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5329 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5330 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5331 | } |
| 5332 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5333 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5334 | if (CanMoveNullCheckToUser(instruction)) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5335 | return; |
| 5336 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5337 | { |
| Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 5338 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5339 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5340 | Location obj = instruction->GetLocations()->InAt(0); |
| 5341 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5342 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5343 | } |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5344 | } |
| 5345 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5346 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5347 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5348 | AddSlowPath(slow_path); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5349 | |
| 5350 | LocationSummary* locations = instruction->GetLocations(); |
| 5351 | Location obj = locations->InAt(0); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5352 | |
| 5353 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5354 | } |
| 5355 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5356 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5357 | codegen_->GenerateNullCheck(instruction); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5358 | } |
| 5359 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5360 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5361 | HandleBinaryOp(instruction); |
| 5362 | } |
| 5363 | |
| 5364 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5365 | HandleBinaryOp(instruction); |
| 5366 | } |
| 5367 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5368 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5369 | LOG(FATAL) << "Unreachable"; |
| 5370 | } |
| 5371 | |
| 5372 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5373 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5374 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5375 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5376 | // The back edge will generate the suspend check. |
| 5377 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5378 | } |
| 5379 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5380 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5381 | } |
| 5382 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5383 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5384 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5385 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5386 | if (location.IsStackSlot()) { |
| 5387 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5388 | } else if (location.IsDoubleStackSlot()) { |
| 5389 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5390 | } |
| 5391 | locations->SetOut(location); |
| 5392 | } |
| 5393 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5394 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5395 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5396 | // Nothing to do, the parameter is already at its location. |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5397 | } |
| 5398 | |
| 5399 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5400 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5401 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5402 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5403 | } |
| 5404 | |
| 5405 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5406 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5407 | // Nothing to do, the method is already at its location. |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5411 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5412 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5413 | locations->SetInAt(i, Location::Any()); |
| 5414 | } |
| 5415 | locations->SetOut(Location::Any()); |
| 5416 | } |
| 5417 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5418 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5419 | LOG(FATAL) << "Unreachable"; |
| 5420 | } |
| 5421 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5422 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5423 | DataType::Type type = rem->GetResultType(); |
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5424 | LocationSummary::CallKind call_kind = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5425 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5426 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5427 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5428 | |
| 5429 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5430 | case DataType::Type::kInt32: |
| 5431 | case DataType::Type::kInt64: |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5432 | locations->SetInAt(0, Location::RequiresRegister()); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5433 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5434 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5435 | break; |
| 5436 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5437 | case DataType::Type::kFloat32: |
| 5438 | case DataType::Type::kFloat64: { |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5439 | InvokeRuntimeCallingConvention calling_convention; |
| 5440 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5441 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5442 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5443 | |
| 5444 | break; |
| 5445 | } |
| 5446 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5447 | default: |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5448 | LOG(FATAL) << "Unexpected rem type " << type; |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5449 | } |
| 5450 | } |
| 5451 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5452 | void InstructionCodeGeneratorARM64::GenerateIntRemForPower2Denom(HRem *instruction) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5453 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5454 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 5455 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 5456 | |
| 5457 | Register out = OutputRegister(instruction); |
| 5458 | Register dividend = InputRegisterAt(instruction, 0); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5459 | |
| Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5460 | if (abs_imm == 2) { |
| 5461 | __ Cmp(dividend, 0); |
| 5462 | __ And(out, dividend, 1); |
| 5463 | __ Csneg(out, out, out, ge); |
| 5464 | } else { |
| 5465 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5466 | Register temp = temps.AcquireSameSizeAs(out); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5467 | |
| Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5468 | __ Negs(temp, dividend); |
| 5469 | __ And(out, dividend, abs_imm - 1); |
| 5470 | __ And(temp, temp, abs_imm - 1); |
| 5471 | __ Csneg(out, out, temp, mi); |
| 5472 | } |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5473 | } |
| 5474 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5475 | void InstructionCodeGeneratorARM64::GenerateIntRemForConstDenom(HRem *instruction) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5476 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5477 | |
| 5478 | if (imm == 0) { |
| 5479 | // Do not generate anything. |
| 5480 | // DivZeroCheck would prevent any code to be executed. |
| 5481 | return; |
| 5482 | } |
| 5483 | |
| Evgeny Astigeevich | f58dc65 | 2018-06-25 17:54:07 +0100 | [diff] [blame] | 5484 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 5485 | // Cases imm == -1 or imm == 1 are handled in constant folding by |
| 5486 | // InstructionWithAbsorbingInputSimplifier. |
| 5487 | // If the cases have survided till code generation they are handled in |
| 5488 | // GenerateIntRemForPower2Denom becauses -1 and 1 are the power of 2 (2^0). |
| 5489 | // The correct code is generated for them, just more instructions. |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5490 | GenerateIntRemForPower2Denom(instruction); |
| 5491 | } else { |
| 5492 | DCHECK(imm < -2 || imm > 2) << imm; |
| 5493 | GenerateDivRemWithAnyConstant(instruction); |
| 5494 | } |
| 5495 | } |
| 5496 | |
| 5497 | void InstructionCodeGeneratorARM64::GenerateIntRem(HRem* instruction) { |
| 5498 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 5499 | << instruction->GetResultType(); |
| 5500 | |
| 5501 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 5502 | GenerateIntRemForConstDenom(instruction); |
| 5503 | } else { |
| 5504 | Register out = OutputRegister(instruction); |
| 5505 | Register dividend = InputRegisterAt(instruction, 0); |
| 5506 | Register divisor = InputRegisterAt(instruction, 1); |
| 5507 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5508 | Register temp = temps.AcquireSameSizeAs(out); |
| 5509 | __ Sdiv(temp, dividend, divisor); |
| 5510 | __ Msub(out, temp, divisor, dividend); |
| 5511 | } |
| 5512 | } |
| 5513 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5514 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5515 | DataType::Type type = rem->GetResultType(); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5516 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5517 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5518 | case DataType::Type::kInt32: |
| 5519 | case DataType::Type::kInt64: { |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5520 | GenerateIntRem(rem); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5521 | break; |
| 5522 | } |
| 5523 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5524 | case DataType::Type::kFloat32: |
| 5525 | case DataType::Type::kFloat64: { |
| 5526 | QuickEntrypointEnum entrypoint = |
| 5527 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5528 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5529 | if (type == DataType::Type::kFloat32) { |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5530 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5531 | } else { |
| 5532 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5533 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5534 | break; |
| 5535 | } |
| 5536 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5537 | default: |
| 5538 | LOG(FATAL) << "Unexpected rem type " << type; |
| Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5539 | UNREACHABLE(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5540 | } |
| 5541 | } |
| 5542 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5543 | void LocationsBuilderARM64::VisitMin(HMin* min) { |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5544 | HandleBinaryOp(min); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5545 | } |
| 5546 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5547 | void InstructionCodeGeneratorARM64::VisitMin(HMin* min) { |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5548 | HandleBinaryOp(min); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5549 | } |
| 5550 | |
| 5551 | void LocationsBuilderARM64::VisitMax(HMax* max) { |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5552 | HandleBinaryOp(max); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5553 | } |
| 5554 | |
| 5555 | void InstructionCodeGeneratorARM64::VisitMax(HMax* max) { |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5556 | HandleBinaryOp(max); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5557 | } |
| 5558 | |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5559 | void LocationsBuilderARM64::VisitAbs(HAbs* abs) { |
| 5560 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 5561 | switch (abs->GetResultType()) { |
| 5562 | case DataType::Type::kInt32: |
| 5563 | case DataType::Type::kInt64: |
| 5564 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5565 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5566 | break; |
| 5567 | case DataType::Type::kFloat32: |
| 5568 | case DataType::Type::kFloat64: |
| 5569 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5570 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5571 | break; |
| 5572 | default: |
| 5573 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5574 | } |
| 5575 | } |
| 5576 | |
| 5577 | void InstructionCodeGeneratorARM64::VisitAbs(HAbs* abs) { |
| 5578 | switch (abs->GetResultType()) { |
| 5579 | case DataType::Type::kInt32: |
| 5580 | case DataType::Type::kInt64: { |
| 5581 | Register in_reg = InputRegisterAt(abs, 0); |
| 5582 | Register out_reg = OutputRegister(abs); |
| 5583 | __ Cmp(in_reg, Operand(0)); |
| 5584 | __ Cneg(out_reg, in_reg, lt); |
| 5585 | break; |
| 5586 | } |
| 5587 | case DataType::Type::kFloat32: |
| 5588 | case DataType::Type::kFloat64: { |
| Evgeny Astigeevich | 7d48dcd | 2019-10-16 12:46:28 +0100 | [diff] [blame] | 5589 | VRegister in_reg = InputFPRegisterAt(abs, 0); |
| 5590 | VRegister out_reg = OutputFPRegister(abs); |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5591 | __ Fabs(out_reg, in_reg); |
| 5592 | break; |
| 5593 | } |
| 5594 | default: |
| 5595 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5596 | } |
| 5597 | } |
| 5598 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5599 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5600 | constructor_fence->SetLocations(nullptr); |
| 5601 | } |
| 5602 | |
| 5603 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5604 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5605 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5606 | } |
| 5607 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5608 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5609 | memory_barrier->SetLocations(nullptr); |
| 5610 | } |
| 5611 | |
| 5612 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5613 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5614 | } |
| 5615 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5616 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5617 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5618 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5619 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5620 | } |
| 5621 | |
| Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 5622 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* ret) { |
| 5623 | if (GetGraph()->IsCompilingOsr()) { |
| 5624 | // To simplify callers of an OSR method, we put the return value in both |
| 5625 | // floating point and core register. |
| 5626 | switch (ret->InputAt(0)->GetType()) { |
| 5627 | case DataType::Type::kFloat32: |
| 5628 | __ Fmov(w0, s0); |
| 5629 | break; |
| 5630 | case DataType::Type::kFloat64: |
| 5631 | __ Fmov(x0, d0); |
| 5632 | break; |
| 5633 | default: |
| 5634 | break; |
| 5635 | } |
| 5636 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5637 | codegen_->GenerateFrameExit(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5638 | } |
| 5639 | |
| 5640 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5641 | instruction->SetLocations(nullptr); |
| 5642 | } |
| 5643 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5644 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5645 | codegen_->GenerateFrameExit(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5646 | } |
| 5647 | |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5648 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5649 | HandleBinaryOp(ror); |
| 5650 | } |
| 5651 | |
| 5652 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5653 | HandleBinaryOp(ror); |
| 5654 | } |
| 5655 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5656 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5657 | HandleShift(shl); |
| 5658 | } |
| 5659 | |
| 5660 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5661 | HandleShift(shl); |
| 5662 | } |
| 5663 | |
| 5664 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5665 | HandleShift(shr); |
| 5666 | } |
| 5667 | |
| 5668 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5669 | HandleShift(shr); |
| 5670 | } |
| 5671 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5672 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5673 | HandleBinaryOp(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5674 | } |
| 5675 | |
| 5676 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5677 | HandleBinaryOp(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5678 | } |
| 5679 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5680 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5681 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5682 | } |
| 5683 | |
| 5684 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5685 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5686 | } |
| 5687 | |
| 5688 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5689 | HandleFieldSet(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5690 | } |
| 5691 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5692 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5693 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5694 | } |
| 5695 | |
| Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 5696 | void LocationsBuilderARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5697 | codegen_->CreateStringBuilderAppendLocations(instruction, LocationFrom(x0)); |
| 5698 | } |
| 5699 | |
| 5700 | void InstructionCodeGeneratorARM64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5701 | __ Mov(w0, instruction->GetFormat()->GetValue()); |
| 5702 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 5703 | } |
| 5704 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5705 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5706 | HUnresolvedInstanceFieldGet* instruction) { |
| 5707 | FieldAccessCallingConventionARM64 calling_convention; |
| 5708 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5709 | instruction, instruction->GetFieldType(), calling_convention); |
| 5710 | } |
| 5711 | |
| 5712 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5713 | HUnresolvedInstanceFieldGet* instruction) { |
| 5714 | FieldAccessCallingConventionARM64 calling_convention; |
| 5715 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5716 | instruction->GetFieldType(), |
| 5717 | instruction->GetFieldIndex(), |
| 5718 | instruction->GetDexPc(), |
| 5719 | calling_convention); |
| 5720 | } |
| 5721 | |
| 5722 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5723 | HUnresolvedInstanceFieldSet* instruction) { |
| 5724 | FieldAccessCallingConventionARM64 calling_convention; |
| 5725 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5726 | instruction, instruction->GetFieldType(), calling_convention); |
| 5727 | } |
| 5728 | |
| 5729 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5730 | HUnresolvedInstanceFieldSet* instruction) { |
| 5731 | FieldAccessCallingConventionARM64 calling_convention; |
| 5732 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5733 | instruction->GetFieldType(), |
| 5734 | instruction->GetFieldIndex(), |
| 5735 | instruction->GetDexPc(), |
| 5736 | calling_convention); |
| 5737 | } |
| 5738 | |
| 5739 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5740 | HUnresolvedStaticFieldGet* instruction) { |
| 5741 | FieldAccessCallingConventionARM64 calling_convention; |
| 5742 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5743 | instruction, instruction->GetFieldType(), calling_convention); |
| 5744 | } |
| 5745 | |
| 5746 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5747 | HUnresolvedStaticFieldGet* instruction) { |
| 5748 | FieldAccessCallingConventionARM64 calling_convention; |
| 5749 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5750 | instruction->GetFieldType(), |
| 5751 | instruction->GetFieldIndex(), |
| 5752 | instruction->GetDexPc(), |
| 5753 | calling_convention); |
| 5754 | } |
| 5755 | |
| 5756 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5757 | HUnresolvedStaticFieldSet* instruction) { |
| 5758 | FieldAccessCallingConventionARM64 calling_convention; |
| 5759 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5760 | instruction, instruction->GetFieldType(), calling_convention); |
| 5761 | } |
| 5762 | |
| 5763 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5764 | HUnresolvedStaticFieldSet* instruction) { |
| 5765 | FieldAccessCallingConventionARM64 calling_convention; |
| 5766 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5767 | instruction->GetFieldType(), |
| 5768 | instruction->GetFieldIndex(), |
| 5769 | instruction->GetDexPc(), |
| 5770 | calling_convention); |
| 5771 | } |
| 5772 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5773 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5774 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5775 | instruction, LocationSummary::kCallOnSlowPath); |
| Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5776 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5777 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5778 | // registers in full width (since the runtime only saves/restores lower part). |
| 5779 | locations->SetCustomSlowPathCallerSaves( |
| 5780 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5781 | } |
| 5782 | |
| 5783 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5784 | HBasicBlock* block = instruction->GetBlock(); |
| 5785 | if (block->GetLoopInformation() != nullptr) { |
| 5786 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5787 | // The back edge will generate the suspend check. |
| 5788 | return; |
| 5789 | } |
| 5790 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5791 | // The goto will generate the suspend check. |
| 5792 | return; |
| 5793 | } |
| 5794 | GenerateSuspendCheck(instruction, nullptr); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5795 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5796 | } |
| 5797 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5798 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5799 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5800 | instruction, LocationSummary::kCallOnMainOnly); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5801 | InvokeRuntimeCallingConvention calling_convention; |
| 5802 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5803 | } |
| 5804 | |
| 5805 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5806 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5807 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5808 | } |
| 5809 | |
| 5810 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5811 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5812 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5813 | DataType::Type input_type = conversion->GetInputType(); |
| 5814 | DataType::Type result_type = conversion->GetResultType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5815 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5816 | << input_type << " -> " << result_type; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5817 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 5818 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5819 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5820 | } |
| 5821 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5822 | if (DataType::IsFloatingPointType(input_type)) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5823 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5824 | } else { |
| 5825 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5826 | } |
| 5827 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5828 | if (DataType::IsFloatingPointType(result_type)) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5829 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5830 | } else { |
| 5831 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5832 | } |
| 5833 | } |
| 5834 | |
| 5835 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5836 | DataType::Type result_type = conversion->GetResultType(); |
| 5837 | DataType::Type input_type = conversion->GetInputType(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5838 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5839 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5840 | << input_type << " -> " << result_type; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5841 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5842 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 5843 | int result_size = DataType::Size(result_type); |
| 5844 | int input_size = DataType::Size(input_type); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5845 | int min_size = std::min(result_size, input_size); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5846 | Register output = OutputRegister(conversion); |
| 5847 | Register source = InputRegisterAt(conversion, 0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5848 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
| Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5849 | // 'int' values are used directly as W registers, discarding the top |
| 5850 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5851 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5852 | // top 32 bits of the target register. We theoretically could leave those |
| 5853 | // bits unchanged, but we would have to make sure that no code uses a |
| 5854 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5855 | // zero. |
| 5856 | __ Mov(output.W(), source.W()); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5857 | } else if (DataType::IsUnsignedType(result_type) || |
| 5858 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 5859 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5860 | } else { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5861 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
| 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 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5864 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5865 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 5866 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5867 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5868 | } else if (DataType::IsFloatingPointType(result_type) && |
| 5869 | DataType::IsFloatingPointType(input_type)) { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5870 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5871 | } else { |
| 5872 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5873 | << " to " << result_type; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5874 | } |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5875 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5876 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5877 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5878 | HandleShift(ushr); |
| 5879 | } |
| 5880 | |
| 5881 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5882 | HandleShift(ushr); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5883 | } |
| 5884 | |
| 5885 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5886 | HandleBinaryOp(instruction); |
| 5887 | } |
| 5888 | |
| 5889 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5890 | HandleBinaryOp(instruction); |
| 5891 | } |
| 5892 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5893 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5894 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5895 | LOG(FATAL) << "Unreachable"; |
| 5896 | } |
| 5897 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5898 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5899 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5900 | LOG(FATAL) << "Unreachable"; |
| 5901 | } |
| 5902 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5903 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5904 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5905 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5906 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5907 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5908 | } |
| 5909 | |
| 5910 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5911 | int32_t lower_bound = switch_instr->GetStartValue(); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5912 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5913 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5914 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5915 | |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5916 | // 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] | 5917 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5918 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5919 | // make sure we don't emit it if the target may run out of range. |
| 5920 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5921 | // ranges and emit the tables only as required. |
| 5922 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5923 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5924 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5925 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5926 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5927 | // Create a series of compare/jumps. |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5928 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5929 | Register temp = temps.AcquireW(); |
| 5930 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5931 | |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5932 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5933 | // Jump to successors[0] if value == lower_bound. |
| 5934 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5935 | int32_t last_index = 0; |
| 5936 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5937 | __ Subs(temp, temp, Operand(2)); |
| 5938 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5939 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5940 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5941 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5942 | } |
| 5943 | if (num_entries - last_index == 2) { |
| 5944 | // The last missing case_value. |
| 5945 | __ Cmp(temp, Operand(1)); |
| 5946 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5947 | } |
| 5948 | |
| 5949 | // And the default for any other value. |
| 5950 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5951 | __ B(codegen_->GetLabelOf(default_block)); |
| 5952 | } |
| 5953 | } else { |
| Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5954 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5955 | |
| 5956 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5957 | |
| 5958 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5959 | // registers, we are free to block one. |
| 5960 | Register temp_w = temps.AcquireW(); |
| 5961 | Register index; |
| 5962 | // Remove the bias. |
| 5963 | if (lower_bound != 0) { |
| 5964 | index = temp_w; |
| 5965 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5966 | } else { |
| 5967 | index = value_reg; |
| 5968 | } |
| 5969 | |
| 5970 | // Jump to default block if index is out of the range. |
| 5971 | __ Cmp(index, Operand(num_entries)); |
| 5972 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5973 | |
| 5974 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5975 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5976 | // register pressure. |
| 5977 | Register table_base = temps.AcquireX(); |
| 5978 | // Load jump offset from the table. |
| 5979 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5980 | Register jump_offset = temp_w; |
| 5981 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5982 | |
| 5983 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5984 | Register target_address = table_base; |
| 5985 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5986 | __ Br(target_address); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5987 | } |
| 5988 | } |
| 5989 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5990 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 5991 | HInstruction* instruction, |
| 5992 | Location out, |
| 5993 | uint32_t offset, |
| 5994 | Location maybe_temp, |
| 5995 | ReadBarrierOption read_barrier_option) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5996 | DataType::Type type = DataType::Type::kReference; |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5997 | Register out_reg = RegisterFrom(out, type); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5998 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5999 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6000 | if (kUseBakerReadBarrier) { |
| 6001 | // Load with fast path based Baker's read barrier. |
| 6002 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6003 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6004 | out, |
| 6005 | out_reg, |
| 6006 | offset, |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6007 | maybe_temp, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6008 | /* needs_null_check= */ false, |
| 6009 | /* use_load_acquire= */ false); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6010 | } else { |
| 6011 | // Load with slow path based read barrier. |
| 6012 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6013 | // in the following move operation, as we will need it for the |
| 6014 | // read barrier below. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6015 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6016 | __ Mov(temp_reg, out_reg); |
| 6017 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6018 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6019 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6020 | } |
| 6021 | } else { |
| 6022 | // Plain load with no read barrier. |
| 6023 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6024 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6025 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6026 | } |
| 6027 | } |
| 6028 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6029 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 6030 | HInstruction* instruction, |
| 6031 | Location out, |
| 6032 | Location obj, |
| 6033 | uint32_t offset, |
| 6034 | Location maybe_temp, |
| 6035 | ReadBarrierOption read_barrier_option) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6036 | DataType::Type type = DataType::Type::kReference; |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6037 | Register out_reg = RegisterFrom(out, type); |
| 6038 | Register obj_reg = RegisterFrom(obj, type); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6039 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6040 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6041 | if (kUseBakerReadBarrier) { |
| 6042 | // Load with fast path based Baker's read barrier. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6043 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6044 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6045 | out, |
| 6046 | obj_reg, |
| 6047 | offset, |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6048 | maybe_temp, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6049 | /* needs_null_check= */ false, |
| 6050 | /* use_load_acquire= */ false); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6051 | } else { |
| 6052 | // Load with slow path based read barrier. |
| 6053 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6054 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6055 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6056 | } |
| 6057 | } else { |
| 6058 | // Plain load with no read barrier. |
| 6059 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6060 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6061 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6062 | } |
| 6063 | } |
| 6064 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6065 | void CodeGeneratorARM64::GenerateGcRootFieldLoad( |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6066 | HInstruction* instruction, |
| 6067 | Location root, |
| 6068 | Register obj, |
| 6069 | uint32_t offset, |
| 6070 | vixl::aarch64::Label* fixup_label, |
| 6071 | ReadBarrierOption read_barrier_option) { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6072 | DCHECK(fixup_label == nullptr || offset == 0u); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6073 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6074 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6075 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6076 | if (kUseBakerReadBarrier) { |
| 6077 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6078 | // Baker's read barrier are used. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6079 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6080 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6081 | // the Marking Register) to decide whether we need to enter |
| 6082 | // the slow path to mark the GC root. |
| 6083 | // |
| 6084 | // We use shared thunks for the slow path; shared within the method |
| 6085 | // for JIT, across methods for AOT. That thunk checks the reference |
| 6086 | // and jumps to the entrypoint if needed. |
| 6087 | // |
| 6088 | // lr = &return_address; |
| 6089 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6090 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6091 | // goto gc_root_thunk<root_reg>(lr) |
| 6092 | // } |
| 6093 | // return_address: |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6094 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6095 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6096 | DCHECK(temps.IsAvailable(ip0)); |
| 6097 | DCHECK(temps.IsAvailable(ip1)); |
| 6098 | temps.Exclude(ip0, ip1); |
| 6099 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
| 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 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6102 | vixl::aarch64::Label return_address; |
| 6103 | __ adr(lr, &return_address); |
| 6104 | if (fixup_label != nullptr) { |
| 6105 | __ bind(fixup_label); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6106 | } |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6107 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6108 | "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] | 6109 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6110 | EmitBakerReadBarrierCbnz(custom_data); |
| 6111 | __ bind(&return_address); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6112 | } else { |
| 6113 | // GC root loaded through a slow path for read barriers other |
| 6114 | // than Baker's. |
| 6115 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6116 | if (fixup_label == nullptr) { |
| 6117 | __ Add(root_reg.X(), obj.X(), offset); |
| 6118 | } else { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6119 | EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6120 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6121 | // /* mirror::Object* */ root = root->Read() |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6122 | GenerateReadBarrierForRootSlow(instruction, root, root); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6123 | } |
| 6124 | } else { |
| 6125 | // Plain GC root load with no read barrier. |
| 6126 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6127 | if (fixup_label == nullptr) { |
| 6128 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6129 | } else { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6130 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6131 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6132 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6133 | // do not have to unpoison `root_reg` here. |
| 6134 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6135 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6136 | } |
| 6137 | |
| Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 6138 | void CodeGeneratorARM64::GenerateUnsafeCasOldValueMovWithBakerReadBarrier( |
| 6139 | vixl::aarch64::Register marked, |
| 6140 | vixl::aarch64::Register old_value) { |
| 6141 | DCHECK(kEmitCompilerReadBarrier); |
| 6142 | DCHECK(kUseBakerReadBarrier); |
| 6143 | |
| 6144 | // Similar to the Baker RB path in GenerateGcRootFieldLoad(), with a MOV instead of LDR. |
| 6145 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(marked.GetCode()); |
| 6146 | |
| 6147 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6148 | vixl::aarch64::Label return_address; |
| 6149 | __ adr(lr, &return_address); |
| 6150 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6151 | "GC root LDR must be 2 instructions (8B) before the return address label."); |
| 6152 | __ mov(marked, old_value); |
| 6153 | EmitBakerReadBarrierCbnz(custom_data); |
| 6154 | __ bind(&return_address); |
| 6155 | } |
| 6156 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6157 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6158 | Location ref, |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6159 | vixl::aarch64::Register obj, |
| 6160 | const vixl::aarch64::MemOperand& src, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6161 | bool needs_null_check, |
| 6162 | bool use_load_acquire) { |
| 6163 | DCHECK(kEmitCompilerReadBarrier); |
| 6164 | DCHECK(kUseBakerReadBarrier); |
| 6165 | |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6166 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6167 | // Marking Register) to decide whether we need to enter the slow |
| 6168 | // path to mark the reference. Then, in the slow path, check the |
| 6169 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6170 | // decide whether to mark `ref` or not. |
| 6171 | // |
| 6172 | // We use shared thunks for the slow path; shared within the method |
| 6173 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6174 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6175 | // it creates a fake dependency and returns to the LDR instruction. |
| 6176 | // |
| 6177 | // lr = &gray_return_address; |
| 6178 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6179 | // goto field_thunk<holder_reg, base_reg, use_load_acquire>(lr) |
| 6180 | // } |
| 6181 | // not_gray_return_address: |
| 6182 | // // Original reference load. If the offset is too large to fit |
| 6183 | // // into LDR, we use an adjusted base register here. |
| 6184 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 6185 | // gray_return_address: |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6186 | |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6187 | DCHECK(src.GetAddrMode() == vixl::aarch64::Offset); |
| 6188 | DCHECK_ALIGNED(src.GetOffset(), sizeof(mirror::HeapReference<mirror::Object>)); |
| 6189 | |
| 6190 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6191 | DCHECK(temps.IsAvailable(ip0)); |
| 6192 | DCHECK(temps.IsAvailable(ip1)); |
| 6193 | temps.Exclude(ip0, ip1); |
| 6194 | uint32_t custom_data = use_load_acquire |
| 6195 | ? EncodeBakerReadBarrierAcquireData(src.GetBaseRegister().GetCode(), obj.GetCode()) |
| 6196 | : EncodeBakerReadBarrierFieldData(src.GetBaseRegister().GetCode(), obj.GetCode()); |
| 6197 | |
| 6198 | { |
| 6199 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6200 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6201 | vixl::aarch64::Label return_address; |
| 6202 | __ adr(lr, &return_address); |
| 6203 | EmitBakerReadBarrierCbnz(custom_data); |
| 6204 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6205 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6206 | " 2 instructions (8B) for heap poisoning."); |
| 6207 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 6208 | if (use_load_acquire) { |
| 6209 | DCHECK_EQ(src.GetOffset(), 0); |
| 6210 | __ ldar(ref_reg, src); |
| 6211 | } else { |
| 6212 | __ ldr(ref_reg, src); |
| 6213 | } |
| 6214 | if (needs_null_check) { |
| 6215 | MaybeRecordImplicitNullCheck(instruction); |
| 6216 | } |
| 6217 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6218 | // macro instructions disallowed in ExactAssemblyScope. |
| 6219 | if (kPoisonHeapReferences) { |
| 6220 | __ neg(ref_reg, Operand(ref_reg)); |
| 6221 | } |
| 6222 | __ bind(&return_address); |
| 6223 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6224 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6225 | } |
| 6226 | |
| 6227 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6228 | Location ref, |
| 6229 | Register obj, |
| 6230 | uint32_t offset, |
| 6231 | Location maybe_temp, |
| 6232 | bool needs_null_check, |
| 6233 | bool use_load_acquire) { |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6234 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6235 | Register base = obj; |
| 6236 | if (use_load_acquire) { |
| 6237 | DCHECK(maybe_temp.IsRegister()); |
| 6238 | base = WRegisterFrom(maybe_temp); |
| 6239 | __ Add(base, obj, offset); |
| 6240 | offset = 0u; |
| 6241 | } else if (offset >= kReferenceLoadMinFarOffset) { |
| 6242 | DCHECK(maybe_temp.IsRegister()); |
| 6243 | base = WRegisterFrom(maybe_temp); |
| 6244 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6245 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6246 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6247 | } |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 6248 | MemOperand src(base.X(), offset); |
| 6249 | GenerateFieldLoadWithBakerReadBarrier( |
| 6250 | instruction, ref, obj, src, needs_null_check, use_load_acquire); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6251 | } |
| 6252 | |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6253 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HArrayGet* instruction, |
| 6254 | Location ref, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6255 | Register obj, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6256 | uint32_t data_offset, |
| 6257 | Location index, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6258 | bool needs_null_check) { |
| 6259 | DCHECK(kEmitCompilerReadBarrier); |
| 6260 | DCHECK(kUseBakerReadBarrier); |
| 6261 | |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6262 | static_assert( |
| 6263 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6264 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6265 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6266 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6267 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6268 | // Marking Register) to decide whether we need to enter the slow |
| 6269 | // path to mark the reference. Then, in the slow path, check the |
| 6270 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6271 | // decide whether to mark `ref` or not. |
| 6272 | // |
| 6273 | // We use shared thunks for the slow path; shared within the method |
| 6274 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6275 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6276 | // it creates a fake dependency and returns to the LDR instruction. |
| 6277 | // |
| 6278 | // lr = &gray_return_address; |
| 6279 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6280 | // goto array_thunk<base_reg>(lr) |
| 6281 | // } |
| 6282 | // not_gray_return_address: |
| 6283 | // // Original reference load. If the offset is too large to fit |
| 6284 | // // into LDR, we use an adjusted base register here. |
| 6285 | // HeapReference<mirror::Object> reference = data[index]; |
| 6286 | // gray_return_address: |
| 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 | DCHECK(index.IsValid()); |
| 6289 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 6290 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6291 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6292 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6293 | DCHECK(temps.IsAvailable(ip0)); |
| 6294 | DCHECK(temps.IsAvailable(ip1)); |
| 6295 | temps.Exclude(ip0, ip1); |
| Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6296 | |
| 6297 | Register temp; |
| 6298 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 6299 | // We do not need to compute the intermediate address from the array: the |
| 6300 | // input instruction has done it already. See the comment in |
| 6301 | // `TryExtractArrayAccessAddress()`. |
| 6302 | if (kIsDebugBuild) { |
| 6303 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 6304 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 6305 | } |
| 6306 | temp = obj; |
| 6307 | } else { |
| 6308 | temp = WRegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 6309 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
| 6310 | } |
| 6311 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6312 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(temp.GetCode()); |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6313 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6314 | { |
| 6315 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6316 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6317 | vixl::aarch64::Label return_address; |
| 6318 | __ adr(lr, &return_address); |
| 6319 | EmitBakerReadBarrierCbnz(custom_data); |
| 6320 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6321 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6322 | " 2 instructions (8B) for heap poisoning."); |
| 6323 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6324 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6325 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6326 | // macro instructions disallowed in ExactAssemblyScope. |
| 6327 | if (kPoisonHeapReferences) { |
| 6328 | __ neg(ref_reg, Operand(ref_reg)); |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6329 | } |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6330 | __ bind(&return_address); |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6331 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6332 | MaybeGenerateMarkingRegisterCheck(/* code= */ __LINE__, /* temp_loc= */ LocationFrom(ip1)); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6333 | } |
| 6334 | |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6335 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6336 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6337 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6338 | // The following condition is a run-time one; it is executed after the |
| 6339 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6340 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6341 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6342 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6343 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6344 | } |
| 6345 | } |
| 6346 | } |
| 6347 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6348 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6349 | Location out, |
| 6350 | Location ref, |
| 6351 | Location obj, |
| 6352 | uint32_t offset, |
| 6353 | Location index) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6354 | DCHECK(kEmitCompilerReadBarrier); |
| 6355 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6356 | // Insert a slow path based read barrier *after* the reference load. |
| 6357 | // |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6358 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6359 | // reference will be carried out by the runtime within the slow |
| 6360 | // path. |
| 6361 | // |
| 6362 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6363 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6364 | // not used by the artReadBarrierSlow entry point. |
| 6365 | // |
| 6366 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6367 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6368 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6369 | AddSlowPath(slow_path); |
| 6370 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6371 | __ B(slow_path->GetEntryLabel()); |
| 6372 | __ Bind(slow_path->GetExitLabel()); |
| 6373 | } |
| 6374 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6375 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6376 | Location out, |
| 6377 | Location ref, |
| 6378 | Location obj, |
| 6379 | uint32_t offset, |
| 6380 | Location index) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6381 | if (kEmitCompilerReadBarrier) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6382 | // Baker's read barriers shall be handled by the fast path |
| 6383 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6384 | DCHECK(!kUseBakerReadBarrier); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6385 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6386 | // by the runtime within the slow path. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6387 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6388 | } else if (kPoisonHeapReferences) { |
| 6389 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6390 | } |
| 6391 | } |
| 6392 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6393 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6394 | Location out, |
| 6395 | Location root) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6396 | DCHECK(kEmitCompilerReadBarrier); |
| 6397 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6398 | // Insert a slow path based read barrier *after* the GC root load. |
| 6399 | // |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6400 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6401 | // not need to do anything special for this here. |
| 6402 | SlowPathCodeARM64* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6403 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6404 | AddSlowPath(slow_path); |
| 6405 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6406 | __ B(slow_path->GetEntryLabel()); |
| 6407 | __ Bind(slow_path->GetExitLabel()); |
| 6408 | } |
| 6409 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6410 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6411 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6412 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6413 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6414 | locations->SetOut(Location::RequiresRegister()); |
| 6415 | } |
| 6416 | |
| 6417 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6418 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6419 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6420 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6421 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6422 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6423 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6424 | } else { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6425 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6426 | instruction->GetIndex(), kArm64PointerSize)); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6427 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6428 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6429 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6430 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6431 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6432 | } |
| 6433 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6434 | static void PatchJitRootUse(uint8_t* code, |
| 6435 | const uint8_t* roots_data, |
| 6436 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6437 | uint64_t index_in_table) { |
| 6438 | uint32_t literal_offset = literal->GetOffset(); |
| 6439 | uintptr_t address = |
| 6440 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6441 | uint8_t* data = code + literal_offset; |
| 6442 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6443 | } |
| 6444 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6445 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6446 | for (const auto& entry : jit_string_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6447 | const StringReference& string_reference = entry.first; |
| 6448 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6449 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6450 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6451 | } |
| 6452 | for (const auto& entry : jit_class_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6453 | const TypeReference& type_reference = entry.first; |
| 6454 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6455 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6456 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6457 | } |
| 6458 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6459 | |
| Artem Serov | 1a719e4 | 2019-07-18 14:24:55 +0100 | [diff] [blame] | 6460 | MemOperand InstructionCodeGeneratorARM64::VecNeonAddress( |
| 6461 | HVecMemoryOperation* instruction, |
| 6462 | UseScratchRegisterScope* temps_scope, |
| 6463 | size_t size, |
| 6464 | bool is_string_char_at, |
| 6465 | /*out*/ Register* scratch) { |
| 6466 | LocationSummary* locations = instruction->GetLocations(); |
| 6467 | Register base = InputRegisterAt(instruction, 0); |
| 6468 | |
| 6469 | if (instruction->InputAt(1)->IsIntermediateAddressIndex()) { |
| 6470 | DCHECK(!is_string_char_at); |
| 6471 | return MemOperand(base.X(), InputRegisterAt(instruction, 1).X()); |
| 6472 | } |
| 6473 | |
| 6474 | Location index = locations->InAt(1); |
| 6475 | uint32_t offset = is_string_char_at |
| 6476 | ? mirror::String::ValueOffset().Uint32Value() |
| 6477 | : mirror::Array::DataOffset(size).Uint32Value(); |
| 6478 | size_t shift = ComponentSizeShiftWidth(size); |
| 6479 | |
| 6480 | // HIntermediateAddress optimization is only applied for scalar ArrayGet and ArraySet. |
| 6481 | DCHECK(!instruction->InputAt(0)->IsIntermediateAddress()); |
| 6482 | |
| 6483 | if (index.IsConstant()) { |
| 6484 | offset += Int64FromLocation(index) << shift; |
| 6485 | return HeapOperand(base, offset); |
| 6486 | } else { |
| 6487 | *scratch = temps_scope->AcquireSameSizeAs(base); |
| 6488 | __ Add(*scratch, base, Operand(WRegisterFrom(index), LSL, shift)); |
| 6489 | return HeapOperand(*scratch, offset); |
| 6490 | } |
| 6491 | } |
| 6492 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6493 | #undef __ |
| 6494 | #undef QUICK_ENTRY_POINT |
| 6495 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6496 | #define __ assembler.GetVIXLAssembler()-> |
| 6497 | |
| 6498 | static void EmitGrayCheckAndFastPath(arm64::Arm64Assembler& assembler, |
| 6499 | vixl::aarch64::Register base_reg, |
| 6500 | vixl::aarch64::MemOperand& lock_word, |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6501 | vixl::aarch64::Label* slow_path, |
| 6502 | vixl::aarch64::Label* throw_npe = nullptr) { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6503 | // Load the lock word containing the rb_state. |
| 6504 | __ Ldr(ip0.W(), lock_word); |
| 6505 | // 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] | 6506 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6507 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 6508 | __ Tbnz(ip0.W(), LockWord::kReadBarrierStateShift, slow_path); |
| 6509 | static_assert( |
| 6510 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET, |
| 6511 | "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] | 6512 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 6513 | if (throw_npe != nullptr) { |
| 6514 | __ Bind(throw_npe); |
| 6515 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6516 | // Adjust the return address back to the LDR (1 instruction; 2 for heap poisoning). |
| 6517 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6518 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6519 | " 2 instructions (8B) for heap poisoning."); |
| 6520 | __ Add(lr, lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6521 | // Introduce a dependency on the lock_word including rb_state, |
| 6522 | // to prevent load-load reordering, and without using |
| 6523 | // a memory barrier (which would be more expensive). |
| 6524 | __ Add(base_reg, base_reg, Operand(ip0, LSR, 32)); |
| 6525 | __ Br(lr); // And return back to the function. |
| 6526 | // Note: The fake dependency is unnecessary for the slow path. |
| 6527 | } |
| 6528 | |
| 6529 | // Load the read barrier introspection entrypoint in register `entrypoint`. |
| 6530 | static void LoadReadBarrierMarkIntrospectionEntrypoint(arm64::Arm64Assembler& assembler, |
| 6531 | vixl::aarch64::Register entrypoint) { |
| 6532 | // entrypoint = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6533 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6534 | const int32_t entry_point_offset = |
| 6535 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6536 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| 6537 | } |
| 6538 | |
| 6539 | void CodeGeneratorARM64::CompileBakerReadBarrierThunk(Arm64Assembler& assembler, |
| 6540 | uint32_t encoded_data, |
| 6541 | /*out*/ std::string* debug_name) { |
| 6542 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 6543 | switch (kind) { |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6544 | case BakerReadBarrierKind::kField: |
| 6545 | case BakerReadBarrierKind::kAcquire: { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6546 | auto base_reg = |
| 6547 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6548 | CheckValidReg(base_reg.GetCode()); |
| 6549 | auto holder_reg = |
| 6550 | Register::GetXRegFromCode(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6551 | CheckValidReg(holder_reg.GetCode()); |
| 6552 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6553 | temps.Exclude(ip0, ip1); |
| Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 6554 | // In the case of a field load (with relaxed semantic), if `base_reg` differs from |
| 6555 | // `holder_reg`, the offset was too large and we must have emitted (during the construction |
| 6556 | // of the HIR graph, see `art::HInstructionBuilder::BuildInstanceFieldAccess`) and preserved |
| 6557 | // (see `art::PrepareForRegisterAllocation::VisitNullCheck`) an explicit null check before |
| 6558 | // the load. Otherwise, for implicit null checks, we need to null-check the holder as we do |
| 6559 | // not necessarily do that check before going to the thunk. |
| 6560 | // |
| 6561 | // In the case of a field load with load-acquire semantics (where `base_reg` always differs |
| 6562 | // from `holder_reg`), we also need an explicit null check when implicit null checks are |
| 6563 | // allowed, as we do not emit one before going to the thunk. |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6564 | vixl::aarch64::Label throw_npe_label; |
| 6565 | vixl::aarch64::Label* throw_npe = nullptr; |
| Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 6566 | if (GetCompilerOptions().GetImplicitNullChecks() && |
| 6567 | (holder_reg.Is(base_reg) || (kind == BakerReadBarrierKind::kAcquire))) { |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6568 | throw_npe = &throw_npe_label; |
| 6569 | __ Cbz(holder_reg.W(), throw_npe); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6570 | } |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6571 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 6572 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 6573 | // to load the reference and call the entrypoint that performs further checks on the |
| 6574 | // reference and marks it if needed. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6575 | vixl::aarch64::Label slow_path; |
| 6576 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6577 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, throw_npe); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6578 | __ Bind(&slow_path); |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6579 | if (kind == BakerReadBarrierKind::kField) { |
| 6580 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6581 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (immediate) unsigned offset. |
| 6582 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6583 | __ Ubfx(ip0.W(), ip0.W(), 10, 12); // Extract the offset. |
| 6584 | __ Ldr(ip0.W(), MemOperand(base_reg, ip0, LSL, 2)); // Load the reference. |
| 6585 | } else { |
| 6586 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 6587 | DCHECK(!base_reg.Is(holder_reg)); |
| 6588 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6589 | __ Ldar(ip0.W(), MemOperand(base_reg)); |
| 6590 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6591 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 6592 | __ Br(ip1); // Jump to the entrypoint. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6593 | break; |
| 6594 | } |
| 6595 | case BakerReadBarrierKind::kArray: { |
| 6596 | auto base_reg = |
| 6597 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6598 | CheckValidReg(base_reg.GetCode()); |
| 6599 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6600 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6601 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6602 | temps.Exclude(ip0, ip1); |
| 6603 | vixl::aarch64::Label slow_path; |
| 6604 | int32_t data_offset = |
| 6605 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 6606 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 6607 | DCHECK_LT(lock_word.GetOffset(), 0); |
| 6608 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path); |
| 6609 | __ Bind(&slow_path); |
| 6610 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| 6611 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (register) unsigned offset. |
| 6612 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6613 | __ Ubfx(ip0, ip0, 16, 6); // Extract the index register, plus 32 (bit 21 is set). |
| 6614 | __ Bfi(ip1, ip0, 3, 6); // Insert ip0 to the entrypoint address to create |
| 6615 | // a switch case target based on the index register. |
| 6616 | __ Mov(ip0, base_reg); // Move the base register to ip0. |
| 6617 | __ Br(ip1); // Jump to the entrypoint's array switch case. |
| 6618 | break; |
| 6619 | } |
| 6620 | case BakerReadBarrierKind::kGcRoot: { |
| 6621 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 6622 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 6623 | // otherwise return the reference (or the extracted forwarding address). |
| 6624 | // There is no gray bit check for GC roots. |
| 6625 | auto root_reg = |
| 6626 | Register::GetWRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6627 | CheckValidReg(root_reg.GetCode()); |
| 6628 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6629 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6630 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6631 | temps.Exclude(ip0, ip1); |
| 6632 | vixl::aarch64::Label return_label, not_marked, forwarding_address; |
| 6633 | __ Cbz(root_reg, &return_label); |
| 6634 | MemOperand lock_word(root_reg.X(), mirror::Object::MonitorOffset().Int32Value()); |
| 6635 | __ Ldr(ip0.W(), lock_word); |
| 6636 | __ Tbz(ip0.W(), LockWord::kMarkBitStateShift, ¬_marked); |
| 6637 | __ Bind(&return_label); |
| 6638 | __ Br(lr); |
| 6639 | __ Bind(¬_marked); |
| 6640 | __ Tst(ip0.W(), Operand(ip0.W(), LSL, 1)); |
| 6641 | __ B(&forwarding_address, mi); |
| 6642 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6643 | // Adjust the art_quick_read_barrier_mark_introspection address in IP1 to |
| 6644 | // art_quick_read_barrier_mark_introspection_gc_roots. |
| 6645 | __ Add(ip1, ip1, Operand(BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET)); |
| 6646 | __ Mov(ip0.W(), root_reg); |
| 6647 | __ Br(ip1); |
| 6648 | __ Bind(&forwarding_address); |
| 6649 | __ Lsl(root_reg, ip0.W(), LockWord::kForwardingAddressShift); |
| 6650 | __ Br(lr); |
| 6651 | break; |
| 6652 | } |
| 6653 | default: |
| 6654 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 6655 | UNREACHABLE(); |
| 6656 | } |
| 6657 | |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6658 | // For JIT, the slow path is considered part of the compiled method, |
| 6659 | // so JIT should pass null as `debug_name`. Tests may not have a runtime. |
| 6660 | DCHECK(Runtime::Current() == nullptr || |
| 6661 | !Runtime::Current()->UseJitCompilation() || |
| 6662 | debug_name == nullptr); |
| 6663 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6664 | std::ostringstream oss; |
| 6665 | oss << "BakerReadBarrierThunk"; |
| 6666 | switch (kind) { |
| 6667 | case BakerReadBarrierKind::kField: |
| 6668 | oss << "Field_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 6669 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 6670 | break; |
| Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6671 | case BakerReadBarrierKind::kAcquire: |
| 6672 | oss << "Acquire_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 6673 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 6674 | break; |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6675 | case BakerReadBarrierKind::kArray: |
| 6676 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6677 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6678 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6679 | break; |
| 6680 | case BakerReadBarrierKind::kGcRoot: |
| 6681 | oss << "GcRoot_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6682 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6683 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6684 | break; |
| 6685 | } |
| 6686 | *debug_name = oss.str(); |
| 6687 | } |
| 6688 | } |
| 6689 | |
| 6690 | #undef __ |
| 6691 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6692 | } // namespace arm64 |
| 6693 | } // namespace art |