| 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" |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 21 | #include "art_method.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 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 53 | namespace art { |
| 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; |
| 67 | using helpers::InputCPURegisterAt; |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 68 | using helpers::InputCPURegisterOrZeroRegAt; |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 | using helpers::InputFPRegisterAt; |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 70 | using helpers::InputOperandAt; |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 71 | using helpers::InputRegisterAt; |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 72 | using helpers::Int64FromLocation; |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 73 | using helpers::IsConstantZeroBitPattern; |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 74 | using helpers::LocationFrom; |
| 75 | using helpers::OperandFromMemOperand; |
| 76 | using helpers::OutputCPURegister; |
| 77 | using helpers::OutputFPRegister; |
| 78 | using helpers::OutputRegister; |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 79 | using helpers::QRegisterFrom; |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 80 | using helpers::RegisterFrom; |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 81 | using helpers::SRegisterFrom; |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 82 | using helpers::StackOperandFrom; |
| 83 | using helpers::VIXLRegCodeFromART; |
| 84 | using helpers::WRegisterFrom; |
| 85 | using helpers::XRegisterFrom; |
| 86 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 87 | // The compare/jump sequence will generate about (1.5 * num_entries + 3) instructions. While jump |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 88 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 89 | // generates less code/data with a small num_entries. |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 90 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 91 | |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 92 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 93 | // offset < 16KiB. For offsets >= 16KiB, the load shall be emitted as two or more instructions. |
| 94 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 95 | // the offset explicitly. |
| 96 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 97 | |
| 98 | // Flags controlling the use of link-time generated thunks for Baker read barriers. |
| Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 99 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 100 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
| Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 101 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 102 | |
| 103 | // Some instructions have special requirements for a temporary, for example |
| 104 | // LoadClass/kBssEntry and LoadString/kBssEntry for Baker read barrier require |
| 105 | // temp that's not an R0 (to avoid an extra move) and Baker read barrier field |
| 106 | // loads with large offsets need a fixed register to limit the number of link-time |
| 107 | // thunks we generate. For these and similar cases, we want to reserve a specific |
| 108 | // register that's neither callee-save nor an argument register. We choose x15. |
| 109 | inline Location FixedTempLocation() { |
| 110 | return Location::RegisterLocation(x15.GetCode()); |
| 111 | } |
| 112 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 113 | inline Condition ARM64Condition(IfCondition cond) { |
| 114 | switch (cond) { |
| 115 | case kCondEQ: return eq; |
| 116 | case kCondNE: return ne; |
| 117 | case kCondLT: return lt; |
| 118 | case kCondLE: return le; |
| 119 | case kCondGT: return gt; |
| 120 | case kCondGE: return ge; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 121 | case kCondB: return lo; |
| 122 | case kCondBE: return ls; |
| 123 | case kCondA: return hi; |
| 124 | case kCondAE: return hs; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 125 | } |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 126 | LOG(FATAL) << "Unreachable"; |
| 127 | UNREACHABLE(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 128 | } |
| 129 | |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 130 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 131 | // The ARM64 condition codes can express all the necessary branches, see the |
| 132 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 133 | // There is no dex instruction or HIR that would need the missing conditions |
| 134 | // "equal or unordered" or "not equal". |
| 135 | switch (cond) { |
| 136 | case kCondEQ: return eq; |
| 137 | case kCondNE: return ne /* unordered */; |
| 138 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 139 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 140 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 141 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 142 | default: |
| 143 | LOG(FATAL) << "UNREACHABLE"; |
| 144 | UNREACHABLE(); |
| 145 | } |
| 146 | } |
| 147 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 148 | Location ARM64ReturnLocation(DataType::Type return_type) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 149 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 150 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 151 | // but we use the exact registers for clarity. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 152 | if (return_type == DataType::Type::kFloat32) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 153 | return LocationFrom(s0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 154 | } else if (return_type == DataType::Type::kFloat64) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 155 | return LocationFrom(d0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 156 | } else if (return_type == DataType::Type::kInt64) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 157 | return LocationFrom(x0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 158 | } else if (return_type == DataType::Type::kVoid) { |
| Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 159 | return Location::NoLocation(); |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 160 | } else { |
| 161 | return LocationFrom(w0); |
| 162 | } |
| 163 | } |
| 164 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 165 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type return_type) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 166 | return ARM64ReturnLocation(return_type); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 167 | } |
| 168 | |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 169 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 170 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 171 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 172 | |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 173 | // Calculate memory accessing operand for save/restore live registers. |
| 174 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 175 | LocationSummary* locations, |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 176 | int64_t spill_offset, |
| 177 | bool is_save) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 178 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 179 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 180 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 181 | codegen->GetNumberOfCoreRegisters(), |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 182 | fp_spills, |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 183 | codegen->GetNumberOfFloatingPointRegisters())); |
| 184 | |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 185 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
| Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 186 | unsigned v_reg_size = codegen->GetGraph()->HasSIMD() ? kQRegSize : kDRegSize; |
| 187 | CPURegList fp_list = CPURegList(CPURegister::kVRegister, v_reg_size, fp_spills); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 188 | |
| 189 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 190 | UseScratchRegisterScope temps(masm); |
| 191 | |
| 192 | Register base = masm->StackPointer(); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 193 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 194 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 195 | int64_t reg_size = kXRegSizeInBytes; |
| 196 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 197 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 198 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 199 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 200 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 201 | // to compute the base address(float point registers spill base address). |
| 202 | Register new_base = temps.AcquireSameSizeAs(base); |
| 203 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 204 | base = new_base; |
| 205 | spill_offset = -core_spill_size; |
| 206 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 207 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 208 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 209 | } |
| 210 | |
| 211 | if (is_save) { |
| 212 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 213 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 214 | } else { |
| 215 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 216 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 221 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 222 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 223 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 224 | // If the register holds an object, update the stack mask. |
| 225 | if (locations->RegisterContainsObject(i)) { |
| 226 | locations->SetStackBit(stack_offset / kVRegSize); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 227 | } |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 228 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 229 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 230 | saved_core_stack_offsets_[i] = stack_offset; |
| 231 | stack_offset += kXRegSizeInBytes; |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 232 | } |
| 233 | |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 234 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 235 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 236 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 237 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 238 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 239 | stack_offset += kDRegSizeInBytes; |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 240 | } |
| 241 | |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 242 | SaveRestoreLiveRegistersHelper(codegen, |
| 243 | locations, |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 244 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 245 | } |
| 246 | |
| 247 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 248 | SaveRestoreLiveRegistersHelper(codegen, |
| 249 | locations, |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 250 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 251 | } |
| 252 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 253 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 254 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 255 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 256 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 257 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 258 | LocationSummary* locations = instruction_->GetLocations(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 259 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 260 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 261 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 262 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 263 | // Live registers will be restored in the catch block if caught. |
| 264 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 265 | } |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 266 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 267 | // move resolver. |
| 268 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 269 | codegen->EmitParallelMoves(locations->InAt(0), |
| 270 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 271 | DataType::Type::kInt32, |
| 272 | locations->InAt(1), |
| 273 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 274 | DataType::Type::kInt32); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 275 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 276 | ? kQuickThrowStringBounds |
| 277 | : kQuickThrowArrayBounds; |
| 278 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 279 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 280 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 281 | } |
| 282 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 283 | bool IsFatal() const OVERRIDE { return true; } |
| 284 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 285 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 286 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 287 | private: |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 288 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 289 | }; |
| 290 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 291 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 292 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 293 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 294 | |
| 295 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 296 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 297 | __ Bind(GetEntryLabel()); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 298 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 299 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 302 | bool IsFatal() const OVERRIDE { return true; } |
| 303 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 304 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 305 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 306 | private: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 307 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 308 | }; |
| 309 | |
| 310 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 311 | public: |
| 312 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 313 | HInstruction* at, |
| 314 | uint32_t dex_pc, |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 315 | bool do_clinit) |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 316 | : SlowPathCodeARM64(at), |
| 317 | cls_(cls), |
| 318 | dex_pc_(dex_pc), |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 319 | do_clinit_(do_clinit) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 320 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 321 | } |
| 322 | |
| 323 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 324 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 325 | Location out = locations->Out(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 326 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 327 | |
| 328 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 329 | SaveLiveRegisters(codegen, locations); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 330 | |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 331 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 332 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 333 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 334 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 335 | : kQuickInitializeType; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 336 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 337 | if (do_clinit_) { |
| Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 338 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 339 | } else { |
| Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 340 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 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 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 353 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 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 | // The dex PC of `at_`. |
| 360 | const uint32_t dex_pc_; |
| 361 | |
| 362 | // Whether to initialize the class. |
| 363 | const bool do_clinit_; |
| 364 | |
| 365 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 366 | }; |
| 367 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 368 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 369 | public: |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 370 | explicit LoadStringSlowPathARM64(HLoadString* instruction) |
| 371 | : SlowPathCodeARM64(instruction) {} |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 372 | |
| 373 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 374 | LocationSummary* locations = instruction_->GetLocations(); |
| 375 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 376 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 377 | |
| 378 | __ Bind(GetEntryLabel()); |
| 379 | SaveLiveRegisters(codegen, locations); |
| 380 | |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 381 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 382 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 383 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 384 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 385 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 386 | DataType::Type type = instruction_->GetType(); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 387 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 388 | |
| 389 | RestoreLiveRegisters(codegen, locations); |
| 390 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 391 | __ B(GetExitLabel()); |
| 392 | } |
| 393 | |
| 394 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 395 | |
| 396 | private: |
| 397 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 398 | }; |
| 399 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 400 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 401 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 402 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 403 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 404 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 405 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 406 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 407 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 408 | // Live registers will be restored in the catch block if caught. |
| 409 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 410 | } |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 411 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 412 | instruction_, |
| 413 | instruction_->GetDexPc(), |
| 414 | this); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 415 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 416 | } |
| 417 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 418 | bool IsFatal() const OVERRIDE { return true; } |
| 419 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 420 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 421 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 422 | private: |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 423 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 424 | }; |
| 425 | |
| 426 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 427 | public: |
| Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 428 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 429 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 430 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 431 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 432 | LocationSummary* locations = instruction_->GetLocations(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 433 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 434 | __ Bind(GetEntryLabel()); |
| Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 435 | SaveLiveRegisters(codegen, locations); // Only saves live 128-bit regs for SIMD. |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 436 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 437 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 438 | RestoreLiveRegisters(codegen, locations); // Only restores live 128-bit regs for SIMD. |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 439 | if (successor_ == nullptr) { |
| 440 | __ B(GetReturnLabel()); |
| 441 | } else { |
| 442 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 443 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 444 | } |
| 445 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 446 | vixl::aarch64::Label* GetReturnLabel() { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 447 | DCHECK(successor_ == nullptr); |
| 448 | return &return_label_; |
| 449 | } |
| 450 | |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 451 | HBasicBlock* GetSuccessor() const { |
| 452 | return successor_; |
| 453 | } |
| 454 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 455 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 456 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 457 | private: |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 458 | // If not null, the block to branch to after the suspend check. |
| 459 | HBasicBlock* const successor_; |
| 460 | |
| 461 | // If `successor_` is null, the label to branch to after the suspend check. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 462 | vixl::aarch64::Label return_label_; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 463 | |
| 464 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 465 | }; |
| 466 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 467 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 468 | public: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 469 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 470 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 471 | |
| 472 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 473 | LocationSummary* locations = instruction_->GetLocations(); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 474 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 475 | DCHECK(instruction_->IsCheckCast() |
| 476 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 477 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 478 | uint32_t dex_pc = instruction_->GetDexPc(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 479 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 480 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 481 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 482 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 483 | SaveLiveRegisters(codegen, locations); |
| 484 | } |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 485 | |
| 486 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 487 | // move resolver. |
| 488 | InvokeRuntimeCallingConvention calling_convention; |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 489 | codegen->EmitParallelMoves(locations->InAt(0), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 490 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 491 | DataType::Type::kReference, |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 492 | locations->InAt(1), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 493 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 494 | DataType::Type::kReference); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 495 | if (instruction_->IsInstanceOf()) { |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 496 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 497 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 498 | DataType::Type ret_type = instruction_->GetType(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 499 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 500 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 501 | } else { |
| 502 | DCHECK(instruction_->IsCheckCast()); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 503 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 504 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 505 | } |
| 506 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 507 | if (!is_fatal_) { |
| 508 | RestoreLiveRegisters(codegen, locations); |
| 509 | __ B(GetExitLabel()); |
| 510 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 513 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
| Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 514 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 515 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 516 | private: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 517 | const bool is_fatal_; |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 518 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 519 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 520 | }; |
| 521 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 522 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 523 | public: |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 524 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 525 | : SlowPathCodeARM64(instruction) {} |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 526 | |
| 527 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 528 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 529 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 530 | LocationSummary* locations = instruction_->GetLocations(); |
| 531 | SaveLiveRegisters(codegen, locations); |
| 532 | InvokeRuntimeCallingConvention calling_convention; |
| 533 | __ Mov(calling_convention.GetRegisterAt(0), |
| 534 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 535 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 536 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 539 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 540 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 541 | private: |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 542 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 543 | }; |
| 544 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 545 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 546 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 547 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 548 | |
| 549 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 550 | LocationSummary* locations = instruction_->GetLocations(); |
| 551 | __ Bind(GetEntryLabel()); |
| 552 | SaveLiveRegisters(codegen, locations); |
| 553 | |
| 554 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 555 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 556 | parallel_move.AddMove( |
| 557 | locations->InAt(0), |
| 558 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 559 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 560 | nullptr); |
| 561 | parallel_move.AddMove( |
| 562 | locations->InAt(1), |
| 563 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 564 | DataType::Type::kInt32, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 565 | nullptr); |
| 566 | parallel_move.AddMove( |
| 567 | locations->InAt(2), |
| 568 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 569 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 570 | nullptr); |
| 571 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 572 | |
| 573 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 574 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 575 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 576 | RestoreLiveRegisters(codegen, locations); |
| 577 | __ B(GetExitLabel()); |
| 578 | } |
| 579 | |
| 580 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 581 | |
| 582 | private: |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 583 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 584 | }; |
| 585 | |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 586 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 587 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 588 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 589 | |
| 590 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 591 | // underlying code buffer and we have generated the jump table with right size. |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 592 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 593 | num_entries * sizeof(int32_t), |
| 594 | CodeBufferCheckScope::kExactSize); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 595 | |
| 596 | __ Bind(&table_start_); |
| 597 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 598 | for (uint32_t i = 0; i < num_entries; i++) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 599 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 600 | DCHECK(target_label->IsBound()); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 601 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 602 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 603 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 604 | Literal<int32_t> literal(jump_offset); |
| 605 | __ place(&literal); |
| 606 | } |
| 607 | } |
| 608 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 609 | // Abstract base class for read barrier slow paths marking a reference |
| 610 | // `ref`. |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 611 | // |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 612 | // Argument `entrypoint` must be a register location holding the read |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 613 | // barrier marking runtime entry point to be invoked or an empty |
| 614 | // location; in the latter case, the read barrier marking runtime |
| 615 | // entry point will be loaded by the slow path code itself. |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 616 | class ReadBarrierMarkSlowPathBaseARM64 : public SlowPathCodeARM64 { |
| 617 | protected: |
| 618 | ReadBarrierMarkSlowPathBaseARM64(HInstruction* instruction, Location ref, Location entrypoint) |
| 619 | : SlowPathCodeARM64(instruction), ref_(ref), entrypoint_(entrypoint) { |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 620 | DCHECK(kEmitCompilerReadBarrier); |
| 621 | } |
| 622 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 623 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM64"; } |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 624 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 625 | // Generate assembly code calling the read barrier marking runtime |
| 626 | // entry point (ReadBarrierMarkRegX). |
| 627 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 628 | // No need to save live registers; it's taken care of by the |
| 629 | // entrypoint. Also, there is no need to update the stack mask, |
| 630 | // as this runtime call will not trigger a garbage collection. |
| 631 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 632 | DCHECK_NE(ref_.reg(), LR); |
| 633 | DCHECK_NE(ref_.reg(), WSP); |
| 634 | DCHECK_NE(ref_.reg(), WZR); |
| 635 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 636 | // as a temporary, it cannot be the entry point's input/output. |
| 637 | DCHECK_NE(ref_.reg(), IP0); |
| 638 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 639 | // "Compact" slow path, saving two moves. |
| 640 | // |
| 641 | // Instead of using the standard runtime calling convention (input |
| 642 | // and output in W0): |
| 643 | // |
| 644 | // W0 <- ref |
| 645 | // W0 <- ReadBarrierMark(W0) |
| 646 | // ref <- W0 |
| 647 | // |
| 648 | // we just use rX (the register containing `ref`) as input and output |
| 649 | // of a dedicated entrypoint: |
| 650 | // |
| 651 | // rX <- ReadBarrierMarkRegX(rX) |
| 652 | // |
| 653 | if (entrypoint_.IsValid()) { |
| 654 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 655 | __ Blr(XRegisterFrom(entrypoint_)); |
| 656 | } else { |
| 657 | // Entrypoint is not already loaded, load from the thread. |
| 658 | int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 659 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 660 | // This runtime call does not require a stack map. |
| 661 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | // The location (register) of the marked object reference. |
| 666 | const Location ref_; |
| 667 | |
| 668 | // The location of the entrypoint if it is already loaded. |
| 669 | const Location entrypoint_; |
| 670 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 671 | private: |
| 672 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM64); |
| 673 | }; |
| 674 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 675 | // Slow path marking an object reference `ref` during a read |
| 676 | // barrier. The field `obj.field` in the object `obj` holding this |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 677 | // reference does not get updated by this slow path after marking. |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 678 | // |
| 679 | // This means that after the execution of this slow path, `ref` will |
| 680 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 681 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 682 | // probably still be a from-space reference (unless it gets updated by |
| 683 | // another thread, or if another thread installed another object |
| 684 | // reference (different from `ref`) in `obj.field`). |
| 685 | // |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 686 | // Argument `entrypoint` must be a register location holding the read |
| 687 | // barrier marking runtime entry point to be invoked or an empty |
| 688 | // location; in the latter case, the read barrier marking runtime |
| 689 | // entry point will be loaded by the slow path code itself. |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 690 | class ReadBarrierMarkSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 691 | public: |
| 692 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 693 | Location ref, |
| 694 | Location entrypoint = Location::NoLocation()) |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 695 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 696 | DCHECK(kEmitCompilerReadBarrier); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 700 | |
| 701 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 702 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 703 | DCHECK(locations->CanCall()); |
| 704 | DCHECK(ref_.IsRegister()) << ref_; |
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 705 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 706 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 707 | << "Unexpected instruction in read barrier marking slow path: " |
| 708 | << instruction_->DebugName(); |
| 709 | |
| 710 | __ Bind(GetEntryLabel()); |
| 711 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 712 | __ B(GetExitLabel()); |
| 713 | } |
| 714 | |
| 715 | private: |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 716 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 717 | }; |
| 718 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 719 | // Slow path loading `obj`'s lock word, loading a reference from |
| 720 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 721 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 722 | // read barrier). The field `obj.field` in the object `obj` holding |
| 723 | // this reference does not get updated by this slow path after marking |
| 724 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 725 | // below for that). |
| 726 | // |
| 727 | // This means that after the execution of this slow path, `ref` will |
| 728 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 729 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 730 | // probably still be a from-space reference (unless it gets updated by |
| 731 | // another thread, or if another thread installed another object |
| 732 | // reference (different from `ref`) in `obj.field`). |
| 733 | // |
| 734 | // Argument `entrypoint` must be a register location holding the read |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 735 | // barrier marking runtime entry point to be invoked or an empty |
| 736 | // location; in the latter case, the read barrier marking runtime |
| 737 | // entry point will be loaded by the slow path code itself. |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 738 | class LoadReferenceWithBakerReadBarrierSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
| 739 | public: |
| 740 | LoadReferenceWithBakerReadBarrierSlowPathARM64(HInstruction* instruction, |
| 741 | Location ref, |
| 742 | Register obj, |
| 743 | uint32_t offset, |
| 744 | Location index, |
| 745 | size_t scale_factor, |
| 746 | bool needs_null_check, |
| 747 | bool use_load_acquire, |
| 748 | Register temp, |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 749 | Location entrypoint = Location::NoLocation()) |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 750 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
| 751 | obj_(obj), |
| 752 | offset_(offset), |
| 753 | index_(index), |
| 754 | scale_factor_(scale_factor), |
| 755 | needs_null_check_(needs_null_check), |
| 756 | use_load_acquire_(use_load_acquire), |
| 757 | temp_(temp) { |
| 758 | DCHECK(kEmitCompilerReadBarrier); |
| 759 | DCHECK(kUseBakerReadBarrier); |
| 760 | } |
| 761 | |
| 762 | const char* GetDescription() const OVERRIDE { |
| 763 | return "LoadReferenceWithBakerReadBarrierSlowPathARM64"; |
| 764 | } |
| 765 | |
| 766 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 767 | LocationSummary* locations = instruction_->GetLocations(); |
| 768 | DCHECK(locations->CanCall()); |
| 769 | DCHECK(ref_.IsRegister()) << ref_; |
| 770 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 771 | DCHECK(obj_.IsW()); |
| 772 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 773 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 774 | instruction_->IsStaticFieldGet() || |
| 775 | instruction_->IsArrayGet() || |
| 776 | instruction_->IsArraySet() || |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 777 | instruction_->IsInstanceOf() || |
| 778 | instruction_->IsCheckCast() || |
| 779 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 780 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 781 | << "Unexpected instruction in read barrier marking slow path: " |
| 782 | << instruction_->DebugName(); |
| 783 | // The read barrier instrumentation of object ArrayGet |
| 784 | // instructions does not support the HIntermediateAddress |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 785 | // instruction. |
| 786 | DCHECK(!(instruction_->IsArrayGet() && |
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 787 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 788 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 789 | // Temporary register `temp_`, used to store the lock word, must |
| 790 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 791 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 792 | // need the lock word to still be in `temp_` after the reference |
| 793 | // load. |
| 794 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 795 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
| 796 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 797 | __ Bind(GetEntryLabel()); |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 798 | |
| 799 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 800 | // inserted after the original load. However, in fast path based |
| 801 | // Baker's read barriers, we need to perform the load of |
| 802 | // mirror::Object::monitor_ *before* the original reference load. |
| 803 | // This load-load ordering is required by the read barrier. |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 804 | // The slow path (for Baker's algorithm) should look like: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 805 | // |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 806 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 807 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 808 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 809 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 810 | // if (is_gray) { |
| 811 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 812 | // } |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 813 | // |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 814 | // Note: the original implementation in ReadBarrier::Barrier is |
| 815 | // slightly more complex as it performs additional checks that we do |
| 816 | // not do here for performance reasons. |
| 817 | |
| 818 | // /* int32_t */ monitor = obj->monitor_ |
| 819 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 820 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 821 | if (needs_null_check_) { |
| 822 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 823 | } |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 824 | // /* LockWord */ lock_word = LockWord(monitor) |
| 825 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 826 | "art::LockWord and int32_t have different sizes."); |
| 827 | |
| 828 | // Introduce a dependency on the lock_word including rb_state, |
| 829 | // to prevent load-load reordering, and without using |
| 830 | // a memory barrier (which would be more expensive). |
| 831 | // `obj` is unchanged by this operation, but its value now depends |
| 832 | // on `temp`. |
| 833 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 834 | |
| 835 | // The actual reference load. |
| 836 | // A possible implicit null check has already been handled above. |
| 837 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 838 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 839 | ref_, |
| 840 | obj_, |
| 841 | offset_, |
| 842 | index_, |
| 843 | scale_factor_, |
| 844 | /* needs_null_check */ false, |
| 845 | use_load_acquire_); |
| 846 | |
| 847 | // Mark the object `ref` when `obj` is gray. |
| 848 | // |
| 849 | // if (rb_state == ReadBarrier::GrayState()) |
| 850 | // ref = ReadBarrier::Mark(ref); |
| 851 | // |
| 852 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 853 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 854 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 855 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 856 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 857 | |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 858 | __ B(GetExitLabel()); |
| 859 | } |
| 860 | |
| 861 | private: |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 862 | // The register containing the object holding the marked object reference field. |
| 863 | Register obj_; |
| 864 | // The offset, index and scale factor to access the reference in `obj_`. |
| 865 | uint32_t offset_; |
| 866 | Location index_; |
| 867 | size_t scale_factor_; |
| 868 | // Is a null check required? |
| 869 | bool needs_null_check_; |
| 870 | // Should this reference load use Load-Acquire semantics? |
| 871 | bool use_load_acquire_; |
| 872 | // A temporary register used to hold the lock word of `obj_`. |
| 873 | Register temp_; |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 874 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 875 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM64); |
| Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 876 | }; |
| 877 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 878 | // Slow path loading `obj`'s lock word, loading a reference from |
| 879 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 880 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 881 | // read barrier). If needed, this slow path also atomically updates |
| 882 | // the field `obj.field` in the object `obj` holding this reference |
| 883 | // after marking (contrary to |
| 884 | // LoadReferenceWithBakerReadBarrierSlowPathARM64 above, which never |
| 885 | // tries to update `obj.field`). |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 886 | // |
| 887 | // This means that after the execution of this slow path, both `ref` |
| 888 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 889 | // hold the same to-space reference (unless another thread installed |
| 890 | // another object reference (different from `ref`) in `obj.field`). |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 891 | // |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 892 | // Argument `entrypoint` must be a register location holding the read |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 893 | // barrier marking runtime entry point to be invoked or an empty |
| 894 | // location; in the latter case, the read barrier marking runtime |
| 895 | // entry point will be loaded by the slow path code itself. |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 896 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 897 | : public ReadBarrierMarkSlowPathBaseARM64 { |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 898 | public: |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 899 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 900 | HInstruction* instruction, |
| 901 | Location ref, |
| 902 | Register obj, |
| 903 | uint32_t offset, |
| 904 | Location index, |
| 905 | size_t scale_factor, |
| 906 | bool needs_null_check, |
| 907 | bool use_load_acquire, |
| 908 | Register temp, |
| 909 | Location entrypoint = Location::NoLocation()) |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 910 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 911 | obj_(obj), |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 912 | offset_(offset), |
| 913 | index_(index), |
| 914 | scale_factor_(scale_factor), |
| 915 | needs_null_check_(needs_null_check), |
| 916 | use_load_acquire_(use_load_acquire), |
| Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 917 | temp_(temp) { |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 918 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 919 | DCHECK(kUseBakerReadBarrier); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | const char* GetDescription() const OVERRIDE { |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 923 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64"; |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 927 | LocationSummary* locations = instruction_->GetLocations(); |
| 928 | Register ref_reg = WRegisterFrom(ref_); |
| 929 | DCHECK(locations->CanCall()); |
| 930 | DCHECK(ref_.IsRegister()) << ref_; |
| 931 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 932 | DCHECK(obj_.IsW()); |
| 933 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
| 934 | |
| 935 | // This slow path is only used by the UnsafeCASObject intrinsic at the moment. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 936 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 937 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 938 | << instruction_->DebugName(); |
| 939 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 940 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 941 | DCHECK_EQ(offset_, 0u); |
| 942 | DCHECK_EQ(scale_factor_, 0u); |
| 943 | DCHECK_EQ(use_load_acquire_, false); |
| 944 | // The location of the offset of the marked reference field within `obj_`. |
| 945 | Location field_offset = index_; |
| 946 | DCHECK(field_offset.IsRegister()) << field_offset; |
| 947 | |
| 948 | // Temporary register `temp_`, used to store the lock word, must |
| 949 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 950 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 951 | // need the lock word to still be in `temp_` after the reference |
| 952 | // load. |
| 953 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 954 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 955 | |
| 956 | __ Bind(GetEntryLabel()); |
| 957 | |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 958 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM64's: |
| 959 | // |
| 960 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 961 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 962 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 963 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 964 | // if (is_gray) { |
| 965 | // old_ref = ref; |
| 966 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 967 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 968 | // } |
| 969 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 970 | // /* int32_t */ monitor = obj->monitor_ |
| 971 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 972 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 973 | if (needs_null_check_) { |
| 974 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 975 | } |
| 976 | // /* LockWord */ lock_word = LockWord(monitor) |
| 977 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 978 | "art::LockWord and int32_t have different sizes."); |
| 979 | |
| 980 | // Introduce a dependency on the lock_word including rb_state, |
| 981 | // to prevent load-load reordering, and without using |
| 982 | // a memory barrier (which would be more expensive). |
| 983 | // `obj` is unchanged by this operation, but its value now depends |
| 984 | // on `temp`. |
| 985 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 986 | |
| 987 | // The actual reference load. |
| 988 | // A possible implicit null check has already been handled above. |
| 989 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 990 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 991 | ref_, |
| 992 | obj_, |
| 993 | offset_, |
| 994 | index_, |
| 995 | scale_factor_, |
| 996 | /* needs_null_check */ false, |
| 997 | use_load_acquire_); |
| 998 | |
| 999 | // Mark the object `ref` when `obj` is gray. |
| 1000 | // |
| 1001 | // if (rb_state == ReadBarrier::GrayState()) |
| 1002 | // ref = ReadBarrier::Mark(ref); |
| 1003 | // |
| 1004 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 1005 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1006 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1007 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 1008 | |
| 1009 | // Save the old value of the reference before marking it. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1010 | // Note that we cannot use IP to save the old reference, as IP is |
| 1011 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1012 | // need the old reference after the call to that entry point. |
| 1013 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1014 | __ Mov(temp_.W(), ref_reg); |
| 1015 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1016 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1017 | |
| 1018 | // If the new reference is different from the old reference, |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1019 | // update the field in the holder (`*(obj_ + field_offset)`). |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1020 | // |
| 1021 | // Note that this field could also hold a different object, if |
| 1022 | // another thread had concurrently changed it. In that case, the |
| 1023 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 1024 | // (CAS) operation below would abort the CAS, leaving the field |
| 1025 | // as-is. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1026 | __ Cmp(temp_.W(), ref_reg); |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1027 | __ B(eq, GetExitLabel()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1028 | |
| 1029 | // Update the the holder's field atomically. This may fail if |
| 1030 | // mutator updates before us, but it's OK. This is achieved |
| 1031 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1032 | // memory synchronization ordering, where the expected value is |
| 1033 | // the old reference and the desired value is the new reference. |
| 1034 | |
| 1035 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 1036 | UseScratchRegisterScope temps(masm); |
| 1037 | |
| 1038 | // Convenience aliases. |
| 1039 | Register base = obj_.W(); |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1040 | Register offset = XRegisterFrom(field_offset); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1041 | Register expected = temp_.W(); |
| 1042 | Register value = ref_reg; |
| 1043 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1044 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 1045 | |
| 1046 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1047 | |
| 1048 | if (kPoisonHeapReferences) { |
| 1049 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1050 | if (value.Is(expected)) { |
| 1051 | // Do not poison `value`, as it is the same register as |
| 1052 | // `expected`, which has just been poisoned. |
| 1053 | } else { |
| 1054 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | // do { |
| 1059 | // tmp_value = [tmp_ptr] - expected; |
| 1060 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1061 | |
| Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1062 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1063 | __ Bind(&loop_head); |
| 1064 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 1065 | __ Cmp(tmp_value, expected); |
| Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1066 | __ B(&comparison_failed, ne); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1067 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 1068 | __ Cbnz(tmp_value, &loop_head); |
| Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1069 | __ B(&exit_loop); |
| 1070 | __ Bind(&comparison_failed); |
| 1071 | __ Clrex(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1072 | __ Bind(&exit_loop); |
| 1073 | |
| 1074 | if (kPoisonHeapReferences) { |
| 1075 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1076 | if (value.Is(expected)) { |
| 1077 | // Do not unpoison `value`, as it is the same register as |
| 1078 | // `expected`, which has just been unpoisoned. |
| 1079 | } else { |
| 1080 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1081 | } |
| 1082 | } |
| 1083 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1084 | __ B(GetExitLabel()); |
| 1085 | } |
| 1086 | |
| 1087 | private: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1088 | // The register containing the object holding the marked object reference field. |
| 1089 | const Register obj_; |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1090 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1091 | uint32_t offset_; |
| 1092 | Location index_; |
| 1093 | size_t scale_factor_; |
| 1094 | // Is a null check required? |
| 1095 | bool needs_null_check_; |
| 1096 | // Should this reference load use Load-Acquire semantics? |
| 1097 | bool use_load_acquire_; |
| 1098 | // A temporary register used to hold the lock word of `obj_`; and |
| 1099 | // also to hold the original reference value, when the reference is |
| 1100 | // marked. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1101 | const Register temp_; |
| 1102 | |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1103 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1104 | }; |
| 1105 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1106 | // Slow path generating a read barrier for a heap reference. |
| 1107 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 1108 | public: |
| 1109 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 1110 | Location out, |
| 1111 | Location ref, |
| 1112 | Location obj, |
| 1113 | uint32_t offset, |
| 1114 | Location index) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1115 | : SlowPathCodeARM64(instruction), |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1116 | out_(out), |
| 1117 | ref_(ref), |
| 1118 | obj_(obj), |
| 1119 | offset_(offset), |
| 1120 | index_(index) { |
| 1121 | DCHECK(kEmitCompilerReadBarrier); |
| 1122 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1123 | // has been overwritten by (or after) the heap object reference load |
| 1124 | // to be instrumented, e.g.: |
| 1125 | // |
| 1126 | // __ Ldr(out, HeapOperand(out, class_offset); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1127 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1128 | // |
| 1129 | // In that case, we have lost the information about the original |
| 1130 | // object, and the emitted read barrier cannot work properly. |
| 1131 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1132 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1133 | } |
| 1134 | |
| 1135 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1136 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1137 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1138 | DataType::Type type = DataType::Type::kReference; |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1139 | DCHECK(locations->CanCall()); |
| 1140 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1141 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1142 | instruction_->IsStaticFieldGet() || |
| 1143 | instruction_->IsArrayGet() || |
| 1144 | instruction_->IsInstanceOf() || |
| 1145 | instruction_->IsCheckCast() || |
| Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1146 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1147 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1148 | << instruction_->DebugName(); |
| Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1149 | // The read barrier instrumentation of object ArrayGet |
| 1150 | // instructions does not support the HIntermediateAddress |
| 1151 | // instruction. |
| Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1152 | DCHECK(!(instruction_->IsArrayGet() && |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1153 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1154 | |
| 1155 | __ Bind(GetEntryLabel()); |
| 1156 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1157 | SaveLiveRegisters(codegen, locations); |
| 1158 | |
| 1159 | // We may have to change the index's value, but as `index_` is a |
| 1160 | // constant member (like other "inputs" of this slow path), |
| 1161 | // introduce a copy of it, `index`. |
| 1162 | Location index = index_; |
| 1163 | if (index_.IsValid()) { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1164 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1165 | if (instruction_->IsArrayGet()) { |
| 1166 | // Compute the actual memory offset and store it in `index`. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1167 | Register index_reg = RegisterFrom(index_, DataType::Type::kInt32); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1168 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 1169 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 1170 | // We are about to change the value of `index_reg` (see the |
| 1171 | // calls to vixl::MacroAssembler::Lsl and |
| 1172 | // vixl::MacroAssembler::Mov below), but it has |
| 1173 | // not been saved by the previous call to |
| 1174 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1175 | // callee-save register -- |
| 1176 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1177 | // callee-save registers, as it has been designed with the |
| 1178 | // assumption that callee-save registers are supposed to be |
| 1179 | // handled by the called function. So, as a callee-save |
| 1180 | // register, `index_reg` _would_ eventually be saved onto |
| 1181 | // the stack, but it would be too late: we would have |
| 1182 | // changed its value earlier. Therefore, we manually save |
| 1183 | // it here into another freely available register, |
| 1184 | // `free_reg`, chosen of course among the caller-save |
| 1185 | // registers (as a callee-save `free_reg` register would |
| 1186 | // exhibit the same problem). |
| 1187 | // |
| 1188 | // Note we could have requested a temporary register from |
| 1189 | // the register allocator instead; but we prefer not to, as |
| 1190 | // this is a slow path, and we know we can find a |
| 1191 | // caller-save register that is available. |
| 1192 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1193 | __ Mov(free_reg.W(), index_reg); |
| 1194 | index_reg = free_reg; |
| 1195 | index = LocationFrom(index_reg); |
| 1196 | } else { |
| 1197 | // The initial register stored in `index_` has already been |
| 1198 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1199 | // (as it is not a callee-save register), so we can freely |
| 1200 | // use it. |
| 1201 | } |
| 1202 | // Shifting the index value contained in `index_reg` by the scale |
| 1203 | // factor (2) cannot overflow in practice, as the runtime is |
| 1204 | // unable to allocate object arrays with a size larger than |
| 1205 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1206 | __ Lsl(index_reg, index_reg, DataType::SizeShift(type)); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1207 | static_assert( |
| 1208 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1209 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1210 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1211 | } else { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1212 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1213 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1214 | // (as in the case of ArrayGet), as it is actually an offset |
| 1215 | // to an object field within an object. |
| 1216 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1217 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1218 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1219 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1220 | << instruction_->AsInvoke()->GetIntrinsic(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1221 | DCHECK_EQ(offset_, 0u); |
| Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1222 | DCHECK(index_.IsRegister()); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | // We're moving two or three locations to locations that could |
| 1227 | // overlap, so we need a parallel move resolver. |
| 1228 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1229 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1230 | parallel_move.AddMove(ref_, |
| 1231 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1232 | type, |
| 1233 | nullptr); |
| 1234 | parallel_move.AddMove(obj_, |
| 1235 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1236 | type, |
| 1237 | nullptr); |
| 1238 | if (index.IsValid()) { |
| 1239 | parallel_move.AddMove(index, |
| 1240 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1241 | DataType::Type::kInt32, |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1242 | nullptr); |
| 1243 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1244 | } else { |
| 1245 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1246 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1247 | } |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1248 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1249 | instruction_, |
| 1250 | instruction_->GetDexPc(), |
| 1251 | this); |
| 1252 | CheckEntrypointTypes< |
| 1253 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1254 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1255 | |
| 1256 | RestoreLiveRegisters(codegen, locations); |
| 1257 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1258 | __ B(GetExitLabel()); |
| 1259 | } |
| 1260 | |
| 1261 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1262 | |
| 1263 | private: |
| 1264 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1265 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1266 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1267 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1268 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1269 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1270 | } |
| 1271 | } |
| 1272 | // We shall never fail to find a free caller-save register, as |
| 1273 | // there are more than two core caller-save registers on ARM64 |
| 1274 | // (meaning it is possible to find one which is different from |
| 1275 | // `ref` and `obj`). |
| 1276 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1277 | LOG(FATAL) << "Could not find a free register"; |
| 1278 | UNREACHABLE(); |
| 1279 | } |
| 1280 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1281 | const Location out_; |
| 1282 | const Location ref_; |
| 1283 | const Location obj_; |
| 1284 | const uint32_t offset_; |
| 1285 | // An additional location containing an index to an array. |
| 1286 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1287 | // UnsafeGetObjectVolatile intrinsics. |
| 1288 | const Location index_; |
| 1289 | |
| 1290 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1291 | }; |
| 1292 | |
| 1293 | // Slow path generating a read barrier for a GC root. |
| 1294 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1295 | public: |
| 1296 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1297 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1298 | DCHECK(kEmitCompilerReadBarrier); |
| 1299 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1300 | |
| 1301 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1302 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1303 | DataType::Type type = DataType::Type::kReference; |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1304 | DCHECK(locations->CanCall()); |
| 1305 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1306 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1307 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1308 | << instruction_->DebugName(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1309 | |
| 1310 | __ Bind(GetEntryLabel()); |
| 1311 | SaveLiveRegisters(codegen, locations); |
| 1312 | |
| 1313 | InvokeRuntimeCallingConvention calling_convention; |
| 1314 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1315 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1316 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1317 | // thus we need a 64-bit move here, and we cannot use |
| 1318 | // |
| 1319 | // arm64_codegen->MoveLocation( |
| 1320 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1321 | // root_, |
| 1322 | // type); |
| 1323 | // |
| 1324 | // 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] | 1325 | // reference type (`DataType::Type::kReference`). |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1326 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1327 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1328 | instruction_, |
| 1329 | instruction_->GetDexPc(), |
| 1330 | this); |
| 1331 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1332 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1333 | |
| 1334 | RestoreLiveRegisters(codegen, locations); |
| 1335 | __ B(GetExitLabel()); |
| 1336 | } |
| 1337 | |
| 1338 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1339 | |
| 1340 | private: |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1341 | const Location out_; |
| 1342 | const Location root_; |
| 1343 | |
| 1344 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1345 | }; |
| 1346 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1347 | #undef __ |
| 1348 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1349 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1350 | Location next_location; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1351 | if (type == DataType::Type::kVoid) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1352 | LOG(FATAL) << "Unreachable type " << type; |
| 1353 | } |
| 1354 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1355 | if (DataType::IsFloatingPointType(type) && |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1356 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1357 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1358 | } else if (!DataType::IsFloatingPointType(type) && |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1359 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 1360 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1361 | } else { |
| 1362 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1363 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1364 | : Location::StackSlot(stack_offset); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1365 | } |
| 1366 | |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1367 | // Space on the stack is reserved for all arguments. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1368 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1369 | return next_location; |
| 1370 | } |
| 1371 | |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1372 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1373 | return LocationFrom(kArtMethodRegister); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1374 | } |
| 1375 | |
| Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1376 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1377 | const CompilerOptions& compiler_options, |
| 1378 | OptimizingCompilerStats* stats) |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1379 | : CodeGenerator(graph, |
| 1380 | kNumberOfAllocatableRegisters, |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1381 | kNumberOfAllocatableFPRegisters, |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1382 | kNumberOfAllocatableRegisterPairs, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1383 | callee_saved_core_registers.GetList(), |
| 1384 | callee_saved_fp_registers.GetList(), |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1385 | compiler_options, |
| 1386 | stats), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1387 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1388 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1389 | location_builder_(graph, this), |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1390 | instruction_visitor_(graph, this), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1391 | move_resolver_(graph->GetAllocator(), this), |
| 1392 | assembler_(graph->GetAllocator()), |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1393 | uint32_literals_(std::less<uint32_t>(), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1394 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1395 | uint64_literals_(std::less<uint64_t>(), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1396 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1397 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1398 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1399 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1400 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1401 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1402 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1403 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1404 | jit_string_patches_(StringReferenceValueComparator(), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1405 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1406 | jit_class_patches_(TypeReferenceValueComparator(), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1407 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1408 | // Save the link register (containing the return address) to mimic Quick. |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1409 | AddAllocatedRegister(LocationFrom(lr)); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1410 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1411 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1412 | #define __ GetVIXLAssembler()-> |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1413 | |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1414 | void CodeGeneratorARM64::EmitJumpTables() { |
| Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1415 | for (auto&& jump_table : jump_tables_) { |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1416 | jump_table->EmitTable(this); |
| 1417 | } |
| 1418 | } |
| 1419 | |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1420 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1421 | EmitJumpTables(); |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1422 | // Ensure we emit the literal pool. |
| 1423 | __ FinalizeCode(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1424 | |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1425 | CodeGenerator::Finalize(allocator); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1426 | |
| 1427 | // Verify Baker read barrier linker patches. |
| 1428 | if (kIsDebugBuild) { |
| 1429 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 1430 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 1431 | DCHECK(info.label.IsBound()); |
| 1432 | uint32_t literal_offset = info.label.GetLocation(); |
| 1433 | DCHECK_ALIGNED(literal_offset, 4u); |
| 1434 | |
| 1435 | auto GetInsn = [&code](uint32_t offset) { |
| 1436 | DCHECK_ALIGNED(offset, 4u); |
| 1437 | return |
| 1438 | (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 1439 | (static_cast<uint32_t>(code[offset + 1]) << 8) + |
| 1440 | (static_cast<uint32_t>(code[offset + 2]) << 16)+ |
| 1441 | (static_cast<uint32_t>(code[offset + 3]) << 24); |
| 1442 | }; |
| 1443 | |
| 1444 | const uint32_t encoded_data = info.custom_data; |
| 1445 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 1446 | // Check that the next instruction matches the expected LDR. |
| 1447 | switch (kind) { |
| 1448 | case BakerReadBarrierKind::kField: { |
| 1449 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1450 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 1451 | // LDR (immediate) with correct base_reg. |
| 1452 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1453 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1454 | CHECK_EQ(next_insn & 0xffc003e0u, 0xb9400000u | (base_reg << 5)); |
| 1455 | break; |
| 1456 | } |
| 1457 | case BakerReadBarrierKind::kArray: { |
| 1458 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1459 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 1460 | // LDR (register) with the correct base_reg, size=10 (32-bit), option=011 (extend = LSL), |
| 1461 | // and S=1 (shift amount = 2 for 32-bit version), i.e. LDR Wt, [Xn, Xm, LSL #2]. |
| 1462 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1463 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1464 | CHECK_EQ(next_insn & 0xffe0ffe0u, 0xb8607800u | (base_reg << 5)); |
| 1465 | CheckValidReg((next_insn >> 16) & 0x1f); // Check index register |
| 1466 | break; |
| 1467 | } |
| 1468 | case BakerReadBarrierKind::kGcRoot: { |
| 1469 | DCHECK_GE(literal_offset, 4u); |
| 1470 | uint32_t prev_insn = GetInsn(literal_offset - 4u); |
| 1471 | // LDR (immediate) with correct root_reg. |
| 1472 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1473 | CHECK_EQ(prev_insn & 0xffc0001fu, 0xb9400000u | root_reg); |
| 1474 | break; |
| 1475 | } |
| 1476 | default: |
| 1477 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 1478 | UNREACHABLE(); |
| 1479 | } |
| 1480 | } |
| 1481 | } |
| Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1484 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1485 | // Note: There are 6 kinds of moves: |
| 1486 | // 1. constant -> GPR/FPR (non-cycle) |
| 1487 | // 2. constant -> stack (non-cycle) |
| 1488 | // 3. GPR/FPR -> GPR/FPR |
| 1489 | // 4. GPR/FPR -> stack |
| 1490 | // 5. stack -> GPR/FPR |
| 1491 | // 6. stack -> stack (non-cycle) |
| 1492 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1493 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1494 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1495 | // dependency. |
| 1496 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1497 | } |
| 1498 | |
| 1499 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1500 | vixl_temps_.Close(); |
| 1501 | } |
| 1502 | |
| 1503 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1504 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1505 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1506 | || kind == Location::kSIMDStackSlot); |
| 1507 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1508 | ? Location::kFpuRegister |
| 1509 | : Location::kRegister; |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1510 | Location scratch = GetScratchLocation(kind); |
| 1511 | if (!scratch.Equals(Location::NoLocation())) { |
| 1512 | return scratch; |
| 1513 | } |
| 1514 | // Allocate from VIXL temp registers. |
| 1515 | if (kind == Location::kRegister) { |
| 1516 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1517 | } else { |
| Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1518 | DCHECK_EQ(kind, Location::kFpuRegister); |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1519 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1520 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1521 | : vixl_temps_.AcquireD()); |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1522 | } |
| 1523 | AddScratchLocation(scratch); |
| 1524 | return scratch; |
| 1525 | } |
| 1526 | |
| 1527 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1528 | if (loc.IsRegister()) { |
| 1529 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1530 | } else { |
| 1531 | DCHECK(loc.IsFpuRegister()); |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1532 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1533 | } |
| 1534 | RemoveScratchLocation(loc); |
| 1535 | } |
| 1536 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1537 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1538 | MoveOperands* move = moves_[index]; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1539 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1542 | void CodeGeneratorARM64::GenerateFrameEntry() { |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1543 | MacroAssembler* masm = GetVIXLAssembler(); |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1544 | __ Bind(&frame_entry_label_); |
| 1545 | |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1546 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1547 | UseScratchRegisterScope temps(masm); |
| 1548 | Register temp = temps.AcquireX(); |
| 1549 | __ Ldrh(temp, MemOperand(kArtMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1550 | __ Add(temp, temp, 1); |
| 1551 | __ Strh(temp, MemOperand(kArtMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1552 | } |
| 1553 | |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1554 | bool do_overflow_check = |
| 1555 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1556 | if (do_overflow_check) { |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1557 | UseScratchRegisterScope temps(masm); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1558 | Register temp = temps.AcquireX(); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1559 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1560 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1561 | { |
| 1562 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1563 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1564 | kInstructionSize, |
| 1565 | CodeBufferCheckScope::kExactSize); |
| 1566 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1567 | RecordPcInfo(nullptr, 0); |
| 1568 | } |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1569 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1570 | |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1571 | if (!HasEmptyFrame()) { |
| 1572 | int frame_size = GetFrameSize(); |
| 1573 | // Stack layout: |
| 1574 | // sp[frame_size - 8] : lr. |
| 1575 | // ... : other preserved core registers. |
| 1576 | // ... : other preserved fp registers. |
| 1577 | // ... : reserved frame space. |
| 1578 | // sp[0] : current method. |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1579 | |
| 1580 | // Save the current method if we need it. Note that we do not |
| 1581 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1582 | // in the SSA graph. |
| 1583 | if (RequiresCurrentMethod()) { |
| 1584 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
| Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1585 | } else { |
| 1586 | __ Claim(frame_size); |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1587 | } |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1588 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
| Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1589 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1590 | frame_size - GetCoreSpillSize()); |
| 1591 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1592 | frame_size - FrameEntrySpillSize()); |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1593 | |
| 1594 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1595 | // Initialize should_deoptimize flag to 0. |
| 1596 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1597 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1598 | } |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1599 | } |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 1600 | |
| 1601 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | void CodeGeneratorARM64::GenerateFrameExit() { |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1605 | GetAssembler()->cfi().RememberState(); |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1606 | if (!HasEmptyFrame()) { |
| 1607 | int frame_size = GetFrameSize(); |
| Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1608 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1609 | frame_size - FrameEntrySpillSize()); |
| 1610 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1611 | frame_size - GetCoreSpillSize()); |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1612 | __ Drop(frame_size); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1613 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1614 | } |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1615 | __ Ret(); |
| 1616 | GetAssembler()->cfi().RestoreState(); |
| 1617 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1618 | } |
| 1619 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1620 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1621 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1622 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1623 | core_spill_mask_); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1624 | } |
| 1625 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1626 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1627 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1628 | GetNumberOfFloatingPointRegisters())); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1629 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1630 | fpu_spill_mask_); |
| Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1631 | } |
| 1632 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1633 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1634 | __ Bind(GetLabelOf(block)); |
| 1635 | } |
| 1636 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1637 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1638 | DCHECK(location.IsRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1639 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1640 | } |
| 1641 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1642 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1643 | if (location.IsRegister()) { |
| 1644 | locations->AddTemp(location); |
| 1645 | } else { |
| 1646 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1647 | } |
| 1648 | } |
| 1649 | |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1650 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1651 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1652 | Register card = temps.AcquireX(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1653 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1654 | vixl::aarch64::Label done; |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1655 | if (value_can_be_null) { |
| 1656 | __ Cbz(value, &done); |
| 1657 | } |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1658 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1659 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1660 | __ Strb(card, MemOperand(card, temp.X())); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1661 | if (value_can_be_null) { |
| 1662 | __ Bind(&done); |
| 1663 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1664 | } |
| 1665 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1666 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1667 | // Blocked core registers: |
| 1668 | // lr : Runtime reserved. |
| 1669 | // tr : Runtime reserved. |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1670 | // mr : Runtime reserved. |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1671 | // ip1 : VIXL core temp. |
| 1672 | // ip0 : VIXL core temp. |
| 1673 | // |
| 1674 | // Blocked fp registers: |
| 1675 | // d31 : VIXL fp temp. |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1676 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1677 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1678 | while (!reserved_core_registers.IsEmpty()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1679 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1680 | } |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1681 | |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1682 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
| Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1683 | while (!reserved_fp_registers.IsEmpty()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1684 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1685 | } |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1686 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1687 | if (GetGraph()->IsDebuggable()) { |
| Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1688 | // Stubs do not save callee-save floating point registers. If the graph |
| 1689 | // is debuggable, we need to deal with these registers differently. For |
| 1690 | // now, just block them. |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1691 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1692 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1693 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
| Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1694 | } |
| 1695 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1696 | } |
| 1697 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1698 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1699 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1700 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1701 | return kArm64WordSize; |
| 1702 | } |
| 1703 | |
| 1704 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1705 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1706 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1707 | return kArm64WordSize; |
| 1708 | } |
| 1709 | |
| 1710 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1711 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1712 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1713 | return kArm64WordSize; |
| 1714 | } |
| 1715 | |
| 1716 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1717 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1718 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1719 | return kArm64WordSize; |
| 1720 | } |
| 1721 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1722 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1723 | stream << XRegister(reg); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1727 | stream << DRegister(reg); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1728 | } |
| 1729 | |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1730 | const Arm64InstructionSetFeatures& CodeGeneratorARM64::GetInstructionSetFeatures() const { |
| 1731 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArm64InstructionSetFeatures(); |
| 1732 | } |
| 1733 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1734 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1735 | if (constant->IsIntConstant()) { |
| 1736 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1737 | } else if (constant->IsLongConstant()) { |
| 1738 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1739 | } else if (constant->IsNullConstant()) { |
| 1740 | __ Mov(Register(destination), 0); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1741 | } else if (constant->IsFloatConstant()) { |
| 1742 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1743 | } else { |
| 1744 | DCHECK(constant->IsDoubleConstant()); |
| 1745 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1746 | } |
| 1747 | } |
| 1748 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1749 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1750 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1751 | DCHECK(constant.IsConstant()); |
| 1752 | HConstant* cst = constant.GetConstant(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1753 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1754 | // 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] | 1755 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1756 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1757 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1758 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1759 | } |
| 1760 | |
| Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1761 | // Allocate a scratch register from the VIXL pool, querying first |
| 1762 | // the floating-point register pool, and then the core register |
| 1763 | // pool. This is essentially a reimplementation of |
| Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1764 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1765 | // using a different allocation strategy. |
| 1766 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1767 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1768 | int size_in_bits) { |
| 1769 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1770 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1771 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1772 | } |
| 1773 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1774 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1775 | Location source, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1776 | DataType::Type dst_type) { |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1777 | if (source.Equals(destination)) { |
| 1778 | return; |
| 1779 | } |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1780 | |
| 1781 | // A valid move can always be inferred from the destination and source |
| 1782 | // locations. When moving from and to a register, the argument type can be |
| 1783 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1784 | // checks the coherency of the locations and the type. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1785 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1786 | |
| 1787 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1788 | if (unspecified_type) { |
| 1789 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1790 | if (source.IsStackSlot() || |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1791 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1792 | || src_cst->IsFloatConstant() |
| 1793 | || src_cst->IsNullConstant()))) { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1794 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1795 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1796 | } else { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1797 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1798 | // type is appropriate. Else the source is a register, and since the |
| 1799 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1800 | // move. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1801 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1802 | } |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1803 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1804 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1805 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1806 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1807 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1808 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1809 | __ Ldr(dst, StackOperandFrom(source)); |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1810 | } else if (source.IsSIMDStackSlot()) { |
| 1811 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1812 | } else if (source.IsConstant()) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1813 | DCHECK(CoherentConstantAndType(source, dst_type)); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1814 | MoveConstant(dst, source.GetConstant()); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1815 | } else if (source.IsRegister()) { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1816 | if (destination.IsRegister()) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1817 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1818 | } else { |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1819 | DCHECK(destination.IsFpuRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1820 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1821 | ? DataType::Type::kInt64 |
| 1822 | : DataType::Type::kInt32; |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1823 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1824 | } |
| 1825 | } else { |
| 1826 | DCHECK(source.IsFpuRegister()); |
| 1827 | if (destination.IsRegister()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1828 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1829 | ? DataType::Type::kFloat64 |
| 1830 | : DataType::Type::kFloat32; |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1831 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1832 | } else { |
| 1833 | DCHECK(destination.IsFpuRegister()); |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1834 | if (GetGraph()->HasSIMD()) { |
| 1835 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1836 | } else { |
| 1837 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1838 | } |
| 1839 | } |
| 1840 | } |
| 1841 | } else if (destination.IsSIMDStackSlot()) { |
| 1842 | if (source.IsFpuRegister()) { |
| 1843 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1844 | } else { |
| 1845 | DCHECK(source.IsSIMDStackSlot()); |
| 1846 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1847 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1848 | Register temp = temps.AcquireX(); |
| 1849 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1850 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1851 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1852 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1853 | } else { |
| 1854 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1855 | __ Ldr(temp, StackOperandFrom(source)); |
| 1856 | __ Str(temp, StackOperandFrom(destination)); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1857 | } |
| 1858 | } |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1859 | } else { // The destination is not a register. It must be a stack slot. |
| 1860 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1861 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1862 | if (unspecified_type) { |
| 1863 | if (source.IsRegister()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1864 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1865 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1866 | dst_type = |
| 1867 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1868 | } |
| 1869 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1870 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1871 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1872 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1873 | } else if (source.IsConstant()) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1874 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1875 | << source << " " << dst_type; |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1876 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1877 | HConstant* src_cst = source.GetConstant(); |
| 1878 | CPURegister temp; |
| Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1879 | if (src_cst->IsZeroBitPattern()) { |
| Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1880 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1881 | ? Register(xzr) |
| 1882 | : Register(wzr); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1883 | } else { |
| Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1884 | if (src_cst->IsIntConstant()) { |
| 1885 | temp = temps.AcquireW(); |
| 1886 | } else if (src_cst->IsLongConstant()) { |
| 1887 | temp = temps.AcquireX(); |
| 1888 | } else if (src_cst->IsFloatConstant()) { |
| 1889 | temp = temps.AcquireS(); |
| 1890 | } else { |
| 1891 | DCHECK(src_cst->IsDoubleConstant()); |
| 1892 | temp = temps.AcquireD(); |
| 1893 | } |
| 1894 | MoveConstant(temp, src_cst); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1895 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1896 | __ Str(temp, StackOperandFrom(destination)); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1897 | } else { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1898 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1899 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1900 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1901 | // Use any scratch register (a core or a floating-point one) |
| 1902 | // from VIXL scratch register pools as a temporary. |
| 1903 | // |
| 1904 | // We used to only use the FP scratch register pool, but in some |
| 1905 | // rare cases the only register from this pool (D31) would |
| 1906 | // already be used (e.g. within a ParallelMove instruction, when |
| 1907 | // a move is blocked by a another move requiring a scratch FP |
| 1908 | // register, which would reserve D31). To prevent this issue, we |
| 1909 | // ask for a scratch register of any type (core or FP). |
| Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1910 | // |
| 1911 | // 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] | 1912 | // demand of scratch core registers is higher. This is why we |
| Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1913 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1914 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1915 | // allocates core scratch registers first. |
| 1916 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1917 | GetVIXLAssembler(), |
| 1918 | &temps, |
| 1919 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1920 | __ Ldr(temp, StackOperandFrom(source)); |
| 1921 | __ Str(temp, StackOperandFrom(destination)); |
| 1922 | } |
| 1923 | } |
| 1924 | } |
| 1925 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1926 | void CodeGeneratorARM64::Load(DataType::Type type, |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1927 | CPURegister dst, |
| 1928 | const MemOperand& src) { |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1929 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1930 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1931 | case DataType::Type::kUint8: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1932 | __ Ldrb(Register(dst), src); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1933 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1934 | case DataType::Type::kInt8: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1935 | __ Ldrsb(Register(dst), src); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1936 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1937 | case DataType::Type::kUint16: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1938 | __ Ldrh(Register(dst), src); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1939 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1940 | case DataType::Type::kInt16: |
| 1941 | __ Ldrsh(Register(dst), src); |
| 1942 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1943 | case DataType::Type::kInt32: |
| 1944 | case DataType::Type::kReference: |
| 1945 | case DataType::Type::kInt64: |
| 1946 | case DataType::Type::kFloat32: |
| 1947 | case DataType::Type::kFloat64: |
| 1948 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1949 | __ Ldr(dst, src); |
| 1950 | break; |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1951 | case DataType::Type::kUint32: |
| 1952 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1953 | case DataType::Type::kVoid: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1954 | LOG(FATAL) << "Unreachable type " << type; |
| 1955 | } |
| 1956 | } |
| 1957 | |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1958 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1959 | CPURegister dst, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1960 | const MemOperand& src, |
| 1961 | bool needs_null_check) { |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1962 | MacroAssembler* masm = GetVIXLAssembler(); |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1963 | UseScratchRegisterScope temps(masm); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1964 | Register temp_base = temps.AcquireX(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1965 | DataType::Type type = instruction->GetType(); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1966 | |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1967 | DCHECK(!src.IsPreIndex()); |
| 1968 | DCHECK(!src.IsPostIndex()); |
| 1969 | |
| 1970 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1971 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1972 | { |
| 1973 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1974 | MemOperand base = MemOperand(temp_base); |
| 1975 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1976 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1977 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1978 | case DataType::Type::kInt8: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1979 | { |
| 1980 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1981 | __ ldarb(Register(dst), base); |
| 1982 | if (needs_null_check) { |
| 1983 | MaybeRecordImplicitNullCheck(instruction); |
| 1984 | } |
| 1985 | } |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1986 | if (type == DataType::Type::kInt8) { |
| 1987 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1988 | } |
| 1989 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1990 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1991 | case DataType::Type::kInt16: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1992 | { |
| 1993 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1994 | __ ldarh(Register(dst), base); |
| 1995 | if (needs_null_check) { |
| 1996 | MaybeRecordImplicitNullCheck(instruction); |
| 1997 | } |
| 1998 | } |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1999 | if (type == DataType::Type::kInt16) { |
| 2000 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 2001 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2002 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2003 | case DataType::Type::kInt32: |
| 2004 | case DataType::Type::kReference: |
| 2005 | case DataType::Type::kInt64: |
| 2006 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2007 | { |
| 2008 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2009 | __ ldar(Register(dst), base); |
| 2010 | if (needs_null_check) { |
| 2011 | MaybeRecordImplicitNullCheck(instruction); |
| 2012 | } |
| 2013 | } |
| 2014 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2015 | case DataType::Type::kFloat32: |
| 2016 | case DataType::Type::kFloat64: { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2017 | DCHECK(dst.IsFPRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2018 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2019 | |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2020 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2021 | { |
| 2022 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2023 | __ ldar(temp, base); |
| 2024 | if (needs_null_check) { |
| 2025 | MaybeRecordImplicitNullCheck(instruction); |
| 2026 | } |
| 2027 | } |
| 2028 | __ Fmov(FPRegister(dst), temp); |
| 2029 | break; |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2030 | } |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2031 | case DataType::Type::kUint32: |
| 2032 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2033 | case DataType::Type::kVoid: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2034 | LOG(FATAL) << "Unreachable type " << type; |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2035 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2036 | } |
| 2037 | } |
| 2038 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2039 | void CodeGeneratorARM64::Store(DataType::Type type, |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2040 | CPURegister src, |
| 2041 | const MemOperand& dst) { |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2042 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2043 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2044 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2045 | case DataType::Type::kInt8: |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2046 | __ Strb(Register(src), dst); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2047 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2048 | case DataType::Type::kUint16: |
| 2049 | case DataType::Type::kInt16: |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2050 | __ Strh(Register(src), dst); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2051 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2052 | case DataType::Type::kInt32: |
| 2053 | case DataType::Type::kReference: |
| 2054 | case DataType::Type::kInt64: |
| 2055 | case DataType::Type::kFloat32: |
| 2056 | case DataType::Type::kFloat64: |
| 2057 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2058 | __ Str(src, dst); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2059 | break; |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2060 | case DataType::Type::kUint32: |
| 2061 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2062 | case DataType::Type::kVoid: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2063 | LOG(FATAL) << "Unreachable type " << type; |
| 2064 | } |
| 2065 | } |
| 2066 | |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2067 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2068 | DataType::Type type, |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2069 | CPURegister src, |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2070 | const MemOperand& dst, |
| 2071 | bool needs_null_check) { |
| 2072 | MacroAssembler* masm = GetVIXLAssembler(); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2073 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2074 | Register temp_base = temps.AcquireX(); |
| 2075 | |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2076 | DCHECK(!dst.IsPreIndex()); |
| 2077 | DCHECK(!dst.IsPostIndex()); |
| 2078 | |
| 2079 | // TODO(vixl): Let the MacroAssembler handle this. |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2080 | Operand op = OperandFromMemOperand(dst); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2081 | __ Add(temp_base, dst.GetBaseRegister(), op); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2082 | MemOperand base = MemOperand(temp_base); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2083 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2084 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2085 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2086 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2087 | case DataType::Type::kInt8: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2088 | { |
| 2089 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2090 | __ stlrb(Register(src), base); |
| 2091 | if (needs_null_check) { |
| 2092 | MaybeRecordImplicitNullCheck(instruction); |
| 2093 | } |
| 2094 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2095 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2096 | case DataType::Type::kUint16: |
| 2097 | case DataType::Type::kInt16: |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2098 | { |
| 2099 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2100 | __ stlrh(Register(src), base); |
| 2101 | if (needs_null_check) { |
| 2102 | MaybeRecordImplicitNullCheck(instruction); |
| 2103 | } |
| 2104 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2105 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2106 | case DataType::Type::kInt32: |
| 2107 | case DataType::Type::kReference: |
| 2108 | case DataType::Type::kInt64: |
| 2109 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2110 | { |
| 2111 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2112 | __ stlr(Register(src), base); |
| 2113 | if (needs_null_check) { |
| 2114 | MaybeRecordImplicitNullCheck(instruction); |
| 2115 | } |
| 2116 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2117 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2118 | case DataType::Type::kFloat32: |
| 2119 | case DataType::Type::kFloat64: { |
| 2120 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2121 | Register temp_src; |
| 2122 | if (src.IsZero()) { |
| 2123 | // The zero register is used to avoid synthesizing zero constants. |
| 2124 | temp_src = Register(src); |
| 2125 | } else { |
| 2126 | DCHECK(src.IsFPRegister()); |
| 2127 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2128 | __ Fmov(temp_src, FPRegister(src)); |
| 2129 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2130 | { |
| 2131 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2132 | __ stlr(temp_src, base); |
| 2133 | if (needs_null_check) { |
| 2134 | MaybeRecordImplicitNullCheck(instruction); |
| 2135 | } |
| 2136 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2137 | break; |
| 2138 | } |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2139 | case DataType::Type::kUint32: |
| 2140 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2141 | case DataType::Type::kVoid: |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2142 | LOG(FATAL) << "Unreachable type " << type; |
| 2143 | } |
| 2144 | } |
| 2145 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2146 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2147 | HInstruction* instruction, |
| 2148 | uint32_t dex_pc, |
| 2149 | SlowPathCode* slow_path) { |
| Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2150 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2151 | |
| 2152 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 2153 | { |
| 2154 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 2155 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2156 | __ blr(lr); |
| 2157 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2158 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2159 | } |
| Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2160 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2161 | } |
| 2162 | |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2163 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2164 | HInstruction* instruction, |
| 2165 | SlowPathCode* slow_path) { |
| 2166 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2167 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2168 | __ Blr(lr); |
| 2169 | } |
| 2170 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2171 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2172 | Register class_reg) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2173 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2174 | Register temp = temps.AcquireW(); |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2175 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 2176 | const size_t status_byte_offset = |
| 2177 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 2178 | constexpr uint32_t shifted_initialized_value = |
| 2179 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2180 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2181 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
| Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2182 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2183 | __ Add(temp, class_reg, status_byte_offset); |
| Igor Murashkin | 86083f7 | 2017-10-27 10:59:04 -0700 | [diff] [blame] | 2184 | __ Ldarb(temp, HeapOperand(temp)); |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2185 | __ Cmp(temp, shifted_initialized_value); |
| Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 2186 | __ B(lo, slow_path->GetEntryLabel()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2187 | __ Bind(slow_path->GetExitLabel()); |
| 2188 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2189 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2190 | void InstructionCodeGeneratorARM64::GenerateBitstringTypeCheckCompare( |
| 2191 | HTypeCheckInstruction* check, vixl::aarch64::Register temp) { |
| 2192 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 2193 | uint32_t mask = check->GetBitstringMask(); |
| 2194 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 2195 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 2196 | |
| 2197 | if (mask_bits == 16u) { |
| 2198 | // Load only the bitstring part of the status word. |
| 2199 | __ Ldrh(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 2200 | } else { |
| 2201 | // /* uint32_t */ temp = temp->status_ |
| 2202 | __ Ldr(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 2203 | // Extract the bitstring bits. |
| 2204 | __ Ubfx(temp, temp, 0, mask_bits); |
| 2205 | } |
| 2206 | // Compare the bitstring bits to `path_to_root`. |
| 2207 | __ Cmp(temp, path_to_root); |
| 2208 | } |
| 2209 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2210 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2211 | BarrierType type = BarrierAll; |
| 2212 | |
| 2213 | switch (kind) { |
| 2214 | case MemBarrierKind::kAnyAny: |
| 2215 | case MemBarrierKind::kAnyStore: { |
| 2216 | type = BarrierAll; |
| 2217 | break; |
| 2218 | } |
| 2219 | case MemBarrierKind::kLoadAny: { |
| 2220 | type = BarrierReads; |
| 2221 | break; |
| 2222 | } |
| 2223 | case MemBarrierKind::kStoreStore: { |
| 2224 | type = BarrierWrites; |
| 2225 | break; |
| 2226 | } |
| 2227 | default: |
| 2228 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2229 | } |
| 2230 | __ Dmb(InnerShareable, type); |
| 2231 | } |
| 2232 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2233 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2234 | HBasicBlock* successor) { |
| 2235 | SuspendCheckSlowPathARM64* slow_path = |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2236 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2237 | if (slow_path == nullptr) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2238 | slow_path = |
| 2239 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2240 | instruction->SetSlowPath(slow_path); |
| 2241 | codegen_->AddSlowPath(slow_path); |
| 2242 | if (successor != nullptr) { |
| 2243 | DCHECK(successor->IsLoopHeader()); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2244 | } |
| 2245 | } else { |
| 2246 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2247 | } |
| 2248 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2249 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2250 | Register temp = temps.AcquireW(); |
| 2251 | |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2252 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2253 | if (successor == nullptr) { |
| 2254 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2255 | __ Bind(slow_path->GetReturnLabel()); |
| 2256 | } else { |
| 2257 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 2258 | __ B(slow_path->GetEntryLabel()); |
| 2259 | // slow_path will return to GetLabelOf(successor). |
| 2260 | } |
| 2261 | } |
| 2262 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2263 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2264 | CodeGeneratorARM64* codegen) |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2265 | : InstructionCodeGenerator(graph, codegen), |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2266 | assembler_(codegen->GetAssembler()), |
| 2267 | codegen_(codegen) {} |
| 2268 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2269 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2270 | DCHECK_EQ(instr->InputCount(), 2U); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2271 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2272 | DataType::Type type = instr->GetResultType(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2273 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2274 | case DataType::Type::kInt32: |
| 2275 | case DataType::Type::kInt64: |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2276 | locations->SetInAt(0, Location::RequiresRegister()); |
| Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2277 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2278 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2279 | break; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2280 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2281 | case DataType::Type::kFloat32: |
| 2282 | case DataType::Type::kFloat64: |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2283 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2284 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2285 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2286 | break; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2287 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2288 | default: |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2289 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2290 | } |
| 2291 | } |
| 2292 | |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2293 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2294 | const FieldInfo& field_info) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2295 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2296 | |
| 2297 | bool object_field_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2298 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2299 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2300 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2301 | object_field_get_with_read_barrier |
| 2302 | ? LocationSummary::kCallOnSlowPath |
| 2303 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2304 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2305 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2306 | // We need a temporary register for the read barrier marking slow |
| 2307 | // path in CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2308 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2309 | !Runtime::Current()->UseJitCompilation() && |
| 2310 | !field_info.IsVolatile()) { |
| 2311 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2312 | // non-volatile loads we need a temporary only if the offset is too big. |
| 2313 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2314 | locations->AddTemp(FixedTempLocation()); |
| 2315 | } |
| 2316 | } else { |
| 2317 | locations->AddTemp(Location::RequiresRegister()); |
| 2318 | } |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2319 | } |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2320 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2321 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2322 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2323 | } else { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2324 | // The output overlaps for an object field get when read barriers |
| 2325 | // are enabled: we do not want the load to overwrite the object's |
| 2326 | // location, as we need it to emit the read barrier. |
| 2327 | locations->SetOut( |
| 2328 | Location::RequiresRegister(), |
| 2329 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2330 | } |
| 2331 | } |
| 2332 | |
| 2333 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2334 | const FieldInfo& field_info) { |
| 2335 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2336 | LocationSummary* locations = instruction->GetLocations(); |
| 2337 | Location base_loc = locations->InAt(0); |
| 2338 | Location out = locations->Out(); |
| 2339 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2340 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 2341 | DataType::Type load_type = instruction->GetType(); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2342 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2343 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2344 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2345 | load_type == DataType::Type::kReference) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2346 | // Object FieldGet with Baker's read barrier case. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2347 | // /* HeapReference<Object> */ out = *(base + offset) |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2348 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2349 | Location maybe_temp = |
| 2350 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2351 | // Note that potential implicit null checks are handled in this |
| 2352 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2353 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2354 | instruction, |
| 2355 | out, |
| 2356 | base, |
| 2357 | offset, |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2358 | maybe_temp, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2359 | /* needs_null_check */ true, |
| Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2360 | field_info.IsVolatile()); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2361 | } else { |
| 2362 | // General case. |
| 2363 | if (field_info.IsVolatile()) { |
| Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2364 | // Note that a potential implicit null check is handled in this |
| 2365 | // CodeGeneratorARM64::LoadAcquire call. |
| 2366 | // NB: LoadAcquire will record the pc info if needed. |
| 2367 | codegen_->LoadAcquire( |
| 2368 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2369 | } else { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2370 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2371 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2372 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2373 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2374 | } |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2375 | if (load_type == DataType::Type::kReference) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2376 | // If read barriers are enabled, emit read barriers other than |
| 2377 | // Baker's using a slow path (and also unpoison the loaded |
| 2378 | // reference, if heap poisoning is enabled). |
| 2379 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2380 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2381 | } |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2385 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2386 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2387 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2388 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2389 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2390 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2391 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2392 | } else { |
| 2393 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2394 | } |
| 2395 | } |
| 2396 | |
| 2397 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2398 | const FieldInfo& field_info, |
| 2399 | bool value_can_be_null) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2400 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2401 | |
| 2402 | Register obj = InputRegisterAt(instruction, 0); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2403 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2404 | CPURegister source = value; |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2405 | Offset offset = field_info.GetFieldOffset(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2406 | DataType::Type field_type = field_info.GetFieldType(); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2407 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2408 | { |
| 2409 | // We use a block to end the scratch scope before the write barrier, thus |
| 2410 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2411 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2412 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2413 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2414 | DCHECK(value.IsW()); |
| 2415 | Register temp = temps.AcquireW(); |
| 2416 | __ Mov(temp, value.W()); |
| 2417 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2418 | source = temp; |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2419 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2420 | |
| 2421 | if (field_info.IsVolatile()) { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2422 | codegen_->StoreRelease( |
| 2423 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2424 | } else { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2425 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2426 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2427 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2428 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2429 | } |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2433 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2434 | } |
| 2435 | } |
| 2436 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2437 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2438 | DataType::Type type = instr->GetType(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2439 | |
| 2440 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2441 | case DataType::Type::kInt32: |
| 2442 | case DataType::Type::kInt64: { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2443 | Register dst = OutputRegister(instr); |
| 2444 | Register lhs = InputRegisterAt(instr, 0); |
| 2445 | Operand rhs = InputOperandAt(instr, 1); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2446 | if (instr->IsAdd()) { |
| 2447 | __ Add(dst, lhs, rhs); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2448 | } else if (instr->IsAnd()) { |
| 2449 | __ And(dst, lhs, rhs); |
| 2450 | } else if (instr->IsOr()) { |
| 2451 | __ Orr(dst, lhs, rhs); |
| 2452 | } else if (instr->IsSub()) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2453 | __ Sub(dst, lhs, rhs); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2454 | } else if (instr->IsRor()) { |
| 2455 | if (rhs.IsImmediate()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2456 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2457 | __ Ror(dst, lhs, shift); |
| 2458 | } else { |
| 2459 | // Ensure shift distance is in the same size register as the result. If |
| 2460 | // we are rotating a long and the shift comes in a w register originally, |
| 2461 | // we don't need to sxtw for use as an x since the shift distances are |
| 2462 | // all & reg_bits - 1. |
| 2463 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2464 | } |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2465 | } else if (instr->IsMin() || instr->IsMax()) { |
| 2466 | __ Cmp(lhs, rhs); |
| 2467 | __ Csel(dst, lhs, rhs, instr->IsMin() ? lt : gt); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2468 | } else { |
| 2469 | DCHECK(instr->IsXor()); |
| 2470 | __ Eor(dst, lhs, rhs); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2471 | } |
| 2472 | break; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2473 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2474 | case DataType::Type::kFloat32: |
| 2475 | case DataType::Type::kFloat64: { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2476 | FPRegister dst = OutputFPRegister(instr); |
| 2477 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2478 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2479 | if (instr->IsAdd()) { |
| 2480 | __ Fadd(dst, lhs, rhs); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2481 | } else if (instr->IsSub()) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2482 | __ Fsub(dst, lhs, rhs); |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2483 | } else if (instr->IsMin()) { |
| 2484 | __ Fmin(dst, lhs, rhs); |
| 2485 | } else if (instr->IsMax()) { |
| 2486 | __ Fmax(dst, lhs, rhs); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2487 | } else { |
| 2488 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2489 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2490 | break; |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2491 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2492 | default: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2493 | LOG(FATAL) << "Unexpected binary operation type " << type; |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2494 | } |
| 2495 | } |
| 2496 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2497 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2498 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2499 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2500 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2501 | DataType::Type type = instr->GetResultType(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2502 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2503 | case DataType::Type::kInt32: |
| 2504 | case DataType::Type::kInt64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2505 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2506 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
| Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2507 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2508 | break; |
| 2509 | } |
| 2510 | default: |
| 2511 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2512 | } |
| 2513 | } |
| 2514 | |
| 2515 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2516 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2517 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2518 | DataType::Type type = instr->GetType(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2519 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2520 | case DataType::Type::kInt32: |
| 2521 | case DataType::Type::kInt64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2522 | Register dst = OutputRegister(instr); |
| 2523 | Register lhs = InputRegisterAt(instr, 0); |
| 2524 | Operand rhs = InputOperandAt(instr, 1); |
| 2525 | if (rhs.IsImmediate()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2526 | uint32_t shift_value = rhs.GetImmediate() & |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2527 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2528 | if (instr->IsShl()) { |
| 2529 | __ Lsl(dst, lhs, shift_value); |
| 2530 | } else if (instr->IsShr()) { |
| 2531 | __ Asr(dst, lhs, shift_value); |
| 2532 | } else { |
| 2533 | __ Lsr(dst, lhs, shift_value); |
| 2534 | } |
| 2535 | } else { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2536 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2537 | |
| 2538 | if (instr->IsShl()) { |
| 2539 | __ Lsl(dst, lhs, rhs_reg); |
| 2540 | } else if (instr->IsShr()) { |
| 2541 | __ Asr(dst, lhs, rhs_reg); |
| 2542 | } else { |
| 2543 | __ Lsr(dst, lhs, rhs_reg); |
| 2544 | } |
| 2545 | } |
| 2546 | break; |
| 2547 | } |
| 2548 | default: |
| 2549 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2550 | } |
| 2551 | } |
| 2552 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2553 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2554 | HandleBinaryOp(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2558 | HandleBinaryOp(instruction); |
| 2559 | } |
| 2560 | |
| 2561 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2562 | HandleBinaryOp(instruction); |
| 2563 | } |
| 2564 | |
| 2565 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2566 | HandleBinaryOp(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2567 | } |
| 2568 | |
| Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2569 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2570 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2571 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
| Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2572 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2573 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2574 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2575 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2576 | } |
| 2577 | |
| Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2578 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
| Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2579 | Register dst = OutputRegister(instr); |
| 2580 | Register lhs = InputRegisterAt(instr, 0); |
| 2581 | Register rhs = InputRegisterAt(instr, 1); |
| 2582 | |
| 2583 | switch (instr->GetOpKind()) { |
| 2584 | case HInstruction::kAnd: |
| 2585 | __ Bic(dst, lhs, rhs); |
| 2586 | break; |
| 2587 | case HInstruction::kOr: |
| 2588 | __ Orn(dst, lhs, rhs); |
| 2589 | break; |
| 2590 | case HInstruction::kXor: |
| 2591 | __ Eon(dst, lhs, rhs); |
| 2592 | break; |
| 2593 | default: |
| 2594 | LOG(FATAL) << "Unreachable"; |
| 2595 | } |
| 2596 | } |
| 2597 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2598 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2599 | HDataProcWithShifterOp* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2600 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2601 | instruction->GetType() == DataType::Type::kInt64); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2602 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2603 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2604 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2605 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2606 | } else { |
| 2607 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2608 | } |
| 2609 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2610 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2611 | } |
| 2612 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2613 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2614 | HDataProcWithShifterOp* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2615 | DataType::Type type = instruction->GetType(); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2616 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2617 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2618 | Register out = OutputRegister(instruction); |
| 2619 | Register left; |
| 2620 | if (kind != HInstruction::kNeg) { |
| 2621 | left = InputRegisterAt(instruction, 0); |
| 2622 | } |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2623 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2624 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2625 | // conversion) can have a different type from the current instruction's type, |
| 2626 | // so we manually indicate the type. |
| 2627 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2628 | Operand right_operand(0); |
| 2629 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2630 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2631 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2632 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2633 | } else { |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2634 | right_operand = Operand(right_reg, |
| 2635 | helpers::ShiftFromOpKind(op_kind), |
| 2636 | instruction->GetShiftAmount()); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | // Logical binary operations do not support extension operations in the |
| 2640 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2641 | // the extension as a separate instruction. |
| 2642 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2643 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2644 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2645 | kind != HInstruction::kNeg)); |
| 2646 | switch (kind) { |
| 2647 | case HInstruction::kAdd: |
| 2648 | __ Add(out, left, right_operand); |
| 2649 | break; |
| 2650 | case HInstruction::kAnd: |
| 2651 | __ And(out, left, right_operand); |
| 2652 | break; |
| 2653 | case HInstruction::kNeg: |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2654 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
| Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2655 | __ Neg(out, right_operand); |
| 2656 | break; |
| 2657 | case HInstruction::kOr: |
| 2658 | __ Orr(out, left, right_operand); |
| 2659 | break; |
| 2660 | case HInstruction::kSub: |
| 2661 | __ Sub(out, left, right_operand); |
| 2662 | break; |
| 2663 | case HInstruction::kXor: |
| 2664 | __ Eor(out, left, right_operand); |
| 2665 | break; |
| 2666 | default: |
| 2667 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2668 | UNREACHABLE(); |
| 2669 | } |
| 2670 | } |
| 2671 | |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2672 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2673 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2674 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2675 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2676 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
| Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2677 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2678 | } |
| 2679 | |
| Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2680 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2681 | __ Add(OutputRegister(instruction), |
| 2682 | InputRegisterAt(instruction, 0), |
| 2683 | Operand(InputOperandAt(instruction, 1))); |
| 2684 | } |
| 2685 | |
| Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2686 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2687 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2688 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2689 | |
| 2690 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2691 | |
| 2692 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2693 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2694 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2695 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2696 | // loop. |
| 2697 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2698 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2699 | : Location::RequiresRegister()); |
| 2700 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2701 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2702 | } |
| 2703 | |
| 2704 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2705 | HIntermediateAddressIndex* instruction) { |
| 2706 | Register index_reg = InputRegisterAt(instruction, 0); |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2707 | uint32_t shift = Int64FromLocation(instruction->GetLocations()->InAt(2)); |
| Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2708 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2709 | |
| 2710 | if (shift == 0) { |
| 2711 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2712 | } else { |
| 2713 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2714 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2715 | } |
| 2716 | } |
| 2717 | |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2718 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2719 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2720 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2721 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2722 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2723 | accumulator->IsConstant() && |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2724 | accumulator->AsConstant()->IsArithmeticZero()) { |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2725 | // Don't allocate register for Mneg instruction. |
| 2726 | } else { |
| 2727 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2728 | Location::RequiresRegister()); |
| 2729 | } |
| 2730 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2731 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2732 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2733 | } |
| 2734 | |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2735 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2736 | Register res = OutputRegister(instr); |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2737 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2738 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2739 | |
| 2740 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2741 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2742 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2743 | if (instr->GetType() == DataType::Type::kInt64 && |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2744 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2745 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2746 | vixl::aarch64::Instruction* prev = |
| 2747 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2748 | if (prev->IsLoadOrStore()) { |
| 2749 | // Make sure we emit only exactly one nop. |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2750 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2751 | __ nop(); |
| 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2756 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2757 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2758 | } else { |
| 2759 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2760 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2761 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2762 | __ Mneg(res, mul_left, mul_right); |
| 2763 | } else { |
| 2764 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2765 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2766 | } |
| Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2767 | } |
| 2768 | } |
| 2769 | |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2770 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2771 | bool object_array_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2772 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2773 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2774 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2775 | object_array_get_with_read_barrier |
| 2776 | ? LocationSummary::kCallOnSlowPath |
| 2777 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2778 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2779 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 2780 | // We need a temporary register for the read barrier marking slow |
| 2781 | // path in CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2782 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2783 | !Runtime::Current()->UseJitCompilation() && |
| 2784 | instruction->GetIndex()->IsConstant()) { |
| 2785 | // Array loads with constant index are treated as field loads. |
| 2786 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2787 | // constant index loads we need a temporary only if the offset is too big. |
| 2788 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2789 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2790 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2791 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2792 | locations->AddTemp(FixedTempLocation()); |
| 2793 | } |
| 2794 | } else { |
| 2795 | locations->AddTemp(Location::RequiresRegister()); |
| 2796 | } |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2797 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2798 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2799 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2800 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2801 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2802 | } else { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2803 | // The output overlaps in the case of an object array get with |
| 2804 | // read barriers enabled: we do not want the move to overwrite the |
| 2805 | // array's location, as we need it to emit the read barrier. |
| 2806 | locations->SetOut( |
| 2807 | Location::RequiresRegister(), |
| 2808 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2809 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2810 | } |
| 2811 | |
| 2812 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2813 | DataType::Type type = instruction->GetType(); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2814 | Register obj = InputRegisterAt(instruction, 0); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2815 | LocationSummary* locations = instruction->GetLocations(); |
| 2816 | Location index = locations->InAt(1); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2817 | Location out = locations->Out(); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2818 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2819 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2820 | instruction->IsStringCharAt(); |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2821 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2822 | UseScratchRegisterScope temps(masm); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2823 | |
| Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2824 | // The read barrier instrumentation of object ArrayGet instructions |
| 2825 | // does not support the HIntermediateAddress instruction. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2826 | DCHECK(!((type == DataType::Type::kReference) && |
| Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2827 | instruction->GetArray()->IsIntermediateAddress() && |
| 2828 | kEmitCompilerReadBarrier)); |
| 2829 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2830 | if (type == DataType::Type::kReference && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2831 | // Object ArrayGet with Baker's read barrier case. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2832 | // Note that a potential implicit null check is handled in the |
| 2833 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2834 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2835 | if (index.IsConstant()) { |
| 2836 | // 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] | 2837 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2838 | Location maybe_temp = |
| 2839 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2840 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2841 | out, |
| 2842 | obj.W(), |
| 2843 | offset, |
| 2844 | maybe_temp, |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2845 | /* needs_null_check */ false, |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2846 | /* use_load_acquire */ false); |
| 2847 | } else { |
| 2848 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
| 2849 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2850 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ false); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2851 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2852 | } else { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2853 | // General case. |
| 2854 | MemOperand source = HeapOperand(obj); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2855 | Register length; |
| 2856 | if (maybe_compressed_char_at) { |
| 2857 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2858 | length = temps.AcquireW(); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2859 | { |
| 2860 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2861 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2862 | |
| 2863 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2864 | DCHECK_LT(count_offset, offset); |
| 2865 | int64_t adjusted_offset = |
| 2866 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2867 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2868 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2869 | } else { |
| 2870 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2871 | } |
| 2872 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2873 | } |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2874 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2875 | if (index.IsConstant()) { |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2876 | if (maybe_compressed_char_at) { |
| 2877 | vixl::aarch64::Label uncompressed_load, done; |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2878 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2879 | "Expecting 0=compressed, 1=uncompressed"); |
| 2880 | __ Tbnz(length.W(), 0, &uncompressed_load); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2881 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2882 | HeapOperand(obj, offset + Int64FromLocation(index))); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2883 | __ B(&done); |
| 2884 | __ Bind(&uncompressed_load); |
| 2885 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2886 | HeapOperand(obj, offset + (Int64FromLocation(index) << 1))); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2887 | __ Bind(&done); |
| 2888 | } else { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2889 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2890 | source = HeapOperand(obj, offset); |
| 2891 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2892 | } else { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2893 | Register temp = temps.AcquireSameSizeAs(obj); |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2894 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2895 | // We do not need to compute the intermediate address from the array: the |
| 2896 | // input instruction has done it already. See the comment in |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2897 | // `TryExtractArrayAccessAddress()`. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2898 | if (kIsDebugBuild) { |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2899 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2900 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2901 | } |
| 2902 | temp = obj; |
| 2903 | } else { |
| 2904 | __ Add(temp, obj, offset); |
| 2905 | } |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2906 | if (maybe_compressed_char_at) { |
| 2907 | vixl::aarch64::Label uncompressed_load, done; |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2908 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2909 | "Expecting 0=compressed, 1=uncompressed"); |
| 2910 | __ Tbnz(length.W(), 0, &uncompressed_load); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2911 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2912 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2913 | __ B(&done); |
| 2914 | __ Bind(&uncompressed_load); |
| 2915 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2916 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2917 | __ Bind(&done); |
| 2918 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2919 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2920 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2921 | } |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2922 | if (!maybe_compressed_char_at) { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2923 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2924 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2925 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2926 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2927 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2928 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2929 | if (type == DataType::Type::kReference) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2930 | static_assert( |
| 2931 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2932 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2933 | Location obj_loc = locations->InAt(0); |
| 2934 | if (index.IsConstant()) { |
| 2935 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2936 | } else { |
| 2937 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2938 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2939 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2940 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2941 | } |
| 2942 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2943 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2944 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2945 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2946 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2950 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2951 | vixl::aarch64::Register out = OutputRegister(instruction); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2952 | { |
| 2953 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2954 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2955 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2956 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2957 | } |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2958 | // Mask out compression flag from String's array length. |
| 2959 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2960 | __ Lsr(out.W(), out.W(), 1u); |
| jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2961 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2962 | } |
| 2963 | |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2964 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2965 | DataType::Type value_type = instruction->GetComponentType(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2966 | |
| 2967 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2968 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2969 | instruction, |
| Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2970 | may_need_runtime_call_for_type_check ? |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2971 | LocationSummary::kCallOnSlowPath : |
| 2972 | LocationSummary::kNoCall); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2973 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2974 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2975 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2976 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2977 | } else if (DataType::IsFloatingPointType(value_type)) { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2978 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2979 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2980 | locations->SetInAt(2, Location::RequiresRegister()); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2985 | DataType::Type value_type = instruction->GetComponentType(); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2986 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2987 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2988 | bool needs_write_barrier = |
| 2989 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2990 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2991 | Register array = InputRegisterAt(instruction, 0); |
| Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2992 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2993 | CPURegister source = value; |
| 2994 | Location index = locations->InAt(1); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2995 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2996 | MemOperand destination = HeapOperand(array); |
| 2997 | MacroAssembler* masm = GetVIXLAssembler(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2998 | |
| 2999 | if (!needs_write_barrier) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3000 | DCHECK(!may_need_runtime_call_for_type_check); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3001 | if (index.IsConstant()) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3002 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3003 | destination = HeapOperand(array, offset); |
| 3004 | } else { |
| 3005 | UseScratchRegisterScope temps(masm); |
| 3006 | Register temp = temps.AcquireSameSizeAs(array); |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3007 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 3008 | // We do not need to compute the intermediate address from the array: the |
| 3009 | // input instruction has done it already. See the comment in |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3010 | // `TryExtractArrayAccessAddress()`. |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 3011 | if (kIsDebugBuild) { |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3012 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 3013 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 3014 | } |
| 3015 | temp = array; |
| 3016 | } else { |
| 3017 | __ Add(temp, array, offset); |
| 3018 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3019 | destination = HeapOperand(temp, |
| 3020 | XRegisterFrom(index), |
| 3021 | LSL, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3022 | DataType::SizeShift(value_type)); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3023 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3024 | { |
| 3025 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3026 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3027 | codegen_->Store(value_type, value, destination); |
| 3028 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3029 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3030 | } else { |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3031 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3032 | vixl::aarch64::Label done; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3033 | SlowPathCodeARM64* slow_path = nullptr; |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3034 | { |
| 3035 | // We use a block to end the scratch scope before the write barrier, thus |
| 3036 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 3037 | UseScratchRegisterScope temps(masm); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3038 | Register temp = temps.AcquireSameSizeAs(array); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3039 | if (index.IsConstant()) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3040 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3041 | destination = HeapOperand(array, offset); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3042 | } else { |
| Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 3043 | destination = HeapOperand(temp, |
| 3044 | XRegisterFrom(index), |
| 3045 | LSL, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3046 | DataType::SizeShift(value_type)); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3047 | } |
| 3048 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3049 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3050 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3051 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3052 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3053 | if (may_need_runtime_call_for_type_check) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3054 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3055 | codegen_->AddSlowPath(slow_path); |
| 3056 | if (instruction->GetValueCanBeNull()) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3057 | vixl::aarch64::Label non_zero; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3058 | __ Cbnz(Register(value), &non_zero); |
| 3059 | if (!index.IsConstant()) { |
| 3060 | __ Add(temp, array, offset); |
| 3061 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3062 | { |
| 3063 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 3064 | // emitted. |
| 3065 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3066 | __ Str(wzr, destination); |
| 3067 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3068 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3069 | __ B(&done); |
| 3070 | __ Bind(&non_zero); |
| 3071 | } |
| 3072 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3073 | // Note that when Baker read barriers are enabled, the type |
| 3074 | // checks are performed without read barriers. This is fine, |
| 3075 | // even in the case where a class object is in the from-space |
| 3076 | // after the flip, as a comparison involving such a type would |
| 3077 | // not produce a false positive; it may of course produce a |
| 3078 | // false negative, in which case we would take the ArraySet |
| 3079 | // slow path. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3080 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3081 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 3082 | // /* HeapReference<Class> */ temp = array->klass_ |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3083 | { |
| 3084 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3085 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3086 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 3087 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3088 | } |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3089 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3090 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3091 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 3092 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 3093 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3094 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 3095 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 3096 | // nor `temp2`, as we are comparing two poisoned references. |
| 3097 | __ Cmp(temp, temp2); |
| 3098 | temps.Release(temp2); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3099 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3100 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3101 | vixl::aarch64::Label do_put; |
| 3102 | __ B(eq, &do_put); |
| 3103 | // If heap poisoning is enabled, the `temp` reference has |
| 3104 | // not been unpoisoned yet; unpoison it now. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3105 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3106 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3107 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 3108 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 3109 | // If heap poisoning is enabled, no need to unpoison |
| 3110 | // `temp`, as we are comparing against null below. |
| 3111 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 3112 | __ Bind(&do_put); |
| 3113 | } else { |
| 3114 | __ B(ne, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3115 | } |
| 3116 | } |
| 3117 | |
| 3118 | if (kPoisonHeapReferences) { |
| Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3119 | Register temp2 = temps.AcquireSameSizeAs(array); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3120 | DCHECK(value.IsW()); |
| Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3121 | __ Mov(temp2, value.W()); |
| 3122 | GetAssembler()->PoisonHeapReference(temp2); |
| 3123 | source = temp2; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | if (!index.IsConstant()) { |
| 3127 | __ Add(temp, array, offset); |
| Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 3128 | } else { |
| 3129 | // We no longer need the `temp` here so release it as the store below may |
| 3130 | // need a scratch register (if the constant index makes the offset too large) |
| 3131 | // and the poisoned `source` could be using the other scratch register. |
| 3132 | temps.Release(temp); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3133 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3134 | { |
| 3135 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3136 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3137 | __ Str(source, destination); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3138 | |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3139 | if (!may_need_runtime_call_for_type_check) { |
| 3140 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3141 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3142 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3143 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3144 | |
| 3145 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 3146 | |
| 3147 | if (done.IsLinked()) { |
| 3148 | __ Bind(&done); |
| 3149 | } |
| 3150 | |
| 3151 | if (slow_path != nullptr) { |
| 3152 | __ Bind(slow_path->GetExitLabel()); |
| Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3153 | } |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3154 | } |
| 3155 | } |
| 3156 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3157 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3158 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3159 | InvokeRuntimeCallingConvention calling_convention; |
| 3160 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3161 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 3162 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3163 | locations->SetInAt(0, Location::RequiresRegister()); |
| Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 3164 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3168 | BoundsCheckSlowPathARM64* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3169 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3170 | codegen_->AddSlowPath(slow_path); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3171 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 3172 | __ B(slow_path->GetEntryLabel(), hs); |
| 3173 | } |
| 3174 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3175 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3176 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3177 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3178 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3179 | if (check->HasUses()) { |
| 3180 | locations->SetOut(Location::SameAsFirstInput()); |
| 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3185 | // We assume the class is not null. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3186 | SlowPathCodeARM64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64( |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3187 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 3188 | codegen_->AddSlowPath(slow_path); |
| 3189 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3190 | } |
| 3191 | |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3192 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3193 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3194 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3195 | } |
| 3196 | |
| 3197 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 3198 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 3199 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3200 | if (rhs_loc.IsConstant()) { |
| 3201 | // 0.0 is the only immediate that can be encoded directly in |
| 3202 | // an FCMP instruction. |
| 3203 | // |
| 3204 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3205 | // specify that in a floating-point comparison, positive zero |
| 3206 | // and negative zero are considered equal, so we can use the |
| 3207 | // literal 0.0 for both cases here. |
| 3208 | // |
| 3209 | // Note however that some methods (Float.equal, Float.compare, |
| 3210 | // Float.compareTo, Double.equal, Double.compare, |
| 3211 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3212 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3213 | // -0.0. So if we ever translate calls to these methods into a |
| 3214 | // HCompare instruction, we must handle the -0.0 case with |
| 3215 | // care here. |
| 3216 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3217 | __ Fcmp(lhs_reg, 0.0); |
| 3218 | } else { |
| 3219 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3220 | } |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3221 | } |
| 3222 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3223 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3224 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3225 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3226 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3227 | switch (in_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3228 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3229 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3230 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3231 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3232 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3233 | case DataType::Type::kInt32: |
| 3234 | case DataType::Type::kInt64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3235 | locations->SetInAt(0, Location::RequiresRegister()); |
| Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3236 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3237 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3238 | break; |
| 3239 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3240 | case DataType::Type::kFloat32: |
| 3241 | case DataType::Type::kFloat64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3242 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3243 | locations->SetInAt(1, |
| 3244 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3245 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3246 | : Location::RequiresFpuRegister()); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3247 | locations->SetOut(Location::RequiresRegister()); |
| 3248 | break; |
| 3249 | } |
| 3250 | default: |
| 3251 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3252 | } |
| 3253 | } |
| 3254 | |
| 3255 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3256 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3257 | |
| 3258 | // 0 if: left == right |
| 3259 | // 1 if: left > right |
| 3260 | // -1 if: left < right |
| 3261 | switch (in_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3262 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3263 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3264 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3265 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3266 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3267 | case DataType::Type::kInt32: |
| 3268 | case DataType::Type::kInt64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3269 | Register result = OutputRegister(compare); |
| 3270 | Register left = InputRegisterAt(compare, 0); |
| 3271 | Operand right = InputOperandAt(compare, 1); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3272 | __ Cmp(left, right); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3273 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3274 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3275 | break; |
| 3276 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3277 | case DataType::Type::kFloat32: |
| 3278 | case DataType::Type::kFloat64: { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3279 | Register result = OutputRegister(compare); |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3280 | GenerateFcmp(compare); |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3281 | __ Cset(result, ne); |
| 3282 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3283 | break; |
| 3284 | } |
| 3285 | default: |
| 3286 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3287 | } |
| 3288 | } |
| 3289 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3290 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3291 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3292 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3293 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3294 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3295 | locations->SetInAt(1, |
| 3296 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3297 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3298 | : Location::RequiresFpuRegister()); |
| 3299 | } else { |
| 3300 | // Integer cases. |
| 3301 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3302 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3303 | } |
| 3304 | |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3305 | if (!instruction->IsEmittedAtUseSite()) { |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3306 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3307 | } |
| 3308 | } |
| 3309 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3310 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3311 | if (instruction->IsEmittedAtUseSite()) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3312 | return; |
| 3313 | } |
| 3314 | |
| 3315 | LocationSummary* locations = instruction->GetLocations(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3316 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3317 | IfCondition if_cond = instruction->GetCondition(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3318 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3319 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3320 | GenerateFcmp(instruction); |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3321 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3322 | } else { |
| 3323 | // Integer cases. |
| 3324 | Register lhs = InputRegisterAt(instruction, 0); |
| 3325 | Operand rhs = InputOperandAt(instruction, 1); |
| 3326 | __ Cmp(lhs, rhs); |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3327 | __ Cset(res, ARM64Condition(if_cond)); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3328 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3332 | M(Equal) \ |
| 3333 | M(NotEqual) \ |
| 3334 | M(LessThan) \ |
| 3335 | M(LessThanOrEqual) \ |
| 3336 | M(GreaterThan) \ |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3337 | M(GreaterThanOrEqual) \ |
| 3338 | M(Below) \ |
| 3339 | M(BelowOrEqual) \ |
| 3340 | M(Above) \ |
| 3341 | M(AboveOrEqual) |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3342 | #define DEFINE_CONDITION_VISITORS(Name) \ |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3343 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3344 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3345 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3346 | #undef DEFINE_CONDITION_VISITORS |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3347 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3348 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3349 | void InstructionCodeGeneratorARM64::GenerateIntDivForPower2Denom(HDiv* instruction) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3350 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3351 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3352 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 3353 | |
| 3354 | Register out = OutputRegister(instruction); |
| 3355 | Register dividend = InputRegisterAt(instruction, 0); |
| Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3356 | |
| 3357 | if (abs_imm == 2) { |
| 3358 | int bits = DataType::Size(instruction->GetResultType()) * kBitsPerByte; |
| 3359 | __ Add(out, dividend, Operand(dividend, LSR, bits - 1)); |
| 3360 | } else { |
| 3361 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3362 | Register temp = temps.AcquireSameSizeAs(out); |
| 3363 | __ Add(temp, dividend, abs_imm - 1); |
| 3364 | __ Cmp(dividend, 0); |
| 3365 | __ Csel(out, temp, dividend, lt); |
| 3366 | } |
| 3367 | |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3368 | int ctz_imm = CTZ(abs_imm); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3369 | if (imm > 0) { |
| 3370 | __ Asr(out, out, ctz_imm); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3371 | } else { |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3372 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3373 | } |
| 3374 | } |
| 3375 | |
| 3376 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3377 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3378 | |
| 3379 | LocationSummary* locations = instruction->GetLocations(); |
| 3380 | Location second = locations->InAt(1); |
| 3381 | DCHECK(second.IsConstant()); |
| 3382 | |
| 3383 | Register out = OutputRegister(instruction); |
| 3384 | Register dividend = InputRegisterAt(instruction, 0); |
| 3385 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3386 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3387 | DataType::Type type = instruction->GetResultType(); |
| 3388 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3389 | |
| 3390 | int64_t magic; |
| 3391 | int shift; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3392 | CalculateMagicAndShiftForDivRem( |
| 3393 | imm, type == DataType::Type::kInt64 /* is_long */, &magic, &shift); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3394 | |
| 3395 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3396 | Register temp = temps.AcquireSameSizeAs(out); |
| 3397 | |
| 3398 | // temp = get_high(dividend * magic) |
| 3399 | __ Mov(temp, magic); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3400 | if (type == DataType::Type::kInt64) { |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3401 | __ Smulh(temp, dividend, temp); |
| 3402 | } else { |
| 3403 | __ Smull(temp.X(), dividend, temp); |
| 3404 | __ Lsr(temp.X(), temp.X(), 32); |
| 3405 | } |
| 3406 | |
| 3407 | if (imm > 0 && magic < 0) { |
| 3408 | __ Add(temp, temp, dividend); |
| 3409 | } else if (imm < 0 && magic > 0) { |
| 3410 | __ Sub(temp, temp, dividend); |
| 3411 | } |
| 3412 | |
| 3413 | if (shift != 0) { |
| 3414 | __ Asr(temp, temp, shift); |
| 3415 | } |
| 3416 | |
| 3417 | if (instruction->IsDiv()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3418 | __ Sub(out, temp, Operand(temp, ASR, type == DataType::Type::kInt64 ? 63 : 31)); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3419 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3420 | __ Sub(temp, temp, Operand(temp, ASR, type == DataType::Type::kInt64 ? 63 : 31)); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3421 | // TODO: Strength reduction for msub. |
| 3422 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3423 | __ Mov(temp_imm, imm); |
| 3424 | __ Msub(out, temp, temp_imm, dividend); |
| 3425 | } |
| 3426 | } |
| 3427 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3428 | void InstructionCodeGeneratorARM64::GenerateIntDivForConstDenom(HDiv *instruction) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3429 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3430 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3431 | if (imm == 0) { |
| 3432 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3433 | return; |
| 3434 | } |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3435 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3436 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3437 | GenerateIntDivForPower2Denom(instruction); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3438 | } else { |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3439 | // Cases imm == -1 or imm == 1 are handled by InstructionSimplifier. |
| 3440 | DCHECK(imm < -2 || imm > 2) << imm; |
| 3441 | GenerateDivRemWithAnyConstant(instruction); |
| 3442 | } |
| 3443 | } |
| 3444 | |
| 3445 | void InstructionCodeGeneratorARM64::GenerateIntDiv(HDiv *instruction) { |
| 3446 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 3447 | << instruction->GetResultType(); |
| 3448 | |
| 3449 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 3450 | GenerateIntDivForConstDenom(instruction); |
| 3451 | } else { |
| 3452 | Register out = OutputRegister(instruction); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3453 | Register dividend = InputRegisterAt(instruction, 0); |
| 3454 | Register divisor = InputRegisterAt(instruction, 1); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3455 | __ Sdiv(out, dividend, divisor); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3456 | } |
| 3457 | } |
| 3458 | |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3459 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3460 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3461 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3462 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3463 | case DataType::Type::kInt32: |
| 3464 | case DataType::Type::kInt64: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3465 | locations->SetInAt(0, Location::RequiresRegister()); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3466 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3467 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3468 | break; |
| 3469 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3470 | case DataType::Type::kFloat32: |
| 3471 | case DataType::Type::kFloat64: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3472 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3473 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3474 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3475 | break; |
| 3476 | |
| 3477 | default: |
| 3478 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3479 | } |
| 3480 | } |
| 3481 | |
| 3482 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3483 | DataType::Type type = div->GetResultType(); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3484 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3485 | case DataType::Type::kInt32: |
| 3486 | case DataType::Type::kInt64: |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3487 | GenerateIntDiv(div); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3488 | break; |
| 3489 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3490 | case DataType::Type::kFloat32: |
| 3491 | case DataType::Type::kFloat64: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3492 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3493 | break; |
| 3494 | |
| 3495 | default: |
| 3496 | LOG(FATAL) << "Unexpected div type " << type; |
| 3497 | } |
| 3498 | } |
| 3499 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3500 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3501 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3502 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3506 | SlowPathCodeARM64* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3507 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3508 | codegen_->AddSlowPath(slow_path); |
| 3509 | Location value = instruction->GetLocations()->InAt(0); |
| 3510 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3511 | DataType::Type type = instruction->GetType(); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3512 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3513 | if (!DataType::IsIntegralType(type)) { |
| Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3514 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3515 | return; |
| 3516 | } |
| 3517 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3518 | if (value.IsConstant()) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3519 | int64_t divisor = Int64FromLocation(value); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3520 | if (divisor == 0) { |
| 3521 | __ B(slow_path->GetEntryLabel()); |
| 3522 | } else { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3523 | // A division by a non-null constant is valid. We don't need to perform |
| 3524 | // any check, so simply fall through. |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3525 | } |
| 3526 | } else { |
| 3527 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3528 | } |
| 3529 | } |
| 3530 | |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3531 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3532 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3533 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3534 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3535 | } |
| 3536 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3537 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3538 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3539 | // Will be generated at use site. |
| 3540 | } |
| 3541 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3542 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3543 | exit->SetLocations(nullptr); |
| 3544 | } |
| 3545 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3546 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3547 | } |
| 3548 | |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3549 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3550 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3551 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3552 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3553 | } |
| 3554 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3555 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3556 | // Will be generated at use site. |
| 3557 | } |
| 3558 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3559 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3560 | if (successor->IsExitBlock()) { |
| 3561 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3562 | return; // no code needed |
| 3563 | } |
| 3564 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3565 | HBasicBlock* block = got->GetBlock(); |
| 3566 | HInstruction* previous = got->GetPrevious(); |
| 3567 | HLoopInformation* info = block->GetLoopInformation(); |
| 3568 | |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3569 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 3570 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 3571 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3572 | Register temp1 = temps.AcquireX(); |
| 3573 | Register temp2 = temps.AcquireX(); |
| 3574 | __ Ldr(temp1, MemOperand(sp, 0)); |
| 3575 | __ Ldrh(temp2, MemOperand(temp1, ArtMethod::HotnessCountOffset().Int32Value())); |
| 3576 | __ Add(temp2, temp2, 1); |
| 3577 | __ Strh(temp2, MemOperand(temp1, ArtMethod::HotnessCountOffset().Int32Value())); |
| 3578 | } |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3579 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3580 | return; |
| 3581 | } |
| 3582 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3583 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 3584 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3585 | } |
| 3586 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3587 | __ B(codegen_->GetLabelOf(successor)); |
| 3588 | } |
| 3589 | } |
| 3590 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3591 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3592 | got->SetLocations(nullptr); |
| 3593 | } |
| 3594 | |
| 3595 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3596 | HandleGoto(got, got->GetSuccessor()); |
| 3597 | } |
| 3598 | |
| 3599 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3600 | try_boundary->SetLocations(nullptr); |
| 3601 | } |
| 3602 | |
| 3603 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3604 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3605 | if (!successor->IsExitBlock()) { |
| 3606 | HandleGoto(try_boundary, successor); |
| 3607 | } |
| 3608 | } |
| 3609 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3610 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3611 | size_t condition_input_index, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3612 | vixl::aarch64::Label* true_target, |
| 3613 | vixl::aarch64::Label* false_target) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3614 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3615 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3616 | if (true_target == nullptr && false_target == nullptr) { |
| 3617 | // Nothing to do. The code always falls through. |
| 3618 | return; |
| 3619 | } else if (cond->IsIntConstant()) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3620 | // Constant condition, statically compared against "true" (integer value 1). |
| 3621 | if (cond->AsIntConstant()->IsTrue()) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3622 | if (true_target != nullptr) { |
| 3623 | __ B(true_target); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3624 | } |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3625 | } else { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3626 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3627 | if (false_target != nullptr) { |
| 3628 | __ B(false_target); |
| 3629 | } |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3630 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3631 | return; |
| 3632 | } |
| 3633 | |
| 3634 | // The following code generates these patterns: |
| 3635 | // (1) true_target == nullptr && false_target != nullptr |
| 3636 | // - opposite condition true => branch to false_target |
| 3637 | // (2) true_target != nullptr && false_target == nullptr |
| 3638 | // - condition true => branch to true_target |
| 3639 | // (3) true_target != nullptr && false_target != nullptr |
| 3640 | // - condition true => branch to true_target |
| 3641 | // - branch to false_target |
| 3642 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3643 | // The condition instruction has been materialized, compare the output to 0. |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3644 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3645 | DCHECK(cond_val.IsRegister()); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3646 | if (true_target == nullptr) { |
| 3647 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3648 | } else { |
| 3649 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3650 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3651 | } else { |
| 3652 | // The condition instruction has not been materialized, use its inputs as |
| 3653 | // the comparison and its condition as the branch condition. |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3654 | HCondition* condition = cond->AsCondition(); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3655 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3656 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3657 | if (DataType::IsFloatingPointType(type)) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3658 | GenerateFcmp(condition); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3659 | if (true_target == nullptr) { |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3660 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3661 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3662 | } else { |
| Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3663 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3664 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3665 | } else { |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3666 | // Integer cases. |
| 3667 | Register lhs = InputRegisterAt(condition, 0); |
| 3668 | Operand rhs = InputOperandAt(condition, 1); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3669 | |
| 3670 | Condition arm64_cond; |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3671 | vixl::aarch64::Label* non_fallthrough_target; |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3672 | if (true_target == nullptr) { |
| 3673 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3674 | non_fallthrough_target = false_target; |
| 3675 | } else { |
| 3676 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3677 | non_fallthrough_target = true_target; |
| 3678 | } |
| 3679 | |
| Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3680 | 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] | 3681 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3682 | switch (arm64_cond) { |
| 3683 | case eq: |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3684 | __ Cbz(lhs, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3685 | break; |
| 3686 | case ne: |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3687 | __ Cbnz(lhs, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3688 | break; |
| 3689 | case lt: |
| 3690 | // Test the sign bit and branch accordingly. |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3691 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3692 | break; |
| 3693 | case ge: |
| 3694 | // Test the sign bit and branch accordingly. |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3695 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3696 | break; |
| 3697 | default: |
| 3698 | // Without the `static_cast` the compiler throws an error for |
| 3699 | // `-Werror=sign-promo`. |
| 3700 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3701 | } |
| 3702 | } else { |
| 3703 | __ Cmp(lhs, rhs); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3704 | __ B(arm64_cond, non_fallthrough_target); |
| Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3705 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3706 | } |
| 3707 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3708 | |
| 3709 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3710 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3711 | if (true_target != nullptr && false_target != nullptr) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3712 | __ B(false_target); |
| 3713 | } |
| 3714 | } |
| 3715 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3716 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3717 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3718 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3719 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3720 | } |
| 3721 | } |
| 3722 | |
| 3723 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3724 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3725 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3726 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3727 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3728 | true_target = nullptr; |
| 3729 | } |
| 3730 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3731 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3732 | false_target = nullptr; |
| 3733 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3734 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3735 | } |
| 3736 | |
| 3737 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3738 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3739 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3740 | InvokeRuntimeCallingConvention calling_convention; |
| 3741 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3742 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3743 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3744 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3745 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3746 | } |
| 3747 | } |
| 3748 | |
| 3749 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3750 | SlowPathCodeARM64* slow_path = |
| 3751 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3752 | GenerateTestAndBranch(deoptimize, |
| 3753 | /* condition_input_index */ 0, |
| 3754 | slow_path->GetEntryLabel(), |
| 3755 | /* false_target */ nullptr); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3756 | } |
| 3757 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3758 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3759 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3760 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3761 | locations->SetOut(Location::RequiresRegister()); |
| 3762 | } |
| 3763 | |
| 3764 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3765 | __ Ldr(OutputRegister(flag), |
| 3766 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3767 | } |
| 3768 | |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3769 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3770 | return condition->IsCondition() && |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3771 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3772 | } |
| 3773 | |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3774 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3775 | IfCondition cond = condition->AsCondition()->GetCondition(); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3776 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3777 | : ARM64Condition(cond); |
| 3778 | } |
| 3779 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3780 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3781 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3782 | if (DataType::IsFloatingPointType(select->GetType())) { |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3783 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3784 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3785 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3786 | } else { |
| 3787 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3788 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3789 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3790 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3791 | // Ask VIXL whether we should synthesize constants in registers. |
| 3792 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3793 | Operand true_op = is_true_value_constant ? |
| 3794 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3795 | Operand false_op = is_false_value_constant ? |
| 3796 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3797 | bool true_value_in_register = false; |
| 3798 | bool false_value_in_register = false; |
| 3799 | MacroAssembler::GetCselSynthesisInformation( |
| 3800 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3801 | true_value_in_register |= !is_true_value_constant; |
| 3802 | false_value_in_register |= !is_false_value_constant; |
| 3803 | |
| 3804 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3805 | : Location::ConstantLocation(cst_true_value)); |
| 3806 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3807 | : Location::ConstantLocation(cst_false_value)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3808 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3809 | } |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3810 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3811 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3812 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3813 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3814 | } |
| 3815 | |
| 3816 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3817 | HInstruction* cond = select->GetCondition(); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3818 | Condition csel_cond; |
| 3819 | |
| 3820 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3821 | if (cond->IsCondition() && cond->GetNext() == select) { |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3822 | // Use the condition flags set by the previous instruction. |
| 3823 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3824 | } else { |
| 3825 | __ Cmp(InputRegisterAt(select, 2), 0); |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3826 | csel_cond = ne; |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3827 | } |
| 3828 | } else if (IsConditionOnFloatingPointValues(cond)) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3829 | GenerateFcmp(cond); |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3830 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3831 | } else { |
| 3832 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3833 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3834 | } |
| 3835 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3836 | if (DataType::IsFloatingPointType(select->GetType())) { |
| Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3837 | __ Fcsel(OutputFPRegister(select), |
| 3838 | InputFPRegisterAt(select, 1), |
| 3839 | InputFPRegisterAt(select, 0), |
| 3840 | csel_cond); |
| 3841 | } else { |
| 3842 | __ Csel(OutputRegister(select), |
| 3843 | InputOperandAt(select, 1), |
| 3844 | InputOperandAt(select, 0), |
| 3845 | csel_cond); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3846 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3847 | } |
| 3848 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3849 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3850 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3851 | } |
| 3852 | |
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3853 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3854 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | void CodeGeneratorARM64::GenerateNop() { |
| 3858 | __ Nop(); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3859 | } |
| 3860 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3861 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3862 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3863 | } |
| 3864 | |
| 3865 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3866 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3870 | HandleFieldSet(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3871 | } |
| 3872 | |
| 3873 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3874 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3875 | } |
| 3876 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3877 | // Temp is used for read barrier. |
| 3878 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3879 | if (kEmitCompilerReadBarrier && |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3880 | (kUseBakerReadBarrier || |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3881 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3882 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3883 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3884 | return 1; |
| 3885 | } |
| 3886 | return 0; |
| 3887 | } |
| 3888 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3889 | // 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] | 3890 | // interface pointer, one for loading the current interface. |
| 3891 | // The other checks have one temp for loading the object's class. |
| 3892 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3893 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3894 | return 3; |
| 3895 | } |
| 3896 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3897 | } |
| 3898 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3899 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3900 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3901 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3902 | bool baker_read_barrier_slow_path = false; |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3903 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3904 | case TypeCheckKind::kExactCheck: |
| 3905 | case TypeCheckKind::kAbstractClassCheck: |
| 3906 | case TypeCheckKind::kClassHierarchyCheck: |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3907 | case TypeCheckKind::kArrayObjectCheck: { |
| 3908 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 3909 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 3910 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3911 | break; |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3912 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3913 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3914 | case TypeCheckKind::kUnresolvedCheck: |
| 3915 | case TypeCheckKind::kInterfaceCheck: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3916 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3917 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3918 | case TypeCheckKind::kBitstringCheck: |
| 3919 | break; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3920 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3921 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3922 | LocationSummary* locations = |
| 3923 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3924 | if (baker_read_barrier_slow_path) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3925 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3926 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3927 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3928 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3929 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3930 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3931 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3932 | } else { |
| 3933 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3934 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3935 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3936 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3937 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3938 | // Add temps if necessary for read barriers. |
| 3939 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3940 | } |
| 3941 | |
| 3942 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3943 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3944 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3945 | Location obj_loc = locations->InAt(0); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3946 | Register obj = InputRegisterAt(instruction, 0); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3947 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 3948 | ? Register() |
| 3949 | : InputRegisterAt(instruction, 1); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3950 | Location out_loc = locations->Out(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3951 | Register out = OutputRegister(instruction); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3952 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3953 | DCHECK_LE(num_temps, 1u); |
| 3954 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3955 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3956 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3957 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3958 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3959 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3960 | vixl::aarch64::Label done, zero; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3961 | SlowPathCodeARM64* slow_path = nullptr; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3962 | |
| 3963 | // Return 0 if `obj` is null. |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3964 | // Avoid null check if we know `obj` is not null. |
| 3965 | if (instruction->MustDoNullCheck()) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3966 | __ Cbz(obj, &zero); |
| 3967 | } |
| 3968 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3969 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3970 | case TypeCheckKind::kExactCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3971 | ReadBarrierOption read_barrier_option = |
| 3972 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3973 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3974 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3975 | out_loc, |
| 3976 | obj_loc, |
| 3977 | class_offset, |
| 3978 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3979 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3980 | __ Cmp(out, cls); |
| 3981 | __ Cset(out, eq); |
| 3982 | if (zero.IsLinked()) { |
| 3983 | __ B(&done); |
| 3984 | } |
| 3985 | break; |
| 3986 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3987 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3988 | case TypeCheckKind::kAbstractClassCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3989 | ReadBarrierOption read_barrier_option = |
| 3990 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3991 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3992 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3993 | out_loc, |
| 3994 | obj_loc, |
| 3995 | class_offset, |
| 3996 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3997 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3998 | // If the class is abstract, we eagerly fetch the super class of the |
| 3999 | // object to avoid doing a comparison we know will fail. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4000 | vixl::aarch64::Label loop, success; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4001 | __ Bind(&loop); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4002 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4003 | GenerateReferenceLoadOneRegister(instruction, |
| 4004 | out_loc, |
| 4005 | super_offset, |
| 4006 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4007 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4008 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4009 | __ Cbz(out, &done); |
| 4010 | __ Cmp(out, cls); |
| 4011 | __ B(ne, &loop); |
| 4012 | __ Mov(out, 1); |
| 4013 | if (zero.IsLinked()) { |
| 4014 | __ B(&done); |
| 4015 | } |
| 4016 | break; |
| 4017 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4018 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4019 | case TypeCheckKind::kClassHierarchyCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4020 | ReadBarrierOption read_barrier_option = |
| 4021 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4022 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4023 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4024 | out_loc, |
| 4025 | obj_loc, |
| 4026 | class_offset, |
| 4027 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4028 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4029 | // Walk over the class hierarchy to find a match. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4030 | vixl::aarch64::Label loop, success; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4031 | __ Bind(&loop); |
| 4032 | __ Cmp(out, cls); |
| 4033 | __ B(eq, &success); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4034 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4035 | GenerateReferenceLoadOneRegister(instruction, |
| 4036 | out_loc, |
| 4037 | super_offset, |
| 4038 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4039 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4040 | __ Cbnz(out, &loop); |
| 4041 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4042 | __ B(&done); |
| 4043 | __ Bind(&success); |
| 4044 | __ Mov(out, 1); |
| 4045 | if (zero.IsLinked()) { |
| 4046 | __ B(&done); |
| 4047 | } |
| 4048 | break; |
| 4049 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4050 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4051 | case TypeCheckKind::kArrayObjectCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4052 | ReadBarrierOption read_barrier_option = |
| 4053 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4054 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4055 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4056 | out_loc, |
| 4057 | obj_loc, |
| 4058 | class_offset, |
| 4059 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4060 | read_barrier_option); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4061 | // Do an exact check. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4062 | vixl::aarch64::Label exact_check; |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4063 | __ Cmp(out, cls); |
| 4064 | __ B(eq, &exact_check); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4065 | // 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] | 4066 | // /* HeapReference<Class> */ out = out->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4067 | GenerateReferenceLoadOneRegister(instruction, |
| 4068 | out_loc, |
| 4069 | component_offset, |
| 4070 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4071 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4072 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4073 | __ Cbz(out, &done); |
| 4074 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4075 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4076 | __ Cbnz(out, &zero); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4077 | __ Bind(&exact_check); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4078 | __ Mov(out, 1); |
| 4079 | __ B(&done); |
| 4080 | break; |
| 4081 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4082 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4083 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4084 | // No read barrier since the slow path will retry upon failure. |
| 4085 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4086 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4087 | out_loc, |
| 4088 | obj_loc, |
| 4089 | class_offset, |
| 4090 | maybe_temp_loc, |
| 4091 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4092 | __ Cmp(out, cls); |
| 4093 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4094 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4095 | instruction, /* is_fatal */ false); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4096 | codegen_->AddSlowPath(slow_path); |
| 4097 | __ B(ne, slow_path->GetEntryLabel()); |
| 4098 | __ Mov(out, 1); |
| 4099 | if (zero.IsLinked()) { |
| 4100 | __ B(&done); |
| 4101 | } |
| 4102 | break; |
| 4103 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4104 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4105 | case TypeCheckKind::kUnresolvedCheck: |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4106 | case TypeCheckKind::kInterfaceCheck: { |
| 4107 | // Note that we indeed only call on slow path, but we always go |
| 4108 | // into the slow path for the unresolved and interface check |
| 4109 | // cases. |
| 4110 | // |
| 4111 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4112 | // entry point without resorting to a type checking slow path |
| 4113 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4114 | // require to assign fixed registers for the inputs of this |
| 4115 | // HInstanceOf instruction (following the runtime calling |
| 4116 | // convention), which might be cluttered by the potential first |
| 4117 | // read barrier emission at the beginning of this method. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4118 | // |
| 4119 | // TODO: Introduce a new runtime entry point taking the object |
| 4120 | // to test (instead of its class) as argument, and let it deal |
| 4121 | // with the read barrier issues. This will let us refactor this |
| 4122 | // case of the `switch` code as it was previously (with a direct |
| 4123 | // call to the runtime not using a type checking slow path). |
| 4124 | // This should also be beneficial for the other cases above. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4125 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4126 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4127 | instruction, /* is_fatal */ false); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4128 | codegen_->AddSlowPath(slow_path); |
| 4129 | __ B(slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4130 | if (zero.IsLinked()) { |
| 4131 | __ B(&done); |
| 4132 | } |
| 4133 | break; |
| 4134 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4135 | |
| 4136 | case TypeCheckKind::kBitstringCheck: { |
| 4137 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4138 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4139 | out_loc, |
| 4140 | obj_loc, |
| 4141 | class_offset, |
| 4142 | maybe_temp_loc, |
| 4143 | kWithoutReadBarrier); |
| 4144 | |
| 4145 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 4146 | __ Cset(out, eq); |
| 4147 | if (zero.IsLinked()) { |
| 4148 | __ B(&done); |
| 4149 | } |
| 4150 | break; |
| 4151 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4152 | } |
| 4153 | |
| 4154 | if (zero.IsLinked()) { |
| 4155 | __ Bind(&zero); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4156 | __ Mov(out, 0); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4157 | } |
| 4158 | |
| 4159 | if (done.IsLinked()) { |
| 4160 | __ Bind(&done); |
| 4161 | } |
| 4162 | |
| 4163 | if (slow_path != nullptr) { |
| 4164 | __ Bind(slow_path->GetExitLabel()); |
| 4165 | } |
| 4166 | } |
| 4167 | |
| 4168 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4169 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4170 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4171 | LocationSummary* locations = |
| 4172 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4173 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4174 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 4175 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 4176 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 4177 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 4178 | } else { |
| 4179 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4180 | } |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4181 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4182 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4183 | } |
| 4184 | |
| 4185 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4186 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4187 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4188 | Location obj_loc = locations->InAt(0); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4189 | Register obj = InputRegisterAt(instruction, 0); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4190 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 4191 | ? Register() |
| 4192 | : InputRegisterAt(instruction, 1); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4193 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4194 | DCHECK_GE(num_temps, 1u); |
| 4195 | DCHECK_LE(num_temps, 3u); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4196 | Location temp_loc = locations->GetTemp(0); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4197 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4198 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4199 | Register temp = WRegisterFrom(temp_loc); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4200 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4201 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4202 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4203 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4204 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4205 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4206 | const uint32_t object_array_data_offset = |
| 4207 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4208 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4209 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4210 | SlowPathCodeARM64* type_check_slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4211 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4212 | instruction, is_type_check_slow_path_fatal); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4213 | codegen_->AddSlowPath(type_check_slow_path); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4214 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4215 | vixl::aarch64::Label done; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4216 | // Avoid null check if we know obj is not null. |
| 4217 | if (instruction->MustDoNullCheck()) { |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4218 | __ Cbz(obj, &done); |
| 4219 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4220 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4221 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4222 | case TypeCheckKind::kExactCheck: |
| 4223 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4224 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4225 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4226 | temp_loc, |
| 4227 | obj_loc, |
| 4228 | class_offset, |
| 4229 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4230 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4231 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4232 | __ Cmp(temp, cls); |
| 4233 | // Jump to slow path for throwing the exception or doing a |
| 4234 | // more involved array check. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4235 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4236 | break; |
| 4237 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4238 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4239 | case TypeCheckKind::kAbstractClassCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4240 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4241 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4242 | temp_loc, |
| 4243 | obj_loc, |
| 4244 | class_offset, |
| 4245 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4246 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4247 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4248 | // If the class is abstract, we eagerly fetch the super class of the |
| 4249 | // object to avoid doing a comparison we know will fail. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4250 | vixl::aarch64::Label loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4251 | __ Bind(&loop); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4252 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4253 | GenerateReferenceLoadOneRegister(instruction, |
| 4254 | temp_loc, |
| 4255 | super_offset, |
| 4256 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4257 | kWithoutReadBarrier); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4258 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4259 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4260 | // exception. |
| 4261 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4262 | // Otherwise, compare classes. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4263 | __ Cmp(temp, cls); |
| 4264 | __ B(ne, &loop); |
| 4265 | break; |
| 4266 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4267 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4268 | case TypeCheckKind::kClassHierarchyCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4269 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4270 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4271 | temp_loc, |
| 4272 | obj_loc, |
| 4273 | class_offset, |
| 4274 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4275 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4276 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4277 | // Walk over the class hierarchy to find a match. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4278 | vixl::aarch64::Label loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4279 | __ Bind(&loop); |
| 4280 | __ Cmp(temp, cls); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4281 | __ B(eq, &done); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4282 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4283 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4284 | GenerateReferenceLoadOneRegister(instruction, |
| 4285 | temp_loc, |
| 4286 | super_offset, |
| 4287 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4288 | kWithoutReadBarrier); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4289 | |
| 4290 | // If the class reference currently in `temp` is not null, jump |
| 4291 | // back at the beginning of the loop. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4292 | __ Cbnz(temp, &loop); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4293 | // Otherwise, jump to the slow path to throw the exception. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4294 | __ B(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4295 | break; |
| 4296 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4297 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4298 | case TypeCheckKind::kArrayObjectCheck: { |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4299 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4300 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4301 | temp_loc, |
| 4302 | obj_loc, |
| 4303 | class_offset, |
| 4304 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4305 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4306 | |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4307 | // Do an exact check. |
| 4308 | __ Cmp(temp, cls); |
| 4309 | __ B(eq, &done); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4310 | |
| 4311 | // 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] | 4312 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4313 | GenerateReferenceLoadOneRegister(instruction, |
| 4314 | temp_loc, |
| 4315 | component_offset, |
| 4316 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4317 | kWithoutReadBarrier); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4318 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4319 | // If the component type is null, jump to the slow path to throw the exception. |
| 4320 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4321 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4322 | // primitive type. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4323 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4324 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4325 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4326 | break; |
| 4327 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4328 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4329 | case TypeCheckKind::kUnresolvedCheck: |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4330 | // 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] | 4331 | // |
| 4332 | // We cannot directly call the CheckCast runtime entry point |
| 4333 | // without resorting to a type checking slow path here (i.e. by |
| 4334 | // calling InvokeRuntime directly), as it would require to |
| 4335 | // assign fixed registers for the inputs of this HInstanceOf |
| 4336 | // instruction (following the runtime calling convention), which |
| 4337 | // might be cluttered by the potential first read barrier |
| 4338 | // emission at the beginning of this method. |
| 4339 | __ B(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4340 | break; |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4341 | case TypeCheckKind::kInterfaceCheck: { |
| 4342 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4343 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4344 | temp_loc, |
| 4345 | obj_loc, |
| 4346 | class_offset, |
| 4347 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4348 | kWithoutReadBarrier); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4349 | |
| 4350 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4351 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4352 | temp_loc, |
| 4353 | temp_loc, |
| 4354 | iftable_offset, |
| 4355 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4356 | kWithoutReadBarrier); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4357 | // Iftable is never null. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4358 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4359 | // Loop through the iftable and check if any class matches. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4360 | vixl::aarch64::Label start_loop; |
| 4361 | __ Bind(&start_loop); |
| Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4362 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4363 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4364 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4365 | // Go to next interface. |
| 4366 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4367 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
| Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4368 | // Compare the classes and continue the loop if they do not match. |
| 4369 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4370 | __ B(ne, &start_loop); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4371 | break; |
| 4372 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4373 | |
| 4374 | case TypeCheckKind::kBitstringCheck: { |
| 4375 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4376 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4377 | temp_loc, |
| 4378 | obj_loc, |
| 4379 | class_offset, |
| 4380 | maybe_temp2_loc, |
| 4381 | kWithoutReadBarrier); |
| 4382 | |
| 4383 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 4384 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 4385 | break; |
| 4386 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4387 | } |
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4388 | __ Bind(&done); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4389 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4390 | __ Bind(type_check_slow_path->GetExitLabel()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4391 | } |
| 4392 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4393 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4394 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4395 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4396 | } |
| 4397 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4398 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4399 | // Will be generated at use site. |
| 4400 | } |
| 4401 | |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4402 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4403 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4404 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4405 | } |
| 4406 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4407 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4408 | // Will be generated at use site. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4409 | } |
| 4410 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4411 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4412 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4413 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4414 | // the method_idx. |
| 4415 | HandleInvoke(invoke); |
| 4416 | } |
| 4417 | |
| 4418 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4419 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4420 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4421 | } |
| 4422 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4423 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4424 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4425 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4426 | } |
| 4427 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4428 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4429 | HandleInvoke(invoke); |
| 4430 | } |
| 4431 | |
| 4432 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4433 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4434 | LocationSummary* locations = invoke->GetLocations(); |
| 4435 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4436 | Location receiver = locations->InAt(0); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4437 | Offset class_offset = mirror::Object::ClassOffset(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4438 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4439 | |
| 4440 | // The register ip1 is required to be used for the hidden argument in |
| 4441 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
| Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4442 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4443 | UseScratchRegisterScope scratch_scope(masm); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4444 | scratch_scope.Exclude(ip1); |
| 4445 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4446 | |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4447 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4448 | if (receiver.IsStackSlot()) { |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4449 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4450 | { |
| 4451 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4452 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4453 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4454 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4455 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4456 | } else { |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4457 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4458 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4459 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4460 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4461 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4462 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4463 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4464 | // emit a read barrier for the previous class reference load. |
| 4465 | // However this is not required in practice, as this is an |
| 4466 | // intermediate/temporary reference and because the current |
| 4467 | // concurrent copying collector keeps the from-space memory |
| 4468 | // intact/accessible until the end of the marking phase (the |
| 4469 | // concurrent copying collector may not in the future). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4470 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4471 | __ Ldr(temp, |
| 4472 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4473 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4474 | invoke->GetImtIndex(), kArm64PointerSize)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4475 | // temp = temp->GetImtEntryAt(method_offset); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4476 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4477 | // lr = temp->GetEntryPoint(); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4478 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4479 | |
| 4480 | { |
| 4481 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4482 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4483 | |
| 4484 | // lr(); |
| 4485 | __ blr(lr); |
| 4486 | DCHECK(!codegen_->IsLeafMethod()); |
| 4487 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4488 | } |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4489 | |
| 4490 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4491 | } |
| 4492 | |
| 4493 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4494 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4495 | if (intrinsic.TryDispatch(invoke)) { |
| 4496 | return; |
| 4497 | } |
| 4498 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4499 | HandleInvoke(invoke); |
| 4500 | } |
| 4501 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4502 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4503 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4504 | // art::PrepareForRegisterAllocation. |
| 4505 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4506 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4507 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4508 | if (intrinsic.TryDispatch(invoke)) { |
| 4509 | return; |
| 4510 | } |
| 4511 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4512 | HandleInvoke(invoke); |
| 4513 | } |
| 4514 | |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4515 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4516 | if (invoke->GetLocations()->Intrinsified()) { |
| 4517 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4518 | intrinsic.Dispatch(invoke); |
| 4519 | return true; |
| 4520 | } |
| 4521 | return false; |
| 4522 | } |
| 4523 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4524 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4525 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4526 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4527 | // On ARM64 we support all dispatch types. |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4528 | return desired_dispatch_info; |
| 4529 | } |
| 4530 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4531 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4532 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4533 | // 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] | 4534 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4535 | switch (invoke->GetMethodLoadKind()) { |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4536 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4537 | uint32_t offset = |
| 4538 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4539 | // temp = thread->string_init_entrypoint |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4540 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4541 | break; |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4542 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4543 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4544 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4545 | break; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4546 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4547 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4548 | // Add ADRP with its PC-relative method patch. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4549 | vixl::aarch64::Label* adrp_label = NewBootImageMethodPatch(invoke->GetTargetMethod()); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4550 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4551 | // Add ADD with its PC-relative method patch. |
| 4552 | vixl::aarch64::Label* add_label = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4553 | NewBootImageMethodPatch(invoke->GetTargetMethod(), adrp_label); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4554 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4555 | break; |
| 4556 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4557 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4558 | // Load method address from literal pool. |
| Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4559 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4560 | break; |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4561 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4562 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4563 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4564 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_offset); |
| 4565 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4566 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| 4567 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| 4568 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 4569 | EmitLdrOffsetPlaceholder(ldr_label, WRegisterFrom(temp), XRegisterFrom(temp)); |
| 4570 | break; |
| 4571 | } |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4572 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4573 | // Add ADRP with its PC-relative .bss entry patch. |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4574 | MethodReference target_method(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4575 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(target_method); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4576 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4577 | // Add LDR with its PC-relative .bss entry patch. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4578 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4579 | NewMethodBssEntryPatch(target_method, adrp_label); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4580 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4581 | break; |
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4582 | } |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4583 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4584 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4585 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4586 | } |
| 4587 | } |
| 4588 | |
| 4589 | switch (invoke->GetCodePtrLocation()) { |
| 4590 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4591 | { |
| 4592 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4593 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4594 | kInstructionSize, |
| 4595 | CodeBufferCheckScope::kExactSize); |
| 4596 | __ bl(&frame_entry_label_); |
| 4597 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4598 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4599 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4600 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4601 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4602 | __ Ldr(lr, MemOperand( |
| Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4603 | XRegisterFrom(callee_method), |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4604 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4605 | { |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4606 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4607 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4608 | kInstructionSize, |
| 4609 | CodeBufferCheckScope::kExactSize); |
| 4610 | // lr() |
| 4611 | __ blr(lr); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4612 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4613 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4614 | break; |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4615 | } |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4616 | |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4617 | DCHECK(!IsLeafMethod()); |
| 4618 | } |
| 4619 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4620 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4621 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4622 | // Use the calling convention instead of the location of the receiver, as |
| 4623 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4624 | // slow path, the arguments have been moved to the right place, so here we are |
| 4625 | // guaranteed that the receiver is the first register of the calling convention. |
| 4626 | InvokeDexCallingConvention calling_convention; |
| 4627 | Register receiver = calling_convention.GetRegisterAt(0); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4628 | Register temp = XRegisterFrom(temp_in); |
| 4629 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4630 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4631 | Offset class_offset = mirror::Object::ClassOffset(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4632 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4633 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4634 | DCHECK(receiver.IsRegister()); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4635 | |
| 4636 | { |
| 4637 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4638 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4639 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4640 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4641 | MaybeRecordImplicitNullCheck(invoke); |
| 4642 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4643 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4644 | // emit a read barrier for the previous class reference load. |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4645 | // intermediate/temporary reference and because the current |
| 4646 | // concurrent copying collector keeps the from-space memory |
| 4647 | // intact/accessible until the end of the marking phase (the |
| 4648 | // concurrent copying collector may not in the future). |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4649 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4650 | // temp = temp->GetMethodAt(method_offset); |
| 4651 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4652 | // lr = temp->GetEntryPoint(); |
| 4653 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4654 | { |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4655 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4656 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4657 | // lr(); |
| 4658 | __ blr(lr); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4659 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4660 | } |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4661 | } |
| 4662 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4663 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4664 | HandleInvoke(invoke); |
| 4665 | } |
| 4666 | |
| 4667 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4668 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4669 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4670 | } |
| 4671 | |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4672 | void LocationsBuilderARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4673 | HandleInvoke(invoke); |
| 4674 | } |
| 4675 | |
| 4676 | void InstructionCodeGeneratorARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4677 | codegen_->GenerateInvokeCustomCall(invoke); |
| 4678 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| 4679 | } |
| 4680 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4681 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageRelRoPatch( |
| 4682 | uint32_t boot_image_offset, |
| 4683 | vixl::aarch64::Label* adrp_label) { |
| 4684 | return NewPcRelativePatch( |
| 4685 | /* dex_file */ nullptr, boot_image_offset, adrp_label, &boot_image_method_patches_); |
| 4686 | } |
| 4687 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4688 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageMethodPatch( |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4689 | MethodReference target_method, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4690 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4691 | return NewPcRelativePatch( |
| 4692 | 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] | 4693 | } |
| 4694 | |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4695 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4696 | MethodReference target_method, |
| 4697 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4698 | return NewPcRelativePatch( |
| 4699 | 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] | 4700 | } |
| 4701 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4702 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageTypePatch( |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4703 | const DexFile& dex_file, |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4704 | dex::TypeIndex type_index, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4705 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4706 | 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] | 4707 | } |
| 4708 | |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4709 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4710 | const DexFile& dex_file, |
| 4711 | dex::TypeIndex type_index, |
| 4712 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4713 | 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] | 4714 | } |
| 4715 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4716 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageStringPatch( |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4717 | const DexFile& dex_file, |
| 4718 | dex::StringIndex string_index, |
| 4719 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4720 | return NewPcRelativePatch( |
| 4721 | &dex_file, string_index.index_, adrp_label, &boot_image_string_patches_); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4722 | } |
| 4723 | |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4724 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4725 | const DexFile& dex_file, |
| 4726 | dex::StringIndex string_index, |
| 4727 | vixl::aarch64::Label* adrp_label) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4728 | 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] | 4729 | } |
| 4730 | |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4731 | vixl::aarch64::Label* CodeGeneratorARM64::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 4732 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4733 | return &baker_read_barrier_patches_.back().label; |
| 4734 | } |
| 4735 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4736 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4737 | const DexFile* dex_file, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4738 | uint32_t offset_or_index, |
| 4739 | vixl::aarch64::Label* adrp_label, |
| 4740 | ArenaDeque<PcRelativePatchInfo>* patches) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4741 | // Add a patch entry and return the label. |
| 4742 | patches->emplace_back(dex_file, offset_or_index); |
| 4743 | PcRelativePatchInfo* info = &patches->back(); |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4744 | vixl::aarch64::Label* label = &info->label; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4745 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4746 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4747 | return label; |
| 4748 | } |
| 4749 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4750 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4751 | uint64_t address) { |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4752 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4753 | } |
| 4754 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4755 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4756 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4757 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4758 | return jit_string_patches_.GetOrCreate( |
| 4759 | StringReference(&dex_file, string_index), |
| 4760 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4761 | } |
| 4762 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4763 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4764 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4765 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4766 | return jit_class_patches_.GetOrCreate( |
| 4767 | TypeReference(&dex_file, type_index), |
| 4768 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4769 | } |
| 4770 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4771 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4772 | vixl::aarch64::Register reg) { |
| 4773 | DCHECK(reg.IsX()); |
| 4774 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4775 | __ Bind(fixup_label); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4776 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4780 | vixl::aarch64::Register out, |
| 4781 | vixl::aarch64::Register base) { |
| 4782 | DCHECK(out.IsX()); |
| 4783 | DCHECK(base.IsX()); |
| 4784 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4785 | __ Bind(fixup_label); |
| 4786 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4787 | } |
| 4788 | |
| 4789 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4790 | vixl::aarch64::Register out, |
| 4791 | vixl::aarch64::Register base) { |
| 4792 | DCHECK(base.IsX()); |
| 4793 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4794 | __ Bind(fixup_label); |
| 4795 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4796 | } |
| 4797 | |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4798 | void CodeGeneratorARM64::LoadBootImageAddress(vixl::aarch64::Register reg, |
| 4799 | uint32_t boot_image_offset) { |
| 4800 | DCHECK(!GetCompilerOptions().IsBootImage()); |
| 4801 | if (GetCompilerOptions().GetCompilePic()) { |
| 4802 | DCHECK(Runtime::Current()->IsAotCompiler()); |
| 4803 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 4804 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_offset); |
| 4805 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4806 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| 4807 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| 4808 | EmitLdrOffsetPlaceholder(ldr_label, reg.W(), reg.X()); |
| 4809 | } else { |
| 4810 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 4811 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| 4812 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_offset; |
| 4813 | __ Ldr(reg.W(), DeduplicateBootImageAddressLiteral(reinterpret_cast<uintptr_t>(address))); |
| 4814 | } |
| 4815 | } |
| 4816 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4817 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4818 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4819 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4820 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4821 | for (const PcRelativePatchInfo& info : infos) { |
| 4822 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4823 | info.target_dex_file, |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4824 | info.pc_insn_label->GetLocation(), |
| 4825 | info.offset_or_index)); |
| 4826 | } |
| 4827 | } |
| 4828 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4829 | linker::LinkerPatch DataBimgRelRoPatchAdapter(size_t literal_offset, |
| 4830 | const DexFile* target_dex_file, |
| 4831 | uint32_t pc_insn_offset, |
| 4832 | uint32_t boot_image_offset) { |
| 4833 | DCHECK(target_dex_file == nullptr); // Unused for DataBimgRelRoPatch(), should be null. |
| 4834 | return linker::LinkerPatch::DataBimgRelRoPatch(literal_offset, pc_insn_offset, boot_image_offset); |
| 4835 | } |
| 4836 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4837 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4838 | DCHECK(linker_patches->empty()); |
| 4839 | size_t size = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4840 | boot_image_method_patches_.size() + |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4841 | method_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4842 | boot_image_type_patches_.size() + |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4843 | type_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4844 | boot_image_string_patches_.size() + |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4845 | string_bss_entry_patches_.size() + |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4846 | baker_read_barrier_patches_.size(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4847 | linker_patches->reserve(size); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4848 | if (GetCompilerOptions().IsBootImage()) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4849 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4850 | boot_image_method_patches_, linker_patches); |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4851 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4852 | boot_image_type_patches_, linker_patches); |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4853 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4854 | boot_image_string_patches_, linker_patches); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4855 | } else { |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4856 | EmitPcRelativeLinkerPatches<DataBimgRelRoPatchAdapter>( |
| 4857 | boot_image_method_patches_, linker_patches); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4858 | DCHECK(boot_image_type_patches_.empty()); |
| 4859 | DCHECK(boot_image_string_patches_.empty()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4860 | } |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4861 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4862 | method_bss_entry_patches_, linker_patches); |
| 4863 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4864 | type_bss_entry_patches_, linker_patches); |
| 4865 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4866 | string_bss_entry_patches_, linker_patches); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4867 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4868 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 4869 | info.label.GetLocation(), info.custom_data)); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4870 | } |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4871 | DCHECK_EQ(size, linker_patches->size()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4872 | } |
| 4873 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4874 | bool CodeGeneratorARM64::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
| 4875 | return patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
| 4876 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 4877 | } |
| 4878 | |
| 4879 | void CodeGeneratorARM64::EmitThunkCode(const linker::LinkerPatch& patch, |
| 4880 | /*out*/ ArenaVector<uint8_t>* code, |
| 4881 | /*out*/ std::string* debug_name) { |
| 4882 | Arm64Assembler assembler(GetGraph()->GetAllocator()); |
| 4883 | switch (patch.GetType()) { |
| 4884 | case linker::LinkerPatch::Type::kCallRelative: { |
| 4885 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 4886 | // to the generic JNI and interpreter trampolines. |
| 4887 | Offset offset(ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4888 | kArm64PointerSize).Int32Value()); |
| 4889 | assembler.JumpTo(ManagedRegister(arm64::X0), offset, ManagedRegister(arm64::IP0)); |
| 4890 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 4891 | *debug_name = "MethodCallThunk"; |
| 4892 | } |
| 4893 | break; |
| 4894 | } |
| 4895 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| 4896 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 4897 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 4898 | break; |
| 4899 | } |
| 4900 | default: |
| 4901 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 4902 | UNREACHABLE(); |
| 4903 | } |
| 4904 | |
| 4905 | // Ensure we emit the literal pool if any. |
| 4906 | assembler.FinalizeCode(); |
| 4907 | code->resize(assembler.CodeSize()); |
| 4908 | MemoryRegion code_region(code->data(), code->size()); |
| 4909 | assembler.FinalizeInstructions(code_region); |
| 4910 | } |
| 4911 | |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4912 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4913 | return uint32_literals_.GetOrCreate( |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4914 | value, |
| 4915 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4916 | } |
| 4917 | |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4918 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4919 | return uint64_literals_.GetOrCreate( |
| 4920 | value, |
| 4921 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4922 | } |
| 4923 | |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4924 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4925 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4926 | // art::PrepareForRegisterAllocation. |
| 4927 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4928 | |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4929 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4930 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4931 | return; |
| 4932 | } |
| 4933 | |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4934 | { |
| 4935 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4936 | // are no pools emitted. |
| 4937 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4938 | LocationSummary* locations = invoke->GetLocations(); |
| 4939 | codegen_->GenerateStaticOrDirectCall( |
| 4940 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| 4941 | } |
| 4942 | |
| 4943 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4947 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4948 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4949 | return; |
| 4950 | } |
| 4951 | |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4952 | { |
| 4953 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4954 | // are no pools emitted. |
| 4955 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4956 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 4957 | DCHECK(!codegen_->IsLeafMethod()); |
| 4958 | } |
| 4959 | |
| 4960 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4961 | } |
| 4962 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4963 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4964 | HLoadClass::LoadKind desired_class_load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4965 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4966 | case HLoadClass::LoadKind::kInvalid: |
| 4967 | LOG(FATAL) << "UNREACHABLE"; |
| 4968 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4969 | case HLoadClass::LoadKind::kReferrersClass: |
| 4970 | break; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4971 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4972 | case HLoadClass::LoadKind::kBootImageRelRo: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4973 | case HLoadClass::LoadKind::kBssEntry: |
| 4974 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4975 | break; |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4976 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4977 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4978 | break; |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4979 | case HLoadClass::LoadKind::kBootImageAddress: |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4980 | case HLoadClass::LoadKind::kRuntimeCall: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4981 | break; |
| 4982 | } |
| 4983 | return desired_class_load_kind; |
| 4984 | } |
| 4985 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4986 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4987 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4988 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4989 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4990 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4991 | cls, |
| 4992 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4993 | LocationFrom(vixl::aarch64::x0)); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4994 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4995 | return; |
| 4996 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4997 | DCHECK(!cls->NeedsAccessCheck()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4998 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4999 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5000 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5001 | ? LocationSummary::kCallOnSlowPath |
| 5002 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5003 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5004 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5005 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5006 | } |
| 5007 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5008 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5009 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5010 | } |
| 5011 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5012 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 5013 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5014 | // Rely on the type resolution or initialization and marking to save everything we need. |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5015 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5016 | InvokeRuntimeCallingConvention calling_convention; |
| 5017 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 5018 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5019 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 5020 | DataType::Type::kReference).GetCode()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5021 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5022 | } else { |
| 5023 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5024 | } |
| 5025 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5026 | } |
| 5027 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5028 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5029 | // move. |
| 5030 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5031 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5032 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5033 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5034 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5035 | return; |
| 5036 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5037 | DCHECK(!cls->NeedsAccessCheck()); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5038 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5039 | Location out_loc = cls->GetLocations()->Out(); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5040 | Register out = OutputRegister(cls); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5041 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5042 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5043 | ? kWithoutReadBarrier |
| 5044 | : kCompilerReadBarrierOption; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5045 | bool generate_null_check = false; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5046 | switch (load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5047 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5048 | DCHECK(!cls->CanCallRuntime()); |
| 5049 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5050 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5051 | Register current_method = InputRegisterAt(cls, 0); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5052 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5053 | out_loc, |
| 5054 | current_method, |
| 5055 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 5056 | /* fixup_label */ nullptr, |
| 5057 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5058 | break; |
| 5059 | } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5060 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5061 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5062 | // Add ADRP with its PC-relative type patch. |
| 5063 | const DexFile& dex_file = cls->GetDexFile(); |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5064 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5065 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageTypePatch(dex_file, type_index); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5066 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5067 | // Add ADD with its PC-relative type patch. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5068 | vixl::aarch64::Label* add_label = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5069 | codegen_->NewBootImageTypePatch(dex_file, type_index, adrp_label); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5070 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5071 | break; |
| 5072 | } |
| 5073 | case HLoadClass::LoadKind::kBootImageAddress: { |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5074 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5075 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5076 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 5077 | DCHECK_NE(address, 0u); |
| 5078 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5079 | break; |
| 5080 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5081 | case HLoadClass::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5082 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5083 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls); |
| 5084 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5085 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5086 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5087 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5088 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5089 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5090 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5091 | break; |
| 5092 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5093 | case HLoadClass::LoadKind::kBssEntry: { |
| 5094 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 5095 | const DexFile& dex_file = cls->GetDexFile(); |
| 5096 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5097 | vixl::aarch64::Register temp = XRegisterFrom(out_loc); |
| 5098 | vixl::aarch64::Label* adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 5099 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5100 | // Add LDR with its PC-relative Class .bss entry patch. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5101 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5102 | codegen_->NewBssEntryTypePatch(dex_file, type_index, adrp_label); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5103 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5104 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5105 | out_loc, |
| 5106 | temp, |
| 5107 | /* offset placeholder */ 0u, |
| 5108 | ldr_label, |
| 5109 | read_barrier_option); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5110 | generate_null_check = true; |
| 5111 | break; |
| 5112 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5113 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5114 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5115 | cls->GetTypeIndex(), |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5116 | cls->GetClass())); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5117 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5118 | out_loc, |
| 5119 | out.X(), |
| 5120 | /* offset */ 0, |
| 5121 | /* fixup_label */ nullptr, |
| 5122 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5123 | break; |
| 5124 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5125 | case HLoadClass::LoadKind::kRuntimeCall: |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5126 | case HLoadClass::LoadKind::kInvalid: |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5127 | LOG(FATAL) << "UNREACHABLE"; |
| 5128 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5129 | } |
| 5130 | |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5131 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5132 | if (generate_null_check || do_clinit) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5133 | DCHECK(cls->CanCallRuntime()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5134 | SlowPathCodeARM64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64( |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5135 | cls, cls, cls->GetDexPc(), do_clinit); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5136 | codegen_->AddSlowPath(slow_path); |
| 5137 | if (generate_null_check) { |
| 5138 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5139 | } |
| 5140 | if (cls->MustGenerateClinitCheck()) { |
| 5141 | GenerateClassInitializationCheck(slow_path, out); |
| 5142 | } else { |
| 5143 | __ Bind(slow_path->GetExitLabel()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5144 | } |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5145 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5146 | } |
| 5147 | } |
| 5148 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 5149 | void LocationsBuilderARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5150 | InvokeRuntimeCallingConvention calling_convention; |
| 5151 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5152 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 5153 | } |
| 5154 | |
| 5155 | void InstructionCodeGeneratorARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5156 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 5157 | } |
| 5158 | |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 5159 | void LocationsBuilderARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5160 | InvokeRuntimeCallingConvention calling_convention; |
| 5161 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5162 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 5163 | } |
| 5164 | |
| 5165 | void InstructionCodeGeneratorARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5166 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 5167 | } |
| 5168 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5169 | static MemOperand GetExceptionTlsAddress() { |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5170 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5171 | } |
| 5172 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5173 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5174 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5175 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5176 | locations->SetOut(Location::RequiresRegister()); |
| 5177 | } |
| 5178 | |
| 5179 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5180 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5181 | } |
| 5182 | |
| 5183 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5184 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5185 | } |
| 5186 | |
| 5187 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5188 | __ Str(wzr, GetExceptionTlsAddress()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5189 | } |
| 5190 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5191 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5192 | HLoadString::LoadKind desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5193 | switch (desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5194 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5195 | case HLoadString::LoadKind::kBootImageRelRo: |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5196 | case HLoadString::LoadKind::kBssEntry: |
| Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5197 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5198 | break; |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5199 | case HLoadString::LoadKind::kJitTableAddress: |
| 5200 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5201 | break; |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5202 | case HLoadString::LoadKind::kBootImageAddress: |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5203 | case HLoadString::LoadKind::kRuntimeCall: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5204 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5205 | } |
| 5206 | return desired_string_load_kind; |
| 5207 | } |
| 5208 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5209 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5210 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5211 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5212 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
| Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5213 | InvokeRuntimeCallingConvention calling_convention; |
| 5214 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5215 | } else { |
| 5216 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5217 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5218 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5219 | // Rely on the pResolveString and marking to save everything we need. |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5220 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5221 | InvokeRuntimeCallingConvention calling_convention; |
| 5222 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 5223 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5224 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 5225 | DataType::Type::kReference).GetCode()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5226 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5227 | } else { |
| 5228 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5229 | } |
| 5230 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5231 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5232 | } |
| 5233 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5234 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5235 | // move. |
| 5236 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5237 | Register out = OutputRegister(load); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5238 | Location out_loc = load->GetLocations()->Out(); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5239 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5240 | switch (load->GetLoadKind()) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5241 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5242 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5243 | // Add ADRP with its PC-relative String patch. |
| 5244 | const DexFile& dex_file = load->GetDexFile(); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5245 | const dex::StringIndex string_index = load->GetStringIndex(); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5246 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageStringPatch(dex_file, string_index); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5247 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5248 | // Add ADD with its PC-relative String patch. |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5249 | vixl::aarch64::Label* add_label = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5250 | codegen_->NewBootImageStringPatch(dex_file, string_index, adrp_label); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5251 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5252 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5253 | } |
| 5254 | case HLoadString::LoadKind::kBootImageAddress: { |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5255 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5256 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5257 | DCHECK_NE(address, 0u); |
| 5258 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5259 | return; |
| 5260 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5261 | case HLoadString::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5262 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5263 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5264 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(load); |
| 5265 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5266 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5267 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5268 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5269 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5270 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 5271 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5272 | } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5273 | case HLoadString::LoadKind::kBssEntry: { |
| 5274 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5275 | const DexFile& dex_file = load->GetDexFile(); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5276 | const dex::StringIndex string_index = load->GetStringIndex(); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5277 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5278 | Register temp = XRegisterFrom(out_loc); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5279 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5280 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5281 | // Add LDR with its PC-relative String .bss entry patch. |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5282 | vixl::aarch64::Label* ldr_label = |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5283 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5284 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5285 | codegen_->GenerateGcRootFieldLoad(load, |
| 5286 | out_loc, |
| 5287 | temp, |
| 5288 | /* offset placeholder */ 0u, |
| 5289 | ldr_label, |
| 5290 | kCompilerReadBarrierOption); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5291 | SlowPathCodeARM64* slow_path = |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5292 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5293 | codegen_->AddSlowPath(slow_path); |
| 5294 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5295 | __ Bind(slow_path->GetExitLabel()); |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5296 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5297 | return; |
| 5298 | } |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5299 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5300 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5301 | load->GetStringIndex(), |
| 5302 | load->GetString())); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5303 | codegen_->GenerateGcRootFieldLoad(load, |
| 5304 | out_loc, |
| 5305 | out.X(), |
| 5306 | /* offset */ 0, |
| 5307 | /* fixup_label */ nullptr, |
| 5308 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5309 | return; |
| 5310 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5311 | default: |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5312 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5313 | } |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5314 | |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5315 | // 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] | 5316 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5317 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5318 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
| Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5319 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5320 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5321 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5322 | } |
| 5323 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5324 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5325 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5326 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5327 | } |
| 5328 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5329 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5330 | // Will be generated at use site. |
| 5331 | } |
| 5332 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5333 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5334 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5335 | instruction, LocationSummary::kCallOnMainOnly); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5336 | InvokeRuntimeCallingConvention calling_convention; |
| 5337 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5338 | } |
| 5339 | |
| 5340 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5341 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5342 | instruction, |
| 5343 | instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5344 | if (instruction->IsEnter()) { |
| 5345 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5346 | } else { |
| 5347 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5348 | } |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5349 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5350 | } |
| 5351 | |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5352 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5353 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5354 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5355 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5356 | case DataType::Type::kInt32: |
| 5357 | case DataType::Type::kInt64: |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5358 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5359 | locations->SetInAt(1, Location::RequiresRegister()); |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5360 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5361 | break; |
| 5362 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5363 | case DataType::Type::kFloat32: |
| 5364 | case DataType::Type::kFloat64: |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5365 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5366 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5367 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5368 | break; |
| 5369 | |
| 5370 | default: |
| 5371 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5372 | } |
| 5373 | } |
| 5374 | |
| 5375 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5376 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5377 | case DataType::Type::kInt32: |
| 5378 | case DataType::Type::kInt64: |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5379 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5380 | break; |
| 5381 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5382 | case DataType::Type::kFloat32: |
| 5383 | case DataType::Type::kFloat64: |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5384 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
| Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5385 | break; |
| 5386 | |
| 5387 | default: |
| 5388 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5389 | } |
| 5390 | } |
| 5391 | |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5392 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5393 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5394 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5395 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5396 | case DataType::Type::kInt32: |
| 5397 | case DataType::Type::kInt64: |
| Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5398 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5399 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5400 | break; |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5401 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5402 | case DataType::Type::kFloat32: |
| 5403 | case DataType::Type::kFloat64: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5404 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5405 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5406 | break; |
| 5407 | |
| 5408 | default: |
| 5409 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5410 | } |
| 5411 | } |
| 5412 | |
| 5413 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5414 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5415 | case DataType::Type::kInt32: |
| 5416 | case DataType::Type::kInt64: |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5417 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5418 | break; |
| 5419 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5420 | case DataType::Type::kFloat32: |
| 5421 | case DataType::Type::kFloat64: |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5422 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5423 | break; |
| 5424 | |
| 5425 | default: |
| 5426 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5427 | } |
| 5428 | } |
| 5429 | |
| 5430 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5431 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5432 | instruction, LocationSummary::kCallOnMainOnly); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5433 | InvokeRuntimeCallingConvention calling_convention; |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5434 | locations->SetOut(LocationFrom(x0)); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5435 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5436 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5437 | } |
| 5438 | |
| 5439 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5440 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5441 | // of poisoning the reference. |
| Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5442 | QuickEntrypointEnum entrypoint = |
| 5443 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5444 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5445 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5446 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5447 | } |
| 5448 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5449 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5450 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5451 | instruction, LocationSummary::kCallOnMainOnly); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5452 | InvokeRuntimeCallingConvention calling_convention; |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5453 | if (instruction->IsStringAlloc()) { |
| 5454 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 5455 | } else { |
| 5456 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5457 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5458 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5459 | } |
| 5460 | |
| 5461 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5462 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5463 | // of poisoning the reference. |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5464 | if (instruction->IsStringAlloc()) { |
| 5465 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5466 | Location temp = instruction->GetLocations()->GetTemp(0); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5467 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5468 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 5469 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5470 | |
| 5471 | { |
| 5472 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 5473 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 5474 | kInstructionSize, |
| 5475 | CodeBufferCheckScope::kExactSize); |
| 5476 | __ blr(lr); |
| 5477 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5478 | } |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5479 | } else { |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5480 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5481 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5482 | } |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5483 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5487 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5488 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5489 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5490 | } |
| 5491 | |
| 5492 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5493 | switch (instruction->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5494 | case DataType::Type::kInt32: |
| 5495 | case DataType::Type::kInt64: |
| Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5496 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5497 | break; |
| 5498 | |
| 5499 | default: |
| 5500 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5501 | } |
| 5502 | } |
| 5503 | |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5504 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5505 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5506 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5507 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5508 | } |
| 5509 | |
| 5510 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5511 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5512 | } |
| 5513 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5514 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5515 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5516 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5517 | } |
| 5518 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5519 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5520 | if (CanMoveNullCheckToUser(instruction)) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5521 | return; |
| 5522 | } |
| Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5523 | { |
| 5524 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5525 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5526 | Location obj = instruction->GetLocations()->InAt(0); |
| 5527 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5528 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5529 | } |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5530 | } |
| 5531 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5532 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5533 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5534 | AddSlowPath(slow_path); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5535 | |
| 5536 | LocationSummary* locations = instruction->GetLocations(); |
| 5537 | Location obj = locations->InAt(0); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5538 | |
| 5539 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5540 | } |
| 5541 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5542 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5543 | codegen_->GenerateNullCheck(instruction); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5544 | } |
| 5545 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5546 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5547 | HandleBinaryOp(instruction); |
| 5548 | } |
| 5549 | |
| 5550 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5551 | HandleBinaryOp(instruction); |
| 5552 | } |
| 5553 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5554 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5555 | LOG(FATAL) << "Unreachable"; |
| 5556 | } |
| 5557 | |
| 5558 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5559 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5560 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5561 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5562 | // The back edge will generate the suspend check. |
| 5563 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5564 | } |
| 5565 | |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5566 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5567 | } |
| 5568 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5569 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5570 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5571 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5572 | if (location.IsStackSlot()) { |
| 5573 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5574 | } else if (location.IsDoubleStackSlot()) { |
| 5575 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5576 | } |
| 5577 | locations->SetOut(location); |
| 5578 | } |
| 5579 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5580 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5581 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5582 | // Nothing to do, the parameter is already at its location. |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5583 | } |
| 5584 | |
| 5585 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5586 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5587 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5588 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5589 | } |
| 5590 | |
| 5591 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5592 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5593 | // Nothing to do, the method is already at its location. |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5594 | } |
| 5595 | |
| 5596 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5597 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5598 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5599 | locations->SetInAt(i, Location::Any()); |
| 5600 | } |
| 5601 | locations->SetOut(Location::Any()); |
| 5602 | } |
| 5603 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5604 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5605 | LOG(FATAL) << "Unreachable"; |
| 5606 | } |
| 5607 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5608 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5609 | DataType::Type type = rem->GetResultType(); |
| Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5610 | LocationSummary::CallKind call_kind = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5611 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5612 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5613 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5614 | |
| 5615 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5616 | case DataType::Type::kInt32: |
| 5617 | case DataType::Type::kInt64: |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5618 | locations->SetInAt(0, Location::RequiresRegister()); |
| Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5619 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5620 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5621 | break; |
| 5622 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5623 | case DataType::Type::kFloat32: |
| 5624 | case DataType::Type::kFloat64: { |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5625 | InvokeRuntimeCallingConvention calling_convention; |
| 5626 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5627 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5628 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5629 | |
| 5630 | break; |
| 5631 | } |
| 5632 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5633 | default: |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5634 | LOG(FATAL) << "Unexpected rem type " << type; |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5635 | } |
| 5636 | } |
| 5637 | |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5638 | void InstructionCodeGeneratorARM64::GenerateIntRemForPower2Denom(HRem *instruction) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5639 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5640 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 5641 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 5642 | |
| 5643 | Register out = OutputRegister(instruction); |
| 5644 | Register dividend = InputRegisterAt(instruction, 0); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5645 | |
| Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5646 | if (abs_imm == 2) { |
| 5647 | __ Cmp(dividend, 0); |
| 5648 | __ And(out, dividend, 1); |
| 5649 | __ Csneg(out, out, out, ge); |
| 5650 | } else { |
| 5651 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5652 | Register temp = temps.AcquireSameSizeAs(out); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5653 | |
| Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5654 | __ Negs(temp, dividend); |
| 5655 | __ And(out, dividend, abs_imm - 1); |
| 5656 | __ And(temp, temp, abs_imm - 1); |
| 5657 | __ Csneg(out, out, temp, mi); |
| 5658 | } |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | void InstructionCodeGeneratorARM64::GenerateIntRemForOneOrMinusOneDenom(HRem *instruction) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5662 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5663 | DCHECK(imm == 1 || imm == -1) << imm; |
| 5664 | |
| 5665 | Register out = OutputRegister(instruction); |
| 5666 | __ Mov(out, 0); |
| 5667 | } |
| 5668 | |
| 5669 | void InstructionCodeGeneratorARM64::GenerateIntRemForConstDenom(HRem *instruction) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5670 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5671 | |
| 5672 | if (imm == 0) { |
| 5673 | // Do not generate anything. |
| 5674 | // DivZeroCheck would prevent any code to be executed. |
| 5675 | return; |
| 5676 | } |
| 5677 | |
| 5678 | if (imm == 1 || imm == -1) { |
| 5679 | // TODO: These cases need to be optimized in InstructionSimplifier |
| 5680 | GenerateIntRemForOneOrMinusOneDenom(instruction); |
| 5681 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 5682 | GenerateIntRemForPower2Denom(instruction); |
| 5683 | } else { |
| 5684 | DCHECK(imm < -2 || imm > 2) << imm; |
| 5685 | GenerateDivRemWithAnyConstant(instruction); |
| 5686 | } |
| 5687 | } |
| 5688 | |
| 5689 | void InstructionCodeGeneratorARM64::GenerateIntRem(HRem* instruction) { |
| 5690 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 5691 | << instruction->GetResultType(); |
| 5692 | |
| 5693 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 5694 | GenerateIntRemForConstDenom(instruction); |
| 5695 | } else { |
| 5696 | Register out = OutputRegister(instruction); |
| 5697 | Register dividend = InputRegisterAt(instruction, 0); |
| 5698 | Register divisor = InputRegisterAt(instruction, 1); |
| 5699 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5700 | Register temp = temps.AcquireSameSizeAs(out); |
| 5701 | __ Sdiv(temp, dividend, divisor); |
| 5702 | __ Msub(out, temp, divisor, dividend); |
| 5703 | } |
| 5704 | } |
| 5705 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5706 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5707 | DataType::Type type = rem->GetResultType(); |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5708 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5709 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5710 | case DataType::Type::kInt32: |
| 5711 | case DataType::Type::kInt64: { |
| Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5712 | GenerateIntRem(rem); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5713 | break; |
| 5714 | } |
| 5715 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5716 | case DataType::Type::kFloat32: |
| 5717 | case DataType::Type::kFloat64: { |
| 5718 | QuickEntrypointEnum entrypoint = |
| 5719 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5720 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5721 | if (type == DataType::Type::kFloat32) { |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5722 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5723 | } else { |
| 5724 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5725 | } |
| Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5726 | break; |
| 5727 | } |
| 5728 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5729 | default: |
| 5730 | LOG(FATAL) << "Unexpected rem type " << type; |
| Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5731 | UNREACHABLE(); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5732 | } |
| 5733 | } |
| 5734 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5735 | void LocationsBuilderARM64::VisitMin(HMin* min) { |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5736 | HandleBinaryOp(min); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5737 | } |
| 5738 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5739 | void InstructionCodeGeneratorARM64::VisitMin(HMin* min) { |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5740 | HandleBinaryOp(min); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5741 | } |
| 5742 | |
| 5743 | void LocationsBuilderARM64::VisitMax(HMax* max) { |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5744 | HandleBinaryOp(max); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5745 | } |
| 5746 | |
| 5747 | void InstructionCodeGeneratorARM64::VisitMax(HMax* max) { |
| Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5748 | HandleBinaryOp(max); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5749 | } |
| 5750 | |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5751 | void LocationsBuilderARM64::VisitAbs(HAbs* abs) { |
| 5752 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 5753 | switch (abs->GetResultType()) { |
| 5754 | case DataType::Type::kInt32: |
| 5755 | case DataType::Type::kInt64: |
| 5756 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5757 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5758 | break; |
| 5759 | case DataType::Type::kFloat32: |
| 5760 | case DataType::Type::kFloat64: |
| 5761 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5762 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5763 | break; |
| 5764 | default: |
| 5765 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5766 | } |
| 5767 | } |
| 5768 | |
| 5769 | void InstructionCodeGeneratorARM64::VisitAbs(HAbs* abs) { |
| 5770 | switch (abs->GetResultType()) { |
| 5771 | case DataType::Type::kInt32: |
| 5772 | case DataType::Type::kInt64: { |
| 5773 | Register in_reg = InputRegisterAt(abs, 0); |
| 5774 | Register out_reg = OutputRegister(abs); |
| 5775 | __ Cmp(in_reg, Operand(0)); |
| 5776 | __ Cneg(out_reg, in_reg, lt); |
| 5777 | break; |
| 5778 | } |
| 5779 | case DataType::Type::kFloat32: |
| 5780 | case DataType::Type::kFloat64: { |
| 5781 | FPRegister in_reg = InputFPRegisterAt(abs, 0); |
| 5782 | FPRegister out_reg = OutputFPRegister(abs); |
| 5783 | __ Fabs(out_reg, in_reg); |
| 5784 | break; |
| 5785 | } |
| 5786 | default: |
| 5787 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5788 | } |
| 5789 | } |
| 5790 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5791 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5792 | constructor_fence->SetLocations(nullptr); |
| 5793 | } |
| 5794 | |
| 5795 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5796 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5797 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5798 | } |
| 5799 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5800 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5801 | memory_barrier->SetLocations(nullptr); |
| 5802 | } |
| 5803 | |
| 5804 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5805 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5806 | } |
| 5807 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5808 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5809 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5810 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
| Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5811 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5812 | } |
| 5813 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5814 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5815 | codegen_->GenerateFrameExit(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5816 | } |
| 5817 | |
| 5818 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5819 | instruction->SetLocations(nullptr); |
| 5820 | } |
| 5821 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5822 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5823 | codegen_->GenerateFrameExit(); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5824 | } |
| 5825 | |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5826 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5827 | HandleBinaryOp(ror); |
| 5828 | } |
| 5829 | |
| 5830 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5831 | HandleBinaryOp(ror); |
| 5832 | } |
| 5833 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5834 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5835 | HandleShift(shl); |
| 5836 | } |
| 5837 | |
| 5838 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5839 | HandleShift(shl); |
| 5840 | } |
| 5841 | |
| 5842 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5843 | HandleShift(shr); |
| 5844 | } |
| 5845 | |
| 5846 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5847 | HandleShift(shr); |
| 5848 | } |
| 5849 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5850 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5851 | HandleBinaryOp(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5852 | } |
| 5853 | |
| 5854 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5855 | HandleBinaryOp(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5856 | } |
| 5857 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5858 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5859 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5860 | } |
| 5861 | |
| 5862 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5863 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
| 5866 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5867 | HandleFieldSet(instruction); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5868 | } |
| 5869 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5870 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5871 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5872 | } |
| 5873 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5874 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5875 | HUnresolvedInstanceFieldGet* instruction) { |
| 5876 | FieldAccessCallingConventionARM64 calling_convention; |
| 5877 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5878 | instruction, instruction->GetFieldType(), calling_convention); |
| 5879 | } |
| 5880 | |
| 5881 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5882 | HUnresolvedInstanceFieldGet* instruction) { |
| 5883 | FieldAccessCallingConventionARM64 calling_convention; |
| 5884 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5885 | instruction->GetFieldType(), |
| 5886 | instruction->GetFieldIndex(), |
| 5887 | instruction->GetDexPc(), |
| 5888 | calling_convention); |
| 5889 | } |
| 5890 | |
| 5891 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5892 | HUnresolvedInstanceFieldSet* instruction) { |
| 5893 | FieldAccessCallingConventionARM64 calling_convention; |
| 5894 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5895 | instruction, instruction->GetFieldType(), calling_convention); |
| 5896 | } |
| 5897 | |
| 5898 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5899 | HUnresolvedInstanceFieldSet* instruction) { |
| 5900 | FieldAccessCallingConventionARM64 calling_convention; |
| 5901 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5902 | instruction->GetFieldType(), |
| 5903 | instruction->GetFieldIndex(), |
| 5904 | instruction->GetDexPc(), |
| 5905 | calling_convention); |
| 5906 | } |
| 5907 | |
| 5908 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5909 | HUnresolvedStaticFieldGet* instruction) { |
| 5910 | FieldAccessCallingConventionARM64 calling_convention; |
| 5911 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5912 | instruction, instruction->GetFieldType(), calling_convention); |
| 5913 | } |
| 5914 | |
| 5915 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5916 | HUnresolvedStaticFieldGet* instruction) { |
| 5917 | FieldAccessCallingConventionARM64 calling_convention; |
| 5918 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5919 | instruction->GetFieldType(), |
| 5920 | instruction->GetFieldIndex(), |
| 5921 | instruction->GetDexPc(), |
| 5922 | calling_convention); |
| 5923 | } |
| 5924 | |
| 5925 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5926 | HUnresolvedStaticFieldSet* instruction) { |
| 5927 | FieldAccessCallingConventionARM64 calling_convention; |
| 5928 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5929 | instruction, instruction->GetFieldType(), calling_convention); |
| 5930 | } |
| 5931 | |
| 5932 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5933 | HUnresolvedStaticFieldSet* instruction) { |
| 5934 | FieldAccessCallingConventionARM64 calling_convention; |
| 5935 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5936 | instruction->GetFieldType(), |
| 5937 | instruction->GetFieldIndex(), |
| 5938 | instruction->GetDexPc(), |
| 5939 | calling_convention); |
| 5940 | } |
| 5941 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5942 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5943 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5944 | instruction, LocationSummary::kCallOnSlowPath); |
| Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5945 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5946 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5947 | // registers in full width (since the runtime only saves/restores lower part). |
| 5948 | locations->SetCustomSlowPathCallerSaves( |
| 5949 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5950 | } |
| 5951 | |
| 5952 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5953 | HBasicBlock* block = instruction->GetBlock(); |
| 5954 | if (block->GetLoopInformation() != nullptr) { |
| 5955 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5956 | // The back edge will generate the suspend check. |
| 5957 | return; |
| 5958 | } |
| 5959 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5960 | // The goto will generate the suspend check. |
| 5961 | return; |
| 5962 | } |
| 5963 | GenerateSuspendCheck(instruction, nullptr); |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5964 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5965 | } |
| 5966 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5967 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5968 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5969 | instruction, LocationSummary::kCallOnMainOnly); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5970 | InvokeRuntimeCallingConvention calling_convention; |
| 5971 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5972 | } |
| 5973 | |
| 5974 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
| Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5975 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5976 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5977 | } |
| 5978 | |
| 5979 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5980 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5981 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5982 | DataType::Type input_type = conversion->GetInputType(); |
| 5983 | DataType::Type result_type = conversion->GetResultType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5984 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5985 | << input_type << " -> " << result_type; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5986 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 5987 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5988 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5989 | } |
| 5990 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5991 | if (DataType::IsFloatingPointType(input_type)) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5992 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5993 | } else { |
| 5994 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5995 | } |
| 5996 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5997 | if (DataType::IsFloatingPointType(result_type)) { |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5998 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5999 | } else { |
| 6000 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6001 | } |
| 6002 | } |
| 6003 | |
| 6004 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6005 | DataType::Type result_type = conversion->GetResultType(); |
| 6006 | DataType::Type input_type = conversion->GetInputType(); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6007 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6008 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6009 | << input_type << " -> " << result_type; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6010 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6011 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 6012 | int result_size = DataType::Size(result_type); |
| 6013 | int input_size = DataType::Size(input_type); |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6014 | int min_size = std::min(result_size, input_size); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6015 | Register output = OutputRegister(conversion); |
| 6016 | Register source = InputRegisterAt(conversion, 0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6017 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
| Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 6018 | // 'int' values are used directly as W registers, discarding the top |
| 6019 | // bits, so we don't need to sign-extend and can just perform a move. |
| 6020 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 6021 | // top 32 bits of the target register. We theoretically could leave those |
| 6022 | // bits unchanged, but we would have to make sure that no code uses a |
| 6023 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 6024 | // zero. |
| 6025 | __ Mov(output.W(), source.W()); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6026 | } else if (DataType::IsUnsignedType(result_type) || |
| 6027 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 6028 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6029 | } else { |
| Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6030 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6031 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6032 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6033 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6034 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 6035 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6036 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6037 | } else if (DataType::IsFloatingPointType(result_type) && |
| 6038 | DataType::IsFloatingPointType(input_type)) { |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6039 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 6040 | } else { |
| 6041 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6042 | << " to " << result_type; |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6043 | } |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6044 | } |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6045 | |
| Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6046 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 6047 | HandleShift(ushr); |
| 6048 | } |
| 6049 | |
| 6050 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 6051 | HandleShift(ushr); |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6052 | } |
| 6053 | |
| 6054 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 6055 | HandleBinaryOp(instruction); |
| 6056 | } |
| 6057 | |
| 6058 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 6059 | HandleBinaryOp(instruction); |
| 6060 | } |
| 6061 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6062 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6063 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6064 | LOG(FATAL) << "Unreachable"; |
| 6065 | } |
| 6066 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6067 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6068 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6069 | LOG(FATAL) << "Unreachable"; |
| 6070 | } |
| 6071 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6072 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6073 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6074 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6075 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6076 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6077 | } |
| 6078 | |
| 6079 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6080 | int32_t lower_bound = switch_instr->GetStartValue(); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6081 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6082 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 6083 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6084 | |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6085 | // 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] | 6086 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6087 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 6088 | // make sure we don't emit it if the target may run out of range. |
| 6089 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 6090 | // ranges and emit the tables only as required. |
| 6091 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6092 | |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6093 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6094 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 6095 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 6096 | // Create a series of compare/jumps. |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6097 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6098 | Register temp = temps.AcquireW(); |
| 6099 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 6100 | |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6101 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6102 | // Jump to successors[0] if value == lower_bound. |
| 6103 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 6104 | int32_t last_index = 0; |
| 6105 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6106 | __ Subs(temp, temp, Operand(2)); |
| 6107 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6108 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6109 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6110 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6111 | } |
| 6112 | if (num_entries - last_index == 2) { |
| 6113 | // The last missing case_value. |
| 6114 | __ Cmp(temp, Operand(1)); |
| 6115 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6116 | } |
| 6117 | |
| 6118 | // And the default for any other value. |
| 6119 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6120 | __ B(codegen_->GetLabelOf(default_block)); |
| 6121 | } |
| 6122 | } else { |
| Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 6123 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
| Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6124 | |
| 6125 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6126 | |
| 6127 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 6128 | // registers, we are free to block one. |
| 6129 | Register temp_w = temps.AcquireW(); |
| 6130 | Register index; |
| 6131 | // Remove the bias. |
| 6132 | if (lower_bound != 0) { |
| 6133 | index = temp_w; |
| 6134 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 6135 | } else { |
| 6136 | index = value_reg; |
| 6137 | } |
| 6138 | |
| 6139 | // Jump to default block if index is out of the range. |
| 6140 | __ Cmp(index, Operand(num_entries)); |
| 6141 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 6142 | |
| 6143 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 6144 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 6145 | // register pressure. |
| 6146 | Register table_base = temps.AcquireX(); |
| 6147 | // Load jump offset from the table. |
| 6148 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 6149 | Register jump_offset = temp_w; |
| 6150 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 6151 | |
| 6152 | // Jump to target block by branching to table_base(pc related) + offset. |
| 6153 | Register target_address = table_base; |
| 6154 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 6155 | __ Br(target_address); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6156 | } |
| 6157 | } |
| 6158 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6159 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 6160 | HInstruction* instruction, |
| 6161 | Location out, |
| 6162 | uint32_t offset, |
| 6163 | Location maybe_temp, |
| 6164 | ReadBarrierOption read_barrier_option) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6165 | DataType::Type type = DataType::Type::kReference; |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6166 | Register out_reg = RegisterFrom(out, type); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6167 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6168 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6169 | if (kUseBakerReadBarrier) { |
| 6170 | // Load with fast path based Baker's read barrier. |
| 6171 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6172 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6173 | out, |
| 6174 | out_reg, |
| 6175 | offset, |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6176 | maybe_temp, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6177 | /* needs_null_check */ false, |
| 6178 | /* use_load_acquire */ false); |
| 6179 | } else { |
| 6180 | // Load with slow path based read barrier. |
| 6181 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6182 | // in the following move operation, as we will need it for the |
| 6183 | // read barrier below. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6184 | Register temp_reg = RegisterFrom(maybe_temp, type); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6185 | __ Mov(temp_reg, out_reg); |
| 6186 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6187 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6188 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6189 | } |
| 6190 | } else { |
| 6191 | // Plain load with no read barrier. |
| 6192 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6193 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6194 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6195 | } |
| 6196 | } |
| 6197 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6198 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 6199 | HInstruction* instruction, |
| 6200 | Location out, |
| 6201 | Location obj, |
| 6202 | uint32_t offset, |
| 6203 | Location maybe_temp, |
| 6204 | ReadBarrierOption read_barrier_option) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6205 | DataType::Type type = DataType::Type::kReference; |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6206 | Register out_reg = RegisterFrom(out, type); |
| 6207 | Register obj_reg = RegisterFrom(obj, type); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6208 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6209 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6210 | if (kUseBakerReadBarrier) { |
| 6211 | // Load with fast path based Baker's read barrier. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6212 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6213 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6214 | out, |
| 6215 | obj_reg, |
| 6216 | offset, |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6217 | maybe_temp, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6218 | /* needs_null_check */ false, |
| 6219 | /* use_load_acquire */ false); |
| 6220 | } else { |
| 6221 | // Load with slow path based read barrier. |
| 6222 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6223 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6224 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6225 | } |
| 6226 | } else { |
| 6227 | // Plain load with no read barrier. |
| 6228 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6229 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6230 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6231 | } |
| 6232 | } |
| 6233 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6234 | void CodeGeneratorARM64::GenerateGcRootFieldLoad( |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6235 | HInstruction* instruction, |
| 6236 | Location root, |
| 6237 | Register obj, |
| 6238 | uint32_t offset, |
| 6239 | vixl::aarch64::Label* fixup_label, |
| 6240 | ReadBarrierOption read_barrier_option) { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6241 | DCHECK(fixup_label == nullptr || offset == 0u); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6242 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6243 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6244 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6245 | if (kUseBakerReadBarrier) { |
| 6246 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6247 | // Baker's read barrier are used. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6248 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 6249 | !Runtime::Current()->UseJitCompilation()) { |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6250 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6251 | // the Marking Register) to decide whether we need to enter |
| 6252 | // the slow path to mark the GC root. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6253 | // |
| 6254 | // We use link-time generated thunks for the slow path. That thunk |
| 6255 | // checks the reference and jumps to the entrypoint if needed. |
| 6256 | // |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6257 | // lr = &return_address; |
| 6258 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6259 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6260 | // goto gc_root_thunk<root_reg>(lr) |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6261 | // } |
| 6262 | // return_address: |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6263 | |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6264 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6265 | DCHECK(temps.IsAvailable(ip0)); |
| 6266 | DCHECK(temps.IsAvailable(ip1)); |
| 6267 | temps.Exclude(ip0, ip1); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6268 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
| 6269 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6270 | |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6271 | EmissionCheckScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6272 | vixl::aarch64::Label return_address; |
| 6273 | __ adr(lr, &return_address); |
| 6274 | if (fixup_label != nullptr) { |
| 6275 | __ Bind(fixup_label); |
| 6276 | } |
| 6277 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6278 | "GC root LDR must be 2 instruction (8B) before the return address label."); |
| 6279 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6280 | __ Bind(cbnz_label); |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6281 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6282 | __ Bind(&return_address); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6283 | } else { |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6284 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6285 | // the Marking Register) to decide whether we need to enter |
| 6286 | // the slow path to mark the GC root. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6287 | // |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6288 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6289 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6290 | // // Slow path. |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6291 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6292 | // root = entrypoint(root); // root = ReadBarrier::Mark(root); // Entry point call. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6293 | // } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6294 | |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6295 | // Slow path marking the GC root `root`. The entrypoint will |
| 6296 | // be loaded by the slow path code. |
| 6297 | SlowPathCodeARM64* slow_path = |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6298 | new (GetScopedAllocator()) ReadBarrierMarkSlowPathARM64(instruction, root); |
| 6299 | AddSlowPath(slow_path); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6300 | |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6301 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6302 | if (fixup_label == nullptr) { |
| 6303 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6304 | } else { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6305 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6306 | } |
| 6307 | static_assert( |
| 6308 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6309 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6310 | "have different sizes."); |
| 6311 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6312 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6313 | "have different sizes."); |
| 6314 | |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6315 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6316 | __ Bind(slow_path->GetExitLabel()); |
| 6317 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6318 | } else { |
| 6319 | // GC root loaded through a slow path for read barriers other |
| 6320 | // than Baker's. |
| 6321 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6322 | if (fixup_label == nullptr) { |
| 6323 | __ Add(root_reg.X(), obj.X(), offset); |
| 6324 | } else { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6325 | EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6326 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6327 | // /* mirror::Object* */ root = root->Read() |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6328 | GenerateReadBarrierForRootSlow(instruction, root, root); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6329 | } |
| 6330 | } else { |
| 6331 | // Plain GC root load with no read barrier. |
| 6332 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6333 | if (fixup_label == nullptr) { |
| 6334 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6335 | } else { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6336 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6337 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6338 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6339 | // do not have to unpoison `root_reg` here. |
| 6340 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6341 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6342 | } |
| 6343 | |
| 6344 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6345 | Location ref, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6346 | Register obj, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6347 | uint32_t offset, |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6348 | Location maybe_temp, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6349 | bool needs_null_check, |
| 6350 | bool use_load_acquire) { |
| 6351 | DCHECK(kEmitCompilerReadBarrier); |
| 6352 | DCHECK(kUseBakerReadBarrier); |
| 6353 | |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6354 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6355 | !use_load_acquire && |
| 6356 | !Runtime::Current()->UseJitCompilation()) { |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6357 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6358 | // Marking Register) to decide whether we need to enter the slow |
| 6359 | // path to mark the reference. Then, in the slow path, check the |
| 6360 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6361 | // decide whether to mark `ref` or not. |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6362 | // |
| 6363 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6364 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6365 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6366 | // |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6367 | // lr = &gray_return_address; |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6368 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6369 | // goto field_thunk<holder_reg, base_reg>(lr) |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6370 | // } |
| 6371 | // not_gray_return_address: |
| 6372 | // // Original reference load. If the offset is too large to fit |
| 6373 | // // into LDR, we use an adjusted base register here. |
| Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6374 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6375 | // gray_return_address: |
| 6376 | |
| 6377 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6378 | Register base = obj; |
| 6379 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6380 | DCHECK(maybe_temp.IsRegister()); |
| 6381 | base = WRegisterFrom(maybe_temp); |
| 6382 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6383 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6384 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 6385 | } |
| 6386 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6387 | DCHECK(temps.IsAvailable(ip0)); |
| 6388 | DCHECK(temps.IsAvailable(ip1)); |
| 6389 | temps.Exclude(ip0, ip1); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6390 | uint32_t custom_data = EncodeBakerReadBarrierFieldData(base.GetCode(), obj.GetCode()); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6391 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6392 | |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6393 | { |
| 6394 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6395 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6396 | vixl::aarch64::Label return_address; |
| 6397 | __ adr(lr, &return_address); |
| 6398 | __ Bind(cbnz_label); |
| 6399 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6400 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6401 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6402 | " 2 instructions (8B) for heap poisoning."); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6403 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6404 | __ ldr(ref_reg, MemOperand(base.X(), offset)); |
| 6405 | if (needs_null_check) { |
| 6406 | MaybeRecordImplicitNullCheck(instruction); |
| 6407 | } |
| 6408 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6409 | __ Bind(&return_address); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6410 | } |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6411 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6412 | return; |
| 6413 | } |
| 6414 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6415 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6416 | Register temp = WRegisterFrom(maybe_temp); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6417 | Location no_index = Location::NoLocation(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6418 | size_t no_scale_factor = 0u; |
| Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6419 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6420 | ref, |
| 6421 | obj, |
| 6422 | offset, |
| 6423 | no_index, |
| 6424 | no_scale_factor, |
| 6425 | temp, |
| 6426 | needs_null_check, |
| 6427 | use_load_acquire); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6428 | } |
| 6429 | |
| 6430 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6431 | Location ref, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6432 | Register obj, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6433 | uint32_t data_offset, |
| 6434 | Location index, |
| 6435 | Register temp, |
| 6436 | bool needs_null_check) { |
| 6437 | DCHECK(kEmitCompilerReadBarrier); |
| 6438 | DCHECK(kUseBakerReadBarrier); |
| 6439 | |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6440 | static_assert( |
| 6441 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6442 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6443 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6444 | |
| 6445 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6446 | !Runtime::Current()->UseJitCompilation()) { |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6447 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6448 | // Marking Register) to decide whether we need to enter the slow |
| 6449 | // path to mark the reference. Then, in the slow path, check the |
| 6450 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6451 | // decide whether to mark `ref` or not. |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6452 | // |
| 6453 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6454 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6455 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6456 | // |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6457 | // lr = &gray_return_address; |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6458 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6459 | // goto array_thunk<base_reg>(lr) |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6460 | // } |
| 6461 | // not_gray_return_address: |
| 6462 | // // Original reference load. If the offset is too large to fit |
| 6463 | // // into LDR, we use an adjusted base register here. |
| Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6464 | // HeapReference<mirror::Object> reference = data[index]; |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6465 | // gray_return_address: |
| 6466 | |
| 6467 | DCHECK(index.IsValid()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6468 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 6469 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6470 | |
| 6471 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6472 | DCHECK(temps.IsAvailable(ip0)); |
| 6473 | DCHECK(temps.IsAvailable(ip1)); |
| 6474 | temps.Exclude(ip0, ip1); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6475 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(temp.GetCode()); |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6476 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6477 | |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6478 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6479 | { |
| 6480 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6481 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6482 | vixl::aarch64::Label return_address; |
| 6483 | __ adr(lr, &return_address); |
| 6484 | __ Bind(cbnz_label); |
| 6485 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6486 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6487 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6488 | " 2 instructions (8B) for heap poisoning."); |
| 6489 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6490 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6491 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6492 | __ Bind(&return_address); |
| 6493 | } |
| 6494 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6495 | return; |
| 6496 | } |
| 6497 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6498 | // Array cells are never volatile variables, therefore array loads |
| 6499 | // never use Load-Acquire instructions on ARM64. |
| 6500 | const bool use_load_acquire = false; |
| 6501 | |
| 6502 | // /* HeapReference<Object> */ ref = |
| 6503 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6504 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6505 | ref, |
| 6506 | obj, |
| 6507 | data_offset, |
| 6508 | index, |
| 6509 | scale_factor, |
| 6510 | temp, |
| 6511 | needs_null_check, |
| 6512 | use_load_acquire); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6513 | } |
| 6514 | |
| 6515 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6516 | Location ref, |
| Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6517 | Register obj, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6518 | uint32_t offset, |
| 6519 | Location index, |
| Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6520 | size_t scale_factor, |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6521 | Register temp, |
| 6522 | bool needs_null_check, |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6523 | bool use_load_acquire) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6524 | DCHECK(kEmitCompilerReadBarrier); |
| 6525 | DCHECK(kUseBakerReadBarrier); |
| Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6526 | // If we are emitting an array load, we should not be using a |
| 6527 | // Load Acquire instruction. In other words: |
| 6528 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6529 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6530 | |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6531 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6532 | // Marking Register) to decide whether we need to enter the slow |
| 6533 | // path to mark the reference. Then, in the slow path, check the |
| 6534 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6535 | // decide whether to mark `ref` or not. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6536 | // |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6537 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6538 | // // Slow path. |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6539 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6540 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6541 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 6542 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6543 | // if (is_gray) { |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6544 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6545 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6546 | // } |
| 6547 | // } else { |
| 6548 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6549 | // } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6550 | |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6551 | // Slow path marking the object `ref` when the GC is marking. The |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6552 | // entrypoint will be loaded by the slow path code. |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6553 | SlowPathCodeARM64* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6554 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierSlowPathARM64( |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6555 | instruction, |
| 6556 | ref, |
| 6557 | obj, |
| 6558 | offset, |
| 6559 | index, |
| 6560 | scale_factor, |
| 6561 | needs_null_check, |
| 6562 | use_load_acquire, |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6563 | temp); |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6564 | AddSlowPath(slow_path); |
| 6565 | |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6566 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6567 | // Fast path: the GC is not marking: just load the reference. |
| Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6568 | GenerateRawReferenceLoad( |
| 6569 | instruction, ref, obj, offset, index, scale_factor, needs_null_check, use_load_acquire); |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6570 | __ Bind(slow_path->GetExitLabel()); |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6571 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6572 | } |
| 6573 | |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6574 | void CodeGeneratorARM64::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 6575 | Location ref, |
| 6576 | Register obj, |
| 6577 | Location field_offset, |
| 6578 | Register temp, |
| 6579 | bool needs_null_check, |
| 6580 | bool use_load_acquire) { |
| 6581 | DCHECK(kEmitCompilerReadBarrier); |
| 6582 | DCHECK(kUseBakerReadBarrier); |
| 6583 | // If we are emitting an array load, we should not be using a |
| 6584 | // Load Acquire instruction. In other words: |
| 6585 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6586 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
| 6587 | |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6588 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6589 | // Marking Register) to decide whether we need to enter the slow |
| 6590 | // path to update the reference field within `obj`. Then, in the |
| 6591 | // slow path, check the gray bit in the lock word of the reference's |
| 6592 | // holder (`obj`) to decide whether to mark `ref` and update the |
| 6593 | // field or not. |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6594 | // |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6595 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6596 | // // Slow path. |
| 6597 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6598 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6599 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
| 6600 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6601 | // if (is_gray) { |
| 6602 | // old_ref = ref; |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6603 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6604 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6605 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 6606 | // } |
| 6607 | // } |
| 6608 | |
| 6609 | // Slow path updating the object reference at address `obj + field_offset` |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6610 | // when the GC is marking. The entrypoint will be loaded by the slow path code. |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6611 | SlowPathCodeARM64* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6612 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6613 | instruction, |
| 6614 | ref, |
| 6615 | obj, |
| 6616 | /* offset */ 0u, |
| 6617 | /* index */ field_offset, |
| 6618 | /* scale_factor */ 0u /* "times 1" */, |
| 6619 | needs_null_check, |
| 6620 | use_load_acquire, |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6621 | temp); |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6622 | AddSlowPath(slow_path); |
| 6623 | |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6624 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6625 | // Fast path: the GC is not marking: nothing to do (the field is |
| 6626 | // up-to-date, and we don't need to load the reference). |
| 6627 | __ Bind(slow_path->GetExitLabel()); |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6628 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6629 | } |
| 6630 | |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6631 | void CodeGeneratorARM64::GenerateRawReferenceLoad(HInstruction* instruction, |
| 6632 | Location ref, |
| 6633 | Register obj, |
| 6634 | uint32_t offset, |
| 6635 | Location index, |
| 6636 | size_t scale_factor, |
| 6637 | bool needs_null_check, |
| 6638 | bool use_load_acquire) { |
| 6639 | DCHECK(obj.IsW()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6640 | DataType::Type type = DataType::Type::kReference; |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6641 | Register ref_reg = RegisterFrom(ref, type); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6642 | |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6643 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 6644 | // that no pools are emitted between the load (macro) instruction |
| 6645 | // and MaybeRecordImplicitNullCheck. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6646 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6647 | if (index.IsValid()) { |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6648 | // Load types involving an "index": ArrayGet, |
| 6649 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6650 | // intrinsics. |
| Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6651 | if (use_load_acquire) { |
| 6652 | // UnsafeGetObjectVolatile intrinsic case. |
| 6653 | // Register `index` is not an index in an object array, but an |
| 6654 | // offset to an object reference field within object `obj`. |
| 6655 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 6656 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 6657 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 6658 | << instruction->AsInvoke()->GetIntrinsic(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6659 | DCHECK_EQ(offset, 0u); |
| 6660 | DCHECK_EQ(scale_factor, 0u); |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6661 | DCHECK_EQ(needs_null_check, false); |
| 6662 | // /* HeapReference<mirror::Object> */ ref = *(obj + index) |
| Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6663 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 6664 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6665 | } else { |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6666 | // ArrayGet and UnsafeGetObject and UnsafeCASObject intrinsics cases. |
| 6667 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
| Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6668 | if (index.IsConstant()) { |
| Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 6669 | uint32_t computed_offset = offset + (Int64FromLocation(index) << scale_factor); |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6670 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6671 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6672 | if (needs_null_check) { |
| 6673 | MaybeRecordImplicitNullCheck(instruction); |
| 6674 | } |
| Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6675 | } else { |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6676 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6677 | Register temp = temps.AcquireW(); |
| 6678 | __ Add(temp, obj, offset); |
| 6679 | { |
| 6680 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6681 | Load(type, ref_reg, HeapOperand(temp, XRegisterFrom(index), LSL, scale_factor)); |
| 6682 | if (needs_null_check) { |
| 6683 | MaybeRecordImplicitNullCheck(instruction); |
| 6684 | } |
| 6685 | } |
| Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6686 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6687 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6688 | } else { |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6689 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6690 | MemOperand field = HeapOperand(obj, offset); |
| 6691 | if (use_load_acquire) { |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6692 | // Implicit null checks are handled by CodeGeneratorARM64::LoadAcquire. |
| 6693 | LoadAcquire(instruction, ref_reg, field, needs_null_check); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6694 | } else { |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6695 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6696 | Load(type, ref_reg, field); |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6697 | if (needs_null_check) { |
| 6698 | MaybeRecordImplicitNullCheck(instruction); |
| 6699 | } |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6700 | } |
| 6701 | } |
| 6702 | |
| 6703 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6704 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6705 | } |
| 6706 | |
| Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6707 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6708 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6709 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6710 | // The following condition is a run-time one; it is executed after the |
| 6711 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6712 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6713 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6714 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6715 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6716 | } |
| 6717 | } |
| 6718 | } |
| 6719 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6720 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6721 | Location out, |
| 6722 | Location ref, |
| 6723 | Location obj, |
| 6724 | uint32_t offset, |
| 6725 | Location index) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6726 | DCHECK(kEmitCompilerReadBarrier); |
| 6727 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6728 | // Insert a slow path based read barrier *after* the reference load. |
| 6729 | // |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6730 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6731 | // reference will be carried out by the runtime within the slow |
| 6732 | // path. |
| 6733 | // |
| 6734 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6735 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6736 | // not used by the artReadBarrierSlow entry point. |
| 6737 | // |
| 6738 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6739 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6740 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6741 | AddSlowPath(slow_path); |
| 6742 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6743 | __ B(slow_path->GetEntryLabel()); |
| 6744 | __ Bind(slow_path->GetExitLabel()); |
| 6745 | } |
| 6746 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6747 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6748 | Location out, |
| 6749 | Location ref, |
| 6750 | Location obj, |
| 6751 | uint32_t offset, |
| 6752 | Location index) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6753 | if (kEmitCompilerReadBarrier) { |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6754 | // Baker's read barriers shall be handled by the fast path |
| 6755 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6756 | DCHECK(!kUseBakerReadBarrier); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6757 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6758 | // by the runtime within the slow path. |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6759 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6760 | } else if (kPoisonHeapReferences) { |
| 6761 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6762 | } |
| 6763 | } |
| 6764 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6765 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6766 | Location out, |
| 6767 | Location root) { |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6768 | DCHECK(kEmitCompilerReadBarrier); |
| 6769 | |
| Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6770 | // Insert a slow path based read barrier *after* the GC root load. |
| 6771 | // |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6772 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6773 | // not need to do anything special for this here. |
| 6774 | SlowPathCodeARM64* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6775 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6776 | AddSlowPath(slow_path); |
| 6777 | |
| Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6778 | __ B(slow_path->GetEntryLabel()); |
| 6779 | __ Bind(slow_path->GetExitLabel()); |
| 6780 | } |
| 6781 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6782 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6783 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6784 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6785 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6786 | locations->SetOut(Location::RequiresRegister()); |
| 6787 | } |
| 6788 | |
| 6789 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6790 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6791 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6792 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6793 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6794 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6795 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6796 | } else { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6797 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6798 | instruction->GetIndex(), kArm64PointerSize)); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6799 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6800 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6801 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6802 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6803 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6804 | } |
| 6805 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6806 | static void PatchJitRootUse(uint8_t* code, |
| 6807 | const uint8_t* roots_data, |
| 6808 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6809 | uint64_t index_in_table) { |
| 6810 | uint32_t literal_offset = literal->GetOffset(); |
| 6811 | uintptr_t address = |
| 6812 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6813 | uint8_t* data = code + literal_offset; |
| 6814 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6815 | } |
| 6816 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6817 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6818 | for (const auto& entry : jit_string_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6819 | const StringReference& string_reference = entry.first; |
| 6820 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6821 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6822 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6823 | } |
| 6824 | for (const auto& entry : jit_class_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6825 | const TypeReference& type_reference = entry.first; |
| 6826 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6827 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6828 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6829 | } |
| 6830 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6831 | |
| Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6832 | #undef __ |
| 6833 | #undef QUICK_ENTRY_POINT |
| 6834 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6835 | #define __ assembler.GetVIXLAssembler()-> |
| 6836 | |
| 6837 | static void EmitGrayCheckAndFastPath(arm64::Arm64Assembler& assembler, |
| 6838 | vixl::aarch64::Register base_reg, |
| 6839 | vixl::aarch64::MemOperand& lock_word, |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6840 | vixl::aarch64::Label* slow_path, |
| 6841 | vixl::aarch64::Label* throw_npe = nullptr) { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6842 | // Load the lock word containing the rb_state. |
| 6843 | __ Ldr(ip0.W(), lock_word); |
| 6844 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 6845 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 6846 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 6847 | __ Tbnz(ip0.W(), LockWord::kReadBarrierStateShift, slow_path); |
| 6848 | static_assert( |
| 6849 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET, |
| 6850 | "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] | 6851 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 6852 | if (throw_npe != nullptr) { |
| 6853 | __ Bind(throw_npe); |
| 6854 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6855 | // Adjust the return address back to the LDR (1 instruction; 2 for heap poisoning). |
| 6856 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6857 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6858 | " 2 instructions (8B) for heap poisoning."); |
| 6859 | __ Add(lr, lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6860 | // Introduce a dependency on the lock_word including rb_state, |
| 6861 | // to prevent load-load reordering, and without using |
| 6862 | // a memory barrier (which would be more expensive). |
| 6863 | __ Add(base_reg, base_reg, Operand(ip0, LSR, 32)); |
| 6864 | __ Br(lr); // And return back to the function. |
| 6865 | // Note: The fake dependency is unnecessary for the slow path. |
| 6866 | } |
| 6867 | |
| 6868 | // Load the read barrier introspection entrypoint in register `entrypoint`. |
| 6869 | static void LoadReadBarrierMarkIntrospectionEntrypoint(arm64::Arm64Assembler& assembler, |
| 6870 | vixl::aarch64::Register entrypoint) { |
| 6871 | // entrypoint = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6872 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6873 | const int32_t entry_point_offset = |
| 6874 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6875 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| 6876 | } |
| 6877 | |
| 6878 | void CodeGeneratorARM64::CompileBakerReadBarrierThunk(Arm64Assembler& assembler, |
| 6879 | uint32_t encoded_data, |
| 6880 | /*out*/ std::string* debug_name) { |
| 6881 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 6882 | switch (kind) { |
| 6883 | case BakerReadBarrierKind::kField: { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6884 | auto base_reg = |
| 6885 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6886 | CheckValidReg(base_reg.GetCode()); |
| 6887 | auto holder_reg = |
| 6888 | Register::GetXRegFromCode(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6889 | CheckValidReg(holder_reg.GetCode()); |
| 6890 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6891 | temps.Exclude(ip0, ip1); |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6892 | // If base_reg differs from holder_reg, the offset was too large and we must have emitted |
| 6893 | // an explicit null check before the load. Otherwise, for implicit null checks, we need to |
| 6894 | // null-check the holder as we do not necessarily do that check before going to the thunk. |
| 6895 | vixl::aarch64::Label throw_npe_label; |
| 6896 | vixl::aarch64::Label* throw_npe = nullptr; |
| 6897 | if (GetCompilerOptions().GetImplicitNullChecks() && holder_reg.Is(base_reg)) { |
| 6898 | throw_npe = &throw_npe_label; |
| 6899 | __ Cbz(holder_reg.W(), throw_npe); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6900 | } |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6901 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 6902 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 6903 | // to load the reference and call the entrypoint that performs further checks on the |
| 6904 | // reference and marks it if needed. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6905 | vixl::aarch64::Label slow_path; |
| 6906 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6907 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, throw_npe); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6908 | __ Bind(&slow_path); |
| 6909 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6910 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (immediate) unsigned offset. |
| 6911 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6912 | __ Ubfx(ip0.W(), ip0.W(), 10, 12); // Extract the offset. |
| 6913 | __ Ldr(ip0.W(), MemOperand(base_reg, ip0, LSL, 2)); // Load the reference. |
| 6914 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 6915 | __ Br(ip1); // Jump to the entrypoint. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6916 | break; |
| 6917 | } |
| 6918 | case BakerReadBarrierKind::kArray: { |
| 6919 | auto base_reg = |
| 6920 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6921 | CheckValidReg(base_reg.GetCode()); |
| 6922 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6923 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6924 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6925 | temps.Exclude(ip0, ip1); |
| 6926 | vixl::aarch64::Label slow_path; |
| 6927 | int32_t data_offset = |
| 6928 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 6929 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 6930 | DCHECK_LT(lock_word.GetOffset(), 0); |
| 6931 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path); |
| 6932 | __ Bind(&slow_path); |
| 6933 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| 6934 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (register) unsigned offset. |
| 6935 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6936 | __ Ubfx(ip0, ip0, 16, 6); // Extract the index register, plus 32 (bit 21 is set). |
| 6937 | __ Bfi(ip1, ip0, 3, 6); // Insert ip0 to the entrypoint address to create |
| 6938 | // a switch case target based on the index register. |
| 6939 | __ Mov(ip0, base_reg); // Move the base register to ip0. |
| 6940 | __ Br(ip1); // Jump to the entrypoint's array switch case. |
| 6941 | break; |
| 6942 | } |
| 6943 | case BakerReadBarrierKind::kGcRoot: { |
| 6944 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 6945 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 6946 | // otherwise return the reference (or the extracted forwarding address). |
| 6947 | // There is no gray bit check for GC roots. |
| 6948 | auto root_reg = |
| 6949 | Register::GetWRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6950 | CheckValidReg(root_reg.GetCode()); |
| 6951 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6952 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6953 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6954 | temps.Exclude(ip0, ip1); |
| 6955 | vixl::aarch64::Label return_label, not_marked, forwarding_address; |
| 6956 | __ Cbz(root_reg, &return_label); |
| 6957 | MemOperand lock_word(root_reg.X(), mirror::Object::MonitorOffset().Int32Value()); |
| 6958 | __ Ldr(ip0.W(), lock_word); |
| 6959 | __ Tbz(ip0.W(), LockWord::kMarkBitStateShift, ¬_marked); |
| 6960 | __ Bind(&return_label); |
| 6961 | __ Br(lr); |
| 6962 | __ Bind(¬_marked); |
| 6963 | __ Tst(ip0.W(), Operand(ip0.W(), LSL, 1)); |
| 6964 | __ B(&forwarding_address, mi); |
| 6965 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6966 | // Adjust the art_quick_read_barrier_mark_introspection address in IP1 to |
| 6967 | // art_quick_read_barrier_mark_introspection_gc_roots. |
| 6968 | __ Add(ip1, ip1, Operand(BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET)); |
| 6969 | __ Mov(ip0.W(), root_reg); |
| 6970 | __ Br(ip1); |
| 6971 | __ Bind(&forwarding_address); |
| 6972 | __ Lsl(root_reg, ip0.W(), LockWord::kForwardingAddressShift); |
| 6973 | __ Br(lr); |
| 6974 | break; |
| 6975 | } |
| 6976 | default: |
| 6977 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 6978 | UNREACHABLE(); |
| 6979 | } |
| 6980 | |
| 6981 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 6982 | std::ostringstream oss; |
| 6983 | oss << "BakerReadBarrierThunk"; |
| 6984 | switch (kind) { |
| 6985 | case BakerReadBarrierKind::kField: |
| 6986 | oss << "Field_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 6987 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 6988 | break; |
| 6989 | case BakerReadBarrierKind::kArray: |
| 6990 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6991 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6992 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6993 | break; |
| 6994 | case BakerReadBarrierKind::kGcRoot: |
| 6995 | oss << "GcRoot_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6996 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6997 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6998 | break; |
| 6999 | } |
| 7000 | *debug_name = oss.str(); |
| 7001 | } |
| 7002 | } |
| 7003 | |
| 7004 | #undef __ |
| 7005 | |
| Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 7006 | } // namespace arm64 |
| 7007 | } // namespace art |