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" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 30 | #include "heap_poisoning.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 31 | #include "intrinsics.h" |
| 32 | #include "intrinsics_arm64.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 33 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 34 | #include "lock_word.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 35 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 36 | #include "mirror/class-inl.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 37 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 38 | #include "thread.h" |
| 39 | #include "utils/arm64/assembler_arm64.h" |
| 40 | #include "utils/assembler.h" |
| 41 | #include "utils/stack_checks.h" |
| 42 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 43 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 44 | using vixl::ExactAssemblyScope; |
| 45 | using vixl::CodeBufferCheckScope; |
| 46 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 47 | |
| 48 | #ifdef __ |
| 49 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 50 | #endif |
| 51 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 52 | namespace art { |
| 53 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 54 | template<class MirrorType> |
| 55 | class GcRoot; |
| 56 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 57 | namespace arm64 { |
| 58 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 59 | using helpers::ARM64EncodableConstantOrRegister; |
| 60 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 61 | using helpers::CPURegisterFrom; |
| 62 | using helpers::DRegisterFrom; |
| 63 | using helpers::FPRegisterFrom; |
| 64 | using helpers::HeapOperand; |
| 65 | using helpers::HeapOperandFrom; |
| 66 | using helpers::InputCPURegisterAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 67 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 68 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 70 | using helpers::InputRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 71 | using helpers::Int64ConstantFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 72 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 73 | using helpers::LocationFrom; |
| 74 | using helpers::OperandFromMemOperand; |
| 75 | using helpers::OutputCPURegister; |
| 76 | using helpers::OutputFPRegister; |
| 77 | using helpers::OutputRegister; |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 78 | using helpers::QRegisterFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 79 | using helpers::RegisterFrom; |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 80 | using helpers::SRegisterFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 81 | using helpers::StackOperandFrom; |
| 82 | using helpers::VIXLRegCodeFromART; |
| 83 | using helpers::WRegisterFrom; |
| 84 | using helpers::XRegisterFrom; |
| 85 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 86 | // The compare/jump sequence will generate about (1.5 * num_entries + 3) instructions. While jump |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 87 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 88 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 89 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 90 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 91 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 92 | // offset < 16KiB. For offsets >= 16KiB, the load shall be emitted as two or more instructions. |
| 93 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 94 | // the offset explicitly. |
| 95 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 96 | |
| 97 | // 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] | 98 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 99 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 100 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 101 | |
| 102 | // Some instructions have special requirements for a temporary, for example |
| 103 | // LoadClass/kBssEntry and LoadString/kBssEntry for Baker read barrier require |
| 104 | // temp that's not an R0 (to avoid an extra move) and Baker read barrier field |
| 105 | // loads with large offsets need a fixed register to limit the number of link-time |
| 106 | // thunks we generate. For these and similar cases, we want to reserve a specific |
| 107 | // register that's neither callee-save nor an argument register. We choose x15. |
| 108 | inline Location FixedTempLocation() { |
| 109 | return Location::RegisterLocation(x15.GetCode()); |
| 110 | } |
| 111 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 112 | inline Condition ARM64Condition(IfCondition cond) { |
| 113 | switch (cond) { |
| 114 | case kCondEQ: return eq; |
| 115 | case kCondNE: return ne; |
| 116 | case kCondLT: return lt; |
| 117 | case kCondLE: return le; |
| 118 | case kCondGT: return gt; |
| 119 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 120 | case kCondB: return lo; |
| 121 | case kCondBE: return ls; |
| 122 | case kCondA: return hi; |
| 123 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 124 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 125 | LOG(FATAL) << "Unreachable"; |
| 126 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 127 | } |
| 128 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 129 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 130 | // The ARM64 condition codes can express all the necessary branches, see the |
| 131 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 132 | // There is no dex instruction or HIR that would need the missing conditions |
| 133 | // "equal or unordered" or "not equal". |
| 134 | switch (cond) { |
| 135 | case kCondEQ: return eq; |
| 136 | case kCondNE: return ne /* unordered */; |
| 137 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 138 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 139 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 140 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 141 | default: |
| 142 | LOG(FATAL) << "UNREACHABLE"; |
| 143 | UNREACHABLE(); |
| 144 | } |
| 145 | } |
| 146 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 147 | Location ARM64ReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 148 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 149 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 150 | // but we use the exact registers for clarity. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 151 | if (return_type == DataType::Type::kFloat32) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 152 | return LocationFrom(s0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 153 | } else if (return_type == DataType::Type::kFloat64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 154 | return LocationFrom(d0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 155 | } else if (return_type == DataType::Type::kInt64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 156 | return LocationFrom(x0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 157 | } else if (return_type == DataType::Type::kVoid) { |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 158 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 159 | } else { |
| 160 | return LocationFrom(w0); |
| 161 | } |
| 162 | } |
| 163 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 164 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 165 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 166 | } |
| 167 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 168 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 169 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 170 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 171 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 172 | // Calculate memory accessing operand for save/restore live registers. |
| 173 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 174 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 175 | int64_t spill_offset, |
| 176 | bool is_save) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 177 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 178 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 179 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 180 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 181 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 182 | codegen->GetNumberOfFloatingPointRegisters())); |
| 183 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 184 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 185 | unsigned v_reg_size = codegen->GetGraph()->HasSIMD() ? kQRegSize : kDRegSize; |
| 186 | CPURegList fp_list = CPURegList(CPURegister::kVRegister, v_reg_size, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 187 | |
| 188 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 189 | UseScratchRegisterScope temps(masm); |
| 190 | |
| 191 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 192 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 193 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 194 | int64_t reg_size = kXRegSizeInBytes; |
| 195 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 196 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 197 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 198 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 199 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 200 | // to compute the base address(float point registers spill base address). |
| 201 | Register new_base = temps.AcquireSameSizeAs(base); |
| 202 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 203 | base = new_base; |
| 204 | spill_offset = -core_spill_size; |
| 205 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 206 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 207 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 208 | } |
| 209 | |
| 210 | if (is_save) { |
| 211 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 212 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 213 | } else { |
| 214 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 215 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 220 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 221 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 222 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 223 | // If the register holds an object, update the stack mask. |
| 224 | if (locations->RegisterContainsObject(i)) { |
| 225 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 226 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 227 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 228 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 229 | saved_core_stack_offsets_[i] = stack_offset; |
| 230 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 231 | } |
| 232 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 233 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 234 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 235 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 236 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 237 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 238 | stack_offset += kDRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 239 | } |
| 240 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 241 | SaveRestoreLiveRegistersHelper(codegen, |
| 242 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 243 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 244 | } |
| 245 | |
| 246 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 247 | SaveRestoreLiveRegistersHelper(codegen, |
| 248 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 249 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 250 | } |
| 251 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 252 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 253 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 254 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 255 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 256 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 257 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 258 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 259 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 260 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 261 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 262 | // Live registers will be restored in the catch block if caught. |
| 263 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 264 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 265 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 266 | // move resolver. |
| 267 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 268 | codegen->EmitParallelMoves(locations->InAt(0), |
| 269 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 270 | DataType::Type::kInt32, |
| 271 | locations->InAt(1), |
| 272 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 273 | DataType::Type::kInt32); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 274 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 275 | ? kQuickThrowStringBounds |
| 276 | : kQuickThrowArrayBounds; |
| 277 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 278 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 279 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 280 | } |
| 281 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 282 | bool IsFatal() const OVERRIDE { return true; } |
| 283 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 284 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 285 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 286 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 287 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 288 | }; |
| 289 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 290 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 291 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 292 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 293 | |
| 294 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 295 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 296 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 297 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 298 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 301 | bool IsFatal() const OVERRIDE { return true; } |
| 302 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 303 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 304 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 305 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 306 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 307 | }; |
| 308 | |
| 309 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 310 | public: |
| 311 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 312 | HInstruction* at, |
| 313 | uint32_t dex_pc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 314 | bool do_clinit) |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 315 | : SlowPathCodeARM64(at), |
| 316 | cls_(cls), |
| 317 | dex_pc_(dex_pc), |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 318 | do_clinit_(do_clinit) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 319 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 320 | } |
| 321 | |
| 322 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 323 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 324 | Location out = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 325 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 326 | |
| 327 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 328 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 329 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 330 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 331 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 332 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 333 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 334 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 335 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 336 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 337 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 338 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 339 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 340 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 341 | |
| 342 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 343 | if (out.IsValid()) { |
| 344 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 345 | DataType::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 346 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 347 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 348 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 349 | __ B(GetExitLabel()); |
| 350 | } |
| 351 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 352 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 353 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 354 | private: |
| 355 | // The class this slow path will load. |
| 356 | HLoadClass* const cls_; |
| 357 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 358 | // The dex PC of `at_`. |
| 359 | const uint32_t dex_pc_; |
| 360 | |
| 361 | // Whether to initialize the class. |
| 362 | const bool do_clinit_; |
| 363 | |
| 364 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 365 | }; |
| 366 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 367 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 368 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 369 | explicit LoadStringSlowPathARM64(HLoadString* instruction) |
| 370 | : SlowPathCodeARM64(instruction) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 371 | |
| 372 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 373 | LocationSummary* locations = instruction_->GetLocations(); |
| 374 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 375 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 376 | |
| 377 | __ Bind(GetEntryLabel()); |
| 378 | SaveLiveRegisters(codegen, locations); |
| 379 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 380 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 381 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 382 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 383 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 384 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 385 | DataType::Type type = instruction_->GetType(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 386 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 387 | |
| 388 | RestoreLiveRegisters(codegen, locations); |
| 389 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 390 | __ B(GetExitLabel()); |
| 391 | } |
| 392 | |
| 393 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 394 | |
| 395 | private: |
| 396 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 397 | }; |
| 398 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 399 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 400 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 401 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 402 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 403 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 404 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 405 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 406 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 407 | // Live registers will be restored in the catch block if caught. |
| 408 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 409 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 410 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 411 | instruction_, |
| 412 | instruction_->GetDexPc(), |
| 413 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 414 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 415 | } |
| 416 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 417 | bool IsFatal() const OVERRIDE { return true; } |
| 418 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 419 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 420 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 421 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 422 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 423 | }; |
| 424 | |
| 425 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 426 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 427 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 428 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 429 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 430 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 431 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 432 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 433 | __ Bind(GetEntryLabel()); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 434 | SaveLiveRegisters(codegen, locations); // Only saves live 128-bit regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 435 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 436 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 437 | RestoreLiveRegisters(codegen, locations); // Only restores live 128-bit regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 438 | if (successor_ == nullptr) { |
| 439 | __ B(GetReturnLabel()); |
| 440 | } else { |
| 441 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 442 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 443 | } |
| 444 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 445 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 446 | DCHECK(successor_ == nullptr); |
| 447 | return &return_label_; |
| 448 | } |
| 449 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 450 | HBasicBlock* GetSuccessor() const { |
| 451 | return successor_; |
| 452 | } |
| 453 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 454 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 455 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 456 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 457 | // If not null, the block to branch to after the suspend check. |
| 458 | HBasicBlock* const successor_; |
| 459 | |
| 460 | // 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] | 461 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 462 | |
| 463 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 464 | }; |
| 465 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 466 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 467 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 468 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 469 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 470 | |
| 471 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 472 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 473 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 474 | DCHECK(instruction_->IsCheckCast() |
| 475 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 476 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 477 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 478 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 479 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 480 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 481 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 482 | SaveLiveRegisters(codegen, locations); |
| 483 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 484 | |
| 485 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 486 | // move resolver. |
| 487 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 488 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 489 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 490 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 491 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 492 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 493 | DataType::Type::kReference); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 494 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 495 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 496 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 497 | DataType::Type ret_type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 498 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 499 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 500 | } else { |
| 501 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 502 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 503 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 506 | if (!is_fatal_) { |
| 507 | RestoreLiveRegisters(codegen, locations); |
| 508 | __ B(GetExitLabel()); |
| 509 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 512 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 513 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 514 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 515 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 516 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 517 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 518 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 519 | }; |
| 520 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 521 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 522 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 523 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 524 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 525 | |
| 526 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 527 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 528 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 529 | LocationSummary* locations = instruction_->GetLocations(); |
| 530 | SaveLiveRegisters(codegen, locations); |
| 531 | InvokeRuntimeCallingConvention calling_convention; |
| 532 | __ Mov(calling_convention.GetRegisterAt(0), |
| 533 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 534 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 535 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 538 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 539 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 540 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 541 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 542 | }; |
| 543 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 544 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 545 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 546 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 547 | |
| 548 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 549 | LocationSummary* locations = instruction_->GetLocations(); |
| 550 | __ Bind(GetEntryLabel()); |
| 551 | SaveLiveRegisters(codegen, locations); |
| 552 | |
| 553 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 554 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 555 | parallel_move.AddMove( |
| 556 | locations->InAt(0), |
| 557 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 558 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 559 | nullptr); |
| 560 | parallel_move.AddMove( |
| 561 | locations->InAt(1), |
| 562 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 563 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 564 | nullptr); |
| 565 | parallel_move.AddMove( |
| 566 | locations->InAt(2), |
| 567 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 568 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 569 | nullptr); |
| 570 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 571 | |
| 572 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 573 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 574 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 575 | RestoreLiveRegisters(codegen, locations); |
| 576 | __ B(GetExitLabel()); |
| 577 | } |
| 578 | |
| 579 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 580 | |
| 581 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 582 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 583 | }; |
| 584 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 585 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 586 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 587 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 588 | |
| 589 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 590 | // 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] | 591 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 592 | num_entries * sizeof(int32_t), |
| 593 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 594 | |
| 595 | __ Bind(&table_start_); |
| 596 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 597 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 598 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 599 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 600 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 601 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 602 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 603 | Literal<int32_t> literal(jump_offset); |
| 604 | __ place(&literal); |
| 605 | } |
| 606 | } |
| 607 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 608 | // Abstract base class for read barrier slow paths marking a reference |
| 609 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 610 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 611 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 612 | // barrier marking runtime entry point to be invoked or an empty |
| 613 | // location; in the latter case, the read barrier marking runtime |
| 614 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 615 | class ReadBarrierMarkSlowPathBaseARM64 : public SlowPathCodeARM64 { |
| 616 | protected: |
| 617 | ReadBarrierMarkSlowPathBaseARM64(HInstruction* instruction, Location ref, Location entrypoint) |
| 618 | : SlowPathCodeARM64(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 619 | DCHECK(kEmitCompilerReadBarrier); |
| 620 | } |
| 621 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 622 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM64"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 623 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 624 | // Generate assembly code calling the read barrier marking runtime |
| 625 | // entry point (ReadBarrierMarkRegX). |
| 626 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 627 | // No need to save live registers; it's taken care of by the |
| 628 | // entrypoint. Also, there is no need to update the stack mask, |
| 629 | // as this runtime call will not trigger a garbage collection. |
| 630 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 631 | DCHECK_NE(ref_.reg(), LR); |
| 632 | DCHECK_NE(ref_.reg(), WSP); |
| 633 | DCHECK_NE(ref_.reg(), WZR); |
| 634 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 635 | // as a temporary, it cannot be the entry point's input/output. |
| 636 | DCHECK_NE(ref_.reg(), IP0); |
| 637 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 638 | // "Compact" slow path, saving two moves. |
| 639 | // |
| 640 | // Instead of using the standard runtime calling convention (input |
| 641 | // and output in W0): |
| 642 | // |
| 643 | // W0 <- ref |
| 644 | // W0 <- ReadBarrierMark(W0) |
| 645 | // ref <- W0 |
| 646 | // |
| 647 | // we just use rX (the register containing `ref`) as input and output |
| 648 | // of a dedicated entrypoint: |
| 649 | // |
| 650 | // rX <- ReadBarrierMarkRegX(rX) |
| 651 | // |
| 652 | if (entrypoint_.IsValid()) { |
| 653 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 654 | __ Blr(XRegisterFrom(entrypoint_)); |
| 655 | } else { |
| 656 | // Entrypoint is not already loaded, load from the thread. |
| 657 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 658 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 659 | // This runtime call does not require a stack map. |
| 660 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | // The location (register) of the marked object reference. |
| 665 | const Location ref_; |
| 666 | |
| 667 | // The location of the entrypoint if it is already loaded. |
| 668 | const Location entrypoint_; |
| 669 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 670 | private: |
| 671 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM64); |
| 672 | }; |
| 673 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 674 | // Slow path marking an object reference `ref` during a read |
| 675 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 676 | // reference does not get updated by this slow path after marking. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 677 | // |
| 678 | // This means that after the execution of this slow path, `ref` will |
| 679 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 680 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 681 | // probably still be a from-space reference (unless it gets updated by |
| 682 | // another thread, or if another thread installed another object |
| 683 | // reference (different from `ref`) in `obj.field`). |
| 684 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 685 | // Argument `entrypoint` must be a register location holding the read |
| 686 | // barrier marking runtime entry point to be invoked or an empty |
| 687 | // location; in the latter case, the read barrier marking runtime |
| 688 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 689 | class ReadBarrierMarkSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 690 | public: |
| 691 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 692 | Location ref, |
| 693 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 694 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 695 | DCHECK(kEmitCompilerReadBarrier); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 699 | |
| 700 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 701 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 702 | DCHECK(locations->CanCall()); |
| 703 | DCHECK(ref_.IsRegister()) << ref_; |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 704 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 705 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 706 | << "Unexpected instruction in read barrier marking slow path: " |
| 707 | << instruction_->DebugName(); |
| 708 | |
| 709 | __ Bind(GetEntryLabel()); |
| 710 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 711 | __ B(GetExitLabel()); |
| 712 | } |
| 713 | |
| 714 | private: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 715 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 716 | }; |
| 717 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 718 | // Slow path loading `obj`'s lock word, loading a reference from |
| 719 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 720 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 721 | // read barrier). The field `obj.field` in the object `obj` holding |
| 722 | // this reference does not get updated by this slow path after marking |
| 723 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 724 | // below for that). |
| 725 | // |
| 726 | // This means that after the execution of this slow path, `ref` will |
| 727 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 728 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 729 | // probably still be a from-space reference (unless it gets updated by |
| 730 | // another thread, or if another thread installed another object |
| 731 | // reference (different from `ref`) in `obj.field`). |
| 732 | // |
| 733 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 734 | // barrier marking runtime entry point to be invoked or an empty |
| 735 | // location; in the latter case, the read barrier marking runtime |
| 736 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 737 | class LoadReferenceWithBakerReadBarrierSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
| 738 | public: |
| 739 | LoadReferenceWithBakerReadBarrierSlowPathARM64(HInstruction* instruction, |
| 740 | Location ref, |
| 741 | Register obj, |
| 742 | uint32_t offset, |
| 743 | Location index, |
| 744 | size_t scale_factor, |
| 745 | bool needs_null_check, |
| 746 | bool use_load_acquire, |
| 747 | Register temp, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 748 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 749 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
| 750 | obj_(obj), |
| 751 | offset_(offset), |
| 752 | index_(index), |
| 753 | scale_factor_(scale_factor), |
| 754 | needs_null_check_(needs_null_check), |
| 755 | use_load_acquire_(use_load_acquire), |
| 756 | temp_(temp) { |
| 757 | DCHECK(kEmitCompilerReadBarrier); |
| 758 | DCHECK(kUseBakerReadBarrier); |
| 759 | } |
| 760 | |
| 761 | const char* GetDescription() const OVERRIDE { |
| 762 | return "LoadReferenceWithBakerReadBarrierSlowPathARM64"; |
| 763 | } |
| 764 | |
| 765 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 766 | LocationSummary* locations = instruction_->GetLocations(); |
| 767 | DCHECK(locations->CanCall()); |
| 768 | DCHECK(ref_.IsRegister()) << ref_; |
| 769 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 770 | DCHECK(obj_.IsW()); |
| 771 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 772 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 773 | instruction_->IsStaticFieldGet() || |
| 774 | instruction_->IsArrayGet() || |
| 775 | instruction_->IsArraySet() || |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 776 | instruction_->IsInstanceOf() || |
| 777 | instruction_->IsCheckCast() || |
| 778 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 779 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 780 | << "Unexpected instruction in read barrier marking slow path: " |
| 781 | << instruction_->DebugName(); |
| 782 | // The read barrier instrumentation of object ArrayGet |
| 783 | // instructions does not support the HIntermediateAddress |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 784 | // instruction. |
| 785 | DCHECK(!(instruction_->IsArrayGet() && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 786 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 787 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 788 | // Temporary register `temp_`, used to store the lock word, must |
| 789 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 790 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 791 | // need the lock word to still be in `temp_` after the reference |
| 792 | // load. |
| 793 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 794 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
| 795 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 796 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 797 | |
| 798 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 799 | // inserted after the original load. However, in fast path based |
| 800 | // Baker's read barriers, we need to perform the load of |
| 801 | // mirror::Object::monitor_ *before* the original reference load. |
| 802 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 803 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 804 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 805 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 806 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 807 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 808 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 809 | // if (is_gray) { |
| 810 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 811 | // } |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 812 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 813 | // Note: the original implementation in ReadBarrier::Barrier is |
| 814 | // slightly more complex as it performs additional checks that we do |
| 815 | // not do here for performance reasons. |
| 816 | |
| 817 | // /* int32_t */ monitor = obj->monitor_ |
| 818 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 819 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 820 | if (needs_null_check_) { |
| 821 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 822 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 823 | // /* LockWord */ lock_word = LockWord(monitor) |
| 824 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 825 | "art::LockWord and int32_t have different sizes."); |
| 826 | |
| 827 | // Introduce a dependency on the lock_word including rb_state, |
| 828 | // to prevent load-load reordering, and without using |
| 829 | // a memory barrier (which would be more expensive). |
| 830 | // `obj` is unchanged by this operation, but its value now depends |
| 831 | // on `temp`. |
| 832 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 833 | |
| 834 | // The actual reference load. |
| 835 | // A possible implicit null check has already been handled above. |
| 836 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 837 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 838 | ref_, |
| 839 | obj_, |
| 840 | offset_, |
| 841 | index_, |
| 842 | scale_factor_, |
| 843 | /* needs_null_check */ false, |
| 844 | use_load_acquire_); |
| 845 | |
| 846 | // Mark the object `ref` when `obj` is gray. |
| 847 | // |
| 848 | // if (rb_state == ReadBarrier::GrayState()) |
| 849 | // ref = ReadBarrier::Mark(ref); |
| 850 | // |
| 851 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 852 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 853 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 854 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 855 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 856 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 857 | __ B(GetExitLabel()); |
| 858 | } |
| 859 | |
| 860 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 861 | // The register containing the object holding the marked object reference field. |
| 862 | Register obj_; |
| 863 | // The offset, index and scale factor to access the reference in `obj_`. |
| 864 | uint32_t offset_; |
| 865 | Location index_; |
| 866 | size_t scale_factor_; |
| 867 | // Is a null check required? |
| 868 | bool needs_null_check_; |
| 869 | // Should this reference load use Load-Acquire semantics? |
| 870 | bool use_load_acquire_; |
| 871 | // A temporary register used to hold the lock word of `obj_`. |
| 872 | Register temp_; |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 873 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 874 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM64); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 875 | }; |
| 876 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 877 | // Slow path loading `obj`'s lock word, loading a reference from |
| 878 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 879 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 880 | // read barrier). If needed, this slow path also atomically updates |
| 881 | // the field `obj.field` in the object `obj` holding this reference |
| 882 | // after marking (contrary to |
| 883 | // LoadReferenceWithBakerReadBarrierSlowPathARM64 above, which never |
| 884 | // tries to update `obj.field`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 885 | // |
| 886 | // This means that after the execution of this slow path, both `ref` |
| 887 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 888 | // hold the same to-space reference (unless another thread installed |
| 889 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 890 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 891 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 892 | // barrier marking runtime entry point to be invoked or an empty |
| 893 | // location; in the latter case, the read barrier marking runtime |
| 894 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 895 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 896 | : public ReadBarrierMarkSlowPathBaseARM64 { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 897 | public: |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 898 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 899 | HInstruction* instruction, |
| 900 | Location ref, |
| 901 | Register obj, |
| 902 | uint32_t offset, |
| 903 | Location index, |
| 904 | size_t scale_factor, |
| 905 | bool needs_null_check, |
| 906 | bool use_load_acquire, |
| 907 | Register temp, |
| 908 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 909 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 910 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 911 | offset_(offset), |
| 912 | index_(index), |
| 913 | scale_factor_(scale_factor), |
| 914 | needs_null_check_(needs_null_check), |
| 915 | use_load_acquire_(use_load_acquire), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 916 | temp_(temp) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 917 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 918 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 922 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64"; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 926 | LocationSummary* locations = instruction_->GetLocations(); |
| 927 | Register ref_reg = WRegisterFrom(ref_); |
| 928 | DCHECK(locations->CanCall()); |
| 929 | DCHECK(ref_.IsRegister()) << ref_; |
| 930 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 931 | DCHECK(obj_.IsW()); |
| 932 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
| 933 | |
| 934 | // 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] | 935 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 936 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 937 | << instruction_->DebugName(); |
| 938 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 939 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 940 | DCHECK_EQ(offset_, 0u); |
| 941 | DCHECK_EQ(scale_factor_, 0u); |
| 942 | DCHECK_EQ(use_load_acquire_, false); |
| 943 | // The location of the offset of the marked reference field within `obj_`. |
| 944 | Location field_offset = index_; |
| 945 | DCHECK(field_offset.IsRegister()) << field_offset; |
| 946 | |
| 947 | // Temporary register `temp_`, used to store the lock word, must |
| 948 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 949 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 950 | // need the lock word to still be in `temp_` after the reference |
| 951 | // load. |
| 952 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 953 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 954 | |
| 955 | __ Bind(GetEntryLabel()); |
| 956 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 957 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM64's: |
| 958 | // |
| 959 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 960 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 961 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 962 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 963 | // if (is_gray) { |
| 964 | // old_ref = ref; |
| 965 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 966 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 967 | // } |
| 968 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 969 | // /* int32_t */ monitor = obj->monitor_ |
| 970 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 971 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 972 | if (needs_null_check_) { |
| 973 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 974 | } |
| 975 | // /* LockWord */ lock_word = LockWord(monitor) |
| 976 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 977 | "art::LockWord and int32_t have different sizes."); |
| 978 | |
| 979 | // Introduce a dependency on the lock_word including rb_state, |
| 980 | // to prevent load-load reordering, and without using |
| 981 | // a memory barrier (which would be more expensive). |
| 982 | // `obj` is unchanged by this operation, but its value now depends |
| 983 | // on `temp`. |
| 984 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 985 | |
| 986 | // The actual reference load. |
| 987 | // A possible implicit null check has already been handled above. |
| 988 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 989 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 990 | ref_, |
| 991 | obj_, |
| 992 | offset_, |
| 993 | index_, |
| 994 | scale_factor_, |
| 995 | /* needs_null_check */ false, |
| 996 | use_load_acquire_); |
| 997 | |
| 998 | // Mark the object `ref` when `obj` is gray. |
| 999 | // |
| 1000 | // if (rb_state == ReadBarrier::GrayState()) |
| 1001 | // ref = ReadBarrier::Mark(ref); |
| 1002 | // |
| 1003 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 1004 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1005 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1006 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 1007 | |
| 1008 | // Save the old value of the reference before marking it. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1009 | // Note that we cannot use IP to save the old reference, as IP is |
| 1010 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1011 | // need the old reference after the call to that entry point. |
| 1012 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1013 | __ Mov(temp_.W(), ref_reg); |
| 1014 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1015 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1016 | |
| 1017 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1018 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1019 | // |
| 1020 | // Note that this field could also hold a different object, if |
| 1021 | // another thread had concurrently changed it. In that case, the |
| 1022 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 1023 | // (CAS) operation below would abort the CAS, leaving the field |
| 1024 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1025 | __ Cmp(temp_.W(), ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1026 | __ B(eq, GetExitLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1027 | |
| 1028 | // Update the the holder's field atomically. This may fail if |
| 1029 | // mutator updates before us, but it's OK. This is achieved |
| 1030 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1031 | // memory synchronization ordering, where the expected value is |
| 1032 | // the old reference and the desired value is the new reference. |
| 1033 | |
| 1034 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 1035 | UseScratchRegisterScope temps(masm); |
| 1036 | |
| 1037 | // Convenience aliases. |
| 1038 | Register base = obj_.W(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1039 | Register offset = XRegisterFrom(field_offset); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1040 | Register expected = temp_.W(); |
| 1041 | Register value = ref_reg; |
| 1042 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1043 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 1044 | |
| 1045 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1046 | |
| 1047 | if (kPoisonHeapReferences) { |
| 1048 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1049 | if (value.Is(expected)) { |
| 1050 | // Do not poison `value`, as it is the same register as |
| 1051 | // `expected`, which has just been poisoned. |
| 1052 | } else { |
| 1053 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | // do { |
| 1058 | // tmp_value = [tmp_ptr] - expected; |
| 1059 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1060 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1061 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1062 | __ Bind(&loop_head); |
| 1063 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 1064 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1065 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1066 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 1067 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1068 | __ B(&exit_loop); |
| 1069 | __ Bind(&comparison_failed); |
| 1070 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1071 | __ Bind(&exit_loop); |
| 1072 | |
| 1073 | if (kPoisonHeapReferences) { |
| 1074 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1075 | if (value.Is(expected)) { |
| 1076 | // Do not unpoison `value`, as it is the same register as |
| 1077 | // `expected`, which has just been unpoisoned. |
| 1078 | } else { |
| 1079 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1080 | } |
| 1081 | } |
| 1082 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1083 | __ B(GetExitLabel()); |
| 1084 | } |
| 1085 | |
| 1086 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1087 | // The register containing the object holding the marked object reference field. |
| 1088 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1089 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1090 | uint32_t offset_; |
| 1091 | Location index_; |
| 1092 | size_t scale_factor_; |
| 1093 | // Is a null check required? |
| 1094 | bool needs_null_check_; |
| 1095 | // Should this reference load use Load-Acquire semantics? |
| 1096 | bool use_load_acquire_; |
| 1097 | // A temporary register used to hold the lock word of `obj_`; and |
| 1098 | // also to hold the original reference value, when the reference is |
| 1099 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1100 | const Register temp_; |
| 1101 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1102 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1103 | }; |
| 1104 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1105 | // Slow path generating a read barrier for a heap reference. |
| 1106 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 1107 | public: |
| 1108 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 1109 | Location out, |
| 1110 | Location ref, |
| 1111 | Location obj, |
| 1112 | uint32_t offset, |
| 1113 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1114 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1115 | out_(out), |
| 1116 | ref_(ref), |
| 1117 | obj_(obj), |
| 1118 | offset_(offset), |
| 1119 | index_(index) { |
| 1120 | DCHECK(kEmitCompilerReadBarrier); |
| 1121 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1122 | // has been overwritten by (or after) the heap object reference load |
| 1123 | // to be instrumented, e.g.: |
| 1124 | // |
| 1125 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1126 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1127 | // |
| 1128 | // In that case, we have lost the information about the original |
| 1129 | // object, and the emitted read barrier cannot work properly. |
| 1130 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1131 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1132 | } |
| 1133 | |
| 1134 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1135 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1136 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1137 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1138 | DCHECK(locations->CanCall()); |
| 1139 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1140 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1141 | instruction_->IsStaticFieldGet() || |
| 1142 | instruction_->IsArrayGet() || |
| 1143 | instruction_->IsInstanceOf() || |
| 1144 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1145 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1146 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1147 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1148 | // The read barrier instrumentation of object ArrayGet |
| 1149 | // instructions does not support the HIntermediateAddress |
| 1150 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1151 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1152 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1153 | |
| 1154 | __ Bind(GetEntryLabel()); |
| 1155 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1156 | SaveLiveRegisters(codegen, locations); |
| 1157 | |
| 1158 | // We may have to change the index's value, but as `index_` is a |
| 1159 | // constant member (like other "inputs" of this slow path), |
| 1160 | // introduce a copy of it, `index`. |
| 1161 | Location index = index_; |
| 1162 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1163 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1164 | if (instruction_->IsArrayGet()) { |
| 1165 | // Compute the actual memory offset and store it in `index`. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1166 | Register index_reg = RegisterFrom(index_, DataType::Type::kInt32); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1167 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 1168 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 1169 | // We are about to change the value of `index_reg` (see the |
| 1170 | // calls to vixl::MacroAssembler::Lsl and |
| 1171 | // vixl::MacroAssembler::Mov below), but it has |
| 1172 | // not been saved by the previous call to |
| 1173 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1174 | // callee-save register -- |
| 1175 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1176 | // callee-save registers, as it has been designed with the |
| 1177 | // assumption that callee-save registers are supposed to be |
| 1178 | // handled by the called function. So, as a callee-save |
| 1179 | // register, `index_reg` _would_ eventually be saved onto |
| 1180 | // the stack, but it would be too late: we would have |
| 1181 | // changed its value earlier. Therefore, we manually save |
| 1182 | // it here into another freely available register, |
| 1183 | // `free_reg`, chosen of course among the caller-save |
| 1184 | // registers (as a callee-save `free_reg` register would |
| 1185 | // exhibit the same problem). |
| 1186 | // |
| 1187 | // Note we could have requested a temporary register from |
| 1188 | // the register allocator instead; but we prefer not to, as |
| 1189 | // this is a slow path, and we know we can find a |
| 1190 | // caller-save register that is available. |
| 1191 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1192 | __ Mov(free_reg.W(), index_reg); |
| 1193 | index_reg = free_reg; |
| 1194 | index = LocationFrom(index_reg); |
| 1195 | } else { |
| 1196 | // The initial register stored in `index_` has already been |
| 1197 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1198 | // (as it is not a callee-save register), so we can freely |
| 1199 | // use it. |
| 1200 | } |
| 1201 | // Shifting the index value contained in `index_reg` by the scale |
| 1202 | // factor (2) cannot overflow in practice, as the runtime is |
| 1203 | // unable to allocate object arrays with a size larger than |
| 1204 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1205 | __ Lsl(index_reg, index_reg, DataType::SizeShift(type)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1206 | static_assert( |
| 1207 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1208 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1209 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1210 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1211 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1212 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1213 | // (as in the case of ArrayGet), as it is actually an offset |
| 1214 | // to an object field within an object. |
| 1215 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1216 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1217 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1218 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1219 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1220 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1221 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | // We're moving two or three locations to locations that could |
| 1226 | // overlap, so we need a parallel move resolver. |
| 1227 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1228 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1229 | parallel_move.AddMove(ref_, |
| 1230 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1231 | type, |
| 1232 | nullptr); |
| 1233 | parallel_move.AddMove(obj_, |
| 1234 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1235 | type, |
| 1236 | nullptr); |
| 1237 | if (index.IsValid()) { |
| 1238 | parallel_move.AddMove(index, |
| 1239 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1240 | DataType::Type::kInt32, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1241 | nullptr); |
| 1242 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1243 | } else { |
| 1244 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1245 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1246 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1247 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1248 | instruction_, |
| 1249 | instruction_->GetDexPc(), |
| 1250 | this); |
| 1251 | CheckEntrypointTypes< |
| 1252 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1253 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1254 | |
| 1255 | RestoreLiveRegisters(codegen, locations); |
| 1256 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1257 | __ B(GetExitLabel()); |
| 1258 | } |
| 1259 | |
| 1260 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1261 | |
| 1262 | private: |
| 1263 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1264 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1265 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1266 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1267 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1268 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1269 | } |
| 1270 | } |
| 1271 | // We shall never fail to find a free caller-save register, as |
| 1272 | // there are more than two core caller-save registers on ARM64 |
| 1273 | // (meaning it is possible to find one which is different from |
| 1274 | // `ref` and `obj`). |
| 1275 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1276 | LOG(FATAL) << "Could not find a free register"; |
| 1277 | UNREACHABLE(); |
| 1278 | } |
| 1279 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1280 | const Location out_; |
| 1281 | const Location ref_; |
| 1282 | const Location obj_; |
| 1283 | const uint32_t offset_; |
| 1284 | // An additional location containing an index to an array. |
| 1285 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1286 | // UnsafeGetObjectVolatile intrinsics. |
| 1287 | const Location index_; |
| 1288 | |
| 1289 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1290 | }; |
| 1291 | |
| 1292 | // Slow path generating a read barrier for a GC root. |
| 1293 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1294 | public: |
| 1295 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1296 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1297 | DCHECK(kEmitCompilerReadBarrier); |
| 1298 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1299 | |
| 1300 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1301 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1302 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1303 | DCHECK(locations->CanCall()); |
| 1304 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1305 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1306 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1307 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1308 | |
| 1309 | __ Bind(GetEntryLabel()); |
| 1310 | SaveLiveRegisters(codegen, locations); |
| 1311 | |
| 1312 | InvokeRuntimeCallingConvention calling_convention; |
| 1313 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1314 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1315 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1316 | // thus we need a 64-bit move here, and we cannot use |
| 1317 | // |
| 1318 | // arm64_codegen->MoveLocation( |
| 1319 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1320 | // root_, |
| 1321 | // type); |
| 1322 | // |
| 1323 | // 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] | 1324 | // reference type (`DataType::Type::kReference`). |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1325 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1326 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1327 | instruction_, |
| 1328 | instruction_->GetDexPc(), |
| 1329 | this); |
| 1330 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1331 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1332 | |
| 1333 | RestoreLiveRegisters(codegen, locations); |
| 1334 | __ B(GetExitLabel()); |
| 1335 | } |
| 1336 | |
| 1337 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1338 | |
| 1339 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1340 | const Location out_; |
| 1341 | const Location root_; |
| 1342 | |
| 1343 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1344 | }; |
| 1345 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1346 | #undef __ |
| 1347 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1348 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1349 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1350 | if (type == DataType::Type::kVoid) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1351 | LOG(FATAL) << "Unreachable type " << type; |
| 1352 | } |
| 1353 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1354 | if (DataType::IsFloatingPointType(type) && |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1355 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1356 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1357 | } else if (!DataType::IsFloatingPointType(type) && |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1358 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 1359 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1360 | } else { |
| 1361 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1362 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1363 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1364 | } |
| 1365 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1366 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1367 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1368 | return next_location; |
| 1369 | } |
| 1370 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1371 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1372 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1373 | } |
| 1374 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1375 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1376 | const Arm64InstructionSetFeatures& isa_features, |
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 | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1393 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1394 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1395 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1396 | uint64_literals_(std::less<uint64_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1397 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1398 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1399 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1400 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1401 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1402 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1403 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1404 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1405 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1406 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1407 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1408 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1409 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1410 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1411 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1412 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1413 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1414 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1415 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1416 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1417 | jump_table->EmitTable(this); |
| 1418 | } |
| 1419 | } |
| 1420 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1421 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1422 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1423 | // Ensure we emit the literal pool. |
| 1424 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1425 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1426 | CodeGenerator::Finalize(allocator); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1427 | |
| 1428 | // Verify Baker read barrier linker patches. |
| 1429 | if (kIsDebugBuild) { |
| 1430 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 1431 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 1432 | DCHECK(info.label.IsBound()); |
| 1433 | uint32_t literal_offset = info.label.GetLocation(); |
| 1434 | DCHECK_ALIGNED(literal_offset, 4u); |
| 1435 | |
| 1436 | auto GetInsn = [&code](uint32_t offset) { |
| 1437 | DCHECK_ALIGNED(offset, 4u); |
| 1438 | return |
| 1439 | (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 1440 | (static_cast<uint32_t>(code[offset + 1]) << 8) + |
| 1441 | (static_cast<uint32_t>(code[offset + 2]) << 16)+ |
| 1442 | (static_cast<uint32_t>(code[offset + 3]) << 24); |
| 1443 | }; |
| 1444 | |
| 1445 | const uint32_t encoded_data = info.custom_data; |
| 1446 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 1447 | // Check that the next instruction matches the expected LDR. |
| 1448 | switch (kind) { |
| 1449 | case BakerReadBarrierKind::kField: { |
| 1450 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1451 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 1452 | // LDR (immediate) with correct base_reg. |
| 1453 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1454 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1455 | CHECK_EQ(next_insn & 0xffc003e0u, 0xb9400000u | (base_reg << 5)); |
| 1456 | break; |
| 1457 | } |
| 1458 | case BakerReadBarrierKind::kArray: { |
| 1459 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1460 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 1461 | // LDR (register) with the correct base_reg, size=10 (32-bit), option=011 (extend = LSL), |
| 1462 | // and S=1 (shift amount = 2 for 32-bit version), i.e. LDR Wt, [Xn, Xm, LSL #2]. |
| 1463 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1464 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1465 | CHECK_EQ(next_insn & 0xffe0ffe0u, 0xb8607800u | (base_reg << 5)); |
| 1466 | CheckValidReg((next_insn >> 16) & 0x1f); // Check index register |
| 1467 | break; |
| 1468 | } |
| 1469 | case BakerReadBarrierKind::kGcRoot: { |
| 1470 | DCHECK_GE(literal_offset, 4u); |
| 1471 | uint32_t prev_insn = GetInsn(literal_offset - 4u); |
| 1472 | // LDR (immediate) with correct root_reg. |
| 1473 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1474 | CHECK_EQ(prev_insn & 0xffc0001fu, 0xb9400000u | root_reg); |
| 1475 | break; |
| 1476 | } |
| 1477 | default: |
| 1478 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 1479 | UNREACHABLE(); |
| 1480 | } |
| 1481 | } |
| 1482 | } |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1485 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1486 | // Note: There are 6 kinds of moves: |
| 1487 | // 1. constant -> GPR/FPR (non-cycle) |
| 1488 | // 2. constant -> stack (non-cycle) |
| 1489 | // 3. GPR/FPR -> GPR/FPR |
| 1490 | // 4. GPR/FPR -> stack |
| 1491 | // 5. stack -> GPR/FPR |
| 1492 | // 6. stack -> stack (non-cycle) |
| 1493 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1494 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1495 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1496 | // dependency. |
| 1497 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1498 | } |
| 1499 | |
| 1500 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1501 | vixl_temps_.Close(); |
| 1502 | } |
| 1503 | |
| 1504 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1505 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1506 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1507 | || kind == Location::kSIMDStackSlot); |
| 1508 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1509 | ? Location::kFpuRegister |
| 1510 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1511 | Location scratch = GetScratchLocation(kind); |
| 1512 | if (!scratch.Equals(Location::NoLocation())) { |
| 1513 | return scratch; |
| 1514 | } |
| 1515 | // Allocate from VIXL temp registers. |
| 1516 | if (kind == Location::kRegister) { |
| 1517 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1518 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1519 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1520 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1521 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1522 | : vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1523 | } |
| 1524 | AddScratchLocation(scratch); |
| 1525 | return scratch; |
| 1526 | } |
| 1527 | |
| 1528 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1529 | if (loc.IsRegister()) { |
| 1530 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1531 | } else { |
| 1532 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1533 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1534 | } |
| 1535 | RemoveScratchLocation(loc); |
| 1536 | } |
| 1537 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1538 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1539 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1540 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1543 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1544 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1545 | __ Bind(&frame_entry_label_); |
| 1546 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1547 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1548 | UseScratchRegisterScope temps(masm); |
| 1549 | Register temp = temps.AcquireX(); |
| 1550 | __ Ldrh(temp, MemOperand(kArtMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1551 | __ Add(temp, temp, 1); |
| 1552 | __ Strh(temp, MemOperand(kArtMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1553 | } |
| 1554 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1555 | bool do_overflow_check = |
| 1556 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1557 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1558 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1559 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1560 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1561 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1562 | { |
| 1563 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1564 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1565 | kInstructionSize, |
| 1566 | CodeBufferCheckScope::kExactSize); |
| 1567 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1568 | RecordPcInfo(nullptr, 0); |
| 1569 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1570 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1571 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1572 | if (!HasEmptyFrame()) { |
| 1573 | int frame_size = GetFrameSize(); |
| 1574 | // Stack layout: |
| 1575 | // sp[frame_size - 8] : lr. |
| 1576 | // ... : other preserved core registers. |
| 1577 | // ... : other preserved fp registers. |
| 1578 | // ... : reserved frame space. |
| 1579 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1580 | |
| 1581 | // Save the current method if we need it. Note that we do not |
| 1582 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1583 | // in the SSA graph. |
| 1584 | if (RequiresCurrentMethod()) { |
| 1585 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1586 | } else { |
| 1587 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1588 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1589 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1590 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1591 | frame_size - GetCoreSpillSize()); |
| 1592 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1593 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1594 | |
| 1595 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1596 | // Initialize should_deoptimize flag to 0. |
| 1597 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1598 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1599 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1600 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 1601 | |
| 1602 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1606 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1607 | if (!HasEmptyFrame()) { |
| 1608 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1609 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1610 | frame_size - FrameEntrySpillSize()); |
| 1611 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1612 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1613 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1614 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1615 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1616 | __ Ret(); |
| 1617 | GetAssembler()->cfi().RestoreState(); |
| 1618 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1619 | } |
| 1620 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1621 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1622 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1623 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1624 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1625 | } |
| 1626 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1627 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1628 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1629 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1630 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1631 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1632 | } |
| 1633 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1634 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1635 | __ Bind(GetLabelOf(block)); |
| 1636 | } |
| 1637 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1638 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1639 | DCHECK(location.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1640 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1641 | } |
| 1642 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1643 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1644 | if (location.IsRegister()) { |
| 1645 | locations->AddTemp(location); |
| 1646 | } else { |
| 1647 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1648 | } |
| 1649 | } |
| 1650 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1651 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1652 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1653 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1654 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1655 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1656 | if (value_can_be_null) { |
| 1657 | __ Cbz(value, &done); |
| 1658 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1659 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1660 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1661 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1662 | if (value_can_be_null) { |
| 1663 | __ Bind(&done); |
| 1664 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1665 | } |
| 1666 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1667 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1668 | // Blocked core registers: |
| 1669 | // lr : Runtime reserved. |
| 1670 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1671 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1672 | // ip1 : VIXL core temp. |
| 1673 | // ip0 : VIXL core temp. |
| 1674 | // |
| 1675 | // Blocked fp registers: |
| 1676 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1677 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1678 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1679 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1680 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1681 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1682 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1683 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1684 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1685 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1686 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1687 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1688 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1689 | // Stubs do not save callee-save floating point registers. If the graph |
| 1690 | // is debuggable, we need to deal with these registers differently. For |
| 1691 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1692 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1693 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1694 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1695 | } |
| 1696 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1697 | } |
| 1698 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1699 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1700 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1701 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1702 | return kArm64WordSize; |
| 1703 | } |
| 1704 | |
| 1705 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1706 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1707 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1708 | return kArm64WordSize; |
| 1709 | } |
| 1710 | |
| 1711 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1712 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1713 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1714 | return kArm64WordSize; |
| 1715 | } |
| 1716 | |
| 1717 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1718 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1719 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1720 | return kArm64WordSize; |
| 1721 | } |
| 1722 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1723 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1724 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1728 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1729 | } |
| 1730 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1731 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1732 | if (constant->IsIntConstant()) { |
| 1733 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1734 | } else if (constant->IsLongConstant()) { |
| 1735 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1736 | } else if (constant->IsNullConstant()) { |
| 1737 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1738 | } else if (constant->IsFloatConstant()) { |
| 1739 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1740 | } else { |
| 1741 | DCHECK(constant->IsDoubleConstant()); |
| 1742 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1743 | } |
| 1744 | } |
| 1745 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1746 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1747 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1748 | DCHECK(constant.IsConstant()); |
| 1749 | HConstant* cst = constant.GetConstant(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1750 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1751 | // 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] | 1752 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1753 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1754 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1755 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1758 | // Allocate a scratch register from the VIXL pool, querying first |
| 1759 | // the floating-point register pool, and then the core register |
| 1760 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1761 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1762 | // using a different allocation strategy. |
| 1763 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1764 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1765 | int size_in_bits) { |
| 1766 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1767 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1768 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1769 | } |
| 1770 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1771 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1772 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1773 | DataType::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1774 | if (source.Equals(destination)) { |
| 1775 | return; |
| 1776 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1777 | |
| 1778 | // A valid move can always be inferred from the destination and source |
| 1779 | // locations. When moving from and to a register, the argument type can be |
| 1780 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1781 | // checks the coherency of the locations and the type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1782 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1783 | |
| 1784 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1785 | if (unspecified_type) { |
| 1786 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1787 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1788 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1789 | || src_cst->IsFloatConstant() |
| 1790 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1791 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1792 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1793 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1794 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1795 | // type is appropriate. Else the source is a register, and since the |
| 1796 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1797 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1798 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1799 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1800 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1801 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1802 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1803 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1804 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1805 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1806 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1807 | } else if (source.IsSIMDStackSlot()) { |
| 1808 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1809 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1810 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1811 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1812 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1813 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1814 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1815 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1816 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1817 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1818 | ? DataType::Type::kInt64 |
| 1819 | : DataType::Type::kInt32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1820 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1821 | } |
| 1822 | } else { |
| 1823 | DCHECK(source.IsFpuRegister()); |
| 1824 | if (destination.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1825 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1826 | ? DataType::Type::kFloat64 |
| 1827 | : DataType::Type::kFloat32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1828 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1829 | } else { |
| 1830 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1831 | if (GetGraph()->HasSIMD()) { |
| 1832 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1833 | } else { |
| 1834 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1835 | } |
| 1836 | } |
| 1837 | } |
| 1838 | } else if (destination.IsSIMDStackSlot()) { |
| 1839 | if (source.IsFpuRegister()) { |
| 1840 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1841 | } else { |
| 1842 | DCHECK(source.IsSIMDStackSlot()); |
| 1843 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1844 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1845 | Register temp = temps.AcquireX(); |
| 1846 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1847 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1848 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1849 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1850 | } else { |
| 1851 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1852 | __ Ldr(temp, StackOperandFrom(source)); |
| 1853 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1854 | } |
| 1855 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1856 | } else { // The destination is not a register. It must be a stack slot. |
| 1857 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1858 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1859 | if (unspecified_type) { |
| 1860 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1861 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1862 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1863 | dst_type = |
| 1864 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1865 | } |
| 1866 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1867 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1868 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1869 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1870 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1871 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1872 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1873 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1874 | HConstant* src_cst = source.GetConstant(); |
| 1875 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1876 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1877 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1878 | ? Register(xzr) |
| 1879 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1880 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1881 | if (src_cst->IsIntConstant()) { |
| 1882 | temp = temps.AcquireW(); |
| 1883 | } else if (src_cst->IsLongConstant()) { |
| 1884 | temp = temps.AcquireX(); |
| 1885 | } else if (src_cst->IsFloatConstant()) { |
| 1886 | temp = temps.AcquireS(); |
| 1887 | } else { |
| 1888 | DCHECK(src_cst->IsDoubleConstant()); |
| 1889 | temp = temps.AcquireD(); |
| 1890 | } |
| 1891 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1892 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1893 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1894 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1895 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1896 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1897 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1898 | // Use any scratch register (a core or a floating-point one) |
| 1899 | // from VIXL scratch register pools as a temporary. |
| 1900 | // |
| 1901 | // We used to only use the FP scratch register pool, but in some |
| 1902 | // rare cases the only register from this pool (D31) would |
| 1903 | // already be used (e.g. within a ParallelMove instruction, when |
| 1904 | // a move is blocked by a another move requiring a scratch FP |
| 1905 | // register, which would reserve D31). To prevent this issue, we |
| 1906 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1907 | // |
| 1908 | // 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] | 1909 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1910 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1911 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1912 | // allocates core scratch registers first. |
| 1913 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1914 | GetVIXLAssembler(), |
| 1915 | &temps, |
| 1916 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1917 | __ Ldr(temp, StackOperandFrom(source)); |
| 1918 | __ Str(temp, StackOperandFrom(destination)); |
| 1919 | } |
| 1920 | } |
| 1921 | } |
| 1922 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1923 | void CodeGeneratorARM64::Load(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1924 | CPURegister dst, |
| 1925 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1926 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1927 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1928 | case DataType::Type::kUint8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1929 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1930 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1931 | case DataType::Type::kInt8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1932 | __ Ldrsb(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::kUint16: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1935 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1936 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1937 | case DataType::Type::kInt16: |
| 1938 | __ Ldrsh(Register(dst), src); |
| 1939 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1940 | case DataType::Type::kInt32: |
| 1941 | case DataType::Type::kReference: |
| 1942 | case DataType::Type::kInt64: |
| 1943 | case DataType::Type::kFloat32: |
| 1944 | case DataType::Type::kFloat64: |
| 1945 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1946 | __ Ldr(dst, src); |
| 1947 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1948 | case DataType::Type::kUint32: |
| 1949 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1950 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1951 | LOG(FATAL) << "Unreachable type " << type; |
| 1952 | } |
| 1953 | } |
| 1954 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1955 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1956 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1957 | const MemOperand& src, |
| 1958 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1959 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1960 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1961 | Register temp_base = temps.AcquireX(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1962 | DataType::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1963 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1964 | DCHECK(!src.IsPreIndex()); |
| 1965 | DCHECK(!src.IsPostIndex()); |
| 1966 | |
| 1967 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1968 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1969 | { |
| 1970 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1971 | MemOperand base = MemOperand(temp_base); |
| 1972 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1973 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1974 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1975 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1976 | { |
| 1977 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1978 | __ ldarb(Register(dst), base); |
| 1979 | if (needs_null_check) { |
| 1980 | MaybeRecordImplicitNullCheck(instruction); |
| 1981 | } |
| 1982 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1983 | if (type == DataType::Type::kInt8) { |
| 1984 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1985 | } |
| 1986 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1987 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1988 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1989 | { |
| 1990 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1991 | __ ldarh(Register(dst), base); |
| 1992 | if (needs_null_check) { |
| 1993 | MaybeRecordImplicitNullCheck(instruction); |
| 1994 | } |
| 1995 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1996 | if (type == DataType::Type::kInt16) { |
| 1997 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 1998 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1999 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2000 | case DataType::Type::kInt32: |
| 2001 | case DataType::Type::kReference: |
| 2002 | case DataType::Type::kInt64: |
| 2003 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2004 | { |
| 2005 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2006 | __ ldar(Register(dst), base); |
| 2007 | if (needs_null_check) { |
| 2008 | MaybeRecordImplicitNullCheck(instruction); |
| 2009 | } |
| 2010 | } |
| 2011 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2012 | case DataType::Type::kFloat32: |
| 2013 | case DataType::Type::kFloat64: { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2014 | DCHECK(dst.IsFPRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2015 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2016 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2017 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2018 | { |
| 2019 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2020 | __ ldar(temp, base); |
| 2021 | if (needs_null_check) { |
| 2022 | MaybeRecordImplicitNullCheck(instruction); |
| 2023 | } |
| 2024 | } |
| 2025 | __ Fmov(FPRegister(dst), temp); |
| 2026 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2027 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2028 | case DataType::Type::kUint32: |
| 2029 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2030 | case DataType::Type::kVoid: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2031 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2032 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2033 | } |
| 2034 | } |
| 2035 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2036 | void CodeGeneratorARM64::Store(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2037 | CPURegister src, |
| 2038 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2039 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2040 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2041 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2042 | case DataType::Type::kInt8: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2043 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2044 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2045 | case DataType::Type::kUint16: |
| 2046 | case DataType::Type::kInt16: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2047 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2048 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2049 | case DataType::Type::kInt32: |
| 2050 | case DataType::Type::kReference: |
| 2051 | case DataType::Type::kInt64: |
| 2052 | case DataType::Type::kFloat32: |
| 2053 | case DataType::Type::kFloat64: |
| 2054 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2055 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2056 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2057 | case DataType::Type::kUint32: |
| 2058 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2059 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2060 | LOG(FATAL) << "Unreachable type " << type; |
| 2061 | } |
| 2062 | } |
| 2063 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2064 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2065 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2066 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2067 | const MemOperand& dst, |
| 2068 | bool needs_null_check) { |
| 2069 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2070 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2071 | Register temp_base = temps.AcquireX(); |
| 2072 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2073 | DCHECK(!dst.IsPreIndex()); |
| 2074 | DCHECK(!dst.IsPostIndex()); |
| 2075 | |
| 2076 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2077 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2078 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2079 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2080 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2081 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2082 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2083 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2084 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2085 | { |
| 2086 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2087 | __ stlrb(Register(src), base); |
| 2088 | if (needs_null_check) { |
| 2089 | MaybeRecordImplicitNullCheck(instruction); |
| 2090 | } |
| 2091 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2092 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2093 | case DataType::Type::kUint16: |
| 2094 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2095 | { |
| 2096 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2097 | __ stlrh(Register(src), base); |
| 2098 | if (needs_null_check) { |
| 2099 | MaybeRecordImplicitNullCheck(instruction); |
| 2100 | } |
| 2101 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2102 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2103 | case DataType::Type::kInt32: |
| 2104 | case DataType::Type::kReference: |
| 2105 | case DataType::Type::kInt64: |
| 2106 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2107 | { |
| 2108 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2109 | __ stlr(Register(src), base); |
| 2110 | if (needs_null_check) { |
| 2111 | MaybeRecordImplicitNullCheck(instruction); |
| 2112 | } |
| 2113 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2114 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2115 | case DataType::Type::kFloat32: |
| 2116 | case DataType::Type::kFloat64: { |
| 2117 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2118 | Register temp_src; |
| 2119 | if (src.IsZero()) { |
| 2120 | // The zero register is used to avoid synthesizing zero constants. |
| 2121 | temp_src = Register(src); |
| 2122 | } else { |
| 2123 | DCHECK(src.IsFPRegister()); |
| 2124 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2125 | __ Fmov(temp_src, FPRegister(src)); |
| 2126 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2127 | { |
| 2128 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2129 | __ stlr(temp_src, base); |
| 2130 | if (needs_null_check) { |
| 2131 | MaybeRecordImplicitNullCheck(instruction); |
| 2132 | } |
| 2133 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2134 | break; |
| 2135 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2136 | case DataType::Type::kUint32: |
| 2137 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2138 | case DataType::Type::kVoid: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2139 | LOG(FATAL) << "Unreachable type " << type; |
| 2140 | } |
| 2141 | } |
| 2142 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2143 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2144 | HInstruction* instruction, |
| 2145 | uint32_t dex_pc, |
| 2146 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2147 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2148 | |
| 2149 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 2150 | { |
| 2151 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 2152 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2153 | __ blr(lr); |
| 2154 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2155 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2156 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2157 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2160 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2161 | HInstruction* instruction, |
| 2162 | SlowPathCode* slow_path) { |
| 2163 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2164 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2165 | __ Blr(lr); |
| 2166 | } |
| 2167 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2168 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2169 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2170 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2171 | Register temp = temps.AcquireW(); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2172 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 2173 | const size_t status_byte_offset = |
| 2174 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 2175 | constexpr uint32_t shifted_initialized_value = |
| 2176 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2177 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2178 | // 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] | 2179 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2180 | __ Add(temp, class_reg, status_byte_offset); |
Igor Murashkin | 86083f7 | 2017-10-27 10:59:04 -0700 | [diff] [blame] | 2181 | __ Ldarb(temp, HeapOperand(temp)); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2182 | __ Cmp(temp, shifted_initialized_value); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 2183 | __ B(lo, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2184 | __ Bind(slow_path->GetExitLabel()); |
| 2185 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2186 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2187 | void InstructionCodeGeneratorARM64::GenerateBitstringTypeCheckCompare( |
| 2188 | HTypeCheckInstruction* check, vixl::aarch64::Register temp) { |
| 2189 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 2190 | uint32_t mask = check->GetBitstringMask(); |
| 2191 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 2192 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 2193 | |
| 2194 | if (mask_bits == 16u) { |
| 2195 | // Load only the bitstring part of the status word. |
| 2196 | __ Ldrh(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 2197 | } else { |
| 2198 | // /* uint32_t */ temp = temp->status_ |
| 2199 | __ Ldr(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 2200 | // Extract the bitstring bits. |
| 2201 | __ Ubfx(temp, temp, 0, mask_bits); |
| 2202 | } |
| 2203 | // Compare the bitstring bits to `path_to_root`. |
| 2204 | __ Cmp(temp, path_to_root); |
| 2205 | } |
| 2206 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2207 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2208 | BarrierType type = BarrierAll; |
| 2209 | |
| 2210 | switch (kind) { |
| 2211 | case MemBarrierKind::kAnyAny: |
| 2212 | case MemBarrierKind::kAnyStore: { |
| 2213 | type = BarrierAll; |
| 2214 | break; |
| 2215 | } |
| 2216 | case MemBarrierKind::kLoadAny: { |
| 2217 | type = BarrierReads; |
| 2218 | break; |
| 2219 | } |
| 2220 | case MemBarrierKind::kStoreStore: { |
| 2221 | type = BarrierWrites; |
| 2222 | break; |
| 2223 | } |
| 2224 | default: |
| 2225 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2226 | } |
| 2227 | __ Dmb(InnerShareable, type); |
| 2228 | } |
| 2229 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2230 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2231 | HBasicBlock* successor) { |
| 2232 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2233 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2234 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2235 | slow_path = |
| 2236 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2237 | instruction->SetSlowPath(slow_path); |
| 2238 | codegen_->AddSlowPath(slow_path); |
| 2239 | if (successor != nullptr) { |
| 2240 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2241 | } |
| 2242 | } else { |
| 2243 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2244 | } |
| 2245 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2246 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2247 | Register temp = temps.AcquireW(); |
| 2248 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2249 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2250 | if (successor == nullptr) { |
| 2251 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2252 | __ Bind(slow_path->GetReturnLabel()); |
| 2253 | } else { |
| 2254 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 2255 | __ B(slow_path->GetEntryLabel()); |
| 2256 | // slow_path will return to GetLabelOf(successor). |
| 2257 | } |
| 2258 | } |
| 2259 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2260 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2261 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2262 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2263 | assembler_(codegen->GetAssembler()), |
| 2264 | codegen_(codegen) {} |
| 2265 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2266 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2267 | DCHECK_EQ(instr->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2268 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2269 | DataType::Type type = instr->GetResultType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2270 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2271 | case DataType::Type::kInt32: |
| 2272 | case DataType::Type::kInt64: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2273 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2274 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2275 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2276 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2277 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2278 | case DataType::Type::kFloat32: |
| 2279 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2280 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2281 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2282 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2283 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2284 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2285 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2286 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2287 | } |
| 2288 | } |
| 2289 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2290 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2291 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2292 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2293 | |
| 2294 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2295 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2296 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2297 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2298 | object_field_get_with_read_barrier |
| 2299 | ? LocationSummary::kCallOnSlowPath |
| 2300 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2301 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2302 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2303 | // We need a temporary register for the read barrier marking slow |
| 2304 | // path in CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2305 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2306 | !Runtime::Current()->UseJitCompilation() && |
| 2307 | !field_info.IsVolatile()) { |
| 2308 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2309 | // non-volatile loads we need a temporary only if the offset is too big. |
| 2310 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2311 | locations->AddTemp(FixedTempLocation()); |
| 2312 | } |
| 2313 | } else { |
| 2314 | locations->AddTemp(Location::RequiresRegister()); |
| 2315 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2316 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2317 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2318 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2319 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2320 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2321 | // The output overlaps for an object field get when read barriers |
| 2322 | // are enabled: we do not want the load to overwrite the object's |
| 2323 | // location, as we need it to emit the read barrier. |
| 2324 | locations->SetOut( |
| 2325 | Location::RequiresRegister(), |
| 2326 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2331 | const FieldInfo& field_info) { |
| 2332 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2333 | LocationSummary* locations = instruction->GetLocations(); |
| 2334 | Location base_loc = locations->InAt(0); |
| 2335 | Location out = locations->Out(); |
| 2336 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2337 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 2338 | DataType::Type load_type = instruction->GetType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2339 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2340 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2341 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2342 | load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2343 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2344 | // /* HeapReference<Object> */ out = *(base + offset) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2345 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2346 | Location maybe_temp = |
| 2347 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2348 | // Note that potential implicit null checks are handled in this |
| 2349 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2350 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2351 | instruction, |
| 2352 | out, |
| 2353 | base, |
| 2354 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2355 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2356 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2357 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2358 | } else { |
| 2359 | // General case. |
| 2360 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2361 | // Note that a potential implicit null check is handled in this |
| 2362 | // CodeGeneratorARM64::LoadAcquire call. |
| 2363 | // NB: LoadAcquire will record the pc info if needed. |
| 2364 | codegen_->LoadAcquire( |
| 2365 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2366 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2367 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2368 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2369 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2370 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2371 | } |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2372 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2373 | // If read barriers are enabled, emit read barriers other than |
| 2374 | // Baker's using a slow path (and also unpoison the loaded |
| 2375 | // reference, if heap poisoning is enabled). |
| 2376 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2377 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2378 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2382 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2383 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2384 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2385 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2386 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2387 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2388 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2389 | } else { |
| 2390 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2391 | } |
| 2392 | } |
| 2393 | |
| 2394 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2395 | const FieldInfo& field_info, |
| 2396 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2397 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2398 | |
| 2399 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2400 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2401 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2402 | Offset offset = field_info.GetFieldOffset(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2403 | DataType::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2404 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2405 | { |
| 2406 | // We use a block to end the scratch scope before the write barrier, thus |
| 2407 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2408 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2409 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2410 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2411 | DCHECK(value.IsW()); |
| 2412 | Register temp = temps.AcquireW(); |
| 2413 | __ Mov(temp, value.W()); |
| 2414 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2415 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2416 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2417 | |
| 2418 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2419 | codegen_->StoreRelease( |
| 2420 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2421 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2422 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2423 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2424 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2425 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2426 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2430 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2431 | } |
| 2432 | } |
| 2433 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2434 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2435 | DataType::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2436 | |
| 2437 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2438 | case DataType::Type::kInt32: |
| 2439 | case DataType::Type::kInt64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2440 | Register dst = OutputRegister(instr); |
| 2441 | Register lhs = InputRegisterAt(instr, 0); |
| 2442 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2443 | if (instr->IsAdd()) { |
| 2444 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2445 | } else if (instr->IsAnd()) { |
| 2446 | __ And(dst, lhs, rhs); |
| 2447 | } else if (instr->IsOr()) { |
| 2448 | __ Orr(dst, lhs, rhs); |
| 2449 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2450 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2451 | } else if (instr->IsRor()) { |
| 2452 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2453 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2454 | __ Ror(dst, lhs, shift); |
| 2455 | } else { |
| 2456 | // Ensure shift distance is in the same size register as the result. If |
| 2457 | // we are rotating a long and the shift comes in a w register originally, |
| 2458 | // we don't need to sxtw for use as an x since the shift distances are |
| 2459 | // all & reg_bits - 1. |
| 2460 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2461 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2462 | } else { |
| 2463 | DCHECK(instr->IsXor()); |
| 2464 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2465 | } |
| 2466 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2467 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2468 | case DataType::Type::kFloat32: |
| 2469 | case DataType::Type::kFloat64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2470 | FPRegister dst = OutputFPRegister(instr); |
| 2471 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2472 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2473 | if (instr->IsAdd()) { |
| 2474 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2475 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2476 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2477 | } else { |
| 2478 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2479 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2480 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2481 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2482 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2483 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2484 | } |
| 2485 | } |
| 2486 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2487 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2488 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2489 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2490 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2491 | DataType::Type type = instr->GetResultType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2492 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2493 | case DataType::Type::kInt32: |
| 2494 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2495 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2496 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2497 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2498 | break; |
| 2499 | } |
| 2500 | default: |
| 2501 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2502 | } |
| 2503 | } |
| 2504 | |
| 2505 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2506 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2507 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2508 | DataType::Type type = instr->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2509 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2510 | case DataType::Type::kInt32: |
| 2511 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2512 | Register dst = OutputRegister(instr); |
| 2513 | Register lhs = InputRegisterAt(instr, 0); |
| 2514 | Operand rhs = InputOperandAt(instr, 1); |
| 2515 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2516 | uint32_t shift_value = rhs.GetImmediate() & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2517 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2518 | if (instr->IsShl()) { |
| 2519 | __ Lsl(dst, lhs, shift_value); |
| 2520 | } else if (instr->IsShr()) { |
| 2521 | __ Asr(dst, lhs, shift_value); |
| 2522 | } else { |
| 2523 | __ Lsr(dst, lhs, shift_value); |
| 2524 | } |
| 2525 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2526 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2527 | |
| 2528 | if (instr->IsShl()) { |
| 2529 | __ Lsl(dst, lhs, rhs_reg); |
| 2530 | } else if (instr->IsShr()) { |
| 2531 | __ Asr(dst, lhs, rhs_reg); |
| 2532 | } else { |
| 2533 | __ Lsr(dst, lhs, rhs_reg); |
| 2534 | } |
| 2535 | } |
| 2536 | break; |
| 2537 | } |
| 2538 | default: |
| 2539 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2540 | } |
| 2541 | } |
| 2542 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2543 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2544 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2548 | HandleBinaryOp(instruction); |
| 2549 | } |
| 2550 | |
| 2551 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2552 | HandleBinaryOp(instruction); |
| 2553 | } |
| 2554 | |
| 2555 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2556 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2557 | } |
| 2558 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2559 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2560 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2561 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2562 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2563 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2564 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2565 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2566 | } |
| 2567 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2568 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2569 | Register dst = OutputRegister(instr); |
| 2570 | Register lhs = InputRegisterAt(instr, 0); |
| 2571 | Register rhs = InputRegisterAt(instr, 1); |
| 2572 | |
| 2573 | switch (instr->GetOpKind()) { |
| 2574 | case HInstruction::kAnd: |
| 2575 | __ Bic(dst, lhs, rhs); |
| 2576 | break; |
| 2577 | case HInstruction::kOr: |
| 2578 | __ Orn(dst, lhs, rhs); |
| 2579 | break; |
| 2580 | case HInstruction::kXor: |
| 2581 | __ Eon(dst, lhs, rhs); |
| 2582 | break; |
| 2583 | default: |
| 2584 | LOG(FATAL) << "Unreachable"; |
| 2585 | } |
| 2586 | } |
| 2587 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2588 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2589 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2590 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2591 | instruction->GetType() == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2592 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2593 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2594 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2595 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2596 | } else { |
| 2597 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2598 | } |
| 2599 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2600 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2601 | } |
| 2602 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2603 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2604 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2605 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2606 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2607 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2608 | Register out = OutputRegister(instruction); |
| 2609 | Register left; |
| 2610 | if (kind != HInstruction::kNeg) { |
| 2611 | left = InputRegisterAt(instruction, 0); |
| 2612 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2613 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2614 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2615 | // conversion) can have a different type from the current instruction's type, |
| 2616 | // so we manually indicate the type. |
| 2617 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2618 | Operand right_operand(0); |
| 2619 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2620 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2621 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2622 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2623 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2624 | right_operand = Operand(right_reg, |
| 2625 | helpers::ShiftFromOpKind(op_kind), |
| 2626 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | // Logical binary operations do not support extension operations in the |
| 2630 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2631 | // the extension as a separate instruction. |
| 2632 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2633 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2634 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2635 | kind != HInstruction::kNeg)); |
| 2636 | switch (kind) { |
| 2637 | case HInstruction::kAdd: |
| 2638 | __ Add(out, left, right_operand); |
| 2639 | break; |
| 2640 | case HInstruction::kAnd: |
| 2641 | __ And(out, left, right_operand); |
| 2642 | break; |
| 2643 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2644 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2645 | __ Neg(out, right_operand); |
| 2646 | break; |
| 2647 | case HInstruction::kOr: |
| 2648 | __ Orr(out, left, right_operand); |
| 2649 | break; |
| 2650 | case HInstruction::kSub: |
| 2651 | __ Sub(out, left, right_operand); |
| 2652 | break; |
| 2653 | case HInstruction::kXor: |
| 2654 | __ Eor(out, left, right_operand); |
| 2655 | break; |
| 2656 | default: |
| 2657 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2658 | UNREACHABLE(); |
| 2659 | } |
| 2660 | } |
| 2661 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2662 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2663 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2664 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2665 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2666 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2667 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2668 | } |
| 2669 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2670 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2671 | __ Add(OutputRegister(instruction), |
| 2672 | InputRegisterAt(instruction, 0), |
| 2673 | Operand(InputOperandAt(instruction, 1))); |
| 2674 | } |
| 2675 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2676 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2677 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2678 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2679 | |
| 2680 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2681 | |
| 2682 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2683 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2684 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2685 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2686 | // loop. |
| 2687 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2688 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2689 | : Location::RequiresRegister()); |
| 2690 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2691 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2692 | } |
| 2693 | |
| 2694 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2695 | HIntermediateAddressIndex* instruction) { |
| 2696 | Register index_reg = InputRegisterAt(instruction, 0); |
| 2697 | uint32_t shift = Int64ConstantFrom(instruction->GetLocations()->InAt(2)); |
| 2698 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2699 | |
| 2700 | if (shift == 0) { |
| 2701 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2702 | } else { |
| 2703 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2704 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2705 | } |
| 2706 | } |
| 2707 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2708 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2709 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2710 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2711 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2712 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2713 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2714 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2715 | // Don't allocate register for Mneg instruction. |
| 2716 | } else { |
| 2717 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2718 | Location::RequiresRegister()); |
| 2719 | } |
| 2720 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2721 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2722 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2723 | } |
| 2724 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2725 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2726 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2727 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2728 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2729 | |
| 2730 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2731 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2732 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2733 | if (instr->GetType() == DataType::Type::kInt64 && |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2734 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2735 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2736 | vixl::aarch64::Instruction* prev = |
| 2737 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2738 | if (prev->IsLoadOrStore()) { |
| 2739 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2740 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2741 | __ nop(); |
| 2742 | } |
| 2743 | } |
| 2744 | |
| 2745 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2746 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2747 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2748 | } else { |
| 2749 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2750 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2751 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2752 | __ Mneg(res, mul_left, mul_right); |
| 2753 | } else { |
| 2754 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2755 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2756 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2757 | } |
| 2758 | } |
| 2759 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2760 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2761 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2762 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2763 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2764 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2765 | object_array_get_with_read_barrier |
| 2766 | ? LocationSummary::kCallOnSlowPath |
| 2767 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2768 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2769 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 2770 | // We need a temporary register for the read barrier marking slow |
| 2771 | // path in CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2772 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2773 | !Runtime::Current()->UseJitCompilation() && |
| 2774 | instruction->GetIndex()->IsConstant()) { |
| 2775 | // Array loads with constant index are treated as field loads. |
| 2776 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2777 | // constant index loads we need a temporary only if the offset is too big. |
| 2778 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2779 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2780 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2781 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2782 | locations->AddTemp(FixedTempLocation()); |
| 2783 | } |
| 2784 | } else { |
| 2785 | locations->AddTemp(Location::RequiresRegister()); |
| 2786 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2787 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2788 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2789 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2790 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2791 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2792 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2793 | // The output overlaps in the case of an object array get with |
| 2794 | // read barriers enabled: we do not want the move to overwrite the |
| 2795 | // array's location, as we need it to emit the read barrier. |
| 2796 | locations->SetOut( |
| 2797 | Location::RequiresRegister(), |
| 2798 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2799 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2803 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2804 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2805 | LocationSummary* locations = instruction->GetLocations(); |
| 2806 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2807 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2808 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2809 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2810 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2811 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2812 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2813 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2814 | // The read barrier instrumentation of object ArrayGet instructions |
| 2815 | // does not support the HIntermediateAddress instruction. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2816 | DCHECK(!((type == DataType::Type::kReference) && |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2817 | instruction->GetArray()->IsIntermediateAddress() && |
| 2818 | kEmitCompilerReadBarrier)); |
| 2819 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2820 | if (type == DataType::Type::kReference && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2821 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2822 | // Note that a potential implicit null check is handled in the |
| 2823 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2824 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2825 | if (index.IsConstant()) { |
| 2826 | // Array load with a constant index can be treated as a field load. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2827 | offset += Int64ConstantFrom(index) << DataType::SizeShift(type); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2828 | Location maybe_temp = |
| 2829 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2830 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2831 | out, |
| 2832 | obj.W(), |
| 2833 | offset, |
| 2834 | maybe_temp, |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2835 | /* needs_null_check */ false, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2836 | /* use_load_acquire */ false); |
| 2837 | } else { |
| 2838 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
| 2839 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2840 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2841 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2842 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2843 | // General case. |
| 2844 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2845 | Register length; |
| 2846 | if (maybe_compressed_char_at) { |
| 2847 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2848 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2849 | { |
| 2850 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2851 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2852 | |
| 2853 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2854 | DCHECK_LT(count_offset, offset); |
| 2855 | int64_t adjusted_offset = |
| 2856 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2857 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2858 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2859 | } else { |
| 2860 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2861 | } |
| 2862 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2863 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2864 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2865 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2866 | if (maybe_compressed_char_at) { |
| 2867 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2868 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2869 | "Expecting 0=compressed, 1=uncompressed"); |
| 2870 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2871 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2872 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2873 | __ B(&done); |
| 2874 | __ Bind(&uncompressed_load); |
| 2875 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2876 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2877 | __ Bind(&done); |
| 2878 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2879 | offset += Int64ConstantFrom(index) << DataType::SizeShift(type); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2880 | source = HeapOperand(obj, offset); |
| 2881 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2882 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2883 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2884 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2885 | // We do not need to compute the intermediate address from the array: the |
| 2886 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2887 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2888 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2889 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2890 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2891 | } |
| 2892 | temp = obj; |
| 2893 | } else { |
| 2894 | __ Add(temp, obj, offset); |
| 2895 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2896 | if (maybe_compressed_char_at) { |
| 2897 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2898 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2899 | "Expecting 0=compressed, 1=uncompressed"); |
| 2900 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2901 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2902 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2903 | __ B(&done); |
| 2904 | __ Bind(&uncompressed_load); |
| 2905 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2906 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2907 | __ Bind(&done); |
| 2908 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2909 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2910 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2911 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2912 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2913 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2914 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2915 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2916 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2917 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2918 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2919 | if (type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2920 | static_assert( |
| 2921 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2922 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2923 | Location obj_loc = locations->InAt(0); |
| 2924 | if (index.IsConstant()) { |
| 2925 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2926 | } else { |
| 2927 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2928 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2929 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2930 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2931 | } |
| 2932 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2933 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2934 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2935 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2936 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2937 | } |
| 2938 | |
| 2939 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2940 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2941 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2942 | { |
| 2943 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2944 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2945 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2946 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2947 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2948 | // Mask out compression flag from String's array length. |
| 2949 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2950 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2951 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2952 | } |
| 2953 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2954 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2955 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2956 | |
| 2957 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2958 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2959 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2960 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2961 | LocationSummary::kCallOnSlowPath : |
| 2962 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2963 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2964 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2965 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2966 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2967 | } else if (DataType::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2968 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2969 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2970 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2971 | } |
| 2972 | } |
| 2973 | |
| 2974 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2975 | DataType::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2976 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2977 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2978 | bool needs_write_barrier = |
| 2979 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2980 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2981 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2982 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2983 | CPURegister source = value; |
| 2984 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2985 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2986 | MemOperand destination = HeapOperand(array); |
| 2987 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2988 | |
| 2989 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2990 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2991 | if (index.IsConstant()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2992 | offset += Int64ConstantFrom(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2993 | destination = HeapOperand(array, offset); |
| 2994 | } else { |
| 2995 | UseScratchRegisterScope temps(masm); |
| 2996 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2997 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2998 | // We do not need to compute the intermediate address from the array: the |
| 2999 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3000 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 3001 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3002 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 3003 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 3004 | } |
| 3005 | temp = array; |
| 3006 | } else { |
| 3007 | __ Add(temp, array, offset); |
| 3008 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3009 | destination = HeapOperand(temp, |
| 3010 | XRegisterFrom(index), |
| 3011 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3012 | DataType::SizeShift(value_type)); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3013 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3014 | { |
| 3015 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3016 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3017 | codegen_->Store(value_type, value, destination); |
| 3018 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3019 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3020 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3021 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3022 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3023 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3024 | { |
| 3025 | // We use a block to end the scratch scope before the write barrier, thus |
| 3026 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 3027 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3028 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3029 | if (index.IsConstant()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3030 | offset += Int64ConstantFrom(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3031 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3032 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 3033 | destination = HeapOperand(temp, |
| 3034 | XRegisterFrom(index), |
| 3035 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3036 | DataType::SizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3037 | } |
| 3038 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3039 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3040 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3041 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3042 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3043 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3044 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3045 | codegen_->AddSlowPath(slow_path); |
| 3046 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3047 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3048 | __ Cbnz(Register(value), &non_zero); |
| 3049 | if (!index.IsConstant()) { |
| 3050 | __ Add(temp, array, offset); |
| 3051 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3052 | { |
| 3053 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 3054 | // emitted. |
| 3055 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3056 | __ Str(wzr, destination); |
| 3057 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3058 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3059 | __ B(&done); |
| 3060 | __ Bind(&non_zero); |
| 3061 | } |
| 3062 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3063 | // Note that when Baker read barriers are enabled, the type |
| 3064 | // checks are performed without read barriers. This is fine, |
| 3065 | // even in the case where a class object is in the from-space |
| 3066 | // after the flip, as a comparison involving such a type would |
| 3067 | // not produce a false positive; it may of course produce a |
| 3068 | // false negative, in which case we would take the ArraySet |
| 3069 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3070 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3071 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 3072 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3073 | { |
| 3074 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3075 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3076 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 3077 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3078 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3079 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
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 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 3082 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 3083 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3084 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 3085 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 3086 | // nor `temp2`, as we are comparing two poisoned references. |
| 3087 | __ Cmp(temp, temp2); |
| 3088 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3089 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3090 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3091 | vixl::aarch64::Label do_put; |
| 3092 | __ B(eq, &do_put); |
| 3093 | // If heap poisoning is enabled, the `temp` reference has |
| 3094 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3095 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3096 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3097 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 3098 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 3099 | // If heap poisoning is enabled, no need to unpoison |
| 3100 | // `temp`, as we are comparing against null below. |
| 3101 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 3102 | __ Bind(&do_put); |
| 3103 | } else { |
| 3104 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3105 | } |
| 3106 | } |
| 3107 | |
| 3108 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3109 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3110 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3111 | __ Mov(temp2, value.W()); |
| 3112 | GetAssembler()->PoisonHeapReference(temp2); |
| 3113 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3114 | } |
| 3115 | |
| 3116 | if (!index.IsConstant()) { |
| 3117 | __ Add(temp, array, offset); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 3118 | } else { |
| 3119 | // We no longer need the `temp` here so release it as the store below may |
| 3120 | // need a scratch register (if the constant index makes the offset too large) |
| 3121 | // and the poisoned `source` could be using the other scratch register. |
| 3122 | temps.Release(temp); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3123 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3124 | { |
| 3125 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3126 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3127 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3128 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3129 | if (!may_need_runtime_call_for_type_check) { |
| 3130 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3131 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3132 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3133 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3134 | |
| 3135 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 3136 | |
| 3137 | if (done.IsLinked()) { |
| 3138 | __ Bind(&done); |
| 3139 | } |
| 3140 | |
| 3141 | if (slow_path != nullptr) { |
| 3142 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3143 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3144 | } |
| 3145 | } |
| 3146 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3147 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3148 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3149 | InvokeRuntimeCallingConvention calling_convention; |
| 3150 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3151 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 3152 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3153 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 3154 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3155 | } |
| 3156 | |
| 3157 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3158 | BoundsCheckSlowPathARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3159 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3160 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3161 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 3162 | __ B(slow_path->GetEntryLabel(), hs); |
| 3163 | } |
| 3164 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3165 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3166 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3167 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3168 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3169 | if (check->HasUses()) { |
| 3170 | locations->SetOut(Location::SameAsFirstInput()); |
| 3171 | } |
| 3172 | } |
| 3173 | |
| 3174 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3175 | // We assume the class is not null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3176 | SlowPathCodeARM64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64( |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3177 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 3178 | codegen_->AddSlowPath(slow_path); |
| 3179 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3180 | } |
| 3181 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3182 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3183 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3184 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3185 | } |
| 3186 | |
| 3187 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 3188 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 3189 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3190 | if (rhs_loc.IsConstant()) { |
| 3191 | // 0.0 is the only immediate that can be encoded directly in |
| 3192 | // an FCMP instruction. |
| 3193 | // |
| 3194 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3195 | // specify that in a floating-point comparison, positive zero |
| 3196 | // and negative zero are considered equal, so we can use the |
| 3197 | // literal 0.0 for both cases here. |
| 3198 | // |
| 3199 | // Note however that some methods (Float.equal, Float.compare, |
| 3200 | // Float.compareTo, Double.equal, Double.compare, |
| 3201 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3202 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3203 | // -0.0. So if we ever translate calls to these methods into a |
| 3204 | // HCompare instruction, we must handle the -0.0 case with |
| 3205 | // care here. |
| 3206 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3207 | __ Fcmp(lhs_reg, 0.0); |
| 3208 | } else { |
| 3209 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3210 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3211 | } |
| 3212 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3213 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3214 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3215 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3216 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3217 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3218 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3219 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3220 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3221 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3222 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3223 | case DataType::Type::kInt32: |
| 3224 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3225 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3226 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3227 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3228 | break; |
| 3229 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3230 | case DataType::Type::kFloat32: |
| 3231 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3232 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3233 | locations->SetInAt(1, |
| 3234 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3235 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3236 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3237 | locations->SetOut(Location::RequiresRegister()); |
| 3238 | break; |
| 3239 | } |
| 3240 | default: |
| 3241 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3242 | } |
| 3243 | } |
| 3244 | |
| 3245 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3246 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3247 | |
| 3248 | // 0 if: left == right |
| 3249 | // 1 if: left > right |
| 3250 | // -1 if: left < right |
| 3251 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3252 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3253 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3254 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3255 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3256 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3257 | case DataType::Type::kInt32: |
| 3258 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3259 | Register result = OutputRegister(compare); |
| 3260 | Register left = InputRegisterAt(compare, 0); |
| 3261 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3262 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3263 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3264 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3265 | break; |
| 3266 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3267 | case DataType::Type::kFloat32: |
| 3268 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3269 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3270 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3271 | __ Cset(result, ne); |
| 3272 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3273 | break; |
| 3274 | } |
| 3275 | default: |
| 3276 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3277 | } |
| 3278 | } |
| 3279 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3280 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3281 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3282 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3283 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3284 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3285 | locations->SetInAt(1, |
| 3286 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3287 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3288 | : Location::RequiresFpuRegister()); |
| 3289 | } else { |
| 3290 | // Integer cases. |
| 3291 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3292 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3293 | } |
| 3294 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3295 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3296 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3297 | } |
| 3298 | } |
| 3299 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3300 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3301 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3302 | return; |
| 3303 | } |
| 3304 | |
| 3305 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3306 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3307 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3308 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3309 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3310 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3311 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3312 | } else { |
| 3313 | // Integer cases. |
| 3314 | Register lhs = InputRegisterAt(instruction, 0); |
| 3315 | Operand rhs = InputOperandAt(instruction, 1); |
| 3316 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3317 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3318 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3319 | } |
| 3320 | |
| 3321 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3322 | M(Equal) \ |
| 3323 | M(NotEqual) \ |
| 3324 | M(LessThan) \ |
| 3325 | M(LessThanOrEqual) \ |
| 3326 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3327 | M(GreaterThanOrEqual) \ |
| 3328 | M(Below) \ |
| 3329 | M(BelowOrEqual) \ |
| 3330 | M(Above) \ |
| 3331 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3332 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3333 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3334 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3335 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3336 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3337 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3338 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3339 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3340 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3341 | |
| 3342 | LocationSummary* locations = instruction->GetLocations(); |
| 3343 | Location second = locations->InAt(1); |
| 3344 | DCHECK(second.IsConstant()); |
| 3345 | |
| 3346 | Register out = OutputRegister(instruction); |
| 3347 | Register dividend = InputRegisterAt(instruction, 0); |
| 3348 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3349 | DCHECK(imm == 1 || imm == -1); |
| 3350 | |
| 3351 | if (instruction->IsRem()) { |
| 3352 | __ Mov(out, 0); |
| 3353 | } else { |
| 3354 | if (imm == 1) { |
| 3355 | __ Mov(out, dividend); |
| 3356 | } else { |
| 3357 | __ Neg(out, dividend); |
| 3358 | } |
| 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3363 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3364 | |
| 3365 | LocationSummary* locations = instruction->GetLocations(); |
| 3366 | Location second = locations->InAt(1); |
| 3367 | DCHECK(second.IsConstant()); |
| 3368 | |
| 3369 | Register out = OutputRegister(instruction); |
| 3370 | Register dividend = InputRegisterAt(instruction, 0); |
| 3371 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3372 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3373 | int ctz_imm = CTZ(abs_imm); |
| 3374 | |
| 3375 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3376 | Register temp = temps.AcquireSameSizeAs(out); |
| 3377 | |
| 3378 | if (instruction->IsDiv()) { |
| 3379 | __ Add(temp, dividend, abs_imm - 1); |
| 3380 | __ Cmp(dividend, 0); |
| 3381 | __ Csel(out, temp, dividend, lt); |
| 3382 | if (imm > 0) { |
| 3383 | __ Asr(out, out, ctz_imm); |
| 3384 | } else { |
| 3385 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 3386 | } |
| 3387 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3388 | int bits = instruction->GetResultType() == DataType::Type::kInt32 ? 32 : 64; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3389 | __ Asr(temp, dividend, bits - 1); |
| 3390 | __ Lsr(temp, temp, bits - ctz_imm); |
| 3391 | __ Add(out, dividend, temp); |
| 3392 | __ And(out, out, abs_imm - 1); |
| 3393 | __ Sub(out, out, temp); |
| 3394 | } |
| 3395 | } |
| 3396 | |
| 3397 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3398 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3399 | |
| 3400 | LocationSummary* locations = instruction->GetLocations(); |
| 3401 | Location second = locations->InAt(1); |
| 3402 | DCHECK(second.IsConstant()); |
| 3403 | |
| 3404 | Register out = OutputRegister(instruction); |
| 3405 | Register dividend = InputRegisterAt(instruction, 0); |
| 3406 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3407 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3408 | DataType::Type type = instruction->GetResultType(); |
| 3409 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3410 | |
| 3411 | int64_t magic; |
| 3412 | int shift; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3413 | CalculateMagicAndShiftForDivRem( |
| 3414 | imm, type == DataType::Type::kInt64 /* is_long */, &magic, &shift); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3415 | |
| 3416 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3417 | Register temp = temps.AcquireSameSizeAs(out); |
| 3418 | |
| 3419 | // temp = get_high(dividend * magic) |
| 3420 | __ Mov(temp, magic); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3421 | if (type == DataType::Type::kInt64) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3422 | __ Smulh(temp, dividend, temp); |
| 3423 | } else { |
| 3424 | __ Smull(temp.X(), dividend, temp); |
| 3425 | __ Lsr(temp.X(), temp.X(), 32); |
| 3426 | } |
| 3427 | |
| 3428 | if (imm > 0 && magic < 0) { |
| 3429 | __ Add(temp, temp, dividend); |
| 3430 | } else if (imm < 0 && magic > 0) { |
| 3431 | __ Sub(temp, temp, dividend); |
| 3432 | } |
| 3433 | |
| 3434 | if (shift != 0) { |
| 3435 | __ Asr(temp, temp, shift); |
| 3436 | } |
| 3437 | |
| 3438 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3439 | __ Sub(out, temp, Operand(temp, ASR, type == DataType::Type::kInt64 ? 63 : 31)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3440 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3441 | __ Sub(temp, temp, Operand(temp, ASR, type == DataType::Type::kInt64 ? 63 : 31)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3442 | // TODO: Strength reduction for msub. |
| 3443 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3444 | __ Mov(temp_imm, imm); |
| 3445 | __ Msub(out, temp, temp_imm, dividend); |
| 3446 | } |
| 3447 | } |
| 3448 | |
| 3449 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3450 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3451 | DataType::Type type = instruction->GetResultType(); |
| 3452 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3453 | |
| 3454 | LocationSummary* locations = instruction->GetLocations(); |
| 3455 | Register out = OutputRegister(instruction); |
| 3456 | Location second = locations->InAt(1); |
| 3457 | |
| 3458 | if (second.IsConstant()) { |
| 3459 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3460 | |
| 3461 | if (imm == 0) { |
| 3462 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3463 | } else if (imm == 1 || imm == -1) { |
| 3464 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3465 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3466 | DivRemByPowerOfTwo(instruction); |
| 3467 | } else { |
| 3468 | DCHECK(imm <= -2 || imm >= 2); |
| 3469 | GenerateDivRemWithAnyConstant(instruction); |
| 3470 | } |
| 3471 | } else { |
| 3472 | Register dividend = InputRegisterAt(instruction, 0); |
| 3473 | Register divisor = InputRegisterAt(instruction, 1); |
| 3474 | if (instruction->IsDiv()) { |
| 3475 | __ Sdiv(out, dividend, divisor); |
| 3476 | } else { |
| 3477 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3478 | Register temp = temps.AcquireSameSizeAs(out); |
| 3479 | __ Sdiv(temp, dividend, divisor); |
| 3480 | __ Msub(out, temp, divisor, dividend); |
| 3481 | } |
| 3482 | } |
| 3483 | } |
| 3484 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3485 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3486 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3487 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3488 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3489 | case DataType::Type::kInt32: |
| 3490 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3491 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3492 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3493 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3494 | break; |
| 3495 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3496 | case DataType::Type::kFloat32: |
| 3497 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3498 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3499 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3500 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3501 | break; |
| 3502 | |
| 3503 | default: |
| 3504 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3505 | } |
| 3506 | } |
| 3507 | |
| 3508 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3509 | DataType::Type type = div->GetResultType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3510 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3511 | case DataType::Type::kInt32: |
| 3512 | case DataType::Type::kInt64: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3513 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3514 | break; |
| 3515 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3516 | case DataType::Type::kFloat32: |
| 3517 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3518 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3519 | break; |
| 3520 | |
| 3521 | default: |
| 3522 | LOG(FATAL) << "Unexpected div type " << type; |
| 3523 | } |
| 3524 | } |
| 3525 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3526 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3527 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3528 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3532 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3533 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3534 | codegen_->AddSlowPath(slow_path); |
| 3535 | Location value = instruction->GetLocations()->InAt(0); |
| 3536 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3537 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3538 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3539 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3540 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3541 | return; |
| 3542 | } |
| 3543 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3544 | if (value.IsConstant()) { |
| 3545 | int64_t divisor = Int64ConstantFrom(value); |
| 3546 | if (divisor == 0) { |
| 3547 | __ B(slow_path->GetEntryLabel()); |
| 3548 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3549 | // A division by a non-null constant is valid. We don't need to perform |
| 3550 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3551 | } |
| 3552 | } else { |
| 3553 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3554 | } |
| 3555 | } |
| 3556 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3557 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3558 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3559 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3560 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3561 | } |
| 3562 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3563 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3564 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3565 | // Will be generated at use site. |
| 3566 | } |
| 3567 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3568 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3569 | exit->SetLocations(nullptr); |
| 3570 | } |
| 3571 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3572 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3573 | } |
| 3574 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3575 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3576 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3577 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3578 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3579 | } |
| 3580 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3581 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3582 | // Will be generated at use site. |
| 3583 | } |
| 3584 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3585 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3586 | if (successor->IsExitBlock()) { |
| 3587 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3588 | return; // no code needed |
| 3589 | } |
| 3590 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3591 | HBasicBlock* block = got->GetBlock(); |
| 3592 | HInstruction* previous = got->GetPrevious(); |
| 3593 | HLoopInformation* info = block->GetLoopInformation(); |
| 3594 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3595 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 3596 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 3597 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3598 | Register temp1 = temps.AcquireX(); |
| 3599 | Register temp2 = temps.AcquireX(); |
| 3600 | __ Ldr(temp1, MemOperand(sp, 0)); |
| 3601 | __ Ldrh(temp2, MemOperand(temp1, ArtMethod::HotnessCountOffset().Int32Value())); |
| 3602 | __ Add(temp2, temp2, 1); |
| 3603 | __ Strh(temp2, MemOperand(temp1, ArtMethod::HotnessCountOffset().Int32Value())); |
| 3604 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3605 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3606 | return; |
| 3607 | } |
| 3608 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3609 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 3610 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3611 | } |
| 3612 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3613 | __ B(codegen_->GetLabelOf(successor)); |
| 3614 | } |
| 3615 | } |
| 3616 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3617 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3618 | got->SetLocations(nullptr); |
| 3619 | } |
| 3620 | |
| 3621 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3622 | HandleGoto(got, got->GetSuccessor()); |
| 3623 | } |
| 3624 | |
| 3625 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3626 | try_boundary->SetLocations(nullptr); |
| 3627 | } |
| 3628 | |
| 3629 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3630 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3631 | if (!successor->IsExitBlock()) { |
| 3632 | HandleGoto(try_boundary, successor); |
| 3633 | } |
| 3634 | } |
| 3635 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3636 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3637 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3638 | vixl::aarch64::Label* true_target, |
| 3639 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3640 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3641 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3642 | if (true_target == nullptr && false_target == nullptr) { |
| 3643 | // Nothing to do. The code always falls through. |
| 3644 | return; |
| 3645 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3646 | // Constant condition, statically compared against "true" (integer value 1). |
| 3647 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3648 | if (true_target != nullptr) { |
| 3649 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3650 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3651 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3652 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3653 | if (false_target != nullptr) { |
| 3654 | __ B(false_target); |
| 3655 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3656 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3657 | return; |
| 3658 | } |
| 3659 | |
| 3660 | // The following code generates these patterns: |
| 3661 | // (1) true_target == nullptr && false_target != nullptr |
| 3662 | // - opposite condition true => branch to false_target |
| 3663 | // (2) true_target != nullptr && false_target == nullptr |
| 3664 | // - condition true => branch to true_target |
| 3665 | // (3) true_target != nullptr && false_target != nullptr |
| 3666 | // - condition true => branch to true_target |
| 3667 | // - branch to false_target |
| 3668 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3669 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3670 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3671 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3672 | if (true_target == nullptr) { |
| 3673 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3674 | } else { |
| 3675 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3676 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3677 | } else { |
| 3678 | // The condition instruction has not been materialized, use its inputs as |
| 3679 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3680 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3681 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3682 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3683 | if (DataType::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3684 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3685 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3686 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3687 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3688 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3689 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3690 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3691 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3692 | // Integer cases. |
| 3693 | Register lhs = InputRegisterAt(condition, 0); |
| 3694 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3695 | |
| 3696 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3697 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3698 | if (true_target == nullptr) { |
| 3699 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3700 | non_fallthrough_target = false_target; |
| 3701 | } else { |
| 3702 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3703 | non_fallthrough_target = true_target; |
| 3704 | } |
| 3705 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3706 | 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] | 3707 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3708 | switch (arm64_cond) { |
| 3709 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3710 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3711 | break; |
| 3712 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3713 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3714 | break; |
| 3715 | case lt: |
| 3716 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3717 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3718 | break; |
| 3719 | case ge: |
| 3720 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3721 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3722 | break; |
| 3723 | default: |
| 3724 | // Without the `static_cast` the compiler throws an error for |
| 3725 | // `-Werror=sign-promo`. |
| 3726 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3727 | } |
| 3728 | } else { |
| 3729 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3730 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3731 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3732 | } |
| 3733 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3734 | |
| 3735 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3736 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3737 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3738 | __ B(false_target); |
| 3739 | } |
| 3740 | } |
| 3741 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3742 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3743 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3744 | if (IsBooleanValueOrMaterializedCondition(if_instr->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::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3750 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3751 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3752 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3753 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3754 | true_target = nullptr; |
| 3755 | } |
| 3756 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3757 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3758 | false_target = nullptr; |
| 3759 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3760 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3761 | } |
| 3762 | |
| 3763 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3764 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3765 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3766 | InvokeRuntimeCallingConvention calling_convention; |
| 3767 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3768 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3769 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3770 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3771 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3772 | } |
| 3773 | } |
| 3774 | |
| 3775 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3776 | SlowPathCodeARM64* slow_path = |
| 3777 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3778 | GenerateTestAndBranch(deoptimize, |
| 3779 | /* condition_input_index */ 0, |
| 3780 | slow_path->GetEntryLabel(), |
| 3781 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3782 | } |
| 3783 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3784 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3785 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3786 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3787 | locations->SetOut(Location::RequiresRegister()); |
| 3788 | } |
| 3789 | |
| 3790 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3791 | __ Ldr(OutputRegister(flag), |
| 3792 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3793 | } |
| 3794 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3795 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3796 | return condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3797 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3798 | } |
| 3799 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3800 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3801 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3802 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3803 | : ARM64Condition(cond); |
| 3804 | } |
| 3805 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3806 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3807 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3808 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3809 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3810 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3811 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3812 | } else { |
| 3813 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3814 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3815 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3816 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3817 | // Ask VIXL whether we should synthesize constants in registers. |
| 3818 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3819 | Operand true_op = is_true_value_constant ? |
| 3820 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3821 | Operand false_op = is_false_value_constant ? |
| 3822 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3823 | bool true_value_in_register = false; |
| 3824 | bool false_value_in_register = false; |
| 3825 | MacroAssembler::GetCselSynthesisInformation( |
| 3826 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3827 | true_value_in_register |= !is_true_value_constant; |
| 3828 | false_value_in_register |= !is_false_value_constant; |
| 3829 | |
| 3830 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3831 | : Location::ConstantLocation(cst_true_value)); |
| 3832 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3833 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3834 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3835 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3836 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3837 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3838 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3839 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3843 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3844 | Condition csel_cond; |
| 3845 | |
| 3846 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3847 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3848 | // Use the condition flags set by the previous instruction. |
| 3849 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3850 | } else { |
| 3851 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3852 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3853 | } |
| 3854 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3855 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3856 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3857 | } else { |
| 3858 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3859 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3860 | } |
| 3861 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3862 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3863 | __ Fcsel(OutputFPRegister(select), |
| 3864 | InputFPRegisterAt(select, 1), |
| 3865 | InputFPRegisterAt(select, 0), |
| 3866 | csel_cond); |
| 3867 | } else { |
| 3868 | __ Csel(OutputRegister(select), |
| 3869 | InputOperandAt(select, 1), |
| 3870 | InputOperandAt(select, 0), |
| 3871 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3872 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3873 | } |
| 3874 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3875 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3876 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3877 | } |
| 3878 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3879 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3880 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3881 | } |
| 3882 | |
| 3883 | void CodeGeneratorARM64::GenerateNop() { |
| 3884 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3885 | } |
| 3886 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3887 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3888 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3889 | } |
| 3890 | |
| 3891 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3892 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3893 | } |
| 3894 | |
| 3895 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3896 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3897 | } |
| 3898 | |
| 3899 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3900 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3901 | } |
| 3902 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3903 | // Temp is used for read barrier. |
| 3904 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3905 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3906 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3907 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3908 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3909 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3910 | return 1; |
| 3911 | } |
| 3912 | return 0; |
| 3913 | } |
| 3914 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3915 | // 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] | 3916 | // interface pointer, one for loading the current interface. |
| 3917 | // The other checks have one temp for loading the object's class. |
| 3918 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3919 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3920 | return 3; |
| 3921 | } |
| 3922 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3923 | } |
| 3924 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3925 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3926 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3927 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3928 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3929 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3930 | case TypeCheckKind::kExactCheck: |
| 3931 | case TypeCheckKind::kAbstractClassCheck: |
| 3932 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3933 | case TypeCheckKind::kArrayObjectCheck: { |
| 3934 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 3935 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 3936 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3937 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3938 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3939 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3940 | case TypeCheckKind::kUnresolvedCheck: |
| 3941 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3942 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3943 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3944 | case TypeCheckKind::kBitstringCheck: |
| 3945 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3946 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3947 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3948 | LocationSummary* locations = |
| 3949 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3950 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3951 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3952 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3953 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3954 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3955 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3956 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3957 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3958 | } else { |
| 3959 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3960 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3961 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3962 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3963 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3964 | // Add temps if necessary for read barriers. |
| 3965 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3966 | } |
| 3967 | |
| 3968 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3969 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3970 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3971 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3972 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3973 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 3974 | ? Register() |
| 3975 | : InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3976 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3977 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3978 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3979 | DCHECK_LE(num_temps, 1u); |
| 3980 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3981 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3982 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3983 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3984 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3985 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3986 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3987 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3988 | |
| 3989 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3990 | // Avoid null check if we know `obj` is not null. |
| 3991 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3992 | __ Cbz(obj, &zero); |
| 3993 | } |
| 3994 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3995 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3996 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3997 | ReadBarrierOption read_barrier_option = |
| 3998 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3999 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4000 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4001 | out_loc, |
| 4002 | obj_loc, |
| 4003 | class_offset, |
| 4004 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4005 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4006 | __ Cmp(out, cls); |
| 4007 | __ Cset(out, eq); |
| 4008 | if (zero.IsLinked()) { |
| 4009 | __ B(&done); |
| 4010 | } |
| 4011 | break; |
| 4012 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4013 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4014 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4015 | ReadBarrierOption read_barrier_option = |
| 4016 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4017 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4018 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4019 | out_loc, |
| 4020 | obj_loc, |
| 4021 | class_offset, |
| 4022 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4023 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4024 | // If the class is abstract, we eagerly fetch the super class of the |
| 4025 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4026 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4027 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4028 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4029 | GenerateReferenceLoadOneRegister(instruction, |
| 4030 | out_loc, |
| 4031 | super_offset, |
| 4032 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4033 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4034 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4035 | __ Cbz(out, &done); |
| 4036 | __ Cmp(out, cls); |
| 4037 | __ B(ne, &loop); |
| 4038 | __ Mov(out, 1); |
| 4039 | if (zero.IsLinked()) { |
| 4040 | __ B(&done); |
| 4041 | } |
| 4042 | break; |
| 4043 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4044 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4045 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4046 | ReadBarrierOption read_barrier_option = |
| 4047 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4048 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4049 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4050 | out_loc, |
| 4051 | obj_loc, |
| 4052 | class_offset, |
| 4053 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4054 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4055 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4056 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4057 | __ Bind(&loop); |
| 4058 | __ Cmp(out, cls); |
| 4059 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4060 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4061 | GenerateReferenceLoadOneRegister(instruction, |
| 4062 | out_loc, |
| 4063 | super_offset, |
| 4064 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4065 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4066 | __ Cbnz(out, &loop); |
| 4067 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4068 | __ B(&done); |
| 4069 | __ Bind(&success); |
| 4070 | __ Mov(out, 1); |
| 4071 | if (zero.IsLinked()) { |
| 4072 | __ B(&done); |
| 4073 | } |
| 4074 | break; |
| 4075 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4076 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4077 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4078 | ReadBarrierOption read_barrier_option = |
| 4079 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4080 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4081 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4082 | out_loc, |
| 4083 | obj_loc, |
| 4084 | class_offset, |
| 4085 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4086 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4087 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4088 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4089 | __ Cmp(out, cls); |
| 4090 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4091 | // 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] | 4092 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4093 | GenerateReferenceLoadOneRegister(instruction, |
| 4094 | out_loc, |
| 4095 | component_offset, |
| 4096 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4097 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4098 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4099 | __ Cbz(out, &done); |
| 4100 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4101 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4102 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4103 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4104 | __ Mov(out, 1); |
| 4105 | __ B(&done); |
| 4106 | break; |
| 4107 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4108 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4109 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4110 | // No read barrier since the slow path will retry upon failure. |
| 4111 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4112 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4113 | out_loc, |
| 4114 | obj_loc, |
| 4115 | class_offset, |
| 4116 | maybe_temp_loc, |
| 4117 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4118 | __ Cmp(out, cls); |
| 4119 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4120 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4121 | instruction, /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4122 | codegen_->AddSlowPath(slow_path); |
| 4123 | __ B(ne, slow_path->GetEntryLabel()); |
| 4124 | __ Mov(out, 1); |
| 4125 | if (zero.IsLinked()) { |
| 4126 | __ B(&done); |
| 4127 | } |
| 4128 | break; |
| 4129 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4130 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4131 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4132 | case TypeCheckKind::kInterfaceCheck: { |
| 4133 | // Note that we indeed only call on slow path, but we always go |
| 4134 | // into the slow path for the unresolved and interface check |
| 4135 | // cases. |
| 4136 | // |
| 4137 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4138 | // entry point without resorting to a type checking slow path |
| 4139 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4140 | // require to assign fixed registers for the inputs of this |
| 4141 | // HInstanceOf instruction (following the runtime calling |
| 4142 | // convention), which might be cluttered by the potential first |
| 4143 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4144 | // |
| 4145 | // TODO: Introduce a new runtime entry point taking the object |
| 4146 | // to test (instead of its class) as argument, and let it deal |
| 4147 | // with the read barrier issues. This will let us refactor this |
| 4148 | // case of the `switch` code as it was previously (with a direct |
| 4149 | // call to the runtime not using a type checking slow path). |
| 4150 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4151 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4152 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4153 | instruction, /* is_fatal */ false); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4154 | codegen_->AddSlowPath(slow_path); |
| 4155 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4156 | if (zero.IsLinked()) { |
| 4157 | __ B(&done); |
| 4158 | } |
| 4159 | break; |
| 4160 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4161 | |
| 4162 | case TypeCheckKind::kBitstringCheck: { |
| 4163 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4164 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4165 | out_loc, |
| 4166 | obj_loc, |
| 4167 | class_offset, |
| 4168 | maybe_temp_loc, |
| 4169 | kWithoutReadBarrier); |
| 4170 | |
| 4171 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 4172 | __ Cset(out, eq); |
| 4173 | if (zero.IsLinked()) { |
| 4174 | __ B(&done); |
| 4175 | } |
| 4176 | break; |
| 4177 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4178 | } |
| 4179 | |
| 4180 | if (zero.IsLinked()) { |
| 4181 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4182 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4183 | } |
| 4184 | |
| 4185 | if (done.IsLinked()) { |
| 4186 | __ Bind(&done); |
| 4187 | } |
| 4188 | |
| 4189 | if (slow_path != nullptr) { |
| 4190 | __ Bind(slow_path->GetExitLabel()); |
| 4191 | } |
| 4192 | } |
| 4193 | |
| 4194 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4195 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4196 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4197 | LocationSummary* locations = |
| 4198 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4199 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4200 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 4201 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 4202 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 4203 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 4204 | } else { |
| 4205 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4206 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4207 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4208 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4209 | } |
| 4210 | |
| 4211 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4212 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4213 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4214 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4215 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4216 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 4217 | ? Register() |
| 4218 | : InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4219 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4220 | DCHECK_GE(num_temps, 1u); |
| 4221 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4222 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4223 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4224 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4225 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4226 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4227 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4228 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4229 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4230 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4231 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4232 | const uint32_t object_array_data_offset = |
| 4233 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4234 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4235 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4236 | SlowPathCodeARM64* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4237 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4238 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4239 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4240 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4241 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4242 | // Avoid null check if we know obj is not null. |
| 4243 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4244 | __ Cbz(obj, &done); |
| 4245 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4246 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4247 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4248 | case TypeCheckKind::kExactCheck: |
| 4249 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4250 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4251 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4252 | temp_loc, |
| 4253 | obj_loc, |
| 4254 | class_offset, |
| 4255 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4256 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4257 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4258 | __ Cmp(temp, cls); |
| 4259 | // Jump to slow path for throwing the exception or doing a |
| 4260 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4261 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4262 | break; |
| 4263 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4264 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4265 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4266 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4267 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4268 | temp_loc, |
| 4269 | obj_loc, |
| 4270 | class_offset, |
| 4271 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4272 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4273 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4274 | // If the class is abstract, we eagerly fetch the super class of the |
| 4275 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4276 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4277 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4278 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4279 | GenerateReferenceLoadOneRegister(instruction, |
| 4280 | temp_loc, |
| 4281 | super_offset, |
| 4282 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4283 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4284 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4285 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4286 | // exception. |
| 4287 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4288 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4289 | __ Cmp(temp, cls); |
| 4290 | __ B(ne, &loop); |
| 4291 | break; |
| 4292 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4293 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4294 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4295 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4296 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4297 | temp_loc, |
| 4298 | obj_loc, |
| 4299 | class_offset, |
| 4300 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4301 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4302 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4303 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4304 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4305 | __ Bind(&loop); |
| 4306 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4307 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4308 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4309 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4310 | GenerateReferenceLoadOneRegister(instruction, |
| 4311 | temp_loc, |
| 4312 | super_offset, |
| 4313 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4314 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4315 | |
| 4316 | // If the class reference currently in `temp` is not null, jump |
| 4317 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4318 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4319 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4320 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4321 | break; |
| 4322 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4323 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4324 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4325 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4326 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4327 | temp_loc, |
| 4328 | obj_loc, |
| 4329 | class_offset, |
| 4330 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4331 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4332 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4333 | // Do an exact check. |
| 4334 | __ Cmp(temp, cls); |
| 4335 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4336 | |
| 4337 | // 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] | 4338 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4339 | GenerateReferenceLoadOneRegister(instruction, |
| 4340 | temp_loc, |
| 4341 | component_offset, |
| 4342 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4343 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4344 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4345 | // If the component type is null, jump to the slow path to throw the exception. |
| 4346 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4347 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4348 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4349 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4350 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4351 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4352 | break; |
| 4353 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4354 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4355 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4356 | // 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] | 4357 | // |
| 4358 | // We cannot directly call the CheckCast runtime entry point |
| 4359 | // without resorting to a type checking slow path here (i.e. by |
| 4360 | // calling InvokeRuntime directly), as it would require to |
| 4361 | // assign fixed registers for the inputs of this HInstanceOf |
| 4362 | // instruction (following the runtime calling convention), which |
| 4363 | // might be cluttered by the potential first read barrier |
| 4364 | // emission at the beginning of this method. |
| 4365 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4366 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4367 | case TypeCheckKind::kInterfaceCheck: { |
| 4368 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4369 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4370 | temp_loc, |
| 4371 | obj_loc, |
| 4372 | class_offset, |
| 4373 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4374 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4375 | |
| 4376 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4377 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4378 | temp_loc, |
| 4379 | temp_loc, |
| 4380 | iftable_offset, |
| 4381 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4382 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4383 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4384 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4385 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4386 | vixl::aarch64::Label start_loop; |
| 4387 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4388 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4389 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4390 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4391 | // Go to next interface. |
| 4392 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4393 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4394 | // Compare the classes and continue the loop if they do not match. |
| 4395 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4396 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4397 | break; |
| 4398 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4399 | |
| 4400 | case TypeCheckKind::kBitstringCheck: { |
| 4401 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4402 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4403 | temp_loc, |
| 4404 | obj_loc, |
| 4405 | class_offset, |
| 4406 | maybe_temp2_loc, |
| 4407 | kWithoutReadBarrier); |
| 4408 | |
| 4409 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 4410 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 4411 | break; |
| 4412 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4413 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4414 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4415 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4416 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4417 | } |
| 4418 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4419 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4420 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4421 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4422 | } |
| 4423 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4424 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4425 | // Will be generated at use site. |
| 4426 | } |
| 4427 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4428 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4429 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4430 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4431 | } |
| 4432 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4433 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4434 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4435 | } |
| 4436 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4437 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4438 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4439 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4440 | // the method_idx. |
| 4441 | HandleInvoke(invoke); |
| 4442 | } |
| 4443 | |
| 4444 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4445 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4446 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4447 | } |
| 4448 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4449 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4450 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4451 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4452 | } |
| 4453 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4454 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4455 | HandleInvoke(invoke); |
| 4456 | } |
| 4457 | |
| 4458 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4459 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4460 | LocationSummary* locations = invoke->GetLocations(); |
| 4461 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4462 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4463 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4464 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4465 | |
| 4466 | // The register ip1 is required to be used for the hidden argument in |
| 4467 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4468 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4469 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4470 | scratch_scope.Exclude(ip1); |
| 4471 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4472 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4473 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4474 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4475 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4476 | { |
| 4477 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4478 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4479 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4480 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4481 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4482 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4483 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4484 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4485 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4486 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4487 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4488 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4489 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4490 | // emit a read barrier for the previous class reference load. |
| 4491 | // However this is not required in practice, as this is an |
| 4492 | // intermediate/temporary reference and because the current |
| 4493 | // concurrent copying collector keeps the from-space memory |
| 4494 | // intact/accessible until the end of the marking phase (the |
| 4495 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4496 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4497 | __ Ldr(temp, |
| 4498 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4499 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4500 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4501 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4502 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4503 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4504 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4505 | |
| 4506 | { |
| 4507 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4508 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4509 | |
| 4510 | // lr(); |
| 4511 | __ blr(lr); |
| 4512 | DCHECK(!codegen_->IsLeafMethod()); |
| 4513 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4514 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4515 | |
| 4516 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4520 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4521 | if (intrinsic.TryDispatch(invoke)) { |
| 4522 | return; |
| 4523 | } |
| 4524 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4525 | HandleInvoke(invoke); |
| 4526 | } |
| 4527 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4528 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4529 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4530 | // art::PrepareForRegisterAllocation. |
| 4531 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4532 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4533 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4534 | if (intrinsic.TryDispatch(invoke)) { |
| 4535 | return; |
| 4536 | } |
| 4537 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4538 | HandleInvoke(invoke); |
| 4539 | } |
| 4540 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4541 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4542 | if (invoke->GetLocations()->Intrinsified()) { |
| 4543 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4544 | intrinsic.Dispatch(invoke); |
| 4545 | return true; |
| 4546 | } |
| 4547 | return false; |
| 4548 | } |
| 4549 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4550 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4551 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4552 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4553 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4554 | return desired_dispatch_info; |
| 4555 | } |
| 4556 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4557 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4558 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4559 | // 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] | 4560 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4561 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4562 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4563 | uint32_t offset = |
| 4564 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4565 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4566 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4567 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4568 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4569 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4570 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4571 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4572 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4573 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4574 | // Add ADRP with its PC-relative method patch. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4575 | vixl::aarch64::Label* adrp_label = NewBootImageMethodPatch(invoke->GetTargetMethod()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4576 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4577 | // Add ADD with its PC-relative method patch. |
| 4578 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4579 | NewBootImageMethodPatch(invoke->GetTargetMethod(), adrp_label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4580 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4581 | break; |
| 4582 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4583 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4584 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4585 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4586 | break; |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4587 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4588 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4589 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4590 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_offset); |
| 4591 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4592 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| 4593 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| 4594 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 4595 | EmitLdrOffsetPlaceholder(ldr_label, WRegisterFrom(temp), XRegisterFrom(temp)); |
| 4596 | break; |
| 4597 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4598 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4599 | // Add ADRP with its PC-relative .bss entry patch. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4600 | MethodReference target_method(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4601 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(target_method); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4602 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4603 | // Add LDR with its PC-relative .bss entry patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4604 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4605 | NewMethodBssEntryPatch(target_method, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4606 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4607 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4608 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4609 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4610 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4611 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4612 | } |
| 4613 | } |
| 4614 | |
| 4615 | switch (invoke->GetCodePtrLocation()) { |
| 4616 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4617 | { |
| 4618 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4619 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4620 | kInstructionSize, |
| 4621 | CodeBufferCheckScope::kExactSize); |
| 4622 | __ bl(&frame_entry_label_); |
| 4623 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4624 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4625 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4626 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4627 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4628 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4629 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4630 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4631 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4632 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4633 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4634 | kInstructionSize, |
| 4635 | CodeBufferCheckScope::kExactSize); |
| 4636 | // lr() |
| 4637 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4638 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4639 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4640 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4641 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4642 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4643 | DCHECK(!IsLeafMethod()); |
| 4644 | } |
| 4645 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4646 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4647 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4648 | // Use the calling convention instead of the location of the receiver, as |
| 4649 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4650 | // slow path, the arguments have been moved to the right place, so here we are |
| 4651 | // guaranteed that the receiver is the first register of the calling convention. |
| 4652 | InvokeDexCallingConvention calling_convention; |
| 4653 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4654 | Register temp = XRegisterFrom(temp_in); |
| 4655 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4656 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4657 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4658 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4659 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4660 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4661 | |
| 4662 | { |
| 4663 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4664 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4665 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4666 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4667 | MaybeRecordImplicitNullCheck(invoke); |
| 4668 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4669 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4670 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4671 | // intermediate/temporary reference and because the current |
| 4672 | // concurrent copying collector keeps the from-space memory |
| 4673 | // intact/accessible until the end of the marking phase (the |
| 4674 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4675 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4676 | // temp = temp->GetMethodAt(method_offset); |
| 4677 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4678 | // lr = temp->GetEntryPoint(); |
| 4679 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4680 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4681 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4682 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4683 | // lr(); |
| 4684 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4685 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4686 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4687 | } |
| 4688 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4689 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4690 | HandleInvoke(invoke); |
| 4691 | } |
| 4692 | |
| 4693 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4694 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4695 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4696 | } |
| 4697 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4698 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageRelRoPatch( |
| 4699 | uint32_t boot_image_offset, |
| 4700 | vixl::aarch64::Label* adrp_label) { |
| 4701 | return NewPcRelativePatch( |
| 4702 | /* dex_file */ nullptr, boot_image_offset, adrp_label, &boot_image_method_patches_); |
| 4703 | } |
| 4704 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4705 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageMethodPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4706 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4707 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4708 | return NewPcRelativePatch( |
| 4709 | 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] | 4710 | } |
| 4711 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4712 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4713 | MethodReference target_method, |
| 4714 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4715 | return NewPcRelativePatch( |
| 4716 | 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] | 4717 | } |
| 4718 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4719 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageTypePatch( |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4720 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4721 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4722 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4723 | 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] | 4724 | } |
| 4725 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4726 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4727 | const DexFile& dex_file, |
| 4728 | dex::TypeIndex type_index, |
| 4729 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4730 | 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] | 4731 | } |
| 4732 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4733 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageStringPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4734 | const DexFile& dex_file, |
| 4735 | dex::StringIndex string_index, |
| 4736 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4737 | return NewPcRelativePatch( |
| 4738 | &dex_file, string_index.index_, adrp_label, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4739 | } |
| 4740 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4741 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4742 | const DexFile& dex_file, |
| 4743 | dex::StringIndex string_index, |
| 4744 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4745 | 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] | 4746 | } |
| 4747 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4748 | vixl::aarch64::Label* CodeGeneratorARM64::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 4749 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4750 | return &baker_read_barrier_patches_.back().label; |
| 4751 | } |
| 4752 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4753 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4754 | const DexFile* dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4755 | uint32_t offset_or_index, |
| 4756 | vixl::aarch64::Label* adrp_label, |
| 4757 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4758 | // Add a patch entry and return the label. |
| 4759 | patches->emplace_back(dex_file, offset_or_index); |
| 4760 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4761 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4762 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4763 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4764 | return label; |
| 4765 | } |
| 4766 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4767 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4768 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4769 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4770 | } |
| 4771 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4772 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4773 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4774 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4775 | return jit_string_patches_.GetOrCreate( |
| 4776 | StringReference(&dex_file, string_index), |
| 4777 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4778 | } |
| 4779 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4780 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4781 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4782 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4783 | return jit_class_patches_.GetOrCreate( |
| 4784 | TypeReference(&dex_file, type_index), |
| 4785 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4786 | } |
| 4787 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4788 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4789 | vixl::aarch64::Register reg) { |
| 4790 | DCHECK(reg.IsX()); |
| 4791 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4792 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4793 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4794 | } |
| 4795 | |
| 4796 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4797 | vixl::aarch64::Register out, |
| 4798 | vixl::aarch64::Register base) { |
| 4799 | DCHECK(out.IsX()); |
| 4800 | DCHECK(base.IsX()); |
| 4801 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4802 | __ Bind(fixup_label); |
| 4803 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4804 | } |
| 4805 | |
| 4806 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4807 | vixl::aarch64::Register out, |
| 4808 | vixl::aarch64::Register base) { |
| 4809 | DCHECK(base.IsX()); |
| 4810 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4811 | __ Bind(fixup_label); |
| 4812 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4813 | } |
| 4814 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4815 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4816 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4817 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4818 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4819 | for (const PcRelativePatchInfo& info : infos) { |
| 4820 | linker_patches->push_back(Factory(info.label.GetLocation(), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4821 | info.target_dex_file, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4822 | info.pc_insn_label->GetLocation(), |
| 4823 | info.offset_or_index)); |
| 4824 | } |
| 4825 | } |
| 4826 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4827 | linker::LinkerPatch DataBimgRelRoPatchAdapter(size_t literal_offset, |
| 4828 | const DexFile* target_dex_file, |
| 4829 | uint32_t pc_insn_offset, |
| 4830 | uint32_t boot_image_offset) { |
| 4831 | DCHECK(target_dex_file == nullptr); // Unused for DataBimgRelRoPatch(), should be null. |
| 4832 | return linker::LinkerPatch::DataBimgRelRoPatch(literal_offset, pc_insn_offset, boot_image_offset); |
| 4833 | } |
| 4834 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4835 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4836 | DCHECK(linker_patches->empty()); |
| 4837 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4838 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4839 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4840 | boot_image_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4841 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4842 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4843 | string_bss_entry_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4844 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4845 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4846 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4847 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4848 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4849 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4850 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4851 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4852 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4853 | } else { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4854 | EmitPcRelativeLinkerPatches<DataBimgRelRoPatchAdapter>( |
| 4855 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4856 | DCHECK(boot_image_type_patches_.empty()); |
| 4857 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4858 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4859 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4860 | method_bss_entry_patches_, linker_patches); |
| 4861 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4862 | type_bss_entry_patches_, linker_patches); |
| 4863 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4864 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4865 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4866 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 4867 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4868 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4869 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4870 | } |
| 4871 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4872 | bool CodeGeneratorARM64::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
| 4873 | return patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
| 4874 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 4875 | } |
| 4876 | |
| 4877 | void CodeGeneratorARM64::EmitThunkCode(const linker::LinkerPatch& patch, |
| 4878 | /*out*/ ArenaVector<uint8_t>* code, |
| 4879 | /*out*/ std::string* debug_name) { |
| 4880 | Arm64Assembler assembler(GetGraph()->GetAllocator()); |
| 4881 | switch (patch.GetType()) { |
| 4882 | case linker::LinkerPatch::Type::kCallRelative: { |
| 4883 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 4884 | // to the generic JNI and interpreter trampolines. |
| 4885 | Offset offset(ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4886 | kArm64PointerSize).Int32Value()); |
| 4887 | assembler.JumpTo(ManagedRegister(arm64::X0), offset, ManagedRegister(arm64::IP0)); |
| 4888 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 4889 | *debug_name = "MethodCallThunk"; |
| 4890 | } |
| 4891 | break; |
| 4892 | } |
| 4893 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| 4894 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 4895 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 4896 | break; |
| 4897 | } |
| 4898 | default: |
| 4899 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 4900 | UNREACHABLE(); |
| 4901 | } |
| 4902 | |
| 4903 | // Ensure we emit the literal pool if any. |
| 4904 | assembler.FinalizeCode(); |
| 4905 | code->resize(assembler.CodeSize()); |
| 4906 | MemoryRegion code_region(code->data(), code->size()); |
| 4907 | assembler.FinalizeInstructions(code_region); |
| 4908 | } |
| 4909 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4910 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4911 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4912 | value, |
| 4913 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4914 | } |
| 4915 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4916 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4917 | return uint64_literals_.GetOrCreate( |
| 4918 | value, |
| 4919 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4920 | } |
| 4921 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4922 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4923 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4924 | // art::PrepareForRegisterAllocation. |
| 4925 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4926 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4927 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4928 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4929 | return; |
| 4930 | } |
| 4931 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4932 | { |
| 4933 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4934 | // are no pools emitted. |
| 4935 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4936 | LocationSummary* locations = invoke->GetLocations(); |
| 4937 | codegen_->GenerateStaticOrDirectCall( |
| 4938 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| 4939 | } |
| 4940 | |
| 4941 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4945 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4946 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4947 | return; |
| 4948 | } |
| 4949 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4950 | { |
| 4951 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4952 | // are no pools emitted. |
| 4953 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4954 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 4955 | DCHECK(!codegen_->IsLeafMethod()); |
| 4956 | } |
| 4957 | |
| 4958 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4959 | } |
| 4960 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4961 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4962 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4963 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4964 | case HLoadClass::LoadKind::kInvalid: |
| 4965 | LOG(FATAL) << "UNREACHABLE"; |
| 4966 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4967 | case HLoadClass::LoadKind::kReferrersClass: |
| 4968 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4969 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4970 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4971 | case HLoadClass::LoadKind::kBssEntry: |
| 4972 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4973 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4974 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4975 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4976 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4977 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4978 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4979 | break; |
| 4980 | } |
| 4981 | return desired_class_load_kind; |
| 4982 | } |
| 4983 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4984 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4985 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4986 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4987 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4988 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4989 | cls, |
| 4990 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4991 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4992 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4993 | return; |
| 4994 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4995 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4996 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4997 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4998 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4999 | ? LocationSummary::kCallOnSlowPath |
| 5000 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5001 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5002 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5003 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5004 | } |
| 5005 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5006 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5007 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5008 | } |
| 5009 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5010 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 5011 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5012 | // 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] | 5013 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5014 | InvokeRuntimeCallingConvention calling_convention; |
| 5015 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 5016 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5017 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 5018 | DataType::Type::kReference).GetCode()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5019 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5020 | } else { |
| 5021 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5022 | } |
| 5023 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5024 | } |
| 5025 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5026 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5027 | // move. |
| 5028 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5029 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5030 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5031 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5032 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5033 | return; |
| 5034 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5035 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5036 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5037 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5038 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5039 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5040 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5041 | ? kWithoutReadBarrier |
| 5042 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5043 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5044 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5045 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5046 | DCHECK(!cls->CanCallRuntime()); |
| 5047 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5048 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5049 | Register current_method = InputRegisterAt(cls, 0); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5050 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5051 | out_loc, |
| 5052 | current_method, |
| 5053 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 5054 | /* fixup_label */ nullptr, |
| 5055 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5056 | break; |
| 5057 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5058 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5059 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5060 | // Add ADRP with its PC-relative type patch. |
| 5061 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5062 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5063 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5064 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5065 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5066 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5067 | codegen_->NewBootImageTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5068 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5069 | break; |
| 5070 | } |
| 5071 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5072 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5073 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5074 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 5075 | DCHECK_NE(address, 0u); |
| 5076 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5077 | break; |
| 5078 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5079 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5080 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5081 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls); |
| 5082 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5083 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5084 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5085 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5086 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5087 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5088 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5089 | break; |
| 5090 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5091 | case HLoadClass::LoadKind::kBssEntry: { |
| 5092 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 5093 | const DexFile& dex_file = cls->GetDexFile(); |
| 5094 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5095 | vixl::aarch64::Register temp = XRegisterFrom(out_loc); |
| 5096 | vixl::aarch64::Label* adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 5097 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5098 | // Add LDR with its PC-relative Class .bss entry patch. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5099 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5100 | codegen_->NewBssEntryTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5101 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5102 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5103 | out_loc, |
| 5104 | temp, |
| 5105 | /* offset placeholder */ 0u, |
| 5106 | ldr_label, |
| 5107 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5108 | generate_null_check = true; |
| 5109 | break; |
| 5110 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5111 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5112 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5113 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5114 | cls->GetClass())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5115 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5116 | out_loc, |
| 5117 | out.X(), |
| 5118 | /* offset */ 0, |
| 5119 | /* fixup_label */ nullptr, |
| 5120 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5121 | break; |
| 5122 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5123 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5124 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5125 | LOG(FATAL) << "UNREACHABLE"; |
| 5126 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5127 | } |
| 5128 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5129 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5130 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5131 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5132 | SlowPathCodeARM64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64( |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5133 | cls, cls, cls->GetDexPc(), do_clinit); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5134 | codegen_->AddSlowPath(slow_path); |
| 5135 | if (generate_null_check) { |
| 5136 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5137 | } |
| 5138 | if (cls->MustGenerateClinitCheck()) { |
| 5139 | GenerateClassInitializationCheck(slow_path, out); |
| 5140 | } else { |
| 5141 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5142 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5143 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5144 | } |
| 5145 | } |
| 5146 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5147 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5148 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5149 | } |
| 5150 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5151 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5152 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5153 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5154 | locations->SetOut(Location::RequiresRegister()); |
| 5155 | } |
| 5156 | |
| 5157 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5158 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5159 | } |
| 5160 | |
| 5161 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5162 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5163 | } |
| 5164 | |
| 5165 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5166 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5167 | } |
| 5168 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5169 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5170 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5171 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5172 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5173 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5174 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5175 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5176 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5177 | case HLoadString::LoadKind::kJitTableAddress: |
| 5178 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5179 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5180 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5181 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5182 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5183 | } |
| 5184 | return desired_string_load_kind; |
| 5185 | } |
| 5186 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5187 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5188 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5189 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5190 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5191 | InvokeRuntimeCallingConvention calling_convention; |
| 5192 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5193 | } else { |
| 5194 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5195 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5196 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5197 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5198 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5199 | InvokeRuntimeCallingConvention calling_convention; |
| 5200 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 5201 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5202 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 5203 | DataType::Type::kReference).GetCode()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5204 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5205 | } else { |
| 5206 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5207 | } |
| 5208 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5209 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5210 | } |
| 5211 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5212 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5213 | // move. |
| 5214 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5215 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5216 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5217 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5218 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5219 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5220 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5221 | // Add ADRP with its PC-relative String patch. |
| 5222 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5223 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5224 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5225 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5226 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5227 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5228 | codegen_->NewBootImageStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5229 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5230 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5231 | } |
| 5232 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5233 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5234 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5235 | DCHECK_NE(address, 0u); |
| 5236 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5237 | return; |
| 5238 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5239 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5240 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5241 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5242 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(load); |
| 5243 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5244 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5245 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5246 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5247 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5248 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 5249 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5250 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5251 | case HLoadString::LoadKind::kBssEntry: { |
| 5252 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5253 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5254 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5255 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5256 | Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5257 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5258 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5259 | // Add LDR with its PC-relative String .bss entry patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5260 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5261 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5262 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5263 | codegen_->GenerateGcRootFieldLoad(load, |
| 5264 | out_loc, |
| 5265 | temp, |
| 5266 | /* offset placeholder */ 0u, |
| 5267 | ldr_label, |
| 5268 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5269 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5270 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5271 | codegen_->AddSlowPath(slow_path); |
| 5272 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5273 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5274 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5275 | return; |
| 5276 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5277 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5278 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5279 | load->GetStringIndex(), |
| 5280 | load->GetString())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5281 | codegen_->GenerateGcRootFieldLoad(load, |
| 5282 | out_loc, |
| 5283 | out.X(), |
| 5284 | /* offset */ 0, |
| 5285 | /* fixup_label */ nullptr, |
| 5286 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5287 | return; |
| 5288 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5289 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5290 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5291 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5292 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5293 | // 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] | 5294 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5295 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5296 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5297 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5298 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5299 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5300 | } |
| 5301 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5302 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5303 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5304 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5305 | } |
| 5306 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5307 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5308 | // Will be generated at use site. |
| 5309 | } |
| 5310 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5311 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5312 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5313 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5314 | InvokeRuntimeCallingConvention calling_convention; |
| 5315 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5316 | } |
| 5317 | |
| 5318 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5319 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5320 | instruction, |
| 5321 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5322 | if (instruction->IsEnter()) { |
| 5323 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5324 | } else { |
| 5325 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5326 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5327 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5328 | } |
| 5329 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5330 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5331 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5332 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5333 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5334 | case DataType::Type::kInt32: |
| 5335 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5336 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5337 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5338 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5339 | break; |
| 5340 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5341 | case DataType::Type::kFloat32: |
| 5342 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5343 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5344 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5345 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5346 | break; |
| 5347 | |
| 5348 | default: |
| 5349 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5350 | } |
| 5351 | } |
| 5352 | |
| 5353 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5354 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5355 | case DataType::Type::kInt32: |
| 5356 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5357 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5358 | break; |
| 5359 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5360 | case DataType::Type::kFloat32: |
| 5361 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5362 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5363 | break; |
| 5364 | |
| 5365 | default: |
| 5366 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5367 | } |
| 5368 | } |
| 5369 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5370 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5371 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5372 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5373 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5374 | case DataType::Type::kInt32: |
| 5375 | case DataType::Type::kInt64: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5376 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5377 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5378 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5379 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5380 | case DataType::Type::kFloat32: |
| 5381 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5382 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5383 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5384 | break; |
| 5385 | |
| 5386 | default: |
| 5387 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5388 | } |
| 5389 | } |
| 5390 | |
| 5391 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5392 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5393 | case DataType::Type::kInt32: |
| 5394 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5395 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5396 | break; |
| 5397 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5398 | case DataType::Type::kFloat32: |
| 5399 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5400 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5401 | break; |
| 5402 | |
| 5403 | default: |
| 5404 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5405 | } |
| 5406 | } |
| 5407 | |
| 5408 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5409 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5410 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5411 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5412 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5413 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5414 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5415 | } |
| 5416 | |
| 5417 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5418 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5419 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5420 | QuickEntrypointEnum entrypoint = |
| 5421 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5422 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5423 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5424 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5425 | } |
| 5426 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5427 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5428 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5429 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5430 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5431 | if (instruction->IsStringAlloc()) { |
| 5432 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 5433 | } else { |
| 5434 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5435 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5436 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5437 | } |
| 5438 | |
| 5439 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* 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. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5442 | if (instruction->IsStringAlloc()) { |
| 5443 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5444 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5445 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5446 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 5447 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5448 | |
| 5449 | { |
| 5450 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 5451 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 5452 | kInstructionSize, |
| 5453 | CodeBufferCheckScope::kExactSize); |
| 5454 | __ blr(lr); |
| 5455 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5456 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5457 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5458 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5459 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5460 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5461 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5462 | } |
| 5463 | |
| 5464 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5465 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5466 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5467 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5468 | } |
| 5469 | |
| 5470 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5471 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5472 | case DataType::Type::kInt32: |
| 5473 | case DataType::Type::kInt64: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5474 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5475 | break; |
| 5476 | |
| 5477 | default: |
| 5478 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5479 | } |
| 5480 | } |
| 5481 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5482 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5483 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5484 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5485 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5486 | } |
| 5487 | |
| 5488 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5489 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5490 | } |
| 5491 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5492 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5493 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5494 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5495 | } |
| 5496 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5497 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5498 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5499 | return; |
| 5500 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5501 | { |
| 5502 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5503 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5504 | Location obj = instruction->GetLocations()->InAt(0); |
| 5505 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5506 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5507 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5508 | } |
| 5509 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5510 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5511 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5512 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5513 | |
| 5514 | LocationSummary* locations = instruction->GetLocations(); |
| 5515 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5516 | |
| 5517 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5518 | } |
| 5519 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5520 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5521 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5522 | } |
| 5523 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5524 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5525 | HandleBinaryOp(instruction); |
| 5526 | } |
| 5527 | |
| 5528 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5529 | HandleBinaryOp(instruction); |
| 5530 | } |
| 5531 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5532 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5533 | LOG(FATAL) << "Unreachable"; |
| 5534 | } |
| 5535 | |
| 5536 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5537 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5538 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5539 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5540 | // The back edge will generate the suspend check. |
| 5541 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5542 | } |
| 5543 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5544 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5545 | } |
| 5546 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5547 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5548 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5549 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5550 | if (location.IsStackSlot()) { |
| 5551 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5552 | } else if (location.IsDoubleStackSlot()) { |
| 5553 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5554 | } |
| 5555 | locations->SetOut(location); |
| 5556 | } |
| 5557 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5558 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5559 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5560 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5561 | } |
| 5562 | |
| 5563 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5564 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5565 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5566 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5567 | } |
| 5568 | |
| 5569 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5570 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5571 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5572 | } |
| 5573 | |
| 5574 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5575 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5576 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5577 | locations->SetInAt(i, Location::Any()); |
| 5578 | } |
| 5579 | locations->SetOut(Location::Any()); |
| 5580 | } |
| 5581 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5582 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5583 | LOG(FATAL) << "Unreachable"; |
| 5584 | } |
| 5585 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5586 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5587 | DataType::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5588 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5589 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5590 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5591 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5592 | |
| 5593 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5594 | case DataType::Type::kInt32: |
| 5595 | case DataType::Type::kInt64: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5596 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5597 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5598 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5599 | break; |
| 5600 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5601 | case DataType::Type::kFloat32: |
| 5602 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5603 | InvokeRuntimeCallingConvention calling_convention; |
| 5604 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5605 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5606 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5607 | |
| 5608 | break; |
| 5609 | } |
| 5610 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5611 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5612 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5613 | } |
| 5614 | } |
| 5615 | |
| 5616 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5617 | DataType::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5618 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5619 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5620 | case DataType::Type::kInt32: |
| 5621 | case DataType::Type::kInt64: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5622 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5623 | break; |
| 5624 | } |
| 5625 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5626 | case DataType::Type::kFloat32: |
| 5627 | case DataType::Type::kFloat64: { |
| 5628 | QuickEntrypointEnum entrypoint = |
| 5629 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5630 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5631 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5632 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5633 | } else { |
| 5634 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5635 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5636 | break; |
| 5637 | } |
| 5638 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5639 | default: |
| 5640 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5641 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5642 | } |
| 5643 | } |
| 5644 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5645 | // TODO: integrate with HandleBinaryOp? |
| 5646 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 5647 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 5648 | switch (minmax->GetResultType()) { |
| 5649 | case DataType::Type::kInt32: |
| 5650 | case DataType::Type::kInt64: |
| 5651 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5652 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5653 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5654 | break; |
| 5655 | case DataType::Type::kFloat32: |
| 5656 | case DataType::Type::kFloat64: |
| 5657 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5658 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5659 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5660 | break; |
| 5661 | default: |
| 5662 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 5663 | } |
| 5664 | } |
| 5665 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 5666 | void InstructionCodeGeneratorARM64::GenerateMinMaxInt(LocationSummary* locations, |
| 5667 | bool is_min, |
| 5668 | DataType::Type type) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5669 | Location op1 = locations->InAt(0); |
| 5670 | Location op2 = locations->InAt(1); |
| 5671 | Location out = locations->Out(); |
| 5672 | |
| 5673 | Register op1_reg; |
| 5674 | Register op2_reg; |
| 5675 | Register out_reg; |
| 5676 | if (type == DataType::Type::kInt64) { |
| 5677 | op1_reg = XRegisterFrom(op1); |
| 5678 | op2_reg = XRegisterFrom(op2); |
| 5679 | out_reg = XRegisterFrom(out); |
| 5680 | } else { |
| 5681 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 5682 | op1_reg = WRegisterFrom(op1); |
| 5683 | op2_reg = WRegisterFrom(op2); |
| 5684 | out_reg = WRegisterFrom(out); |
| 5685 | } |
| 5686 | |
| 5687 | __ Cmp(op1_reg, op2_reg); |
| 5688 | __ Csel(out_reg, op1_reg, op2_reg, is_min ? lt : gt); |
| 5689 | } |
| 5690 | |
| 5691 | void InstructionCodeGeneratorARM64::GenerateMinMaxFP(LocationSummary* locations, |
| 5692 | bool is_min, |
| 5693 | DataType::Type type) { |
| 5694 | Location op1 = locations->InAt(0); |
| 5695 | Location op2 = locations->InAt(1); |
| 5696 | Location out = locations->Out(); |
| 5697 | |
| 5698 | FPRegister op1_reg; |
| 5699 | FPRegister op2_reg; |
| 5700 | FPRegister out_reg; |
| 5701 | if (type == DataType::Type::kFloat64) { |
| 5702 | op1_reg = DRegisterFrom(op1); |
| 5703 | op2_reg = DRegisterFrom(op2); |
| 5704 | out_reg = DRegisterFrom(out); |
| 5705 | } else { |
| 5706 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 5707 | op1_reg = SRegisterFrom(op1); |
| 5708 | op2_reg = SRegisterFrom(op2); |
| 5709 | out_reg = SRegisterFrom(out); |
| 5710 | } |
| 5711 | |
| 5712 | if (is_min) { |
| 5713 | __ Fmin(out_reg, op1_reg, op2_reg); |
| 5714 | } else { |
| 5715 | __ Fmax(out_reg, op1_reg, op2_reg); |
| 5716 | } |
| 5717 | } |
| 5718 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 5719 | // TODO: integrate with HandleBinaryOp? |
| 5720 | void InstructionCodeGeneratorARM64::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 5721 | DataType::Type type = minmax->GetResultType(); |
| 5722 | switch (type) { |
| 5723 | case DataType::Type::kInt32: |
| 5724 | case DataType::Type::kInt64: |
| 5725 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 5726 | break; |
| 5727 | case DataType::Type::kFloat32: |
| 5728 | case DataType::Type::kFloat64: |
| 5729 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 5730 | break; |
| 5731 | default: |
| 5732 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 5733 | } |
| 5734 | } |
| 5735 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5736 | void LocationsBuilderARM64::VisitMin(HMin* min) { |
| 5737 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 5738 | } |
| 5739 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5740 | void InstructionCodeGeneratorARM64::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 5741 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5742 | } |
| 5743 | |
| 5744 | void LocationsBuilderARM64::VisitMax(HMax* max) { |
| 5745 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 5746 | } |
| 5747 | |
| 5748 | void InstructionCodeGeneratorARM64::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 5749 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5750 | } |
| 5751 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5752 | void LocationsBuilderARM64::VisitAbs(HAbs* abs) { |
| 5753 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 5754 | switch (abs->GetResultType()) { |
| 5755 | case DataType::Type::kInt32: |
| 5756 | case DataType::Type::kInt64: |
| 5757 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5758 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5759 | break; |
| 5760 | case DataType::Type::kFloat32: |
| 5761 | case DataType::Type::kFloat64: |
| 5762 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5763 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5764 | break; |
| 5765 | default: |
| 5766 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5767 | } |
| 5768 | } |
| 5769 | |
| 5770 | void InstructionCodeGeneratorARM64::VisitAbs(HAbs* abs) { |
| 5771 | switch (abs->GetResultType()) { |
| 5772 | case DataType::Type::kInt32: |
| 5773 | case DataType::Type::kInt64: { |
| 5774 | Register in_reg = InputRegisterAt(abs, 0); |
| 5775 | Register out_reg = OutputRegister(abs); |
| 5776 | __ Cmp(in_reg, Operand(0)); |
| 5777 | __ Cneg(out_reg, in_reg, lt); |
| 5778 | break; |
| 5779 | } |
| 5780 | case DataType::Type::kFloat32: |
| 5781 | case DataType::Type::kFloat64: { |
| 5782 | FPRegister in_reg = InputFPRegisterAt(abs, 0); |
| 5783 | FPRegister out_reg = OutputFPRegister(abs); |
| 5784 | __ Fabs(out_reg, in_reg); |
| 5785 | break; |
| 5786 | } |
| 5787 | default: |
| 5788 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5789 | } |
| 5790 | } |
| 5791 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5792 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5793 | constructor_fence->SetLocations(nullptr); |
| 5794 | } |
| 5795 | |
| 5796 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5797 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5798 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5799 | } |
| 5800 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5801 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5802 | memory_barrier->SetLocations(nullptr); |
| 5803 | } |
| 5804 | |
| 5805 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5806 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5807 | } |
| 5808 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5809 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5810 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5811 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5812 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5813 | } |
| 5814 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5815 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5816 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5817 | } |
| 5818 | |
| 5819 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5820 | instruction->SetLocations(nullptr); |
| 5821 | } |
| 5822 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5823 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5824 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5825 | } |
| 5826 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5827 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5828 | HandleBinaryOp(ror); |
| 5829 | } |
| 5830 | |
| 5831 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5832 | HandleBinaryOp(ror); |
| 5833 | } |
| 5834 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5835 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5836 | HandleShift(shl); |
| 5837 | } |
| 5838 | |
| 5839 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5840 | HandleShift(shl); |
| 5841 | } |
| 5842 | |
| 5843 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5844 | HandleShift(shr); |
| 5845 | } |
| 5846 | |
| 5847 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5848 | HandleShift(shr); |
| 5849 | } |
| 5850 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5851 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5852 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5853 | } |
| 5854 | |
| 5855 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5856 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5857 | } |
| 5858 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5859 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5860 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5861 | } |
| 5862 | |
| 5863 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5864 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5865 | } |
| 5866 | |
| 5867 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5868 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5869 | } |
| 5870 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5871 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5872 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5873 | } |
| 5874 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5875 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5876 | HUnresolvedInstanceFieldGet* instruction) { |
| 5877 | FieldAccessCallingConventionARM64 calling_convention; |
| 5878 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5879 | instruction, instruction->GetFieldType(), calling_convention); |
| 5880 | } |
| 5881 | |
| 5882 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5883 | HUnresolvedInstanceFieldGet* instruction) { |
| 5884 | FieldAccessCallingConventionARM64 calling_convention; |
| 5885 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5886 | instruction->GetFieldType(), |
| 5887 | instruction->GetFieldIndex(), |
| 5888 | instruction->GetDexPc(), |
| 5889 | calling_convention); |
| 5890 | } |
| 5891 | |
| 5892 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5893 | HUnresolvedInstanceFieldSet* instruction) { |
| 5894 | FieldAccessCallingConventionARM64 calling_convention; |
| 5895 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5896 | instruction, instruction->GetFieldType(), calling_convention); |
| 5897 | } |
| 5898 | |
| 5899 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5900 | HUnresolvedInstanceFieldSet* instruction) { |
| 5901 | FieldAccessCallingConventionARM64 calling_convention; |
| 5902 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5903 | instruction->GetFieldType(), |
| 5904 | instruction->GetFieldIndex(), |
| 5905 | instruction->GetDexPc(), |
| 5906 | calling_convention); |
| 5907 | } |
| 5908 | |
| 5909 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5910 | HUnresolvedStaticFieldGet* instruction) { |
| 5911 | FieldAccessCallingConventionARM64 calling_convention; |
| 5912 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5913 | instruction, instruction->GetFieldType(), calling_convention); |
| 5914 | } |
| 5915 | |
| 5916 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5917 | HUnresolvedStaticFieldGet* instruction) { |
| 5918 | FieldAccessCallingConventionARM64 calling_convention; |
| 5919 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5920 | instruction->GetFieldType(), |
| 5921 | instruction->GetFieldIndex(), |
| 5922 | instruction->GetDexPc(), |
| 5923 | calling_convention); |
| 5924 | } |
| 5925 | |
| 5926 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5927 | HUnresolvedStaticFieldSet* instruction) { |
| 5928 | FieldAccessCallingConventionARM64 calling_convention; |
| 5929 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5930 | instruction, instruction->GetFieldType(), calling_convention); |
| 5931 | } |
| 5932 | |
| 5933 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5934 | HUnresolvedStaticFieldSet* instruction) { |
| 5935 | FieldAccessCallingConventionARM64 calling_convention; |
| 5936 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5937 | instruction->GetFieldType(), |
| 5938 | instruction->GetFieldIndex(), |
| 5939 | instruction->GetDexPc(), |
| 5940 | calling_convention); |
| 5941 | } |
| 5942 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5943 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5944 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5945 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5946 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5947 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5948 | // registers in full width (since the runtime only saves/restores lower part). |
| 5949 | locations->SetCustomSlowPathCallerSaves( |
| 5950 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5951 | } |
| 5952 | |
| 5953 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5954 | HBasicBlock* block = instruction->GetBlock(); |
| 5955 | if (block->GetLoopInformation() != nullptr) { |
| 5956 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5957 | // The back edge will generate the suspend check. |
| 5958 | return; |
| 5959 | } |
| 5960 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5961 | // The goto will generate the suspend check. |
| 5962 | return; |
| 5963 | } |
| 5964 | GenerateSuspendCheck(instruction, nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5965 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5966 | } |
| 5967 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5968 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5969 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5970 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5971 | InvokeRuntimeCallingConvention calling_convention; |
| 5972 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5973 | } |
| 5974 | |
| 5975 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5976 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5977 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5978 | } |
| 5979 | |
| 5980 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5981 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5982 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5983 | DataType::Type input_type = conversion->GetInputType(); |
| 5984 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5985 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5986 | << input_type << " -> " << result_type; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5987 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 5988 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5989 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5990 | } |
| 5991 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5992 | if (DataType::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5993 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5994 | } else { |
| 5995 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5996 | } |
| 5997 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5998 | if (DataType::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5999 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6000 | } else { |
| 6001 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6002 | } |
| 6003 | } |
| 6004 | |
| 6005 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6006 | DataType::Type result_type = conversion->GetResultType(); |
| 6007 | DataType::Type input_type = conversion->GetInputType(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6008 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6009 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 6010 | << input_type << " -> " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6011 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6012 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 6013 | int result_size = DataType::Size(result_type); |
| 6014 | int input_size = DataType::Size(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6015 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6016 | Register output = OutputRegister(conversion); |
| 6017 | Register source = InputRegisterAt(conversion, 0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6018 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 6019 | // 'int' values are used directly as W registers, discarding the top |
| 6020 | // bits, so we don't need to sign-extend and can just perform a move. |
| 6021 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 6022 | // top 32 bits of the target register. We theoretically could leave those |
| 6023 | // bits unchanged, but we would have to make sure that no code uses a |
| 6024 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 6025 | // zero. |
| 6026 | __ Mov(output.W(), source.W()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6027 | } else if (DataType::IsUnsignedType(result_type) || |
| 6028 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 6029 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6030 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6031 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6032 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6033 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6034 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6035 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 6036 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6037 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6038 | } else if (DataType::IsFloatingPointType(result_type) && |
| 6039 | DataType::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6040 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 6041 | } else { |
| 6042 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6043 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6044 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6045 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6046 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6047 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 6048 | HandleShift(ushr); |
| 6049 | } |
| 6050 | |
| 6051 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 6052 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6053 | } |
| 6054 | |
| 6055 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 6056 | HandleBinaryOp(instruction); |
| 6057 | } |
| 6058 | |
| 6059 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 6060 | HandleBinaryOp(instruction); |
| 6061 | } |
| 6062 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6063 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6064 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6065 | LOG(FATAL) << "Unreachable"; |
| 6066 | } |
| 6067 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6068 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6069 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6070 | LOG(FATAL) << "Unreachable"; |
| 6071 | } |
| 6072 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6073 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6074 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6075 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6076 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6077 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6078 | } |
| 6079 | |
| 6080 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6081 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6082 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6083 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 6084 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6085 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6086 | // 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] | 6087 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6088 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 6089 | // make sure we don't emit it if the target may run out of range. |
| 6090 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 6091 | // ranges and emit the tables only as required. |
| 6092 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6093 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6094 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6095 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 6096 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 6097 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6098 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6099 | Register temp = temps.AcquireW(); |
| 6100 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 6101 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6102 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6103 | // Jump to successors[0] if value == lower_bound. |
| 6104 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 6105 | int32_t last_index = 0; |
| 6106 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6107 | __ Subs(temp, temp, Operand(2)); |
| 6108 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6109 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6110 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6111 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6112 | } |
| 6113 | if (num_entries - last_index == 2) { |
| 6114 | // The last missing case_value. |
| 6115 | __ Cmp(temp, Operand(1)); |
| 6116 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6117 | } |
| 6118 | |
| 6119 | // And the default for any other value. |
| 6120 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6121 | __ B(codegen_->GetLabelOf(default_block)); |
| 6122 | } |
| 6123 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 6124 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6125 | |
| 6126 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6127 | |
| 6128 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 6129 | // registers, we are free to block one. |
| 6130 | Register temp_w = temps.AcquireW(); |
| 6131 | Register index; |
| 6132 | // Remove the bias. |
| 6133 | if (lower_bound != 0) { |
| 6134 | index = temp_w; |
| 6135 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 6136 | } else { |
| 6137 | index = value_reg; |
| 6138 | } |
| 6139 | |
| 6140 | // Jump to default block if index is out of the range. |
| 6141 | __ Cmp(index, Operand(num_entries)); |
| 6142 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 6143 | |
| 6144 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 6145 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 6146 | // register pressure. |
| 6147 | Register table_base = temps.AcquireX(); |
| 6148 | // Load jump offset from the table. |
| 6149 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 6150 | Register jump_offset = temp_w; |
| 6151 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 6152 | |
| 6153 | // Jump to target block by branching to table_base(pc related) + offset. |
| 6154 | Register target_address = table_base; |
| 6155 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 6156 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6157 | } |
| 6158 | } |
| 6159 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6160 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 6161 | HInstruction* instruction, |
| 6162 | Location out, |
| 6163 | uint32_t offset, |
| 6164 | Location maybe_temp, |
| 6165 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6166 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6167 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6168 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6169 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6170 | if (kUseBakerReadBarrier) { |
| 6171 | // Load with fast path based Baker's read barrier. |
| 6172 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6173 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6174 | out, |
| 6175 | out_reg, |
| 6176 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6177 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6178 | /* needs_null_check */ false, |
| 6179 | /* use_load_acquire */ false); |
| 6180 | } else { |
| 6181 | // Load with slow path based read barrier. |
| 6182 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6183 | // in the following move operation, as we will need it for the |
| 6184 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6185 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6186 | __ Mov(temp_reg, out_reg); |
| 6187 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6188 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6189 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6190 | } |
| 6191 | } else { |
| 6192 | // Plain load with no read barrier. |
| 6193 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6194 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6195 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6196 | } |
| 6197 | } |
| 6198 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6199 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 6200 | HInstruction* instruction, |
| 6201 | Location out, |
| 6202 | Location obj, |
| 6203 | uint32_t offset, |
| 6204 | Location maybe_temp, |
| 6205 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6206 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6207 | Register out_reg = RegisterFrom(out, type); |
| 6208 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6209 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6210 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6211 | if (kUseBakerReadBarrier) { |
| 6212 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6213 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6214 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6215 | out, |
| 6216 | obj_reg, |
| 6217 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6218 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6219 | /* needs_null_check */ false, |
| 6220 | /* use_load_acquire */ false); |
| 6221 | } else { |
| 6222 | // Load with slow path based read barrier. |
| 6223 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6224 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6225 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6226 | } |
| 6227 | } else { |
| 6228 | // Plain load with no read barrier. |
| 6229 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6230 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6231 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6232 | } |
| 6233 | } |
| 6234 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6235 | void CodeGeneratorARM64::GenerateGcRootFieldLoad( |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6236 | HInstruction* instruction, |
| 6237 | Location root, |
| 6238 | Register obj, |
| 6239 | uint32_t offset, |
| 6240 | vixl::aarch64::Label* fixup_label, |
| 6241 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6242 | DCHECK(fixup_label == nullptr || offset == 0u); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6243 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6244 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6245 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6246 | if (kUseBakerReadBarrier) { |
| 6247 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6248 | // Baker's read barrier are used. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6249 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 6250 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6251 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6252 | // the Marking Register) to decide whether we need to enter |
| 6253 | // the slow path to mark the GC root. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6254 | // |
| 6255 | // We use link-time generated thunks for the slow path. That thunk |
| 6256 | // checks the reference and jumps to the entrypoint if needed. |
| 6257 | // |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6258 | // lr = &return_address; |
| 6259 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6260 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6261 | // goto gc_root_thunk<root_reg>(lr) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6262 | // } |
| 6263 | // return_address: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6264 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6265 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6266 | DCHECK(temps.IsAvailable(ip0)); |
| 6267 | DCHECK(temps.IsAvailable(ip1)); |
| 6268 | temps.Exclude(ip0, ip1); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6269 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
| 6270 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6271 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6272 | EmissionCheckScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6273 | vixl::aarch64::Label return_address; |
| 6274 | __ adr(lr, &return_address); |
| 6275 | if (fixup_label != nullptr) { |
| 6276 | __ Bind(fixup_label); |
| 6277 | } |
| 6278 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6279 | "GC root LDR must be 2 instruction (8B) before the return address label."); |
| 6280 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6281 | __ Bind(cbnz_label); |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6282 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6283 | __ Bind(&return_address); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6284 | } else { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6285 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6286 | // the Marking Register) to decide whether we need to enter |
| 6287 | // the slow path to mark the GC root. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6288 | // |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6289 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6290 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6291 | // // Slow path. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6292 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6293 | // root = entrypoint(root); // root = ReadBarrier::Mark(root); // Entry point call. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6294 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6295 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6296 | // Slow path marking the GC root `root`. The entrypoint will |
| 6297 | // be loaded by the slow path code. |
| 6298 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6299 | new (GetScopedAllocator()) ReadBarrierMarkSlowPathARM64(instruction, root); |
| 6300 | AddSlowPath(slow_path); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6301 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6302 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6303 | if (fixup_label == nullptr) { |
| 6304 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6305 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6306 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6307 | } |
| 6308 | static_assert( |
| 6309 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6310 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6311 | "have different sizes."); |
| 6312 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6313 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6314 | "have different sizes."); |
| 6315 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6316 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6317 | __ Bind(slow_path->GetExitLabel()); |
| 6318 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6319 | } else { |
| 6320 | // GC root loaded through a slow path for read barriers other |
| 6321 | // than Baker's. |
| 6322 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6323 | if (fixup_label == nullptr) { |
| 6324 | __ Add(root_reg.X(), obj.X(), offset); |
| 6325 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6326 | EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6327 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6328 | // /* mirror::Object* */ root = root->Read() |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6329 | GenerateReadBarrierForRootSlow(instruction, root, root); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6330 | } |
| 6331 | } else { |
| 6332 | // Plain GC root load with no read barrier. |
| 6333 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6334 | if (fixup_label == nullptr) { |
| 6335 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6336 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6337 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6338 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6339 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6340 | // do not have to unpoison `root_reg` here. |
| 6341 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6342 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6343 | } |
| 6344 | |
| 6345 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6346 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6347 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6348 | uint32_t offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6349 | Location maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6350 | bool needs_null_check, |
| 6351 | bool use_load_acquire) { |
| 6352 | DCHECK(kEmitCompilerReadBarrier); |
| 6353 | DCHECK(kUseBakerReadBarrier); |
| 6354 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6355 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6356 | !use_load_acquire && |
| 6357 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6358 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6359 | // Marking Register) to decide whether we need to enter the slow |
| 6360 | // path to mark the reference. Then, in the slow path, check the |
| 6361 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6362 | // decide whether to mark `ref` or not. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6363 | // |
| 6364 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6365 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6366 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6367 | // |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6368 | // lr = &gray_return_address; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6369 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6370 | // goto field_thunk<holder_reg, base_reg>(lr) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6371 | // } |
| 6372 | // not_gray_return_address: |
| 6373 | // // Original reference load. If the offset is too large to fit |
| 6374 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6375 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6376 | // gray_return_address: |
| 6377 | |
| 6378 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6379 | Register base = obj; |
| 6380 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6381 | DCHECK(maybe_temp.IsRegister()); |
| 6382 | base = WRegisterFrom(maybe_temp); |
| 6383 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6384 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6385 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 6386 | } |
| 6387 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6388 | DCHECK(temps.IsAvailable(ip0)); |
| 6389 | DCHECK(temps.IsAvailable(ip1)); |
| 6390 | temps.Exclude(ip0, ip1); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6391 | uint32_t custom_data = EncodeBakerReadBarrierFieldData(base.GetCode(), obj.GetCode()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6392 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6393 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6394 | { |
| 6395 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6396 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6397 | vixl::aarch64::Label return_address; |
| 6398 | __ adr(lr, &return_address); |
| 6399 | __ Bind(cbnz_label); |
| 6400 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6401 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6402 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6403 | " 2 instructions (8B) for heap poisoning."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6404 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6405 | __ ldr(ref_reg, MemOperand(base.X(), offset)); |
| 6406 | if (needs_null_check) { |
| 6407 | MaybeRecordImplicitNullCheck(instruction); |
| 6408 | } |
| 6409 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6410 | __ Bind(&return_address); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6411 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6412 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6413 | return; |
| 6414 | } |
| 6415 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6416 | // /* HeapReference<Object> */ ref = *(obj + offset) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6417 | Register temp = WRegisterFrom(maybe_temp); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6418 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6419 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6420 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6421 | ref, |
| 6422 | obj, |
| 6423 | offset, |
| 6424 | no_index, |
| 6425 | no_scale_factor, |
| 6426 | temp, |
| 6427 | needs_null_check, |
| 6428 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6429 | } |
| 6430 | |
| 6431 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6432 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6433 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6434 | uint32_t data_offset, |
| 6435 | Location index, |
| 6436 | Register temp, |
| 6437 | bool needs_null_check) { |
| 6438 | DCHECK(kEmitCompilerReadBarrier); |
| 6439 | DCHECK(kUseBakerReadBarrier); |
| 6440 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6441 | static_assert( |
| 6442 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6443 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6444 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6445 | |
| 6446 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6447 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6448 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6449 | // Marking Register) to decide whether we need to enter the slow |
| 6450 | // path to mark the reference. Then, in the slow path, check the |
| 6451 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6452 | // decide whether to mark `ref` or not. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6453 | // |
| 6454 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6455 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6456 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6457 | // |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6458 | // lr = &gray_return_address; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6459 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6460 | // goto array_thunk<base_reg>(lr) |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6461 | // } |
| 6462 | // not_gray_return_address: |
| 6463 | // // Original reference load. If the offset is too large to fit |
| 6464 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6465 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6466 | // gray_return_address: |
| 6467 | |
| 6468 | DCHECK(index.IsValid()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6469 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 6470 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6471 | |
| 6472 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6473 | DCHECK(temps.IsAvailable(ip0)); |
| 6474 | DCHECK(temps.IsAvailable(ip1)); |
| 6475 | temps.Exclude(ip0, ip1); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6476 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(temp.GetCode()); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6477 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6478 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6479 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6480 | { |
| 6481 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6482 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6483 | vixl::aarch64::Label return_address; |
| 6484 | __ adr(lr, &return_address); |
| 6485 | __ Bind(cbnz_label); |
| 6486 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6487 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6488 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6489 | " 2 instructions (8B) for heap poisoning."); |
| 6490 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6491 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6492 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6493 | __ Bind(&return_address); |
| 6494 | } |
| 6495 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6496 | return; |
| 6497 | } |
| 6498 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6499 | // Array cells are never volatile variables, therefore array loads |
| 6500 | // never use Load-Acquire instructions on ARM64. |
| 6501 | const bool use_load_acquire = false; |
| 6502 | |
| 6503 | // /* HeapReference<Object> */ ref = |
| 6504 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6505 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6506 | ref, |
| 6507 | obj, |
| 6508 | data_offset, |
| 6509 | index, |
| 6510 | scale_factor, |
| 6511 | temp, |
| 6512 | needs_null_check, |
| 6513 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6514 | } |
| 6515 | |
| 6516 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6517 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6518 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6519 | uint32_t offset, |
| 6520 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6521 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6522 | Register temp, |
| 6523 | bool needs_null_check, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6524 | bool use_load_acquire) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6525 | DCHECK(kEmitCompilerReadBarrier); |
| 6526 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6527 | // If we are emitting an array load, we should not be using a |
| 6528 | // Load Acquire instruction. In other words: |
| 6529 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6530 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6531 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6532 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6533 | // Marking Register) to decide whether we need to enter the slow |
| 6534 | // path to mark the reference. Then, in the slow path, check the |
| 6535 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6536 | // decide whether to mark `ref` or not. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6537 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6538 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6539 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6540 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6541 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6542 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 6543 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6544 | // if (is_gray) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6545 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6546 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6547 | // } |
| 6548 | // } else { |
| 6549 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6550 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6551 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6552 | // Slow path marking the object `ref` when the GC is marking. The |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6553 | // entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6554 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6555 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierSlowPathARM64( |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6556 | instruction, |
| 6557 | ref, |
| 6558 | obj, |
| 6559 | offset, |
| 6560 | index, |
| 6561 | scale_factor, |
| 6562 | needs_null_check, |
| 6563 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6564 | temp); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6565 | AddSlowPath(slow_path); |
| 6566 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6567 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6568 | // Fast path: the GC is not marking: just load the reference. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6569 | GenerateRawReferenceLoad( |
| 6570 | 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] | 6571 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6572 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6573 | } |
| 6574 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6575 | void CodeGeneratorARM64::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 6576 | Location ref, |
| 6577 | Register obj, |
| 6578 | Location field_offset, |
| 6579 | Register temp, |
| 6580 | bool needs_null_check, |
| 6581 | bool use_load_acquire) { |
| 6582 | DCHECK(kEmitCompilerReadBarrier); |
| 6583 | DCHECK(kUseBakerReadBarrier); |
| 6584 | // If we are emitting an array load, we should not be using a |
| 6585 | // Load Acquire instruction. In other words: |
| 6586 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6587 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
| 6588 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6589 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6590 | // Marking Register) to decide whether we need to enter the slow |
| 6591 | // path to update the reference field within `obj`. Then, in the |
| 6592 | // slow path, check the gray bit in the lock word of the reference's |
| 6593 | // holder (`obj`) to decide whether to mark `ref` and update the |
| 6594 | // field or not. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6595 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6596 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6597 | // // Slow path. |
| 6598 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6599 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6600 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
| 6601 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6602 | // if (is_gray) { |
| 6603 | // old_ref = ref; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6604 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6605 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6606 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 6607 | // } |
| 6608 | // } |
| 6609 | |
| 6610 | // Slow path updating the object reference at address `obj + field_offset` |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6611 | // 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] | 6612 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6613 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6614 | instruction, |
| 6615 | ref, |
| 6616 | obj, |
| 6617 | /* offset */ 0u, |
| 6618 | /* index */ field_offset, |
| 6619 | /* scale_factor */ 0u /* "times 1" */, |
| 6620 | needs_null_check, |
| 6621 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6622 | temp); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6623 | AddSlowPath(slow_path); |
| 6624 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6625 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6626 | // Fast path: the GC is not marking: nothing to do (the field is |
| 6627 | // up-to-date, and we don't need to load the reference). |
| 6628 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6629 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6630 | } |
| 6631 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6632 | void CodeGeneratorARM64::GenerateRawReferenceLoad(HInstruction* instruction, |
| 6633 | Location ref, |
| 6634 | Register obj, |
| 6635 | uint32_t offset, |
| 6636 | Location index, |
| 6637 | size_t scale_factor, |
| 6638 | bool needs_null_check, |
| 6639 | bool use_load_acquire) { |
| 6640 | DCHECK(obj.IsW()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6641 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6642 | Register ref_reg = RegisterFrom(ref, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6643 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6644 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 6645 | // that no pools are emitted between the load (macro) instruction |
| 6646 | // and MaybeRecordImplicitNullCheck. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6647 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6648 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6649 | // Load types involving an "index": ArrayGet, |
| 6650 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6651 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6652 | if (use_load_acquire) { |
| 6653 | // UnsafeGetObjectVolatile intrinsic case. |
| 6654 | // Register `index` is not an index in an object array, but an |
| 6655 | // offset to an object reference field within object `obj`. |
| 6656 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 6657 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 6658 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 6659 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6660 | DCHECK_EQ(offset, 0u); |
| 6661 | DCHECK_EQ(scale_factor, 0u); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6662 | DCHECK_EQ(needs_null_check, false); |
| 6663 | // /* HeapReference<mirror::Object> */ ref = *(obj + index) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6664 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 6665 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6666 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6667 | // ArrayGet and UnsafeGetObject and UnsafeCASObject intrinsics cases. |
| 6668 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6669 | if (index.IsConstant()) { |
| 6670 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6671 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6672 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6673 | if (needs_null_check) { |
| 6674 | MaybeRecordImplicitNullCheck(instruction); |
| 6675 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6676 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6677 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6678 | Register temp = temps.AcquireW(); |
| 6679 | __ Add(temp, obj, offset); |
| 6680 | { |
| 6681 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6682 | Load(type, ref_reg, HeapOperand(temp, XRegisterFrom(index), LSL, scale_factor)); |
| 6683 | if (needs_null_check) { |
| 6684 | MaybeRecordImplicitNullCheck(instruction); |
| 6685 | } |
| 6686 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6687 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6688 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6689 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6690 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6691 | MemOperand field = HeapOperand(obj, offset); |
| 6692 | if (use_load_acquire) { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6693 | // Implicit null checks are handled by CodeGeneratorARM64::LoadAcquire. |
| 6694 | LoadAcquire(instruction, ref_reg, field, needs_null_check); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6695 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6696 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6697 | Load(type, ref_reg, field); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6698 | if (needs_null_check) { |
| 6699 | MaybeRecordImplicitNullCheck(instruction); |
| 6700 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6701 | } |
| 6702 | } |
| 6703 | |
| 6704 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6705 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6706 | } |
| 6707 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6708 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6709 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6710 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6711 | // The following condition is a run-time one; it is executed after the |
| 6712 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6713 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6714 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6715 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6716 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6717 | } |
| 6718 | } |
| 6719 | } |
| 6720 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6721 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6722 | Location out, |
| 6723 | Location ref, |
| 6724 | Location obj, |
| 6725 | uint32_t offset, |
| 6726 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6727 | DCHECK(kEmitCompilerReadBarrier); |
| 6728 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6729 | // Insert a slow path based read barrier *after* the reference load. |
| 6730 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6731 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6732 | // reference will be carried out by the runtime within the slow |
| 6733 | // path. |
| 6734 | // |
| 6735 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6736 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6737 | // not used by the artReadBarrierSlow entry point. |
| 6738 | // |
| 6739 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6740 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6741 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6742 | AddSlowPath(slow_path); |
| 6743 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6744 | __ B(slow_path->GetEntryLabel()); |
| 6745 | __ Bind(slow_path->GetExitLabel()); |
| 6746 | } |
| 6747 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6748 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6749 | Location out, |
| 6750 | Location ref, |
| 6751 | Location obj, |
| 6752 | uint32_t offset, |
| 6753 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6754 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6755 | // Baker's read barriers shall be handled by the fast path |
| 6756 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6757 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6758 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6759 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6760 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6761 | } else if (kPoisonHeapReferences) { |
| 6762 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6763 | } |
| 6764 | } |
| 6765 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6766 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6767 | Location out, |
| 6768 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6769 | DCHECK(kEmitCompilerReadBarrier); |
| 6770 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6771 | // Insert a slow path based read barrier *after* the GC root load. |
| 6772 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6773 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6774 | // not need to do anything special for this here. |
| 6775 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6776 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6777 | AddSlowPath(slow_path); |
| 6778 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6779 | __ B(slow_path->GetEntryLabel()); |
| 6780 | __ Bind(slow_path->GetExitLabel()); |
| 6781 | } |
| 6782 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6783 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6784 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6785 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6786 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6787 | locations->SetOut(Location::RequiresRegister()); |
| 6788 | } |
| 6789 | |
| 6790 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6791 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6792 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6793 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6794 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6795 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6796 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6797 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6798 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6799 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6800 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6801 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6802 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6803 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6804 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6805 | } |
| 6806 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6807 | static void PatchJitRootUse(uint8_t* code, |
| 6808 | const uint8_t* roots_data, |
| 6809 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6810 | uint64_t index_in_table) { |
| 6811 | uint32_t literal_offset = literal->GetOffset(); |
| 6812 | uintptr_t address = |
| 6813 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6814 | uint8_t* data = code + literal_offset; |
| 6815 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6816 | } |
| 6817 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6818 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6819 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6820 | const StringReference& string_reference = entry.first; |
| 6821 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6822 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6823 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6824 | } |
| 6825 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6826 | const TypeReference& type_reference = entry.first; |
| 6827 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6828 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6829 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6830 | } |
| 6831 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6832 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6833 | #undef __ |
| 6834 | #undef QUICK_ENTRY_POINT |
| 6835 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6836 | #define __ assembler.GetVIXLAssembler()-> |
| 6837 | |
| 6838 | static void EmitGrayCheckAndFastPath(arm64::Arm64Assembler& assembler, |
| 6839 | vixl::aarch64::Register base_reg, |
| 6840 | vixl::aarch64::MemOperand& lock_word, |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame^] | 6841 | vixl::aarch64::Label* slow_path, |
| 6842 | vixl::aarch64::Label* throw_npe = nullptr) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6843 | // Load the lock word containing the rb_state. |
| 6844 | __ Ldr(ip0.W(), lock_word); |
| 6845 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 6846 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 6847 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 6848 | __ Tbnz(ip0.W(), LockWord::kReadBarrierStateShift, slow_path); |
| 6849 | static_assert( |
| 6850 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET, |
| 6851 | "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^] | 6852 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 6853 | if (throw_npe != nullptr) { |
| 6854 | __ Bind(throw_npe); |
| 6855 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6856 | // Adjust the return address back to the LDR (1 instruction; 2 for heap poisoning). |
| 6857 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6858 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6859 | " 2 instructions (8B) for heap poisoning."); |
| 6860 | __ Add(lr, lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6861 | // Introduce a dependency on the lock_word including rb_state, |
| 6862 | // to prevent load-load reordering, and without using |
| 6863 | // a memory barrier (which would be more expensive). |
| 6864 | __ Add(base_reg, base_reg, Operand(ip0, LSR, 32)); |
| 6865 | __ Br(lr); // And return back to the function. |
| 6866 | // Note: The fake dependency is unnecessary for the slow path. |
| 6867 | } |
| 6868 | |
| 6869 | // Load the read barrier introspection entrypoint in register `entrypoint`. |
| 6870 | static void LoadReadBarrierMarkIntrospectionEntrypoint(arm64::Arm64Assembler& assembler, |
| 6871 | vixl::aarch64::Register entrypoint) { |
| 6872 | // entrypoint = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6873 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6874 | const int32_t entry_point_offset = |
| 6875 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6876 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| 6877 | } |
| 6878 | |
| 6879 | void CodeGeneratorARM64::CompileBakerReadBarrierThunk(Arm64Assembler& assembler, |
| 6880 | uint32_t encoded_data, |
| 6881 | /*out*/ std::string* debug_name) { |
| 6882 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 6883 | switch (kind) { |
| 6884 | case BakerReadBarrierKind::kField: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6885 | auto base_reg = |
| 6886 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6887 | CheckValidReg(base_reg.GetCode()); |
| 6888 | auto holder_reg = |
| 6889 | Register::GetXRegFromCode(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6890 | CheckValidReg(holder_reg.GetCode()); |
| 6891 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6892 | temps.Exclude(ip0, ip1); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame^] | 6893 | // If base_reg differs from holder_reg, the offset was too large and we must have emitted |
| 6894 | // an explicit null check before the load. Otherwise, for implicit null checks, we need to |
| 6895 | // null-check the holder as we do not necessarily do that check before going to the thunk. |
| 6896 | vixl::aarch64::Label throw_npe_label; |
| 6897 | vixl::aarch64::Label* throw_npe = nullptr; |
| 6898 | if (GetCompilerOptions().GetImplicitNullChecks() && holder_reg.Is(base_reg)) { |
| 6899 | throw_npe = &throw_npe_label; |
| 6900 | __ Cbz(holder_reg.W(), throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6901 | } |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame^] | 6902 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 6903 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 6904 | // to load the reference and call the entrypoint that performs further checks on the |
| 6905 | // reference and marks it if needed. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6906 | vixl::aarch64::Label slow_path; |
| 6907 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame^] | 6908 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6909 | __ Bind(&slow_path); |
| 6910 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6911 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (immediate) unsigned offset. |
| 6912 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6913 | __ Ubfx(ip0.W(), ip0.W(), 10, 12); // Extract the offset. |
| 6914 | __ Ldr(ip0.W(), MemOperand(base_reg, ip0, LSL, 2)); // Load the reference. |
| 6915 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 6916 | __ Br(ip1); // Jump to the entrypoint. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6917 | break; |
| 6918 | } |
| 6919 | case BakerReadBarrierKind::kArray: { |
| 6920 | auto base_reg = |
| 6921 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6922 | CheckValidReg(base_reg.GetCode()); |
| 6923 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6924 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6925 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6926 | temps.Exclude(ip0, ip1); |
| 6927 | vixl::aarch64::Label slow_path; |
| 6928 | int32_t data_offset = |
| 6929 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 6930 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 6931 | DCHECK_LT(lock_word.GetOffset(), 0); |
| 6932 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path); |
| 6933 | __ Bind(&slow_path); |
| 6934 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| 6935 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (register) unsigned offset. |
| 6936 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6937 | __ Ubfx(ip0, ip0, 16, 6); // Extract the index register, plus 32 (bit 21 is set). |
| 6938 | __ Bfi(ip1, ip0, 3, 6); // Insert ip0 to the entrypoint address to create |
| 6939 | // a switch case target based on the index register. |
| 6940 | __ Mov(ip0, base_reg); // Move the base register to ip0. |
| 6941 | __ Br(ip1); // Jump to the entrypoint's array switch case. |
| 6942 | break; |
| 6943 | } |
| 6944 | case BakerReadBarrierKind::kGcRoot: { |
| 6945 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 6946 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 6947 | // otherwise return the reference (or the extracted forwarding address). |
| 6948 | // There is no gray bit check for GC roots. |
| 6949 | auto root_reg = |
| 6950 | Register::GetWRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6951 | CheckValidReg(root_reg.GetCode()); |
| 6952 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6953 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6954 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6955 | temps.Exclude(ip0, ip1); |
| 6956 | vixl::aarch64::Label return_label, not_marked, forwarding_address; |
| 6957 | __ Cbz(root_reg, &return_label); |
| 6958 | MemOperand lock_word(root_reg.X(), mirror::Object::MonitorOffset().Int32Value()); |
| 6959 | __ Ldr(ip0.W(), lock_word); |
| 6960 | __ Tbz(ip0.W(), LockWord::kMarkBitStateShift, ¬_marked); |
| 6961 | __ Bind(&return_label); |
| 6962 | __ Br(lr); |
| 6963 | __ Bind(¬_marked); |
| 6964 | __ Tst(ip0.W(), Operand(ip0.W(), LSL, 1)); |
| 6965 | __ B(&forwarding_address, mi); |
| 6966 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6967 | // Adjust the art_quick_read_barrier_mark_introspection address in IP1 to |
| 6968 | // art_quick_read_barrier_mark_introspection_gc_roots. |
| 6969 | __ Add(ip1, ip1, Operand(BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET)); |
| 6970 | __ Mov(ip0.W(), root_reg); |
| 6971 | __ Br(ip1); |
| 6972 | __ Bind(&forwarding_address); |
| 6973 | __ Lsl(root_reg, ip0.W(), LockWord::kForwardingAddressShift); |
| 6974 | __ Br(lr); |
| 6975 | break; |
| 6976 | } |
| 6977 | default: |
| 6978 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 6979 | UNREACHABLE(); |
| 6980 | } |
| 6981 | |
| 6982 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 6983 | std::ostringstream oss; |
| 6984 | oss << "BakerReadBarrierThunk"; |
| 6985 | switch (kind) { |
| 6986 | case BakerReadBarrierKind::kField: |
| 6987 | oss << "Field_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 6988 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 6989 | break; |
| 6990 | case BakerReadBarrierKind::kArray: |
| 6991 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6992 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6993 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6994 | break; |
| 6995 | case BakerReadBarrierKind::kGcRoot: |
| 6996 | oss << "GcRoot_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6997 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6998 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6999 | break; |
| 7000 | } |
| 7001 | *debug_name = oss.str(); |
| 7002 | } |
| 7003 | } |
| 7004 | |
| 7005 | #undef __ |
| 7006 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 7007 | } // namespace arm64 |
| 7008 | } // namespace art |