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 | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 33 | #include "linker/arm64/relative_patcher_arm64.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 34 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 35 | #include "lock_word.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 36 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 37 | #include "mirror/class-inl.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 38 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 39 | #include "thread.h" |
| 40 | #include "utils/arm64/assembler_arm64.h" |
| 41 | #include "utils/assembler.h" |
| 42 | #include "utils/stack_checks.h" |
| 43 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 44 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 45 | using vixl::ExactAssemblyScope; |
| 46 | using vixl::CodeBufferCheckScope; |
| 47 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 48 | |
| 49 | #ifdef __ |
| 50 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 51 | #endif |
| 52 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 53 | namespace art { |
| 54 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 55 | template<class MirrorType> |
| 56 | class GcRoot; |
| 57 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 58 | namespace arm64 { |
| 59 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 60 | using helpers::ARM64EncodableConstantOrRegister; |
| 61 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 62 | using helpers::CPURegisterFrom; |
| 63 | using helpers::DRegisterFrom; |
| 64 | using helpers::FPRegisterFrom; |
| 65 | using helpers::HeapOperand; |
| 66 | using helpers::HeapOperandFrom; |
| 67 | using helpers::InputCPURegisterAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 68 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 70 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 71 | using helpers::InputRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 72 | using helpers::Int64ConstantFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 73 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 74 | using helpers::LocationFrom; |
| 75 | using helpers::OperandFromMemOperand; |
| 76 | using helpers::OutputCPURegister; |
| 77 | using helpers::OutputFPRegister; |
| 78 | using helpers::OutputRegister; |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 79 | using helpers::QRegisterFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 80 | using helpers::RegisterFrom; |
| 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 | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 314 | bool do_clinit, |
| 315 | vixl::aarch64::Register bss_entry_temp = vixl::aarch64::Register(), |
| 316 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr) |
| 317 | : SlowPathCodeARM64(at), |
| 318 | cls_(cls), |
| 319 | dex_pc_(dex_pc), |
| 320 | do_clinit_(do_clinit), |
| 321 | bss_entry_temp_(bss_entry_temp), |
| 322 | bss_entry_adrp_label_(bss_entry_adrp_label) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 323 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 324 | } |
| 325 | |
| 326 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 327 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 328 | Location out = locations->Out(); |
| 329 | constexpr bool call_saves_everything_except_r0_ip0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 330 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 331 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 332 | InvokeRuntimeCallingConvention calling_convention; |
| 333 | // For HLoadClass/kBssEntry/kSaveEverything, the page address of the entry is in a temp |
| 334 | // register, make sure it's not clobbered by the call or by saving/restoring registers. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 335 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 336 | bool is_load_class_bss_entry = |
| 337 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 338 | if (is_load_class_bss_entry) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 339 | DCHECK(bss_entry_temp_.IsValid()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 340 | DCHECK(!bss_entry_temp_.Is(calling_convention.GetRegisterAt(0))); |
| 341 | DCHECK( |
| 342 | !UseScratchRegisterScope(arm64_codegen->GetVIXLAssembler()).IsAvailable(bss_entry_temp_)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 345 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 346 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 347 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 348 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 349 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 350 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 351 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 352 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 353 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 354 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 355 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 356 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 357 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 358 | |
| 359 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 360 | if (out.IsValid()) { |
| 361 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 362 | DataType::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 363 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 364 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 365 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 366 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 367 | if (is_load_class_bss_entry) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 368 | DCHECK(out.IsValid()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 369 | const DexFile& dex_file = cls_->GetDexFile(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 370 | if (call_saves_everything_except_r0_ip0) { |
| 371 | // The class entry page address was preserved in bss_entry_temp_ thanks to kSaveEverything. |
| 372 | } else { |
| 373 | // For non-Baker read barrier, we need to re-calculate the address of the class entry page. |
| 374 | bss_entry_adrp_label_ = arm64_codegen->NewBssEntryTypePatch(dex_file, type_index); |
| 375 | arm64_codegen->EmitAdrpPlaceholder(bss_entry_adrp_label_, bss_entry_temp_); |
| 376 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 377 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 378 | arm64_codegen->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label_); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 379 | { |
| 380 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 381 | __ Bind(strp_label); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 382 | __ str(RegisterFrom(locations->Out(), DataType::Type::kReference), |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 383 | MemOperand(bss_entry_temp_, /* offset placeholder */ 0)); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 384 | } |
| 385 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 386 | __ B(GetExitLabel()); |
| 387 | } |
| 388 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 389 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 390 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 391 | private: |
| 392 | // The class this slow path will load. |
| 393 | HLoadClass* const cls_; |
| 394 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 395 | // The dex PC of `at_`. |
| 396 | const uint32_t dex_pc_; |
| 397 | |
| 398 | // Whether to initialize the class. |
| 399 | const bool do_clinit_; |
| 400 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 401 | // For HLoadClass/kBssEntry, the temp register and the label of the ADRP where it was loaded. |
| 402 | vixl::aarch64::Register bss_entry_temp_; |
| 403 | vixl::aarch64::Label* bss_entry_adrp_label_; |
| 404 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 405 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 406 | }; |
| 407 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 408 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 409 | public: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 410 | LoadStringSlowPathARM64(HLoadString* instruction, Register temp, vixl::aarch64::Label* adrp_label) |
| 411 | : SlowPathCodeARM64(instruction), |
| 412 | temp_(temp), |
| 413 | adrp_label_(adrp_label) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 414 | |
| 415 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 416 | LocationSummary* locations = instruction_->GetLocations(); |
| 417 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 418 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 419 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 420 | InvokeRuntimeCallingConvention calling_convention; |
| 421 | // Make sure `temp_` is not clobbered by the call or by saving/restoring registers. |
| 422 | DCHECK(temp_.IsValid()); |
| 423 | DCHECK(!temp_.Is(calling_convention.GetRegisterAt(0))); |
| 424 | DCHECK(!UseScratchRegisterScope(arm64_codegen->GetVIXLAssembler()).IsAvailable(temp_)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 425 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 426 | __ Bind(GetEntryLabel()); |
| 427 | SaveLiveRegisters(codegen, locations); |
| 428 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 429 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 430 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 431 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 432 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 433 | DataType::Type type = instruction_->GetType(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 434 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 435 | |
| 436 | RestoreLiveRegisters(codegen, locations); |
| 437 | |
| 438 | // Store the resolved String to the BSS entry. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 439 | const DexFile& dex_file = instruction_->AsLoadString()->GetDexFile(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 440 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 441 | // The string entry page address was preserved in temp_ thanks to kSaveEverything. |
| 442 | } else { |
| 443 | // For non-Baker read barrier, we need to re-calculate the address of the string entry page. |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 444 | adrp_label_ = arm64_codegen->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 445 | arm64_codegen->EmitAdrpPlaceholder(adrp_label_, temp_); |
| 446 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 447 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 448 | arm64_codegen->NewStringBssEntryPatch(dex_file, string_index, adrp_label_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 449 | { |
| 450 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 451 | __ Bind(strp_label); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 452 | __ str(RegisterFrom(locations->Out(), DataType::Type::kReference), |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 453 | MemOperand(temp_, /* offset placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | __ B(GetExitLabel()); |
| 457 | } |
| 458 | |
| 459 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 460 | |
| 461 | private: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 462 | const Register temp_; |
| 463 | vixl::aarch64::Label* adrp_label_; |
| 464 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 465 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 466 | }; |
| 467 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 468 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 469 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 470 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 471 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 472 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 473 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 474 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 475 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 476 | // Live registers will be restored in the catch block if caught. |
| 477 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 478 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 479 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 480 | instruction_, |
| 481 | instruction_->GetDexPc(), |
| 482 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 483 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 484 | } |
| 485 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 486 | bool IsFatal() const OVERRIDE { return true; } |
| 487 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 488 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 489 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 490 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 491 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 492 | }; |
| 493 | |
| 494 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 495 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 496 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 497 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 498 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 499 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 500 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 501 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 502 | __ Bind(GetEntryLabel()); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 503 | SaveLiveRegisters(codegen, locations); // Only saves live 128-bit regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 504 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 505 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 506 | RestoreLiveRegisters(codegen, locations); // Only restores live 128-bit regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 507 | if (successor_ == nullptr) { |
| 508 | __ B(GetReturnLabel()); |
| 509 | } else { |
| 510 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 511 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 512 | } |
| 513 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 514 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 515 | DCHECK(successor_ == nullptr); |
| 516 | return &return_label_; |
| 517 | } |
| 518 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 519 | HBasicBlock* GetSuccessor() const { |
| 520 | return successor_; |
| 521 | } |
| 522 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 523 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 524 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 525 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 526 | // If not null, the block to branch to after the suspend check. |
| 527 | HBasicBlock* const successor_; |
| 528 | |
| 529 | // 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] | 530 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 531 | |
| 532 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 533 | }; |
| 534 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 535 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 536 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 537 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 538 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 539 | |
| 540 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 541 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 542 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 543 | DCHECK(instruction_->IsCheckCast() |
| 544 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 545 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 546 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 547 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 548 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 549 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 550 | if (!is_fatal_) { |
| 551 | SaveLiveRegisters(codegen, locations); |
| 552 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 553 | |
| 554 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 555 | // move resolver. |
| 556 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 557 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 558 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 559 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 560 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 561 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 562 | DataType::Type::kReference); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 563 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 564 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 565 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 566 | DataType::Type ret_type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 567 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 568 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 569 | } else { |
| 570 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 571 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 572 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 575 | if (!is_fatal_) { |
| 576 | RestoreLiveRegisters(codegen, locations); |
| 577 | __ B(GetExitLabel()); |
| 578 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 581 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 582 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 583 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 584 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 585 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 586 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 587 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 588 | }; |
| 589 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 590 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 591 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 592 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 593 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 594 | |
| 595 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 596 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 597 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 598 | LocationSummary* locations = instruction_->GetLocations(); |
| 599 | SaveLiveRegisters(codegen, locations); |
| 600 | InvokeRuntimeCallingConvention calling_convention; |
| 601 | __ Mov(calling_convention.GetRegisterAt(0), |
| 602 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 603 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 604 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 607 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 608 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 609 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 610 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 611 | }; |
| 612 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 613 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 614 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 615 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 616 | |
| 617 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 618 | LocationSummary* locations = instruction_->GetLocations(); |
| 619 | __ Bind(GetEntryLabel()); |
| 620 | SaveLiveRegisters(codegen, locations); |
| 621 | |
| 622 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 623 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 624 | parallel_move.AddMove( |
| 625 | locations->InAt(0), |
| 626 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 627 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 628 | nullptr); |
| 629 | parallel_move.AddMove( |
| 630 | locations->InAt(1), |
| 631 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 632 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 633 | nullptr); |
| 634 | parallel_move.AddMove( |
| 635 | locations->InAt(2), |
| 636 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 637 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 638 | nullptr); |
| 639 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 640 | |
| 641 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 642 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 643 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 644 | RestoreLiveRegisters(codegen, locations); |
| 645 | __ B(GetExitLabel()); |
| 646 | } |
| 647 | |
| 648 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 649 | |
| 650 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 651 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 652 | }; |
| 653 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 654 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 655 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 656 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 657 | |
| 658 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 659 | // 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] | 660 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 661 | num_entries * sizeof(int32_t), |
| 662 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 663 | |
| 664 | __ Bind(&table_start_); |
| 665 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 666 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 667 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 668 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 669 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 670 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 671 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 672 | Literal<int32_t> literal(jump_offset); |
| 673 | __ place(&literal); |
| 674 | } |
| 675 | } |
| 676 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 677 | // Abstract base class for read barrier slow paths marking a reference |
| 678 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 679 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 680 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 681 | // barrier marking runtime entry point to be invoked or an empty |
| 682 | // location; in the latter case, the read barrier marking runtime |
| 683 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 684 | class ReadBarrierMarkSlowPathBaseARM64 : public SlowPathCodeARM64 { |
| 685 | protected: |
| 686 | ReadBarrierMarkSlowPathBaseARM64(HInstruction* instruction, Location ref, Location entrypoint) |
| 687 | : SlowPathCodeARM64(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 688 | DCHECK(kEmitCompilerReadBarrier); |
| 689 | } |
| 690 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 691 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM64"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 692 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 693 | // Generate assembly code calling the read barrier marking runtime |
| 694 | // entry point (ReadBarrierMarkRegX). |
| 695 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 696 | // No need to save live registers; it's taken care of by the |
| 697 | // entrypoint. Also, there is no need to update the stack mask, |
| 698 | // as this runtime call will not trigger a garbage collection. |
| 699 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 700 | DCHECK_NE(ref_.reg(), LR); |
| 701 | DCHECK_NE(ref_.reg(), WSP); |
| 702 | DCHECK_NE(ref_.reg(), WZR); |
| 703 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 704 | // as a temporary, it cannot be the entry point's input/output. |
| 705 | DCHECK_NE(ref_.reg(), IP0); |
| 706 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 707 | // "Compact" slow path, saving two moves. |
| 708 | // |
| 709 | // Instead of using the standard runtime calling convention (input |
| 710 | // and output in W0): |
| 711 | // |
| 712 | // W0 <- ref |
| 713 | // W0 <- ReadBarrierMark(W0) |
| 714 | // ref <- W0 |
| 715 | // |
| 716 | // we just use rX (the register containing `ref`) as input and output |
| 717 | // of a dedicated entrypoint: |
| 718 | // |
| 719 | // rX <- ReadBarrierMarkRegX(rX) |
| 720 | // |
| 721 | if (entrypoint_.IsValid()) { |
| 722 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 723 | __ Blr(XRegisterFrom(entrypoint_)); |
| 724 | } else { |
| 725 | // Entrypoint is not already loaded, load from the thread. |
| 726 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 727 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 728 | // This runtime call does not require a stack map. |
| 729 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | // The location (register) of the marked object reference. |
| 734 | const Location ref_; |
| 735 | |
| 736 | // The location of the entrypoint if it is already loaded. |
| 737 | const Location entrypoint_; |
| 738 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 739 | private: |
| 740 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM64); |
| 741 | }; |
| 742 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 743 | // Slow path marking an object reference `ref` during a read |
| 744 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 745 | // reference does not get updated by this slow path after marking. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 746 | // |
| 747 | // This means that after the execution of this slow path, `ref` will |
| 748 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 749 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 750 | // probably still be a from-space reference (unless it gets updated by |
| 751 | // another thread, or if another thread installed another object |
| 752 | // reference (different from `ref`) in `obj.field`). |
| 753 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 754 | // Argument `entrypoint` must be a register location holding the read |
| 755 | // barrier marking runtime entry point to be invoked or an empty |
| 756 | // location; in the latter case, the read barrier marking runtime |
| 757 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 758 | class ReadBarrierMarkSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 759 | public: |
| 760 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 761 | Location ref, |
| 762 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 763 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 764 | DCHECK(kEmitCompilerReadBarrier); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 768 | |
| 769 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 770 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 771 | DCHECK(locations->CanCall()); |
| 772 | DCHECK(ref_.IsRegister()) << ref_; |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 773 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 774 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 775 | << "Unexpected instruction in read barrier marking slow path: " |
| 776 | << instruction_->DebugName(); |
| 777 | |
| 778 | __ Bind(GetEntryLabel()); |
| 779 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 780 | __ B(GetExitLabel()); |
| 781 | } |
| 782 | |
| 783 | private: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 784 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 785 | }; |
| 786 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 787 | // Slow path loading `obj`'s lock word, loading a reference from |
| 788 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 789 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 790 | // read barrier). The field `obj.field` in the object `obj` holding |
| 791 | // this reference does not get updated by this slow path after marking |
| 792 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 793 | // below for that). |
| 794 | // |
| 795 | // This means that after the execution of this slow path, `ref` will |
| 796 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 797 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 798 | // probably still be a from-space reference (unless it gets updated by |
| 799 | // another thread, or if another thread installed another object |
| 800 | // reference (different from `ref`) in `obj.field`). |
| 801 | // |
| 802 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 803 | // barrier marking runtime entry point to be invoked or an empty |
| 804 | // location; in the latter case, the read barrier marking runtime |
| 805 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 806 | class LoadReferenceWithBakerReadBarrierSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
| 807 | public: |
| 808 | LoadReferenceWithBakerReadBarrierSlowPathARM64(HInstruction* instruction, |
| 809 | Location ref, |
| 810 | Register obj, |
| 811 | uint32_t offset, |
| 812 | Location index, |
| 813 | size_t scale_factor, |
| 814 | bool needs_null_check, |
| 815 | bool use_load_acquire, |
| 816 | Register temp, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 817 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 818 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
| 819 | obj_(obj), |
| 820 | offset_(offset), |
| 821 | index_(index), |
| 822 | scale_factor_(scale_factor), |
| 823 | needs_null_check_(needs_null_check), |
| 824 | use_load_acquire_(use_load_acquire), |
| 825 | temp_(temp) { |
| 826 | DCHECK(kEmitCompilerReadBarrier); |
| 827 | DCHECK(kUseBakerReadBarrier); |
| 828 | } |
| 829 | |
| 830 | const char* GetDescription() const OVERRIDE { |
| 831 | return "LoadReferenceWithBakerReadBarrierSlowPathARM64"; |
| 832 | } |
| 833 | |
| 834 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 835 | LocationSummary* locations = instruction_->GetLocations(); |
| 836 | DCHECK(locations->CanCall()); |
| 837 | DCHECK(ref_.IsRegister()) << ref_; |
| 838 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 839 | DCHECK(obj_.IsW()); |
| 840 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 841 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 842 | instruction_->IsStaticFieldGet() || |
| 843 | instruction_->IsArrayGet() || |
| 844 | instruction_->IsArraySet() || |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 845 | instruction_->IsInstanceOf() || |
| 846 | instruction_->IsCheckCast() || |
| 847 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 848 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 849 | << "Unexpected instruction in read barrier marking slow path: " |
| 850 | << instruction_->DebugName(); |
| 851 | // The read barrier instrumentation of object ArrayGet |
| 852 | // instructions does not support the HIntermediateAddress |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 853 | // instruction. |
| 854 | DCHECK(!(instruction_->IsArrayGet() && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 855 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 856 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 857 | // Temporary register `temp_`, used to store the lock word, must |
| 858 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 859 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 860 | // need the lock word to still be in `temp_` after the reference |
| 861 | // load. |
| 862 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 863 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
| 864 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 865 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 866 | |
| 867 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 868 | // inserted after the original load. However, in fast path based |
| 869 | // Baker's read barriers, we need to perform the load of |
| 870 | // mirror::Object::monitor_ *before* the original reference load. |
| 871 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 872 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 873 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 874 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 875 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 876 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 877 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 878 | // if (is_gray) { |
| 879 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 880 | // } |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 881 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 882 | // Note: the original implementation in ReadBarrier::Barrier is |
| 883 | // slightly more complex as it performs additional checks that we do |
| 884 | // not do here for performance reasons. |
| 885 | |
| 886 | // /* int32_t */ monitor = obj->monitor_ |
| 887 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 888 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 889 | if (needs_null_check_) { |
| 890 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 891 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 892 | // /* LockWord */ lock_word = LockWord(monitor) |
| 893 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 894 | "art::LockWord and int32_t have different sizes."); |
| 895 | |
| 896 | // Introduce a dependency on the lock_word including rb_state, |
| 897 | // to prevent load-load reordering, and without using |
| 898 | // a memory barrier (which would be more expensive). |
| 899 | // `obj` is unchanged by this operation, but its value now depends |
| 900 | // on `temp`. |
| 901 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 902 | |
| 903 | // The actual reference load. |
| 904 | // A possible implicit null check has already been handled above. |
| 905 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 906 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 907 | ref_, |
| 908 | obj_, |
| 909 | offset_, |
| 910 | index_, |
| 911 | scale_factor_, |
| 912 | /* needs_null_check */ false, |
| 913 | use_load_acquire_); |
| 914 | |
| 915 | // Mark the object `ref` when `obj` is gray. |
| 916 | // |
| 917 | // if (rb_state == ReadBarrier::GrayState()) |
| 918 | // ref = ReadBarrier::Mark(ref); |
| 919 | // |
| 920 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 921 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 922 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 923 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 924 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 925 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 926 | __ B(GetExitLabel()); |
| 927 | } |
| 928 | |
| 929 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 930 | // The register containing the object holding the marked object reference field. |
| 931 | Register obj_; |
| 932 | // The offset, index and scale factor to access the reference in `obj_`. |
| 933 | uint32_t offset_; |
| 934 | Location index_; |
| 935 | size_t scale_factor_; |
| 936 | // Is a null check required? |
| 937 | bool needs_null_check_; |
| 938 | // Should this reference load use Load-Acquire semantics? |
| 939 | bool use_load_acquire_; |
| 940 | // A temporary register used to hold the lock word of `obj_`. |
| 941 | Register temp_; |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 942 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 943 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM64); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 944 | }; |
| 945 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 946 | // Slow path loading `obj`'s lock word, loading a reference from |
| 947 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 948 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 949 | // read barrier). If needed, this slow path also atomically updates |
| 950 | // the field `obj.field` in the object `obj` holding this reference |
| 951 | // after marking (contrary to |
| 952 | // LoadReferenceWithBakerReadBarrierSlowPathARM64 above, which never |
| 953 | // tries to update `obj.field`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 954 | // |
| 955 | // This means that after the execution of this slow path, both `ref` |
| 956 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 957 | // hold the same to-space reference (unless another thread installed |
| 958 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 959 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 960 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 961 | // barrier marking runtime entry point to be invoked or an empty |
| 962 | // location; in the latter case, the read barrier marking runtime |
| 963 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 964 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 965 | : public ReadBarrierMarkSlowPathBaseARM64 { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 966 | public: |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 967 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 968 | HInstruction* instruction, |
| 969 | Location ref, |
| 970 | Register obj, |
| 971 | uint32_t offset, |
| 972 | Location index, |
| 973 | size_t scale_factor, |
| 974 | bool needs_null_check, |
| 975 | bool use_load_acquire, |
| 976 | Register temp, |
| 977 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 978 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 979 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 980 | offset_(offset), |
| 981 | index_(index), |
| 982 | scale_factor_(scale_factor), |
| 983 | needs_null_check_(needs_null_check), |
| 984 | use_load_acquire_(use_load_acquire), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 985 | temp_(temp) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 986 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 987 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 991 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64"; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 995 | LocationSummary* locations = instruction_->GetLocations(); |
| 996 | Register ref_reg = WRegisterFrom(ref_); |
| 997 | DCHECK(locations->CanCall()); |
| 998 | DCHECK(ref_.IsRegister()) << ref_; |
| 999 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1000 | DCHECK(obj_.IsW()); |
| 1001 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
| 1002 | |
| 1003 | // 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] | 1004 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 1005 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 1006 | << instruction_->DebugName(); |
| 1007 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1008 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1009 | DCHECK_EQ(offset_, 0u); |
| 1010 | DCHECK_EQ(scale_factor_, 0u); |
| 1011 | DCHECK_EQ(use_load_acquire_, false); |
| 1012 | // The location of the offset of the marked reference field within `obj_`. |
| 1013 | Location field_offset = index_; |
| 1014 | DCHECK(field_offset.IsRegister()) << field_offset; |
| 1015 | |
| 1016 | // Temporary register `temp_`, used to store the lock word, must |
| 1017 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 1018 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 1019 | // need the lock word to still be in `temp_` after the reference |
| 1020 | // load. |
| 1021 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1022 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1023 | |
| 1024 | __ Bind(GetEntryLabel()); |
| 1025 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 1026 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM64's: |
| 1027 | // |
| 1028 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 1029 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 1030 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 1031 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 1032 | // if (is_gray) { |
| 1033 | // old_ref = ref; |
| 1034 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 1035 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1036 | // } |
| 1037 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1038 | // /* int32_t */ monitor = obj->monitor_ |
| 1039 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1040 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 1041 | if (needs_null_check_) { |
| 1042 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1043 | } |
| 1044 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1045 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1046 | "art::LockWord and int32_t have different sizes."); |
| 1047 | |
| 1048 | // Introduce a dependency on the lock_word including rb_state, |
| 1049 | // to prevent load-load reordering, and without using |
| 1050 | // a memory barrier (which would be more expensive). |
| 1051 | // `obj` is unchanged by this operation, but its value now depends |
| 1052 | // on `temp`. |
| 1053 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 1054 | |
| 1055 | // The actual reference load. |
| 1056 | // A possible implicit null check has already been handled above. |
| 1057 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1058 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 1059 | ref_, |
| 1060 | obj_, |
| 1061 | offset_, |
| 1062 | index_, |
| 1063 | scale_factor_, |
| 1064 | /* needs_null_check */ false, |
| 1065 | use_load_acquire_); |
| 1066 | |
| 1067 | // Mark the object `ref` when `obj` is gray. |
| 1068 | // |
| 1069 | // if (rb_state == ReadBarrier::GrayState()) |
| 1070 | // ref = ReadBarrier::Mark(ref); |
| 1071 | // |
| 1072 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 1073 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1074 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1075 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 1076 | |
| 1077 | // Save the old value of the reference before marking it. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1078 | // Note that we cannot use IP to save the old reference, as IP is |
| 1079 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1080 | // need the old reference after the call to that entry point. |
| 1081 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1082 | __ Mov(temp_.W(), ref_reg); |
| 1083 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1084 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1085 | |
| 1086 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1087 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1088 | // |
| 1089 | // Note that this field could also hold a different object, if |
| 1090 | // another thread had concurrently changed it. In that case, the |
| 1091 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 1092 | // (CAS) operation below would abort the CAS, leaving the field |
| 1093 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1094 | __ Cmp(temp_.W(), ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1095 | __ B(eq, GetExitLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1096 | |
| 1097 | // Update the the holder's field atomically. This may fail if |
| 1098 | // mutator updates before us, but it's OK. This is achieved |
| 1099 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1100 | // memory synchronization ordering, where the expected value is |
| 1101 | // the old reference and the desired value is the new reference. |
| 1102 | |
| 1103 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 1104 | UseScratchRegisterScope temps(masm); |
| 1105 | |
| 1106 | // Convenience aliases. |
| 1107 | Register base = obj_.W(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1108 | Register offset = XRegisterFrom(field_offset); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1109 | Register expected = temp_.W(); |
| 1110 | Register value = ref_reg; |
| 1111 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1112 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 1113 | |
| 1114 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1115 | |
| 1116 | if (kPoisonHeapReferences) { |
| 1117 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1118 | if (value.Is(expected)) { |
| 1119 | // Do not poison `value`, as it is the same register as |
| 1120 | // `expected`, which has just been poisoned. |
| 1121 | } else { |
| 1122 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | // do { |
| 1127 | // tmp_value = [tmp_ptr] - expected; |
| 1128 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1129 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1130 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1131 | __ Bind(&loop_head); |
| 1132 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 1133 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1134 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1135 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 1136 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1137 | __ B(&exit_loop); |
| 1138 | __ Bind(&comparison_failed); |
| 1139 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1140 | __ Bind(&exit_loop); |
| 1141 | |
| 1142 | if (kPoisonHeapReferences) { |
| 1143 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1144 | if (value.Is(expected)) { |
| 1145 | // Do not unpoison `value`, as it is the same register as |
| 1146 | // `expected`, which has just been unpoisoned. |
| 1147 | } else { |
| 1148 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1149 | } |
| 1150 | } |
| 1151 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1152 | __ B(GetExitLabel()); |
| 1153 | } |
| 1154 | |
| 1155 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1156 | // The register containing the object holding the marked object reference field. |
| 1157 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1158 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1159 | uint32_t offset_; |
| 1160 | Location index_; |
| 1161 | size_t scale_factor_; |
| 1162 | // Is a null check required? |
| 1163 | bool needs_null_check_; |
| 1164 | // Should this reference load use Load-Acquire semantics? |
| 1165 | bool use_load_acquire_; |
| 1166 | // A temporary register used to hold the lock word of `obj_`; and |
| 1167 | // also to hold the original reference value, when the reference is |
| 1168 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1169 | const Register temp_; |
| 1170 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1171 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1172 | }; |
| 1173 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1174 | // Slow path generating a read barrier for a heap reference. |
| 1175 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 1176 | public: |
| 1177 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 1178 | Location out, |
| 1179 | Location ref, |
| 1180 | Location obj, |
| 1181 | uint32_t offset, |
| 1182 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1183 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1184 | out_(out), |
| 1185 | ref_(ref), |
| 1186 | obj_(obj), |
| 1187 | offset_(offset), |
| 1188 | index_(index) { |
| 1189 | DCHECK(kEmitCompilerReadBarrier); |
| 1190 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1191 | // has been overwritten by (or after) the heap object reference load |
| 1192 | // to be instrumented, e.g.: |
| 1193 | // |
| 1194 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1195 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1196 | // |
| 1197 | // In that case, we have lost the information about the original |
| 1198 | // object, and the emitted read barrier cannot work properly. |
| 1199 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1200 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1201 | } |
| 1202 | |
| 1203 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1204 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1205 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1206 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1207 | DCHECK(locations->CanCall()); |
| 1208 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1209 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1210 | instruction_->IsStaticFieldGet() || |
| 1211 | instruction_->IsArrayGet() || |
| 1212 | instruction_->IsInstanceOf() || |
| 1213 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1214 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1215 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1216 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1217 | // The read barrier instrumentation of object ArrayGet |
| 1218 | // instructions does not support the HIntermediateAddress |
| 1219 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1220 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1221 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1222 | |
| 1223 | __ Bind(GetEntryLabel()); |
| 1224 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1225 | SaveLiveRegisters(codegen, locations); |
| 1226 | |
| 1227 | // We may have to change the index's value, but as `index_` is a |
| 1228 | // constant member (like other "inputs" of this slow path), |
| 1229 | // introduce a copy of it, `index`. |
| 1230 | Location index = index_; |
| 1231 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1232 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1233 | if (instruction_->IsArrayGet()) { |
| 1234 | // Compute the actual memory offset and store it in `index`. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1235 | Register index_reg = RegisterFrom(index_, DataType::Type::kInt32); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1236 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 1237 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 1238 | // We are about to change the value of `index_reg` (see the |
| 1239 | // calls to vixl::MacroAssembler::Lsl and |
| 1240 | // vixl::MacroAssembler::Mov below), but it has |
| 1241 | // not been saved by the previous call to |
| 1242 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1243 | // callee-save register -- |
| 1244 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1245 | // callee-save registers, as it has been designed with the |
| 1246 | // assumption that callee-save registers are supposed to be |
| 1247 | // handled by the called function. So, as a callee-save |
| 1248 | // register, `index_reg` _would_ eventually be saved onto |
| 1249 | // the stack, but it would be too late: we would have |
| 1250 | // changed its value earlier. Therefore, we manually save |
| 1251 | // it here into another freely available register, |
| 1252 | // `free_reg`, chosen of course among the caller-save |
| 1253 | // registers (as a callee-save `free_reg` register would |
| 1254 | // exhibit the same problem). |
| 1255 | // |
| 1256 | // Note we could have requested a temporary register from |
| 1257 | // the register allocator instead; but we prefer not to, as |
| 1258 | // this is a slow path, and we know we can find a |
| 1259 | // caller-save register that is available. |
| 1260 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1261 | __ Mov(free_reg.W(), index_reg); |
| 1262 | index_reg = free_reg; |
| 1263 | index = LocationFrom(index_reg); |
| 1264 | } else { |
| 1265 | // The initial register stored in `index_` has already been |
| 1266 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1267 | // (as it is not a callee-save register), so we can freely |
| 1268 | // use it. |
| 1269 | } |
| 1270 | // Shifting the index value contained in `index_reg` by the scale |
| 1271 | // factor (2) cannot overflow in practice, as the runtime is |
| 1272 | // unable to allocate object arrays with a size larger than |
| 1273 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1274 | __ Lsl(index_reg, index_reg, DataType::SizeShift(type)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1275 | static_assert( |
| 1276 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1277 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1278 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1279 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1280 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1281 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1282 | // (as in the case of ArrayGet), as it is actually an offset |
| 1283 | // to an object field within an object. |
| 1284 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1285 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1286 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1287 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1288 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1289 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1290 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | // We're moving two or three locations to locations that could |
| 1295 | // overlap, so we need a parallel move resolver. |
| 1296 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1297 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1298 | parallel_move.AddMove(ref_, |
| 1299 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1300 | type, |
| 1301 | nullptr); |
| 1302 | parallel_move.AddMove(obj_, |
| 1303 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1304 | type, |
| 1305 | nullptr); |
| 1306 | if (index.IsValid()) { |
| 1307 | parallel_move.AddMove(index, |
| 1308 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1309 | DataType::Type::kInt32, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1310 | nullptr); |
| 1311 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1312 | } else { |
| 1313 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1314 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1315 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1316 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1317 | instruction_, |
| 1318 | instruction_->GetDexPc(), |
| 1319 | this); |
| 1320 | CheckEntrypointTypes< |
| 1321 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1322 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1323 | |
| 1324 | RestoreLiveRegisters(codegen, locations); |
| 1325 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1326 | __ B(GetExitLabel()); |
| 1327 | } |
| 1328 | |
| 1329 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1330 | |
| 1331 | private: |
| 1332 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1333 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1334 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1335 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1336 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1337 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1338 | } |
| 1339 | } |
| 1340 | // We shall never fail to find a free caller-save register, as |
| 1341 | // there are more than two core caller-save registers on ARM64 |
| 1342 | // (meaning it is possible to find one which is different from |
| 1343 | // `ref` and `obj`). |
| 1344 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1345 | LOG(FATAL) << "Could not find a free register"; |
| 1346 | UNREACHABLE(); |
| 1347 | } |
| 1348 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1349 | const Location out_; |
| 1350 | const Location ref_; |
| 1351 | const Location obj_; |
| 1352 | const uint32_t offset_; |
| 1353 | // An additional location containing an index to an array. |
| 1354 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1355 | // UnsafeGetObjectVolatile intrinsics. |
| 1356 | const Location index_; |
| 1357 | |
| 1358 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1359 | }; |
| 1360 | |
| 1361 | // Slow path generating a read barrier for a GC root. |
| 1362 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1363 | public: |
| 1364 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1365 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1366 | DCHECK(kEmitCompilerReadBarrier); |
| 1367 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1368 | |
| 1369 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1370 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1371 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1372 | DCHECK(locations->CanCall()); |
| 1373 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1374 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1375 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1376 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1377 | |
| 1378 | __ Bind(GetEntryLabel()); |
| 1379 | SaveLiveRegisters(codegen, locations); |
| 1380 | |
| 1381 | InvokeRuntimeCallingConvention calling_convention; |
| 1382 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1383 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1384 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1385 | // thus we need a 64-bit move here, and we cannot use |
| 1386 | // |
| 1387 | // arm64_codegen->MoveLocation( |
| 1388 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1389 | // root_, |
| 1390 | // type); |
| 1391 | // |
| 1392 | // 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] | 1393 | // reference type (`DataType::Type::kReference`). |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1394 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1395 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1396 | instruction_, |
| 1397 | instruction_->GetDexPc(), |
| 1398 | this); |
| 1399 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1400 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1401 | |
| 1402 | RestoreLiveRegisters(codegen, locations); |
| 1403 | __ B(GetExitLabel()); |
| 1404 | } |
| 1405 | |
| 1406 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1407 | |
| 1408 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1409 | const Location out_; |
| 1410 | const Location root_; |
| 1411 | |
| 1412 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1413 | }; |
| 1414 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1415 | #undef __ |
| 1416 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1417 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1418 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1419 | if (type == DataType::Type::kVoid) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1420 | LOG(FATAL) << "Unreachable type " << type; |
| 1421 | } |
| 1422 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1423 | if (DataType::IsFloatingPointType(type) && |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1424 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1425 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1426 | } else if (!DataType::IsFloatingPointType(type) && |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1427 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 1428 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1429 | } else { |
| 1430 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1431 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1432 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1433 | } |
| 1434 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1435 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1436 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1437 | return next_location; |
| 1438 | } |
| 1439 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1440 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1441 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1442 | } |
| 1443 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1444 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1445 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1446 | const CompilerOptions& compiler_options, |
| 1447 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1448 | : CodeGenerator(graph, |
| 1449 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1450 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1451 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1452 | callee_saved_core_registers.GetList(), |
| 1453 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1454 | compiler_options, |
| 1455 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1456 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1457 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1458 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1459 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1460 | move_resolver_(graph->GetAllocator(), this), |
| 1461 | assembler_(graph->GetAllocator()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1462 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1463 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1464 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1465 | uint64_literals_(std::less<uint64_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1466 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1467 | pc_relative_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1468 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1469 | pc_relative_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1470 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1471 | pc_relative_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1472 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1473 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1474 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1475 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1476 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1477 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1478 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1479 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1480 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1481 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1482 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1483 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1484 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1485 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1486 | jump_table->EmitTable(this); |
| 1487 | } |
| 1488 | } |
| 1489 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1490 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1491 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1492 | // Ensure we emit the literal pool. |
| 1493 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1494 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1495 | CodeGenerator::Finalize(allocator); |
| 1496 | } |
| 1497 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1498 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1499 | // Note: There are 6 kinds of moves: |
| 1500 | // 1. constant -> GPR/FPR (non-cycle) |
| 1501 | // 2. constant -> stack (non-cycle) |
| 1502 | // 3. GPR/FPR -> GPR/FPR |
| 1503 | // 4. GPR/FPR -> stack |
| 1504 | // 5. stack -> GPR/FPR |
| 1505 | // 6. stack -> stack (non-cycle) |
| 1506 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1507 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1508 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1509 | // dependency. |
| 1510 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1511 | } |
| 1512 | |
| 1513 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1514 | vixl_temps_.Close(); |
| 1515 | } |
| 1516 | |
| 1517 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1518 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1519 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1520 | || kind == Location::kSIMDStackSlot); |
| 1521 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1522 | ? Location::kFpuRegister |
| 1523 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1524 | Location scratch = GetScratchLocation(kind); |
| 1525 | if (!scratch.Equals(Location::NoLocation())) { |
| 1526 | return scratch; |
| 1527 | } |
| 1528 | // Allocate from VIXL temp registers. |
| 1529 | if (kind == Location::kRegister) { |
| 1530 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1531 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1532 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1533 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1534 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1535 | : vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1536 | } |
| 1537 | AddScratchLocation(scratch); |
| 1538 | return scratch; |
| 1539 | } |
| 1540 | |
| 1541 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1542 | if (loc.IsRegister()) { |
| 1543 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1544 | } else { |
| 1545 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1546 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1547 | } |
| 1548 | RemoveScratchLocation(loc); |
| 1549 | } |
| 1550 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1551 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1552 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1553 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1556 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1557 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1558 | __ Bind(&frame_entry_label_); |
| 1559 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1560 | bool do_overflow_check = |
| 1561 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1562 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1563 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1564 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1565 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1566 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1567 | { |
| 1568 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1569 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1570 | kInstructionSize, |
| 1571 | CodeBufferCheckScope::kExactSize); |
| 1572 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1573 | RecordPcInfo(nullptr, 0); |
| 1574 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1575 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1576 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1577 | if (!HasEmptyFrame()) { |
| 1578 | int frame_size = GetFrameSize(); |
| 1579 | // Stack layout: |
| 1580 | // sp[frame_size - 8] : lr. |
| 1581 | // ... : other preserved core registers. |
| 1582 | // ... : other preserved fp registers. |
| 1583 | // ... : reserved frame space. |
| 1584 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1585 | |
| 1586 | // Save the current method if we need it. Note that we do not |
| 1587 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1588 | // in the SSA graph. |
| 1589 | if (RequiresCurrentMethod()) { |
| 1590 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1591 | } else { |
| 1592 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1593 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1594 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1595 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1596 | frame_size - GetCoreSpillSize()); |
| 1597 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1598 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1599 | |
| 1600 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1601 | // Initialize should_deoptimize flag to 0. |
| 1602 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1603 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1604 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1605 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 1606 | |
| 1607 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1611 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1612 | if (!HasEmptyFrame()) { |
| 1613 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1614 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1615 | frame_size - FrameEntrySpillSize()); |
| 1616 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1617 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1618 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1619 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1620 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1621 | __ Ret(); |
| 1622 | GetAssembler()->cfi().RestoreState(); |
| 1623 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1624 | } |
| 1625 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1626 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1627 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1628 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1629 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1630 | } |
| 1631 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1632 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1633 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1634 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1635 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1636 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1637 | } |
| 1638 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1639 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1640 | __ Bind(GetLabelOf(block)); |
| 1641 | } |
| 1642 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1643 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1644 | DCHECK(location.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1645 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1646 | } |
| 1647 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1648 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1649 | if (location.IsRegister()) { |
| 1650 | locations->AddTemp(location); |
| 1651 | } else { |
| 1652 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1653 | } |
| 1654 | } |
| 1655 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1656 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1657 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1658 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1659 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1660 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1661 | if (value_can_be_null) { |
| 1662 | __ Cbz(value, &done); |
| 1663 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1664 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1665 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1666 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1667 | if (value_can_be_null) { |
| 1668 | __ Bind(&done); |
| 1669 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1670 | } |
| 1671 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1672 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1673 | // Blocked core registers: |
| 1674 | // lr : Runtime reserved. |
| 1675 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1676 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1677 | // ip1 : VIXL core temp. |
| 1678 | // ip0 : VIXL core temp. |
| 1679 | // |
| 1680 | // Blocked fp registers: |
| 1681 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1682 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1683 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1684 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1685 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1686 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1687 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1688 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1689 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1690 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1691 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1692 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1693 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1694 | // Stubs do not save callee-save floating point registers. If the graph |
| 1695 | // is debuggable, we need to deal with these registers differently. For |
| 1696 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1697 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1698 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1699 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1700 | } |
| 1701 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1702 | } |
| 1703 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1704 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1705 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1706 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1707 | return kArm64WordSize; |
| 1708 | } |
| 1709 | |
| 1710 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1711 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1712 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1713 | return kArm64WordSize; |
| 1714 | } |
| 1715 | |
| 1716 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1717 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1718 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1719 | return kArm64WordSize; |
| 1720 | } |
| 1721 | |
| 1722 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1723 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1724 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1725 | return kArm64WordSize; |
| 1726 | } |
| 1727 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1728 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1729 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1733 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1734 | } |
| 1735 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1736 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1737 | if (constant->IsIntConstant()) { |
| 1738 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1739 | } else if (constant->IsLongConstant()) { |
| 1740 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1741 | } else if (constant->IsNullConstant()) { |
| 1742 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1743 | } else if (constant->IsFloatConstant()) { |
| 1744 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1745 | } else { |
| 1746 | DCHECK(constant->IsDoubleConstant()); |
| 1747 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1748 | } |
| 1749 | } |
| 1750 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1751 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1752 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1753 | DCHECK(constant.IsConstant()); |
| 1754 | HConstant* cst = constant.GetConstant(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1755 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1756 | // 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] | 1757 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1758 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1759 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1760 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1761 | } |
| 1762 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1763 | // Allocate a scratch register from the VIXL pool, querying first |
| 1764 | // the floating-point register pool, and then the core register |
| 1765 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1766 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1767 | // using a different allocation strategy. |
| 1768 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1769 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1770 | int size_in_bits) { |
| 1771 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1772 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1773 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1774 | } |
| 1775 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1776 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1777 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1778 | DataType::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1779 | if (source.Equals(destination)) { |
| 1780 | return; |
| 1781 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1782 | |
| 1783 | // A valid move can always be inferred from the destination and source |
| 1784 | // locations. When moving from and to a register, the argument type can be |
| 1785 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1786 | // checks the coherency of the locations and the type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1787 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1788 | |
| 1789 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1790 | if (unspecified_type) { |
| 1791 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1792 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1793 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1794 | || src_cst->IsFloatConstant() |
| 1795 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1796 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1797 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1798 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1799 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1800 | // type is appropriate. Else the source is a register, and since the |
| 1801 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1802 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1803 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1804 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1805 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1806 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1807 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1808 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1809 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1810 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1811 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1812 | } else if (source.IsSIMDStackSlot()) { |
| 1813 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1814 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1815 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1816 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1817 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1818 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1819 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1820 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1821 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1822 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1823 | ? DataType::Type::kInt64 |
| 1824 | : DataType::Type::kInt32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1825 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1826 | } |
| 1827 | } else { |
| 1828 | DCHECK(source.IsFpuRegister()); |
| 1829 | if (destination.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1830 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1831 | ? DataType::Type::kFloat64 |
| 1832 | : DataType::Type::kFloat32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1833 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1834 | } else { |
| 1835 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1836 | if (GetGraph()->HasSIMD()) { |
| 1837 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1838 | } else { |
| 1839 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1840 | } |
| 1841 | } |
| 1842 | } |
| 1843 | } else if (destination.IsSIMDStackSlot()) { |
| 1844 | if (source.IsFpuRegister()) { |
| 1845 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1846 | } else { |
| 1847 | DCHECK(source.IsSIMDStackSlot()); |
| 1848 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1849 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1850 | Register temp = temps.AcquireX(); |
| 1851 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1852 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1853 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1854 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1855 | } else { |
| 1856 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1857 | __ Ldr(temp, StackOperandFrom(source)); |
| 1858 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1859 | } |
| 1860 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1861 | } else { // The destination is not a register. It must be a stack slot. |
| 1862 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1863 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1864 | if (unspecified_type) { |
| 1865 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1866 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1867 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1868 | dst_type = |
| 1869 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1870 | } |
| 1871 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1872 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1873 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1874 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1875 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1876 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1877 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1878 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1879 | HConstant* src_cst = source.GetConstant(); |
| 1880 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1881 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1882 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1883 | ? Register(xzr) |
| 1884 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1885 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1886 | if (src_cst->IsIntConstant()) { |
| 1887 | temp = temps.AcquireW(); |
| 1888 | } else if (src_cst->IsLongConstant()) { |
| 1889 | temp = temps.AcquireX(); |
| 1890 | } else if (src_cst->IsFloatConstant()) { |
| 1891 | temp = temps.AcquireS(); |
| 1892 | } else { |
| 1893 | DCHECK(src_cst->IsDoubleConstant()); |
| 1894 | temp = temps.AcquireD(); |
| 1895 | } |
| 1896 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1897 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1898 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1899 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1900 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1901 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1902 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1903 | // Use any scratch register (a core or a floating-point one) |
| 1904 | // from VIXL scratch register pools as a temporary. |
| 1905 | // |
| 1906 | // We used to only use the FP scratch register pool, but in some |
| 1907 | // rare cases the only register from this pool (D31) would |
| 1908 | // already be used (e.g. within a ParallelMove instruction, when |
| 1909 | // a move is blocked by a another move requiring a scratch FP |
| 1910 | // register, which would reserve D31). To prevent this issue, we |
| 1911 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1912 | // |
| 1913 | // 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] | 1914 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1915 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1916 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1917 | // allocates core scratch registers first. |
| 1918 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1919 | GetVIXLAssembler(), |
| 1920 | &temps, |
| 1921 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1922 | __ Ldr(temp, StackOperandFrom(source)); |
| 1923 | __ Str(temp, StackOperandFrom(destination)); |
| 1924 | } |
| 1925 | } |
| 1926 | } |
| 1927 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1928 | void CodeGeneratorARM64::Load(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1929 | CPURegister dst, |
| 1930 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1931 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1932 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1933 | case DataType::Type::kUint8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1934 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1935 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1936 | case DataType::Type::kInt8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1937 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1938 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1939 | case DataType::Type::kUint16: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1940 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1941 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1942 | case DataType::Type::kInt16: |
| 1943 | __ Ldrsh(Register(dst), src); |
| 1944 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1945 | case DataType::Type::kInt32: |
| 1946 | case DataType::Type::kReference: |
| 1947 | case DataType::Type::kInt64: |
| 1948 | case DataType::Type::kFloat32: |
| 1949 | case DataType::Type::kFloat64: |
| 1950 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1951 | __ Ldr(dst, src); |
| 1952 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1953 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1954 | LOG(FATAL) << "Unreachable type " << type; |
| 1955 | } |
| 1956 | } |
| 1957 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1958 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1959 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1960 | const MemOperand& src, |
| 1961 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1962 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1963 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1964 | Register temp_base = temps.AcquireX(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1965 | DataType::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1966 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1967 | DCHECK(!src.IsPreIndex()); |
| 1968 | DCHECK(!src.IsPostIndex()); |
| 1969 | |
| 1970 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1971 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1972 | { |
| 1973 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1974 | MemOperand base = MemOperand(temp_base); |
| 1975 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1976 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1977 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1978 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1979 | { |
| 1980 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1981 | __ ldarb(Register(dst), base); |
| 1982 | if (needs_null_check) { |
| 1983 | MaybeRecordImplicitNullCheck(instruction); |
| 1984 | } |
| 1985 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1986 | if (type == DataType::Type::kInt8) { |
| 1987 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1988 | } |
| 1989 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1990 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1991 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1992 | { |
| 1993 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1994 | __ ldarh(Register(dst), base); |
| 1995 | if (needs_null_check) { |
| 1996 | MaybeRecordImplicitNullCheck(instruction); |
| 1997 | } |
| 1998 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1999 | if (type == DataType::Type::kInt16) { |
| 2000 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 2001 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2002 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2003 | case DataType::Type::kInt32: |
| 2004 | case DataType::Type::kReference: |
| 2005 | case DataType::Type::kInt64: |
| 2006 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2007 | { |
| 2008 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2009 | __ ldar(Register(dst), base); |
| 2010 | if (needs_null_check) { |
| 2011 | MaybeRecordImplicitNullCheck(instruction); |
| 2012 | } |
| 2013 | } |
| 2014 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2015 | case DataType::Type::kFloat32: |
| 2016 | case DataType::Type::kFloat64: { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2017 | DCHECK(dst.IsFPRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2018 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2019 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2020 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2021 | { |
| 2022 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2023 | __ ldar(temp, base); |
| 2024 | if (needs_null_check) { |
| 2025 | MaybeRecordImplicitNullCheck(instruction); |
| 2026 | } |
| 2027 | } |
| 2028 | __ Fmov(FPRegister(dst), temp); |
| 2029 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2030 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2031 | case DataType::Type::kVoid: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2032 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2033 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2034 | } |
| 2035 | } |
| 2036 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2037 | void CodeGeneratorARM64::Store(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2038 | CPURegister src, |
| 2039 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2040 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2041 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2042 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2043 | case DataType::Type::kInt8: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2044 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2045 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2046 | case DataType::Type::kUint16: |
| 2047 | case DataType::Type::kInt16: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2048 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2049 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2050 | case DataType::Type::kInt32: |
| 2051 | case DataType::Type::kReference: |
| 2052 | case DataType::Type::kInt64: |
| 2053 | case DataType::Type::kFloat32: |
| 2054 | case DataType::Type::kFloat64: |
| 2055 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2056 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2057 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2058 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2059 | LOG(FATAL) << "Unreachable type " << type; |
| 2060 | } |
| 2061 | } |
| 2062 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2063 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2064 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2065 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2066 | const MemOperand& dst, |
| 2067 | bool needs_null_check) { |
| 2068 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2069 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2070 | Register temp_base = temps.AcquireX(); |
| 2071 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2072 | DCHECK(!dst.IsPreIndex()); |
| 2073 | DCHECK(!dst.IsPostIndex()); |
| 2074 | |
| 2075 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2076 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2077 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2078 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2079 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2080 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2081 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2082 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2083 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2084 | { |
| 2085 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2086 | __ stlrb(Register(src), base); |
| 2087 | if (needs_null_check) { |
| 2088 | MaybeRecordImplicitNullCheck(instruction); |
| 2089 | } |
| 2090 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2091 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2092 | case DataType::Type::kUint16: |
| 2093 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2094 | { |
| 2095 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2096 | __ stlrh(Register(src), base); |
| 2097 | if (needs_null_check) { |
| 2098 | MaybeRecordImplicitNullCheck(instruction); |
| 2099 | } |
| 2100 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2101 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2102 | case DataType::Type::kInt32: |
| 2103 | case DataType::Type::kReference: |
| 2104 | case DataType::Type::kInt64: |
| 2105 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2106 | { |
| 2107 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2108 | __ stlr(Register(src), base); |
| 2109 | if (needs_null_check) { |
| 2110 | MaybeRecordImplicitNullCheck(instruction); |
| 2111 | } |
| 2112 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2113 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2114 | case DataType::Type::kFloat32: |
| 2115 | case DataType::Type::kFloat64: { |
| 2116 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2117 | Register temp_src; |
| 2118 | if (src.IsZero()) { |
| 2119 | // The zero register is used to avoid synthesizing zero constants. |
| 2120 | temp_src = Register(src); |
| 2121 | } else { |
| 2122 | DCHECK(src.IsFPRegister()); |
| 2123 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2124 | __ Fmov(temp_src, FPRegister(src)); |
| 2125 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2126 | { |
| 2127 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2128 | __ stlr(temp_src, base); |
| 2129 | if (needs_null_check) { |
| 2130 | MaybeRecordImplicitNullCheck(instruction); |
| 2131 | } |
| 2132 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2133 | break; |
| 2134 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2135 | case DataType::Type::kVoid: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2136 | LOG(FATAL) << "Unreachable type " << type; |
| 2137 | } |
| 2138 | } |
| 2139 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2140 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2141 | HInstruction* instruction, |
| 2142 | uint32_t dex_pc, |
| 2143 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2144 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2145 | |
| 2146 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 2147 | { |
| 2148 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 2149 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2150 | __ blr(lr); |
| 2151 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2152 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2153 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2154 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2157 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2158 | HInstruction* instruction, |
| 2159 | SlowPathCode* slow_path) { |
| 2160 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2161 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2162 | __ Blr(lr); |
| 2163 | } |
| 2164 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2165 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2166 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2167 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2168 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2169 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 2170 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2171 | // 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] | 2172 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 2173 | __ Add(temp, class_reg, status_offset); |
Igor Murashkin | 86083f7 | 2017-10-27 10:59:04 -0700 | [diff] [blame] | 2174 | __ Ldarb(temp, HeapOperand(temp)); |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2175 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
Igor Murashkin | 86083f7 | 2017-10-27 10:59:04 -0700 | [diff] [blame] | 2176 | __ B(ne, slow_path->GetEntryLabel()); |
| 2177 | // Use Bne instead of Blt because ARM64 doesn't have Ldarsb. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2178 | __ Bind(slow_path->GetExitLabel()); |
| 2179 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2180 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2181 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2182 | BarrierType type = BarrierAll; |
| 2183 | |
| 2184 | switch (kind) { |
| 2185 | case MemBarrierKind::kAnyAny: |
| 2186 | case MemBarrierKind::kAnyStore: { |
| 2187 | type = BarrierAll; |
| 2188 | break; |
| 2189 | } |
| 2190 | case MemBarrierKind::kLoadAny: { |
| 2191 | type = BarrierReads; |
| 2192 | break; |
| 2193 | } |
| 2194 | case MemBarrierKind::kStoreStore: { |
| 2195 | type = BarrierWrites; |
| 2196 | break; |
| 2197 | } |
| 2198 | default: |
| 2199 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2200 | } |
| 2201 | __ Dmb(InnerShareable, type); |
| 2202 | } |
| 2203 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2204 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2205 | HBasicBlock* successor) { |
| 2206 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2207 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2208 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2209 | slow_path = |
| 2210 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2211 | instruction->SetSlowPath(slow_path); |
| 2212 | codegen_->AddSlowPath(slow_path); |
| 2213 | if (successor != nullptr) { |
| 2214 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2215 | } |
| 2216 | } else { |
| 2217 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2218 | } |
| 2219 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2220 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2221 | Register temp = temps.AcquireW(); |
| 2222 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2223 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2224 | if (successor == nullptr) { |
| 2225 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2226 | __ Bind(slow_path->GetReturnLabel()); |
| 2227 | } else { |
| 2228 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 2229 | __ B(slow_path->GetEntryLabel()); |
| 2230 | // slow_path will return to GetLabelOf(successor). |
| 2231 | } |
| 2232 | } |
| 2233 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2234 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2235 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2236 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2237 | assembler_(codegen->GetAssembler()), |
| 2238 | codegen_(codegen) {} |
| 2239 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2240 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2241 | DCHECK_EQ(instr->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2242 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2243 | DataType::Type type = instr->GetResultType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2244 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2245 | case DataType::Type::kInt32: |
| 2246 | case DataType::Type::kInt64: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2247 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2248 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2249 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2250 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2251 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2252 | case DataType::Type::kFloat32: |
| 2253 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2254 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2255 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2256 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2257 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2258 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2259 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2260 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2261 | } |
| 2262 | } |
| 2263 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2264 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2265 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2266 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2267 | |
| 2268 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2269 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2270 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2271 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2272 | object_field_get_with_read_barrier |
| 2273 | ? LocationSummary::kCallOnSlowPath |
| 2274 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2275 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2276 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2277 | // We need a temporary register for the read barrier marking slow |
| 2278 | // path in CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2279 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2280 | !Runtime::Current()->UseJitCompilation() && |
| 2281 | !field_info.IsVolatile()) { |
| 2282 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2283 | // non-volatile loads we need a temporary only if the offset is too big. |
| 2284 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2285 | locations->AddTemp(FixedTempLocation()); |
| 2286 | } |
| 2287 | } else { |
| 2288 | locations->AddTemp(Location::RequiresRegister()); |
| 2289 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2290 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2291 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2292 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2293 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2294 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2295 | // The output overlaps for an object field get when read barriers |
| 2296 | // are enabled: we do not want the load to overwrite the object's |
| 2297 | // location, as we need it to emit the read barrier. |
| 2298 | locations->SetOut( |
| 2299 | Location::RequiresRegister(), |
| 2300 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2305 | const FieldInfo& field_info) { |
| 2306 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2307 | LocationSummary* locations = instruction->GetLocations(); |
| 2308 | Location base_loc = locations->InAt(0); |
| 2309 | Location out = locations->Out(); |
| 2310 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2311 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 2312 | DataType::Type load_type = instruction->GetType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2313 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2314 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2315 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2316 | load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2317 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2318 | // /* HeapReference<Object> */ out = *(base + offset) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2319 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2320 | Location maybe_temp = |
| 2321 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2322 | // Note that potential implicit null checks are handled in this |
| 2323 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2324 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2325 | instruction, |
| 2326 | out, |
| 2327 | base, |
| 2328 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2329 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2330 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2331 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2332 | } else { |
| 2333 | // General case. |
| 2334 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2335 | // Note that a potential implicit null check is handled in this |
| 2336 | // CodeGeneratorARM64::LoadAcquire call. |
| 2337 | // NB: LoadAcquire will record the pc info if needed. |
| 2338 | codegen_->LoadAcquire( |
| 2339 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2340 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2341 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2342 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2343 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2344 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2345 | } |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2346 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2347 | // If read barriers are enabled, emit read barriers other than |
| 2348 | // Baker's using a slow path (and also unpoison the loaded |
| 2349 | // reference, if heap poisoning is enabled). |
| 2350 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2351 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2352 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2356 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2357 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2358 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2359 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2360 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2361 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2362 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2363 | } else { |
| 2364 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2365 | } |
| 2366 | } |
| 2367 | |
| 2368 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2369 | const FieldInfo& field_info, |
| 2370 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2371 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2372 | |
| 2373 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2374 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2375 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2376 | Offset offset = field_info.GetFieldOffset(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2377 | DataType::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2378 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2379 | { |
| 2380 | // We use a block to end the scratch scope before the write barrier, thus |
| 2381 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2382 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2383 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2384 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2385 | DCHECK(value.IsW()); |
| 2386 | Register temp = temps.AcquireW(); |
| 2387 | __ Mov(temp, value.W()); |
| 2388 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2389 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2390 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2391 | |
| 2392 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2393 | codegen_->StoreRelease( |
| 2394 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2395 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2396 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2397 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2398 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2399 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2400 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2404 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2405 | } |
| 2406 | } |
| 2407 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2408 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2409 | DataType::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2410 | |
| 2411 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2412 | case DataType::Type::kInt32: |
| 2413 | case DataType::Type::kInt64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2414 | Register dst = OutputRegister(instr); |
| 2415 | Register lhs = InputRegisterAt(instr, 0); |
| 2416 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2417 | if (instr->IsAdd()) { |
| 2418 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2419 | } else if (instr->IsAnd()) { |
| 2420 | __ And(dst, lhs, rhs); |
| 2421 | } else if (instr->IsOr()) { |
| 2422 | __ Orr(dst, lhs, rhs); |
| 2423 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2424 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2425 | } else if (instr->IsRor()) { |
| 2426 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2427 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2428 | __ Ror(dst, lhs, shift); |
| 2429 | } else { |
| 2430 | // Ensure shift distance is in the same size register as the result. If |
| 2431 | // we are rotating a long and the shift comes in a w register originally, |
| 2432 | // we don't need to sxtw for use as an x since the shift distances are |
| 2433 | // all & reg_bits - 1. |
| 2434 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2435 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2436 | } else { |
| 2437 | DCHECK(instr->IsXor()); |
| 2438 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2439 | } |
| 2440 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2441 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2442 | case DataType::Type::kFloat32: |
| 2443 | case DataType::Type::kFloat64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2444 | FPRegister dst = OutputFPRegister(instr); |
| 2445 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2446 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2447 | if (instr->IsAdd()) { |
| 2448 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2449 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2450 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2451 | } else { |
| 2452 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2453 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2454 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2455 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2456 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2457 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2458 | } |
| 2459 | } |
| 2460 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2461 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2462 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2463 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2464 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2465 | DataType::Type type = instr->GetResultType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2466 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2467 | case DataType::Type::kInt32: |
| 2468 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2469 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2470 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2471 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2472 | break; |
| 2473 | } |
| 2474 | default: |
| 2475 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2480 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2481 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2482 | DataType::Type type = instr->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2483 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2484 | case DataType::Type::kInt32: |
| 2485 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2486 | Register dst = OutputRegister(instr); |
| 2487 | Register lhs = InputRegisterAt(instr, 0); |
| 2488 | Operand rhs = InputOperandAt(instr, 1); |
| 2489 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2490 | uint32_t shift_value = rhs.GetImmediate() & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2491 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2492 | if (instr->IsShl()) { |
| 2493 | __ Lsl(dst, lhs, shift_value); |
| 2494 | } else if (instr->IsShr()) { |
| 2495 | __ Asr(dst, lhs, shift_value); |
| 2496 | } else { |
| 2497 | __ Lsr(dst, lhs, shift_value); |
| 2498 | } |
| 2499 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2500 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2501 | |
| 2502 | if (instr->IsShl()) { |
| 2503 | __ Lsl(dst, lhs, rhs_reg); |
| 2504 | } else if (instr->IsShr()) { |
| 2505 | __ Asr(dst, lhs, rhs_reg); |
| 2506 | } else { |
| 2507 | __ Lsr(dst, lhs, rhs_reg); |
| 2508 | } |
| 2509 | } |
| 2510 | break; |
| 2511 | } |
| 2512 | default: |
| 2513 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2514 | } |
| 2515 | } |
| 2516 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2517 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2518 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2522 | HandleBinaryOp(instruction); |
| 2523 | } |
| 2524 | |
| 2525 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2526 | HandleBinaryOp(instruction); |
| 2527 | } |
| 2528 | |
| 2529 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2530 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2531 | } |
| 2532 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2533 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2534 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2535 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2536 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2537 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2538 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2539 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2540 | } |
| 2541 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2542 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2543 | Register dst = OutputRegister(instr); |
| 2544 | Register lhs = InputRegisterAt(instr, 0); |
| 2545 | Register rhs = InputRegisterAt(instr, 1); |
| 2546 | |
| 2547 | switch (instr->GetOpKind()) { |
| 2548 | case HInstruction::kAnd: |
| 2549 | __ Bic(dst, lhs, rhs); |
| 2550 | break; |
| 2551 | case HInstruction::kOr: |
| 2552 | __ Orn(dst, lhs, rhs); |
| 2553 | break; |
| 2554 | case HInstruction::kXor: |
| 2555 | __ Eon(dst, lhs, rhs); |
| 2556 | break; |
| 2557 | default: |
| 2558 | LOG(FATAL) << "Unreachable"; |
| 2559 | } |
| 2560 | } |
| 2561 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2562 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2563 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2564 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2565 | instruction->GetType() == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2566 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2567 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2568 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2569 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2570 | } else { |
| 2571 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2572 | } |
| 2573 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2574 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2575 | } |
| 2576 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2577 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2578 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2579 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2580 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2581 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2582 | Register out = OutputRegister(instruction); |
| 2583 | Register left; |
| 2584 | if (kind != HInstruction::kNeg) { |
| 2585 | left = InputRegisterAt(instruction, 0); |
| 2586 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2587 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2588 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2589 | // conversion) can have a different type from the current instruction's type, |
| 2590 | // so we manually indicate the type. |
| 2591 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2592 | Operand right_operand(0); |
| 2593 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2594 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2595 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2596 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2597 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2598 | right_operand = Operand(right_reg, |
| 2599 | helpers::ShiftFromOpKind(op_kind), |
| 2600 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | // Logical binary operations do not support extension operations in the |
| 2604 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2605 | // the extension as a separate instruction. |
| 2606 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2607 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2608 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2609 | kind != HInstruction::kNeg)); |
| 2610 | switch (kind) { |
| 2611 | case HInstruction::kAdd: |
| 2612 | __ Add(out, left, right_operand); |
| 2613 | break; |
| 2614 | case HInstruction::kAnd: |
| 2615 | __ And(out, left, right_operand); |
| 2616 | break; |
| 2617 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2618 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2619 | __ Neg(out, right_operand); |
| 2620 | break; |
| 2621 | case HInstruction::kOr: |
| 2622 | __ Orr(out, left, right_operand); |
| 2623 | break; |
| 2624 | case HInstruction::kSub: |
| 2625 | __ Sub(out, left, right_operand); |
| 2626 | break; |
| 2627 | case HInstruction::kXor: |
| 2628 | __ Eor(out, left, right_operand); |
| 2629 | break; |
| 2630 | default: |
| 2631 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2632 | UNREACHABLE(); |
| 2633 | } |
| 2634 | } |
| 2635 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2636 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2637 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2638 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2639 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2640 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2641 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2642 | } |
| 2643 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2644 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2645 | __ Add(OutputRegister(instruction), |
| 2646 | InputRegisterAt(instruction, 0), |
| 2647 | Operand(InputOperandAt(instruction, 1))); |
| 2648 | } |
| 2649 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2650 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2651 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2652 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2653 | |
| 2654 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2655 | |
| 2656 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2657 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2658 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2659 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2660 | // loop. |
| 2661 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2662 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2663 | : Location::RequiresRegister()); |
| 2664 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2665 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2666 | } |
| 2667 | |
| 2668 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2669 | HIntermediateAddressIndex* instruction) { |
| 2670 | Register index_reg = InputRegisterAt(instruction, 0); |
| 2671 | uint32_t shift = Int64ConstantFrom(instruction->GetLocations()->InAt(2)); |
| 2672 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2673 | |
| 2674 | if (shift == 0) { |
| 2675 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2676 | } else { |
| 2677 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2678 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2679 | } |
| 2680 | } |
| 2681 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2682 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2683 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2684 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2685 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2686 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2687 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2688 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2689 | // Don't allocate register for Mneg instruction. |
| 2690 | } else { |
| 2691 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2692 | Location::RequiresRegister()); |
| 2693 | } |
| 2694 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2695 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2696 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2697 | } |
| 2698 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2699 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2700 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2701 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2702 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2703 | |
| 2704 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2705 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2706 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2707 | if (instr->GetType() == DataType::Type::kInt64 && |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2708 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2709 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2710 | vixl::aarch64::Instruction* prev = |
| 2711 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2712 | if (prev->IsLoadOrStore()) { |
| 2713 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2714 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2715 | __ nop(); |
| 2716 | } |
| 2717 | } |
| 2718 | |
| 2719 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2720 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2721 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2722 | } else { |
| 2723 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2724 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2725 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2726 | __ Mneg(res, mul_left, mul_right); |
| 2727 | } else { |
| 2728 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2729 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2730 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2731 | } |
| 2732 | } |
| 2733 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2734 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2735 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2736 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2737 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2738 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2739 | object_array_get_with_read_barrier |
| 2740 | ? LocationSummary::kCallOnSlowPath |
| 2741 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2742 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2743 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 2744 | // We need a temporary register for the read barrier marking slow |
| 2745 | // path in CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2746 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2747 | !Runtime::Current()->UseJitCompilation() && |
| 2748 | instruction->GetIndex()->IsConstant()) { |
| 2749 | // Array loads with constant index are treated as field loads. |
| 2750 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2751 | // constant index loads we need a temporary only if the offset is too big. |
| 2752 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2753 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2754 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2755 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2756 | locations->AddTemp(FixedTempLocation()); |
| 2757 | } |
| 2758 | } else { |
| 2759 | locations->AddTemp(Location::RequiresRegister()); |
| 2760 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2761 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2762 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2763 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2764 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2765 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2766 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2767 | // The output overlaps in the case of an object array get with |
| 2768 | // read barriers enabled: we do not want the move to overwrite the |
| 2769 | // array's location, as we need it to emit the read barrier. |
| 2770 | locations->SetOut( |
| 2771 | Location::RequiresRegister(), |
| 2772 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2773 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2777 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2778 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2779 | LocationSummary* locations = instruction->GetLocations(); |
| 2780 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2781 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2782 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2783 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2784 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2785 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2786 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2787 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2788 | // The read barrier instrumentation of object ArrayGet instructions |
| 2789 | // does not support the HIntermediateAddress instruction. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2790 | DCHECK(!((type == DataType::Type::kReference) && |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2791 | instruction->GetArray()->IsIntermediateAddress() && |
| 2792 | kEmitCompilerReadBarrier)); |
| 2793 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2794 | if (type == DataType::Type::kReference && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2795 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2796 | // Note that a potential implicit null check is handled in the |
| 2797 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2798 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2799 | if (index.IsConstant()) { |
| 2800 | // 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] | 2801 | offset += Int64ConstantFrom(index) << DataType::SizeShift(type); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2802 | Location maybe_temp = |
| 2803 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2804 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2805 | out, |
| 2806 | obj.W(), |
| 2807 | offset, |
| 2808 | maybe_temp, |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2809 | /* needs_null_check */ false, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2810 | /* use_load_acquire */ false); |
| 2811 | } else { |
| 2812 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
| 2813 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2814 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2815 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2816 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2817 | // General case. |
| 2818 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2819 | Register length; |
| 2820 | if (maybe_compressed_char_at) { |
| 2821 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2822 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2823 | { |
| 2824 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2825 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2826 | |
| 2827 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2828 | DCHECK_LT(count_offset, offset); |
| 2829 | int64_t adjusted_offset = |
| 2830 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2831 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2832 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2833 | } else { |
| 2834 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2835 | } |
| 2836 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2837 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2838 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2839 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2840 | if (maybe_compressed_char_at) { |
| 2841 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2842 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2843 | "Expecting 0=compressed, 1=uncompressed"); |
| 2844 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2845 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2846 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2847 | __ B(&done); |
| 2848 | __ Bind(&uncompressed_load); |
| 2849 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2850 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2851 | __ Bind(&done); |
| 2852 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2853 | offset += Int64ConstantFrom(index) << DataType::SizeShift(type); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2854 | source = HeapOperand(obj, offset); |
| 2855 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2856 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2857 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2858 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2859 | // We do not need to compute the intermediate address from the array: the |
| 2860 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2861 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2862 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2863 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2864 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2865 | } |
| 2866 | temp = obj; |
| 2867 | } else { |
| 2868 | __ Add(temp, obj, offset); |
| 2869 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2870 | if (maybe_compressed_char_at) { |
| 2871 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2872 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2873 | "Expecting 0=compressed, 1=uncompressed"); |
| 2874 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2875 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2876 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2877 | __ B(&done); |
| 2878 | __ Bind(&uncompressed_load); |
| 2879 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2880 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2881 | __ Bind(&done); |
| 2882 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2883 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2884 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2885 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2886 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2887 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2888 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2889 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2890 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2891 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2892 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2893 | if (type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2894 | static_assert( |
| 2895 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2896 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2897 | Location obj_loc = locations->InAt(0); |
| 2898 | if (index.IsConstant()) { |
| 2899 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2900 | } else { |
| 2901 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2902 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2903 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2904 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2905 | } |
| 2906 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2907 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2908 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2909 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2910 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2914 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2915 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2916 | { |
| 2917 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2918 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2919 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2920 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2921 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2922 | // Mask out compression flag from String's array length. |
| 2923 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2924 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2925 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2926 | } |
| 2927 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2928 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2929 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2930 | |
| 2931 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2932 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2933 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2934 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2935 | LocationSummary::kCallOnSlowPath : |
| 2936 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2937 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2938 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2939 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2940 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2941 | } else if (DataType::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2942 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2943 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2944 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2945 | } |
| 2946 | } |
| 2947 | |
| 2948 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2949 | DataType::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2950 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2951 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2952 | bool needs_write_barrier = |
| 2953 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2954 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2955 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2956 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2957 | CPURegister source = value; |
| 2958 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2959 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2960 | MemOperand destination = HeapOperand(array); |
| 2961 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2962 | |
| 2963 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2964 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2965 | if (index.IsConstant()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2966 | offset += Int64ConstantFrom(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2967 | destination = HeapOperand(array, offset); |
| 2968 | } else { |
| 2969 | UseScratchRegisterScope temps(masm); |
| 2970 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2971 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2972 | // We do not need to compute the intermediate address from the array: the |
| 2973 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2974 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2975 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2976 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2977 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2978 | } |
| 2979 | temp = array; |
| 2980 | } else { |
| 2981 | __ Add(temp, array, offset); |
| 2982 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2983 | destination = HeapOperand(temp, |
| 2984 | XRegisterFrom(index), |
| 2985 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2986 | DataType::SizeShift(value_type)); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2987 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2988 | { |
| 2989 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2990 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2991 | codegen_->Store(value_type, value, destination); |
| 2992 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2993 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2994 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2995 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2996 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2997 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2998 | { |
| 2999 | // We use a block to end the scratch scope before the write barrier, thus |
| 3000 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 3001 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3002 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3003 | if (index.IsConstant()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3004 | offset += Int64ConstantFrom(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3005 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3006 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 3007 | destination = HeapOperand(temp, |
| 3008 | XRegisterFrom(index), |
| 3009 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3010 | DataType::SizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3011 | } |
| 3012 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3013 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3014 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3015 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3016 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3017 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3018 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3019 | codegen_->AddSlowPath(slow_path); |
| 3020 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3021 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3022 | __ Cbnz(Register(value), &non_zero); |
| 3023 | if (!index.IsConstant()) { |
| 3024 | __ Add(temp, array, offset); |
| 3025 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3026 | { |
| 3027 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 3028 | // emitted. |
| 3029 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3030 | __ Str(wzr, destination); |
| 3031 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3032 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3033 | __ B(&done); |
| 3034 | __ Bind(&non_zero); |
| 3035 | } |
| 3036 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3037 | // Note that when Baker read barriers are enabled, the type |
| 3038 | // checks are performed without read barriers. This is fine, |
| 3039 | // even in the case where a class object is in the from-space |
| 3040 | // after the flip, as a comparison involving such a type would |
| 3041 | // not produce a false positive; it may of course produce a |
| 3042 | // false negative, in which case we would take the ArraySet |
| 3043 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3044 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3045 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 3046 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3047 | { |
| 3048 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3049 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3050 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 3051 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3052 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3053 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3054 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3055 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 3056 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 3057 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3058 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 3059 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 3060 | // nor `temp2`, as we are comparing two poisoned references. |
| 3061 | __ Cmp(temp, temp2); |
| 3062 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3063 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3064 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3065 | vixl::aarch64::Label do_put; |
| 3066 | __ B(eq, &do_put); |
| 3067 | // If heap poisoning is enabled, the `temp` reference has |
| 3068 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3069 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3070 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3071 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 3072 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 3073 | // If heap poisoning is enabled, no need to unpoison |
| 3074 | // `temp`, as we are comparing against null below. |
| 3075 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 3076 | __ Bind(&do_put); |
| 3077 | } else { |
| 3078 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3079 | } |
| 3080 | } |
| 3081 | |
| 3082 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3083 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3084 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3085 | __ Mov(temp2, value.W()); |
| 3086 | GetAssembler()->PoisonHeapReference(temp2); |
| 3087 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3088 | } |
| 3089 | |
| 3090 | if (!index.IsConstant()) { |
| 3091 | __ Add(temp, array, offset); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 3092 | } else { |
| 3093 | // We no longer need the `temp` here so release it as the store below may |
| 3094 | // need a scratch register (if the constant index makes the offset too large) |
| 3095 | // and the poisoned `source` could be using the other scratch register. |
| 3096 | temps.Release(temp); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3097 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3098 | { |
| 3099 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3100 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3101 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3102 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3103 | if (!may_need_runtime_call_for_type_check) { |
| 3104 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3105 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3106 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3107 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3108 | |
| 3109 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 3110 | |
| 3111 | if (done.IsLinked()) { |
| 3112 | __ Bind(&done); |
| 3113 | } |
| 3114 | |
| 3115 | if (slow_path != nullptr) { |
| 3116 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3117 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3118 | } |
| 3119 | } |
| 3120 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3121 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3122 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3123 | InvokeRuntimeCallingConvention calling_convention; |
| 3124 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3125 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 3126 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3127 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 3128 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3132 | BoundsCheckSlowPathARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3133 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3134 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3135 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 3136 | __ B(slow_path->GetEntryLabel(), hs); |
| 3137 | } |
| 3138 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3139 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3140 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3141 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3142 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3143 | if (check->HasUses()) { |
| 3144 | locations->SetOut(Location::SameAsFirstInput()); |
| 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3149 | // We assume the class is not null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3150 | SlowPathCodeARM64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64( |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3151 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 3152 | codegen_->AddSlowPath(slow_path); |
| 3153 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3154 | } |
| 3155 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3156 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3157 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3158 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3159 | } |
| 3160 | |
| 3161 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 3162 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 3163 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3164 | if (rhs_loc.IsConstant()) { |
| 3165 | // 0.0 is the only immediate that can be encoded directly in |
| 3166 | // an FCMP instruction. |
| 3167 | // |
| 3168 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3169 | // specify that in a floating-point comparison, positive zero |
| 3170 | // and negative zero are considered equal, so we can use the |
| 3171 | // literal 0.0 for both cases here. |
| 3172 | // |
| 3173 | // Note however that some methods (Float.equal, Float.compare, |
| 3174 | // Float.compareTo, Double.equal, Double.compare, |
| 3175 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3176 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3177 | // -0.0. So if we ever translate calls to these methods into a |
| 3178 | // HCompare instruction, we must handle the -0.0 case with |
| 3179 | // care here. |
| 3180 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3181 | __ Fcmp(lhs_reg, 0.0); |
| 3182 | } else { |
| 3183 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3184 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3185 | } |
| 3186 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3187 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3188 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3189 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3190 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3191 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3192 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3193 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3194 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3195 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3196 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3197 | case DataType::Type::kInt32: |
| 3198 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3199 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3200 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3201 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3202 | break; |
| 3203 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3204 | case DataType::Type::kFloat32: |
| 3205 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3206 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3207 | locations->SetInAt(1, |
| 3208 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3209 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3210 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3211 | locations->SetOut(Location::RequiresRegister()); |
| 3212 | break; |
| 3213 | } |
| 3214 | default: |
| 3215 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3220 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3221 | |
| 3222 | // 0 if: left == right |
| 3223 | // 1 if: left > right |
| 3224 | // -1 if: left < right |
| 3225 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3226 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3227 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3228 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3229 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3230 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3231 | case DataType::Type::kInt32: |
| 3232 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3233 | Register result = OutputRegister(compare); |
| 3234 | Register left = InputRegisterAt(compare, 0); |
| 3235 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3236 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3237 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3238 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3239 | break; |
| 3240 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3241 | case DataType::Type::kFloat32: |
| 3242 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3243 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3244 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3245 | __ Cset(result, ne); |
| 3246 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3247 | break; |
| 3248 | } |
| 3249 | default: |
| 3250 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3251 | } |
| 3252 | } |
| 3253 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3254 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3255 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3256 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3257 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3258 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3259 | locations->SetInAt(1, |
| 3260 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3261 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3262 | : Location::RequiresFpuRegister()); |
| 3263 | } else { |
| 3264 | // Integer cases. |
| 3265 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3266 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3267 | } |
| 3268 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3269 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3270 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3271 | } |
| 3272 | } |
| 3273 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3274 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3275 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3276 | return; |
| 3277 | } |
| 3278 | |
| 3279 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3280 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3281 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [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 | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3284 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3285 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3286 | } else { |
| 3287 | // Integer cases. |
| 3288 | Register lhs = InputRegisterAt(instruction, 0); |
| 3289 | Operand rhs = InputOperandAt(instruction, 1); |
| 3290 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3291 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3292 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3296 | M(Equal) \ |
| 3297 | M(NotEqual) \ |
| 3298 | M(LessThan) \ |
| 3299 | M(LessThanOrEqual) \ |
| 3300 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3301 | M(GreaterThanOrEqual) \ |
| 3302 | M(Below) \ |
| 3303 | M(BelowOrEqual) \ |
| 3304 | M(Above) \ |
| 3305 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3306 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3307 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3308 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3309 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3310 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3311 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3312 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3313 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3314 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3315 | |
| 3316 | LocationSummary* locations = instruction->GetLocations(); |
| 3317 | Location second = locations->InAt(1); |
| 3318 | DCHECK(second.IsConstant()); |
| 3319 | |
| 3320 | Register out = OutputRegister(instruction); |
| 3321 | Register dividend = InputRegisterAt(instruction, 0); |
| 3322 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3323 | DCHECK(imm == 1 || imm == -1); |
| 3324 | |
| 3325 | if (instruction->IsRem()) { |
| 3326 | __ Mov(out, 0); |
| 3327 | } else { |
| 3328 | if (imm == 1) { |
| 3329 | __ Mov(out, dividend); |
| 3330 | } else { |
| 3331 | __ Neg(out, dividend); |
| 3332 | } |
| 3333 | } |
| 3334 | } |
| 3335 | |
| 3336 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3337 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3338 | |
| 3339 | LocationSummary* locations = instruction->GetLocations(); |
| 3340 | Location second = locations->InAt(1); |
| 3341 | DCHECK(second.IsConstant()); |
| 3342 | |
| 3343 | Register out = OutputRegister(instruction); |
| 3344 | Register dividend = InputRegisterAt(instruction, 0); |
| 3345 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3346 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3347 | int ctz_imm = CTZ(abs_imm); |
| 3348 | |
| 3349 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3350 | Register temp = temps.AcquireSameSizeAs(out); |
| 3351 | |
| 3352 | if (instruction->IsDiv()) { |
| 3353 | __ Add(temp, dividend, abs_imm - 1); |
| 3354 | __ Cmp(dividend, 0); |
| 3355 | __ Csel(out, temp, dividend, lt); |
| 3356 | if (imm > 0) { |
| 3357 | __ Asr(out, out, ctz_imm); |
| 3358 | } else { |
| 3359 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 3360 | } |
| 3361 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3362 | int bits = instruction->GetResultType() == DataType::Type::kInt32 ? 32 : 64; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3363 | __ Asr(temp, dividend, bits - 1); |
| 3364 | __ Lsr(temp, temp, bits - ctz_imm); |
| 3365 | __ Add(out, dividend, temp); |
| 3366 | __ And(out, out, abs_imm - 1); |
| 3367 | __ Sub(out, out, temp); |
| 3368 | } |
| 3369 | } |
| 3370 | |
| 3371 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3372 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3373 | |
| 3374 | LocationSummary* locations = instruction->GetLocations(); |
| 3375 | Location second = locations->InAt(1); |
| 3376 | DCHECK(second.IsConstant()); |
| 3377 | |
| 3378 | Register out = OutputRegister(instruction); |
| 3379 | Register dividend = InputRegisterAt(instruction, 0); |
| 3380 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3381 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3382 | DataType::Type type = instruction->GetResultType(); |
| 3383 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3384 | |
| 3385 | int64_t magic; |
| 3386 | int shift; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3387 | CalculateMagicAndShiftForDivRem( |
| 3388 | imm, type == DataType::Type::kInt64 /* is_long */, &magic, &shift); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3389 | |
| 3390 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3391 | Register temp = temps.AcquireSameSizeAs(out); |
| 3392 | |
| 3393 | // temp = get_high(dividend * magic) |
| 3394 | __ Mov(temp, magic); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3395 | if (type == DataType::Type::kInt64) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3396 | __ Smulh(temp, dividend, temp); |
| 3397 | } else { |
| 3398 | __ Smull(temp.X(), dividend, temp); |
| 3399 | __ Lsr(temp.X(), temp.X(), 32); |
| 3400 | } |
| 3401 | |
| 3402 | if (imm > 0 && magic < 0) { |
| 3403 | __ Add(temp, temp, dividend); |
| 3404 | } else if (imm < 0 && magic > 0) { |
| 3405 | __ Sub(temp, temp, dividend); |
| 3406 | } |
| 3407 | |
| 3408 | if (shift != 0) { |
| 3409 | __ Asr(temp, temp, shift); |
| 3410 | } |
| 3411 | |
| 3412 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3413 | __ Sub(out, temp, Operand(temp, ASR, type == DataType::Type::kInt64 ? 63 : 31)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3414 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3415 | __ Sub(temp, temp, Operand(temp, ASR, type == DataType::Type::kInt64 ? 63 : 31)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3416 | // TODO: Strength reduction for msub. |
| 3417 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3418 | __ Mov(temp_imm, imm); |
| 3419 | __ Msub(out, temp, temp_imm, dividend); |
| 3420 | } |
| 3421 | } |
| 3422 | |
| 3423 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3424 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3425 | DataType::Type type = instruction->GetResultType(); |
| 3426 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3427 | |
| 3428 | LocationSummary* locations = instruction->GetLocations(); |
| 3429 | Register out = OutputRegister(instruction); |
| 3430 | Location second = locations->InAt(1); |
| 3431 | |
| 3432 | if (second.IsConstant()) { |
| 3433 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3434 | |
| 3435 | if (imm == 0) { |
| 3436 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3437 | } else if (imm == 1 || imm == -1) { |
| 3438 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3439 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3440 | DivRemByPowerOfTwo(instruction); |
| 3441 | } else { |
| 3442 | DCHECK(imm <= -2 || imm >= 2); |
| 3443 | GenerateDivRemWithAnyConstant(instruction); |
| 3444 | } |
| 3445 | } else { |
| 3446 | Register dividend = InputRegisterAt(instruction, 0); |
| 3447 | Register divisor = InputRegisterAt(instruction, 1); |
| 3448 | if (instruction->IsDiv()) { |
| 3449 | __ Sdiv(out, dividend, divisor); |
| 3450 | } else { |
| 3451 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3452 | Register temp = temps.AcquireSameSizeAs(out); |
| 3453 | __ Sdiv(temp, dividend, divisor); |
| 3454 | __ Msub(out, temp, divisor, dividend); |
| 3455 | } |
| 3456 | } |
| 3457 | } |
| 3458 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3459 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3460 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3461 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3462 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3463 | case DataType::Type::kInt32: |
| 3464 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3465 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3466 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3467 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3468 | break; |
| 3469 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3470 | case DataType::Type::kFloat32: |
| 3471 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3472 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3473 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3474 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3475 | break; |
| 3476 | |
| 3477 | default: |
| 3478 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3479 | } |
| 3480 | } |
| 3481 | |
| 3482 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3483 | DataType::Type type = div->GetResultType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3484 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3485 | case DataType::Type::kInt32: |
| 3486 | case DataType::Type::kInt64: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3487 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3488 | break; |
| 3489 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3490 | case DataType::Type::kFloat32: |
| 3491 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3492 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3493 | break; |
| 3494 | |
| 3495 | default: |
| 3496 | LOG(FATAL) << "Unexpected div type " << type; |
| 3497 | } |
| 3498 | } |
| 3499 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3500 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3501 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3502 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3506 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3507 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3508 | codegen_->AddSlowPath(slow_path); |
| 3509 | Location value = instruction->GetLocations()->InAt(0); |
| 3510 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3511 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3512 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3513 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3514 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3515 | return; |
| 3516 | } |
| 3517 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3518 | if (value.IsConstant()) { |
| 3519 | int64_t divisor = Int64ConstantFrom(value); |
| 3520 | if (divisor == 0) { |
| 3521 | __ B(slow_path->GetEntryLabel()); |
| 3522 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3523 | // A division by a non-null constant is valid. We don't need to perform |
| 3524 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3525 | } |
| 3526 | } else { |
| 3527 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3528 | } |
| 3529 | } |
| 3530 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3531 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3532 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3533 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3534 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3535 | } |
| 3536 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3537 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3538 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3539 | // Will be generated at use site. |
| 3540 | } |
| 3541 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3542 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3543 | exit->SetLocations(nullptr); |
| 3544 | } |
| 3545 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3546 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3547 | } |
| 3548 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3549 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3550 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3551 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3552 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3553 | } |
| 3554 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3555 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3556 | // Will be generated at use site. |
| 3557 | } |
| 3558 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3559 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3560 | DCHECK(!successor->IsExitBlock()); |
| 3561 | HBasicBlock* block = got->GetBlock(); |
| 3562 | HInstruction* previous = got->GetPrevious(); |
| 3563 | HLoopInformation* info = block->GetLoopInformation(); |
| 3564 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3565 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3566 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3567 | return; |
| 3568 | } |
| 3569 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3570 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 3571 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3572 | } |
| 3573 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3574 | __ B(codegen_->GetLabelOf(successor)); |
| 3575 | } |
| 3576 | } |
| 3577 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3578 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3579 | got->SetLocations(nullptr); |
| 3580 | } |
| 3581 | |
| 3582 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3583 | HandleGoto(got, got->GetSuccessor()); |
| 3584 | } |
| 3585 | |
| 3586 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3587 | try_boundary->SetLocations(nullptr); |
| 3588 | } |
| 3589 | |
| 3590 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3591 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3592 | if (!successor->IsExitBlock()) { |
| 3593 | HandleGoto(try_boundary, successor); |
| 3594 | } |
| 3595 | } |
| 3596 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3597 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3598 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3599 | vixl::aarch64::Label* true_target, |
| 3600 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3601 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3602 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3603 | if (true_target == nullptr && false_target == nullptr) { |
| 3604 | // Nothing to do. The code always falls through. |
| 3605 | return; |
| 3606 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3607 | // Constant condition, statically compared against "true" (integer value 1). |
| 3608 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3609 | if (true_target != nullptr) { |
| 3610 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3611 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3612 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3613 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3614 | if (false_target != nullptr) { |
| 3615 | __ B(false_target); |
| 3616 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3617 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3618 | return; |
| 3619 | } |
| 3620 | |
| 3621 | // The following code generates these patterns: |
| 3622 | // (1) true_target == nullptr && false_target != nullptr |
| 3623 | // - opposite condition true => branch to false_target |
| 3624 | // (2) true_target != nullptr && false_target == nullptr |
| 3625 | // - condition true => branch to true_target |
| 3626 | // (3) true_target != nullptr && false_target != nullptr |
| 3627 | // - condition true => branch to true_target |
| 3628 | // - branch to false_target |
| 3629 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3630 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3631 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3632 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3633 | if (true_target == nullptr) { |
| 3634 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3635 | } else { |
| 3636 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3637 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3638 | } else { |
| 3639 | // The condition instruction has not been materialized, use its inputs as |
| 3640 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3641 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3642 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3643 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3644 | if (DataType::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3645 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3646 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3647 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3648 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3649 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3650 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3651 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3652 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3653 | // Integer cases. |
| 3654 | Register lhs = InputRegisterAt(condition, 0); |
| 3655 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3656 | |
| 3657 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3658 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3659 | if (true_target == nullptr) { |
| 3660 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3661 | non_fallthrough_target = false_target; |
| 3662 | } else { |
| 3663 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3664 | non_fallthrough_target = true_target; |
| 3665 | } |
| 3666 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3667 | 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] | 3668 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3669 | switch (arm64_cond) { |
| 3670 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3671 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3672 | break; |
| 3673 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3674 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3675 | break; |
| 3676 | case lt: |
| 3677 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3678 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3679 | break; |
| 3680 | case ge: |
| 3681 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3682 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3683 | break; |
| 3684 | default: |
| 3685 | // Without the `static_cast` the compiler throws an error for |
| 3686 | // `-Werror=sign-promo`. |
| 3687 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3688 | } |
| 3689 | } else { |
| 3690 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3691 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3692 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3693 | } |
| 3694 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3695 | |
| 3696 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3697 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3698 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3699 | __ B(false_target); |
| 3700 | } |
| 3701 | } |
| 3702 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3703 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3704 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3705 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3706 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3707 | } |
| 3708 | } |
| 3709 | |
| 3710 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3711 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3712 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3713 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3714 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3715 | true_target = nullptr; |
| 3716 | } |
| 3717 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3718 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3719 | false_target = nullptr; |
| 3720 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3721 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3725 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3726 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3727 | InvokeRuntimeCallingConvention calling_convention; |
| 3728 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3729 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3730 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3731 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3732 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3733 | } |
| 3734 | } |
| 3735 | |
| 3736 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3737 | SlowPathCodeARM64* slow_path = |
| 3738 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3739 | GenerateTestAndBranch(deoptimize, |
| 3740 | /* condition_input_index */ 0, |
| 3741 | slow_path->GetEntryLabel(), |
| 3742 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3745 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3746 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3747 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3748 | locations->SetOut(Location::RequiresRegister()); |
| 3749 | } |
| 3750 | |
| 3751 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3752 | __ Ldr(OutputRegister(flag), |
| 3753 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3754 | } |
| 3755 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3756 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3757 | return condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3758 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3759 | } |
| 3760 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3761 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3762 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3763 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3764 | : ARM64Condition(cond); |
| 3765 | } |
| 3766 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3767 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3768 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3769 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3770 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3771 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3772 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3773 | } else { |
| 3774 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3775 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3776 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3777 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3778 | // Ask VIXL whether we should synthesize constants in registers. |
| 3779 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3780 | Operand true_op = is_true_value_constant ? |
| 3781 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3782 | Operand false_op = is_false_value_constant ? |
| 3783 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3784 | bool true_value_in_register = false; |
| 3785 | bool false_value_in_register = false; |
| 3786 | MacroAssembler::GetCselSynthesisInformation( |
| 3787 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3788 | true_value_in_register |= !is_true_value_constant; |
| 3789 | false_value_in_register |= !is_false_value_constant; |
| 3790 | |
| 3791 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3792 | : Location::ConstantLocation(cst_true_value)); |
| 3793 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3794 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3795 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3796 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3797 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3798 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3799 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3800 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3804 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3805 | Condition csel_cond; |
| 3806 | |
| 3807 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3808 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3809 | // Use the condition flags set by the previous instruction. |
| 3810 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3811 | } else { |
| 3812 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3813 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3814 | } |
| 3815 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3816 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3817 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3818 | } else { |
| 3819 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3820 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3821 | } |
| 3822 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3823 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3824 | __ Fcsel(OutputFPRegister(select), |
| 3825 | InputFPRegisterAt(select, 1), |
| 3826 | InputFPRegisterAt(select, 0), |
| 3827 | csel_cond); |
| 3828 | } else { |
| 3829 | __ Csel(OutputRegister(select), |
| 3830 | InputOperandAt(select, 1), |
| 3831 | InputOperandAt(select, 0), |
| 3832 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3833 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3834 | } |
| 3835 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3836 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3837 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3838 | } |
| 3839 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3840 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3841 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3842 | } |
| 3843 | |
| 3844 | void CodeGeneratorARM64::GenerateNop() { |
| 3845 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3846 | } |
| 3847 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3848 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3849 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3850 | } |
| 3851 | |
| 3852 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3853 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3854 | } |
| 3855 | |
| 3856 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3857 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3861 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3862 | } |
| 3863 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3864 | // Temp is used for read barrier. |
| 3865 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3866 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3867 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3868 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3869 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3870 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3871 | return 1; |
| 3872 | } |
| 3873 | return 0; |
| 3874 | } |
| 3875 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3876 | // 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] | 3877 | // interface pointer, one for loading the current interface. |
| 3878 | // The other checks have one temp for loading the object's class. |
| 3879 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3880 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3881 | return 3; |
| 3882 | } |
| 3883 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3884 | } |
| 3885 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3886 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3887 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3888 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3889 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3890 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3891 | case TypeCheckKind::kExactCheck: |
| 3892 | case TypeCheckKind::kAbstractClassCheck: |
| 3893 | case TypeCheckKind::kClassHierarchyCheck: |
| 3894 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3895 | call_kind = |
| 3896 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3897 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3898 | break; |
| 3899 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3900 | case TypeCheckKind::kUnresolvedCheck: |
| 3901 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3902 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3903 | break; |
| 3904 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3905 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3906 | LocationSummary* locations = |
| 3907 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3908 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3909 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3910 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3911 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3912 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3913 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3914 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3915 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3916 | // Add temps if necessary for read barriers. |
| 3917 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3918 | } |
| 3919 | |
| 3920 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3921 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3922 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3923 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3924 | Register obj = InputRegisterAt(instruction, 0); |
| 3925 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3926 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3927 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3928 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3929 | DCHECK_LE(num_temps, 1u); |
| 3930 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3931 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3932 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3933 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3934 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3935 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3936 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3937 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3938 | |
| 3939 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3940 | // Avoid null check if we know `obj` is not null. |
| 3941 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3942 | __ Cbz(obj, &zero); |
| 3943 | } |
| 3944 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3945 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3946 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3947 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3948 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3949 | out_loc, |
| 3950 | obj_loc, |
| 3951 | class_offset, |
| 3952 | maybe_temp_loc, |
| 3953 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3954 | __ Cmp(out, cls); |
| 3955 | __ Cset(out, eq); |
| 3956 | if (zero.IsLinked()) { |
| 3957 | __ B(&done); |
| 3958 | } |
| 3959 | break; |
| 3960 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3961 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3962 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3963 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3964 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3965 | out_loc, |
| 3966 | obj_loc, |
| 3967 | class_offset, |
| 3968 | maybe_temp_loc, |
| 3969 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3970 | // If the class is abstract, we eagerly fetch the super class of the |
| 3971 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3972 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3973 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3974 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3975 | GenerateReferenceLoadOneRegister(instruction, |
| 3976 | out_loc, |
| 3977 | super_offset, |
| 3978 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3979 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3980 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3981 | __ Cbz(out, &done); |
| 3982 | __ Cmp(out, cls); |
| 3983 | __ B(ne, &loop); |
| 3984 | __ Mov(out, 1); |
| 3985 | if (zero.IsLinked()) { |
| 3986 | __ B(&done); |
| 3987 | } |
| 3988 | break; |
| 3989 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3990 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3991 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3992 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3993 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3994 | out_loc, |
| 3995 | obj_loc, |
| 3996 | class_offset, |
| 3997 | maybe_temp_loc, |
| 3998 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3999 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4000 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4001 | __ Bind(&loop); |
| 4002 | __ Cmp(out, cls); |
| 4003 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4004 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4005 | GenerateReferenceLoadOneRegister(instruction, |
| 4006 | out_loc, |
| 4007 | super_offset, |
| 4008 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4009 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4010 | __ Cbnz(out, &loop); |
| 4011 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4012 | __ B(&done); |
| 4013 | __ Bind(&success); |
| 4014 | __ Mov(out, 1); |
| 4015 | if (zero.IsLinked()) { |
| 4016 | __ B(&done); |
| 4017 | } |
| 4018 | break; |
| 4019 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4020 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4021 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4022 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4023 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4024 | out_loc, |
| 4025 | obj_loc, |
| 4026 | class_offset, |
| 4027 | maybe_temp_loc, |
| 4028 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4029 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4030 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4031 | __ Cmp(out, cls); |
| 4032 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4033 | // 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] | 4034 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4035 | GenerateReferenceLoadOneRegister(instruction, |
| 4036 | out_loc, |
| 4037 | component_offset, |
| 4038 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4039 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4040 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4041 | __ Cbz(out, &done); |
| 4042 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4043 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4044 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4045 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4046 | __ Mov(out, 1); |
| 4047 | __ B(&done); |
| 4048 | break; |
| 4049 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4050 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4051 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4052 | // No read barrier since the slow path will retry upon failure. |
| 4053 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4054 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4055 | out_loc, |
| 4056 | obj_loc, |
| 4057 | class_offset, |
| 4058 | maybe_temp_loc, |
| 4059 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4060 | __ Cmp(out, cls); |
| 4061 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4062 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4063 | instruction, /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4064 | codegen_->AddSlowPath(slow_path); |
| 4065 | __ B(ne, slow_path->GetEntryLabel()); |
| 4066 | __ Mov(out, 1); |
| 4067 | if (zero.IsLinked()) { |
| 4068 | __ B(&done); |
| 4069 | } |
| 4070 | break; |
| 4071 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4072 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4073 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4074 | case TypeCheckKind::kInterfaceCheck: { |
| 4075 | // Note that we indeed only call on slow path, but we always go |
| 4076 | // into the slow path for the unresolved and interface check |
| 4077 | // cases. |
| 4078 | // |
| 4079 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4080 | // entry point without resorting to a type checking slow path |
| 4081 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4082 | // require to assign fixed registers for the inputs of this |
| 4083 | // HInstanceOf instruction (following the runtime calling |
| 4084 | // convention), which might be cluttered by the potential first |
| 4085 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4086 | // |
| 4087 | // TODO: Introduce a new runtime entry point taking the object |
| 4088 | // to test (instead of its class) as argument, and let it deal |
| 4089 | // with the read barrier issues. This will let us refactor this |
| 4090 | // case of the `switch` code as it was previously (with a direct |
| 4091 | // call to the runtime not using a type checking slow path). |
| 4092 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4093 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4094 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4095 | instruction, /* is_fatal */ false); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4096 | codegen_->AddSlowPath(slow_path); |
| 4097 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4098 | if (zero.IsLinked()) { |
| 4099 | __ B(&done); |
| 4100 | } |
| 4101 | break; |
| 4102 | } |
| 4103 | } |
| 4104 | |
| 4105 | if (zero.IsLinked()) { |
| 4106 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4107 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4108 | } |
| 4109 | |
| 4110 | if (done.IsLinked()) { |
| 4111 | __ Bind(&done); |
| 4112 | } |
| 4113 | |
| 4114 | if (slow_path != nullptr) { |
| 4115 | __ Bind(slow_path->GetExitLabel()); |
| 4116 | } |
| 4117 | } |
| 4118 | |
| 4119 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 4120 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4121 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 4122 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4123 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 4124 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4125 | case TypeCheckKind::kExactCheck: |
| 4126 | case TypeCheckKind::kAbstractClassCheck: |
| 4127 | case TypeCheckKind::kClassHierarchyCheck: |
| 4128 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4129 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 4130 | LocationSummary::kCallOnSlowPath : |
| 4131 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4132 | break; |
| 4133 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4134 | case TypeCheckKind::kUnresolvedCheck: |
| 4135 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4136 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4137 | break; |
| 4138 | } |
| 4139 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4140 | LocationSummary* locations = |
| 4141 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4142 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4143 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4144 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4145 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4146 | } |
| 4147 | |
| 4148 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4149 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4150 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4151 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4152 | Register obj = InputRegisterAt(instruction, 0); |
| 4153 | Register cls = InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4154 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4155 | DCHECK_GE(num_temps, 1u); |
| 4156 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4157 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4158 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4159 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4160 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4161 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4162 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4163 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4164 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4165 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4166 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4167 | const uint32_t object_array_data_offset = |
| 4168 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4169 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4170 | bool is_type_check_slow_path_fatal = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4171 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 4172 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 4173 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4174 | if (!kEmitCompilerReadBarrier) { |
| 4175 | is_type_check_slow_path_fatal = |
| 4176 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 4177 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 4178 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 4179 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 4180 | !instruction->CanThrowIntoCatchBlock(); |
| 4181 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4182 | SlowPathCodeARM64* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4183 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4184 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4185 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4186 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4187 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4188 | // Avoid null check if we know obj is not null. |
| 4189 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4190 | __ Cbz(obj, &done); |
| 4191 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4192 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4193 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4194 | case TypeCheckKind::kExactCheck: |
| 4195 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4196 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4197 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4198 | temp_loc, |
| 4199 | obj_loc, |
| 4200 | class_offset, |
| 4201 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4202 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4203 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4204 | __ Cmp(temp, cls); |
| 4205 | // Jump to slow path for throwing the exception or doing a |
| 4206 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4207 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4208 | break; |
| 4209 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4210 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4211 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4212 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4213 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4214 | temp_loc, |
| 4215 | obj_loc, |
| 4216 | class_offset, |
| 4217 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4218 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4219 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4220 | // If the class is abstract, we eagerly fetch the super class of the |
| 4221 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4222 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4223 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4224 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4225 | GenerateReferenceLoadOneRegister(instruction, |
| 4226 | temp_loc, |
| 4227 | super_offset, |
| 4228 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4229 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4230 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4231 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4232 | // exception. |
| 4233 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4234 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4235 | __ Cmp(temp, cls); |
| 4236 | __ B(ne, &loop); |
| 4237 | break; |
| 4238 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4239 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4240 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4241 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4242 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4243 | temp_loc, |
| 4244 | obj_loc, |
| 4245 | class_offset, |
| 4246 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4247 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4248 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4249 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4250 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4251 | __ Bind(&loop); |
| 4252 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4253 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4254 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4255 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4256 | GenerateReferenceLoadOneRegister(instruction, |
| 4257 | temp_loc, |
| 4258 | super_offset, |
| 4259 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4260 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4261 | |
| 4262 | // If the class reference currently in `temp` is not null, jump |
| 4263 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4264 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4265 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4266 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4267 | break; |
| 4268 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4269 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4270 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4271 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4272 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4273 | temp_loc, |
| 4274 | obj_loc, |
| 4275 | class_offset, |
| 4276 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4277 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4278 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4279 | // Do an exact check. |
| 4280 | __ Cmp(temp, cls); |
| 4281 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4282 | |
| 4283 | // 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] | 4284 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4285 | GenerateReferenceLoadOneRegister(instruction, |
| 4286 | temp_loc, |
| 4287 | component_offset, |
| 4288 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4289 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4290 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4291 | // If the component type is null, jump to the slow path to throw the exception. |
| 4292 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4293 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4294 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4295 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4296 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4297 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4298 | break; |
| 4299 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4300 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4301 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4302 | // 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] | 4303 | // |
| 4304 | // We cannot directly call the CheckCast runtime entry point |
| 4305 | // without resorting to a type checking slow path here (i.e. by |
| 4306 | // calling InvokeRuntime directly), as it would require to |
| 4307 | // assign fixed registers for the inputs of this HInstanceOf |
| 4308 | // instruction (following the runtime calling convention), which |
| 4309 | // might be cluttered by the potential first read barrier |
| 4310 | // emission at the beginning of this method. |
| 4311 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4312 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4313 | case TypeCheckKind::kInterfaceCheck: { |
| 4314 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4315 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4316 | temp_loc, |
| 4317 | obj_loc, |
| 4318 | class_offset, |
| 4319 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4320 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4321 | |
| 4322 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4323 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4324 | temp_loc, |
| 4325 | temp_loc, |
| 4326 | iftable_offset, |
| 4327 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4328 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4329 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4330 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4331 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4332 | vixl::aarch64::Label start_loop; |
| 4333 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4334 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4335 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4336 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4337 | // Go to next interface. |
| 4338 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4339 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4340 | // Compare the classes and continue the loop if they do not match. |
| 4341 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4342 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4343 | break; |
| 4344 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4345 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4346 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4347 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4348 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4349 | } |
| 4350 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4351 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4352 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4353 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4354 | } |
| 4355 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4356 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4357 | // Will be generated at use site. |
| 4358 | } |
| 4359 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4360 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4361 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4362 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4363 | } |
| 4364 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4365 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4366 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4367 | } |
| 4368 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4369 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4370 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4371 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4372 | // the method_idx. |
| 4373 | HandleInvoke(invoke); |
| 4374 | } |
| 4375 | |
| 4376 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4377 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4378 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4379 | } |
| 4380 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4381 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4382 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4383 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4384 | } |
| 4385 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4386 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4387 | HandleInvoke(invoke); |
| 4388 | } |
| 4389 | |
| 4390 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4391 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4392 | LocationSummary* locations = invoke->GetLocations(); |
| 4393 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4394 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4395 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4396 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4397 | |
| 4398 | // The register ip1 is required to be used for the hidden argument in |
| 4399 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4400 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4401 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4402 | scratch_scope.Exclude(ip1); |
| 4403 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4404 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4405 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4406 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4407 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4408 | { |
| 4409 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4410 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4411 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4412 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4413 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4414 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4415 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4416 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4417 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4418 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4419 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4420 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4421 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4422 | // emit a read barrier for the previous class reference load. |
| 4423 | // However this is not required in practice, as this is an |
| 4424 | // intermediate/temporary reference and because the current |
| 4425 | // concurrent copying collector keeps the from-space memory |
| 4426 | // intact/accessible until the end of the marking phase (the |
| 4427 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4428 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4429 | __ Ldr(temp, |
| 4430 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4431 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4432 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4433 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4434 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4435 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4436 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4437 | |
| 4438 | { |
| 4439 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4440 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4441 | |
| 4442 | // lr(); |
| 4443 | __ blr(lr); |
| 4444 | DCHECK(!codegen_->IsLeafMethod()); |
| 4445 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4446 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4447 | |
| 4448 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4452 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4453 | if (intrinsic.TryDispatch(invoke)) { |
| 4454 | return; |
| 4455 | } |
| 4456 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4457 | HandleInvoke(invoke); |
| 4458 | } |
| 4459 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4460 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4461 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4462 | // art::PrepareForRegisterAllocation. |
| 4463 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4464 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4465 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4466 | if (intrinsic.TryDispatch(invoke)) { |
| 4467 | return; |
| 4468 | } |
| 4469 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4470 | HandleInvoke(invoke); |
| 4471 | } |
| 4472 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4473 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4474 | if (invoke->GetLocations()->Intrinsified()) { |
| 4475 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4476 | intrinsic.Dispatch(invoke); |
| 4477 | return true; |
| 4478 | } |
| 4479 | return false; |
| 4480 | } |
| 4481 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4482 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4483 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4484 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4485 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4486 | return desired_dispatch_info; |
| 4487 | } |
| 4488 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4489 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4490 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4491 | // 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] | 4492 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4493 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4494 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4495 | uint32_t offset = |
| 4496 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4497 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4498 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4499 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4500 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4501 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4502 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4503 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4504 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4505 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4506 | // Add ADRP with its PC-relative method patch. |
| 4507 | vixl::aarch64::Label* adrp_label = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 4508 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4509 | // Add ADD with its PC-relative method patch. |
| 4510 | vixl::aarch64::Label* add_label = |
| 4511 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), adrp_label); |
| 4512 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4513 | break; |
| 4514 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4515 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4516 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4517 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4518 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4519 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4520 | // Add ADRP with its PC-relative DexCache access patch. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4521 | MethodReference target_method(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4522 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(target_method); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4523 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4524 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4525 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4526 | NewMethodBssEntryPatch(target_method, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4527 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4528 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4529 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4530 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4531 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4532 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4533 | } |
| 4534 | } |
| 4535 | |
| 4536 | switch (invoke->GetCodePtrLocation()) { |
| 4537 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4538 | { |
| 4539 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4540 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4541 | kInstructionSize, |
| 4542 | CodeBufferCheckScope::kExactSize); |
| 4543 | __ bl(&frame_entry_label_); |
| 4544 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4545 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4546 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4547 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4548 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4549 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4550 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4551 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4552 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4553 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4554 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4555 | kInstructionSize, |
| 4556 | CodeBufferCheckScope::kExactSize); |
| 4557 | // lr() |
| 4558 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4559 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4560 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4561 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4562 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4563 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4564 | DCHECK(!IsLeafMethod()); |
| 4565 | } |
| 4566 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4567 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4568 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4569 | // Use the calling convention instead of the location of the receiver, as |
| 4570 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4571 | // slow path, the arguments have been moved to the right place, so here we are |
| 4572 | // guaranteed that the receiver is the first register of the calling convention. |
| 4573 | InvokeDexCallingConvention calling_convention; |
| 4574 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4575 | Register temp = XRegisterFrom(temp_in); |
| 4576 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4577 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4578 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4579 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4580 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4581 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4582 | |
| 4583 | { |
| 4584 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4585 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4586 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4587 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4588 | MaybeRecordImplicitNullCheck(invoke); |
| 4589 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4590 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4591 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4592 | // intermediate/temporary reference and because the current |
| 4593 | // concurrent copying collector keeps the from-space memory |
| 4594 | // intact/accessible until the end of the marking phase (the |
| 4595 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4596 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4597 | // temp = temp->GetMethodAt(method_offset); |
| 4598 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4599 | // lr = temp->GetEntryPoint(); |
| 4600 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4601 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4602 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4603 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4604 | // lr(); |
| 4605 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4606 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4607 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4608 | } |
| 4609 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4610 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4611 | HandleInvoke(invoke); |
| 4612 | } |
| 4613 | |
| 4614 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4615 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4616 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4617 | } |
| 4618 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4619 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeMethodPatch( |
| 4620 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4621 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4622 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4623 | target_method.index, |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4624 | adrp_label, |
| 4625 | &pc_relative_method_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4626 | } |
| 4627 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4628 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4629 | MethodReference target_method, |
| 4630 | vixl::aarch64::Label* adrp_label) { |
| 4631 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4632 | target_method.index, |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4633 | adrp_label, |
| 4634 | &method_bss_entry_patches_); |
| 4635 | } |
| 4636 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4637 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 4638 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4639 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4640 | vixl::aarch64::Label* adrp_label) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4641 | return NewPcRelativePatch(dex_file, type_index.index_, adrp_label, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4642 | } |
| 4643 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4644 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4645 | const DexFile& dex_file, |
| 4646 | dex::TypeIndex type_index, |
| 4647 | vixl::aarch64::Label* adrp_label) { |
| 4648 | return NewPcRelativePatch(dex_file, type_index.index_, adrp_label, &type_bss_entry_patches_); |
| 4649 | } |
| 4650 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4651 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 4652 | const DexFile& dex_file, |
| 4653 | dex::StringIndex string_index, |
| 4654 | vixl::aarch64::Label* adrp_label) { |
| 4655 | return |
| 4656 | NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &pc_relative_string_patches_); |
| 4657 | } |
| 4658 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4659 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4660 | const DexFile& dex_file, |
| 4661 | dex::StringIndex string_index, |
| 4662 | vixl::aarch64::Label* adrp_label) { |
| 4663 | return NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &string_bss_entry_patches_); |
| 4664 | } |
| 4665 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4666 | vixl::aarch64::Label* CodeGeneratorARM64::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 4667 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4668 | return &baker_read_barrier_patches_.back().label; |
| 4669 | } |
| 4670 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4671 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 4672 | const DexFile& dex_file, |
| 4673 | uint32_t offset_or_index, |
| 4674 | vixl::aarch64::Label* adrp_label, |
| 4675 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4676 | // Add a patch entry and return the label. |
| 4677 | patches->emplace_back(dex_file, offset_or_index); |
| 4678 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4679 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4680 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4681 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4682 | return label; |
| 4683 | } |
| 4684 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4685 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4686 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4687 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4688 | } |
| 4689 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4690 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4691 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4692 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4693 | return jit_string_patches_.GetOrCreate( |
| 4694 | StringReference(&dex_file, string_index), |
| 4695 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4696 | } |
| 4697 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4698 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4699 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4700 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4701 | return jit_class_patches_.GetOrCreate( |
| 4702 | TypeReference(&dex_file, type_index), |
| 4703 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4704 | } |
| 4705 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4706 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4707 | vixl::aarch64::Register reg) { |
| 4708 | DCHECK(reg.IsX()); |
| 4709 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4710 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4711 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4712 | } |
| 4713 | |
| 4714 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4715 | vixl::aarch64::Register out, |
| 4716 | vixl::aarch64::Register base) { |
| 4717 | DCHECK(out.IsX()); |
| 4718 | DCHECK(base.IsX()); |
| 4719 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4720 | __ Bind(fixup_label); |
| 4721 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4722 | } |
| 4723 | |
| 4724 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4725 | vixl::aarch64::Register out, |
| 4726 | vixl::aarch64::Register base) { |
| 4727 | DCHECK(base.IsX()); |
| 4728 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4729 | __ Bind(fixup_label); |
| 4730 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4731 | } |
| 4732 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4733 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4734 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4735 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4736 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4737 | for (const PcRelativePatchInfo& info : infos) { |
| 4738 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 4739 | &info.target_dex_file, |
| 4740 | info.pc_insn_label->GetLocation(), |
| 4741 | info.offset_or_index)); |
| 4742 | } |
| 4743 | } |
| 4744 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4745 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4746 | DCHECK(linker_patches->empty()); |
| 4747 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4748 | pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4749 | method_bss_entry_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4750 | pc_relative_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4751 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4752 | pc_relative_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4753 | string_bss_entry_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4754 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4755 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4756 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4757 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 4758 | pc_relative_method_patches_, linker_patches); |
| 4759 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 4760 | pc_relative_type_patches_, linker_patches); |
| 4761 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 4762 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4763 | } else { |
| 4764 | DCHECK(pc_relative_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4765 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 4766 | pc_relative_type_patches_, linker_patches); |
| 4767 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 4768 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4769 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4770 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4771 | method_bss_entry_patches_, linker_patches); |
| 4772 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4773 | type_bss_entry_patches_, linker_patches); |
| 4774 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4775 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4776 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4777 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 4778 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4779 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4780 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4781 | } |
| 4782 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4783 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4784 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4785 | value, |
| 4786 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4787 | } |
| 4788 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4789 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4790 | return uint64_literals_.GetOrCreate( |
| 4791 | value, |
| 4792 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4793 | } |
| 4794 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4795 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4796 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4797 | // art::PrepareForRegisterAllocation. |
| 4798 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4799 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4800 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4801 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4802 | return; |
| 4803 | } |
| 4804 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4805 | { |
| 4806 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4807 | // are no pools emitted. |
| 4808 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4809 | LocationSummary* locations = invoke->GetLocations(); |
| 4810 | codegen_->GenerateStaticOrDirectCall( |
| 4811 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| 4812 | } |
| 4813 | |
| 4814 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4815 | } |
| 4816 | |
| 4817 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4818 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4819 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4820 | return; |
| 4821 | } |
| 4822 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4823 | { |
| 4824 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4825 | // are no pools emitted. |
| 4826 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4827 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 4828 | DCHECK(!codegen_->IsLeafMethod()); |
| 4829 | } |
| 4830 | |
| 4831 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4832 | } |
| 4833 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4834 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4835 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4836 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4837 | case HLoadClass::LoadKind::kInvalid: |
| 4838 | LOG(FATAL) << "UNREACHABLE"; |
| 4839 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4840 | case HLoadClass::LoadKind::kReferrersClass: |
| 4841 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4842 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4843 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4844 | case HLoadClass::LoadKind::kBssEntry: |
| 4845 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4846 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4847 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4848 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4849 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4850 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4851 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4852 | break; |
| 4853 | } |
| 4854 | return desired_class_load_kind; |
| 4855 | } |
| 4856 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4857 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4858 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4859 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4860 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4861 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4862 | cls, |
| 4863 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4864 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4865 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4866 | return; |
| 4867 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4868 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4869 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4870 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4871 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4872 | ? LocationSummary::kCallOnSlowPath |
| 4873 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4874 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4875 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4876 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4877 | } |
| 4878 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4879 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4880 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4881 | } |
| 4882 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4883 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 4884 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4885 | // Rely on the type resolution or initialization and marking to save everything we need. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4886 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4887 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4888 | InvokeRuntimeCallingConvention calling_convention; |
| 4889 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4890 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4891 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 4892 | DataType::Type::kReference).GetCode()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4893 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4894 | } else { |
| 4895 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4896 | } |
| 4897 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4898 | } |
| 4899 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4900 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4901 | // move. |
| 4902 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4903 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4904 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4905 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4906 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4907 | return; |
| 4908 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4909 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4910 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4911 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4912 | Register out = OutputRegister(cls); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4913 | Register bss_entry_temp; |
| 4914 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4915 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4916 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4917 | ? kWithoutReadBarrier |
| 4918 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4919 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4920 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4921 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4922 | DCHECK(!cls->CanCallRuntime()); |
| 4923 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4924 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4925 | Register current_method = InputRegisterAt(cls, 0); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4926 | GenerateGcRootFieldLoad(cls, |
| 4927 | out_loc, |
| 4928 | current_method, |
| 4929 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4930 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4931 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4932 | break; |
| 4933 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4934 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4935 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4936 | // Add ADRP with its PC-relative type patch. |
| 4937 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4938 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4939 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4940 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4941 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4942 | vixl::aarch64::Label* add_label = |
| 4943 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4944 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4945 | break; |
| 4946 | } |
| 4947 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4948 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4949 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 4950 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 4951 | DCHECK_NE(address, 0u); |
| 4952 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4953 | break; |
| 4954 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4955 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 4956 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 4957 | // Add ADRP with its PC-relative type patch. |
| 4958 | const DexFile& dex_file = cls->GetDexFile(); |
| 4959 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
| 4960 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
| 4961 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| 4962 | // Add LDR with its PC-relative type patch. |
| 4963 | vixl::aarch64::Label* ldr_label = |
| 4964 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
| 4965 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 4966 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 4967 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 4968 | ComputeModifiedUtf8Hash(dex_file.StringByTypeIdx(type_index))); |
| 4969 | if (masked_hash != 0) { |
| 4970 | __ Sub(out.W(), out.W(), Operand(masked_hash)); |
| 4971 | } |
| 4972 | break; |
| 4973 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4974 | case HLoadClass::LoadKind::kBssEntry: { |
| 4975 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 4976 | const DexFile& dex_file = cls->GetDexFile(); |
| 4977 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4978 | bss_entry_temp = XRegisterFrom(cls->GetLocations()->GetTemp(0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4979 | bss_entry_adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 4980 | codegen_->EmitAdrpPlaceholder(bss_entry_adrp_label, bss_entry_temp); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4981 | // Add LDR with its PC-relative Class patch. |
| 4982 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4983 | codegen_->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4984 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 4985 | GenerateGcRootFieldLoad(cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4986 | out_loc, |
| 4987 | bss_entry_temp, |
| 4988 | /* offset placeholder */ 0u, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4989 | ldr_label, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4990 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4991 | generate_null_check = true; |
| 4992 | break; |
| 4993 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4994 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 4995 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 4996 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4997 | cls->GetClass())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4998 | GenerateGcRootFieldLoad(cls, |
| 4999 | out_loc, |
| 5000 | out.X(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5001 | /* offset */ 0, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5002 | /* fixup_label */ nullptr, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5003 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5004 | break; |
| 5005 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5006 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5007 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5008 | LOG(FATAL) << "UNREACHABLE"; |
| 5009 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5010 | } |
| 5011 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5012 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5013 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5014 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5015 | SlowPathCodeARM64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64( |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5016 | cls, cls, cls->GetDexPc(), do_clinit, bss_entry_temp, bss_entry_adrp_label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5017 | codegen_->AddSlowPath(slow_path); |
| 5018 | if (generate_null_check) { |
| 5019 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5020 | } |
| 5021 | if (cls->MustGenerateClinitCheck()) { |
| 5022 | GenerateClassInitializationCheck(slow_path, out); |
| 5023 | } else { |
| 5024 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5025 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5026 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5027 | } |
| 5028 | } |
| 5029 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5030 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5031 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5032 | } |
| 5033 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5034 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5035 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5036 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5037 | locations->SetOut(Location::RequiresRegister()); |
| 5038 | } |
| 5039 | |
| 5040 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5041 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5042 | } |
| 5043 | |
| 5044 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5045 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5046 | } |
| 5047 | |
| 5048 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5049 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5050 | } |
| 5051 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5052 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5053 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5054 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5055 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5056 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5057 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5058 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5059 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5060 | case HLoadString::LoadKind::kJitTableAddress: |
| 5061 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5062 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5063 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5064 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5065 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5066 | } |
| 5067 | return desired_string_load_kind; |
| 5068 | } |
| 5069 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5070 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5071 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5072 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5073 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5074 | InvokeRuntimeCallingConvention calling_convention; |
| 5075 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5076 | } else { |
| 5077 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5078 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5079 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5080 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5081 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5082 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5083 | InvokeRuntimeCallingConvention calling_convention; |
| 5084 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 5085 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5086 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 5087 | DataType::Type::kReference).GetCode()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5088 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5089 | } else { |
| 5090 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5091 | } |
| 5092 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5093 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5094 | } |
| 5095 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5096 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5097 | // move. |
| 5098 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5099 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5100 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5101 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5102 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5103 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5104 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5105 | // Add ADRP with its PC-relative String patch. |
| 5106 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5107 | const dex::StringIndex string_index = load->GetStringIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5108 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5109 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5110 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5111 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5112 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5113 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5114 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5115 | } |
| 5116 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5117 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5118 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5119 | DCHECK_NE(address, 0u); |
| 5120 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5121 | return; |
| 5122 | } |
| 5123 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 5124 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5125 | // Add ADRP with its PC-relative String patch. |
| 5126 | const DexFile& dex_file = load->GetDexFile(); |
| 5127 | const dex::StringIndex string_index = load->GetStringIndex(); |
| 5128 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
| 5129 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| 5130 | // Add LDR with its PC-relative String patch. |
| 5131 | vixl::aarch64::Label* ldr_label = |
| 5132 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
| 5133 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 5134 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5135 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5136 | case HLoadString::LoadKind::kBssEntry: { |
| 5137 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5138 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5139 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5140 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5141 | Register temp = XRegisterFrom(load->GetLocations()->GetTemp(0)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5142 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5143 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5144 | // Add LDR with its .bss entry String patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5145 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5146 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5147 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5148 | GenerateGcRootFieldLoad(load, |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5149 | out_loc, |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5150 | temp, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5151 | /* offset placeholder */ 0u, |
| 5152 | ldr_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5153 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5154 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5155 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load, temp, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5156 | codegen_->AddSlowPath(slow_path); |
| 5157 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5158 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5159 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5160 | return; |
| 5161 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5162 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5163 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5164 | load->GetStringIndex(), |
| 5165 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5166 | GenerateGcRootFieldLoad(load, |
| 5167 | out_loc, |
| 5168 | out.X(), |
| 5169 | /* offset */ 0, |
| 5170 | /* fixup_label */ nullptr, |
| 5171 | kCompilerReadBarrierOption); |
| 5172 | return; |
| 5173 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5174 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5175 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5176 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5177 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5178 | // 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] | 5179 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5180 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5181 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5182 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5183 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5184 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5185 | } |
| 5186 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5187 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5188 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5189 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5190 | } |
| 5191 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5192 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5193 | // Will be generated at use site. |
| 5194 | } |
| 5195 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5196 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5197 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5198 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5199 | InvokeRuntimeCallingConvention calling_convention; |
| 5200 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5201 | } |
| 5202 | |
| 5203 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5204 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5205 | instruction, |
| 5206 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5207 | if (instruction->IsEnter()) { |
| 5208 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5209 | } else { |
| 5210 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5211 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5212 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5213 | } |
| 5214 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5215 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5216 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5217 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5218 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5219 | case DataType::Type::kInt32: |
| 5220 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5221 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5222 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5223 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5224 | break; |
| 5225 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5226 | case DataType::Type::kFloat32: |
| 5227 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5228 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5229 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5230 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5231 | break; |
| 5232 | |
| 5233 | default: |
| 5234 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5235 | } |
| 5236 | } |
| 5237 | |
| 5238 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5239 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5240 | case DataType::Type::kInt32: |
| 5241 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5242 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5243 | break; |
| 5244 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5245 | case DataType::Type::kFloat32: |
| 5246 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5247 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5248 | break; |
| 5249 | |
| 5250 | default: |
| 5251 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5252 | } |
| 5253 | } |
| 5254 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5255 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5256 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5257 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5258 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5259 | case DataType::Type::kInt32: |
| 5260 | case DataType::Type::kInt64: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5261 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5262 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5263 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5264 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5265 | case DataType::Type::kFloat32: |
| 5266 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5267 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5268 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5269 | break; |
| 5270 | |
| 5271 | default: |
| 5272 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5273 | } |
| 5274 | } |
| 5275 | |
| 5276 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5277 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5278 | case DataType::Type::kInt32: |
| 5279 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5280 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5281 | break; |
| 5282 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5283 | case DataType::Type::kFloat32: |
| 5284 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5285 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5286 | break; |
| 5287 | |
| 5288 | default: |
| 5289 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5290 | } |
| 5291 | } |
| 5292 | |
| 5293 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5294 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5295 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5296 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5297 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5298 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5299 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5300 | } |
| 5301 | |
| 5302 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5303 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5304 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5305 | QuickEntrypointEnum entrypoint = |
| 5306 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5307 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5308 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5309 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5310 | } |
| 5311 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5312 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5313 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5314 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5315 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5316 | if (instruction->IsStringAlloc()) { |
| 5317 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 5318 | } else { |
| 5319 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5320 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5321 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5322 | } |
| 5323 | |
| 5324 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5325 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5326 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5327 | if (instruction->IsStringAlloc()) { |
| 5328 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5329 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5330 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5331 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 5332 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5333 | |
| 5334 | { |
| 5335 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 5336 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 5337 | kInstructionSize, |
| 5338 | CodeBufferCheckScope::kExactSize); |
| 5339 | __ blr(lr); |
| 5340 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5341 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5342 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5343 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5344 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5345 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5346 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5347 | } |
| 5348 | |
| 5349 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5350 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5351 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5352 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5353 | } |
| 5354 | |
| 5355 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5356 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5357 | case DataType::Type::kInt32: |
| 5358 | case DataType::Type::kInt64: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5359 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5360 | break; |
| 5361 | |
| 5362 | default: |
| 5363 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5364 | } |
| 5365 | } |
| 5366 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5367 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5368 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5369 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5370 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5371 | } |
| 5372 | |
| 5373 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5374 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5375 | } |
| 5376 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5377 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5378 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5379 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5380 | } |
| 5381 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5382 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5383 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5384 | return; |
| 5385 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5386 | { |
| 5387 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5388 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5389 | Location obj = instruction->GetLocations()->InAt(0); |
| 5390 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5391 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5392 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5393 | } |
| 5394 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5395 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5396 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5397 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5398 | |
| 5399 | LocationSummary* locations = instruction->GetLocations(); |
| 5400 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5401 | |
| 5402 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5403 | } |
| 5404 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5405 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5406 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5407 | } |
| 5408 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5409 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5410 | HandleBinaryOp(instruction); |
| 5411 | } |
| 5412 | |
| 5413 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5414 | HandleBinaryOp(instruction); |
| 5415 | } |
| 5416 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5417 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5418 | LOG(FATAL) << "Unreachable"; |
| 5419 | } |
| 5420 | |
| 5421 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5422 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5423 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5424 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5425 | // The back edge will generate the suspend check. |
| 5426 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5427 | } |
| 5428 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5429 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5430 | } |
| 5431 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5432 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5433 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5434 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5435 | if (location.IsStackSlot()) { |
| 5436 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5437 | } else if (location.IsDoubleStackSlot()) { |
| 5438 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5439 | } |
| 5440 | locations->SetOut(location); |
| 5441 | } |
| 5442 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5443 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5444 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5445 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5446 | } |
| 5447 | |
| 5448 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5449 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5450 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5451 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5452 | } |
| 5453 | |
| 5454 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5455 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5456 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5457 | } |
| 5458 | |
| 5459 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5460 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5461 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5462 | locations->SetInAt(i, Location::Any()); |
| 5463 | } |
| 5464 | locations->SetOut(Location::Any()); |
| 5465 | } |
| 5466 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5467 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5468 | LOG(FATAL) << "Unreachable"; |
| 5469 | } |
| 5470 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5471 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5472 | DataType::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5473 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5474 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5475 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5476 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5477 | |
| 5478 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5479 | case DataType::Type::kInt32: |
| 5480 | case DataType::Type::kInt64: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5481 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5482 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5483 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5484 | break; |
| 5485 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5486 | case DataType::Type::kFloat32: |
| 5487 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5488 | InvokeRuntimeCallingConvention calling_convention; |
| 5489 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5490 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5491 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5492 | |
| 5493 | break; |
| 5494 | } |
| 5495 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5496 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5497 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5498 | } |
| 5499 | } |
| 5500 | |
| 5501 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5502 | DataType::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5503 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5504 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5505 | case DataType::Type::kInt32: |
| 5506 | case DataType::Type::kInt64: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5507 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5508 | break; |
| 5509 | } |
| 5510 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5511 | case DataType::Type::kFloat32: |
| 5512 | case DataType::Type::kFloat64: { |
| 5513 | QuickEntrypointEnum entrypoint = |
| 5514 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5515 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5516 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5517 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5518 | } else { |
| 5519 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5520 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5521 | break; |
| 5522 | } |
| 5523 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5524 | default: |
| 5525 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5526 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5527 | } |
| 5528 | } |
| 5529 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5530 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5531 | constructor_fence->SetLocations(nullptr); |
| 5532 | } |
| 5533 | |
| 5534 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5535 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5536 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5537 | } |
| 5538 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5539 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5540 | memory_barrier->SetLocations(nullptr); |
| 5541 | } |
| 5542 | |
| 5543 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5544 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5545 | } |
| 5546 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5547 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5548 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5549 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5550 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5551 | } |
| 5552 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5553 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5554 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5555 | } |
| 5556 | |
| 5557 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5558 | instruction->SetLocations(nullptr); |
| 5559 | } |
| 5560 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5561 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5562 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5563 | } |
| 5564 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5565 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5566 | HandleBinaryOp(ror); |
| 5567 | } |
| 5568 | |
| 5569 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5570 | HandleBinaryOp(ror); |
| 5571 | } |
| 5572 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5573 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5574 | HandleShift(shl); |
| 5575 | } |
| 5576 | |
| 5577 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5578 | HandleShift(shl); |
| 5579 | } |
| 5580 | |
| 5581 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5582 | HandleShift(shr); |
| 5583 | } |
| 5584 | |
| 5585 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5586 | HandleShift(shr); |
| 5587 | } |
| 5588 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5589 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5590 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5591 | } |
| 5592 | |
| 5593 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5594 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5595 | } |
| 5596 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5597 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5598 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5599 | } |
| 5600 | |
| 5601 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5602 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5606 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5607 | } |
| 5608 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5609 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5610 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5611 | } |
| 5612 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5613 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5614 | HUnresolvedInstanceFieldGet* instruction) { |
| 5615 | FieldAccessCallingConventionARM64 calling_convention; |
| 5616 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5617 | instruction, instruction->GetFieldType(), calling_convention); |
| 5618 | } |
| 5619 | |
| 5620 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5621 | HUnresolvedInstanceFieldGet* instruction) { |
| 5622 | FieldAccessCallingConventionARM64 calling_convention; |
| 5623 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5624 | instruction->GetFieldType(), |
| 5625 | instruction->GetFieldIndex(), |
| 5626 | instruction->GetDexPc(), |
| 5627 | calling_convention); |
| 5628 | } |
| 5629 | |
| 5630 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5631 | HUnresolvedInstanceFieldSet* instruction) { |
| 5632 | FieldAccessCallingConventionARM64 calling_convention; |
| 5633 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5634 | instruction, instruction->GetFieldType(), calling_convention); |
| 5635 | } |
| 5636 | |
| 5637 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5638 | HUnresolvedInstanceFieldSet* instruction) { |
| 5639 | FieldAccessCallingConventionARM64 calling_convention; |
| 5640 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5641 | instruction->GetFieldType(), |
| 5642 | instruction->GetFieldIndex(), |
| 5643 | instruction->GetDexPc(), |
| 5644 | calling_convention); |
| 5645 | } |
| 5646 | |
| 5647 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5648 | HUnresolvedStaticFieldGet* instruction) { |
| 5649 | FieldAccessCallingConventionARM64 calling_convention; |
| 5650 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5651 | instruction, instruction->GetFieldType(), calling_convention); |
| 5652 | } |
| 5653 | |
| 5654 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5655 | HUnresolvedStaticFieldGet* instruction) { |
| 5656 | FieldAccessCallingConventionARM64 calling_convention; |
| 5657 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5658 | instruction->GetFieldType(), |
| 5659 | instruction->GetFieldIndex(), |
| 5660 | instruction->GetDexPc(), |
| 5661 | calling_convention); |
| 5662 | } |
| 5663 | |
| 5664 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5665 | HUnresolvedStaticFieldSet* instruction) { |
| 5666 | FieldAccessCallingConventionARM64 calling_convention; |
| 5667 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5668 | instruction, instruction->GetFieldType(), calling_convention); |
| 5669 | } |
| 5670 | |
| 5671 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5672 | HUnresolvedStaticFieldSet* instruction) { |
| 5673 | FieldAccessCallingConventionARM64 calling_convention; |
| 5674 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5675 | instruction->GetFieldType(), |
| 5676 | instruction->GetFieldIndex(), |
| 5677 | instruction->GetDexPc(), |
| 5678 | calling_convention); |
| 5679 | } |
| 5680 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5681 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5682 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5683 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5684 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5685 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5686 | // registers in full width (since the runtime only saves/restores lower part). |
| 5687 | locations->SetCustomSlowPathCallerSaves( |
| 5688 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5689 | } |
| 5690 | |
| 5691 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5692 | HBasicBlock* block = instruction->GetBlock(); |
| 5693 | if (block->GetLoopInformation() != nullptr) { |
| 5694 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5695 | // The back edge will generate the suspend check. |
| 5696 | return; |
| 5697 | } |
| 5698 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5699 | // The goto will generate the suspend check. |
| 5700 | return; |
| 5701 | } |
| 5702 | GenerateSuspendCheck(instruction, nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5703 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5704 | } |
| 5705 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5706 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5707 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5708 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5709 | InvokeRuntimeCallingConvention calling_convention; |
| 5710 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5711 | } |
| 5712 | |
| 5713 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5714 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5715 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5716 | } |
| 5717 | |
| 5718 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5719 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5720 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5721 | DataType::Type input_type = conversion->GetInputType(); |
| 5722 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5723 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5724 | << input_type << " -> " << result_type; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5725 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 5726 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5727 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5728 | } |
| 5729 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5730 | if (DataType::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5731 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5732 | } else { |
| 5733 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5734 | } |
| 5735 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5736 | if (DataType::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5737 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5738 | } else { |
| 5739 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5740 | } |
| 5741 | } |
| 5742 | |
| 5743 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5744 | DataType::Type result_type = conversion->GetResultType(); |
| 5745 | DataType::Type input_type = conversion->GetInputType(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5746 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5747 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5748 | << input_type << " -> " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5749 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5750 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 5751 | int result_size = DataType::Size(result_type); |
| 5752 | int input_size = DataType::Size(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5753 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5754 | Register output = OutputRegister(conversion); |
| 5755 | Register source = InputRegisterAt(conversion, 0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5756 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5757 | // 'int' values are used directly as W registers, discarding the top |
| 5758 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5759 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5760 | // top 32 bits of the target register. We theoretically could leave those |
| 5761 | // bits unchanged, but we would have to make sure that no code uses a |
| 5762 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5763 | // zero. |
| 5764 | __ Mov(output.W(), source.W()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5765 | } else if (DataType::IsUnsignedType(result_type) || |
| 5766 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 5767 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5768 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5769 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5770 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5771 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5772 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5773 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 5774 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5775 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5776 | } else if (DataType::IsFloatingPointType(result_type) && |
| 5777 | DataType::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5778 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5779 | } else { |
| 5780 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5781 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5782 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5783 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5784 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5785 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5786 | HandleShift(ushr); |
| 5787 | } |
| 5788 | |
| 5789 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5790 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5791 | } |
| 5792 | |
| 5793 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5794 | HandleBinaryOp(instruction); |
| 5795 | } |
| 5796 | |
| 5797 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5798 | HandleBinaryOp(instruction); |
| 5799 | } |
| 5800 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5801 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5802 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5803 | LOG(FATAL) << "Unreachable"; |
| 5804 | } |
| 5805 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5806 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5807 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5808 | LOG(FATAL) << "Unreachable"; |
| 5809 | } |
| 5810 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5811 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5812 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5813 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5814 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5815 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5816 | } |
| 5817 | |
| 5818 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5819 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5820 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5821 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5822 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5823 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5824 | // 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] | 5825 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5826 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5827 | // make sure we don't emit it if the target may run out of range. |
| 5828 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5829 | // ranges and emit the tables only as required. |
| 5830 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5831 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5832 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5833 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5834 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5835 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5836 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5837 | Register temp = temps.AcquireW(); |
| 5838 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5839 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5840 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5841 | // Jump to successors[0] if value == lower_bound. |
| 5842 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5843 | int32_t last_index = 0; |
| 5844 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5845 | __ Subs(temp, temp, Operand(2)); |
| 5846 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5847 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5848 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5849 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5850 | } |
| 5851 | if (num_entries - last_index == 2) { |
| 5852 | // The last missing case_value. |
| 5853 | __ Cmp(temp, Operand(1)); |
| 5854 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5855 | } |
| 5856 | |
| 5857 | // And the default for any other value. |
| 5858 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5859 | __ B(codegen_->GetLabelOf(default_block)); |
| 5860 | } |
| 5861 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5862 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5863 | |
| 5864 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5865 | |
| 5866 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5867 | // registers, we are free to block one. |
| 5868 | Register temp_w = temps.AcquireW(); |
| 5869 | Register index; |
| 5870 | // Remove the bias. |
| 5871 | if (lower_bound != 0) { |
| 5872 | index = temp_w; |
| 5873 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5874 | } else { |
| 5875 | index = value_reg; |
| 5876 | } |
| 5877 | |
| 5878 | // Jump to default block if index is out of the range. |
| 5879 | __ Cmp(index, Operand(num_entries)); |
| 5880 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5881 | |
| 5882 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5883 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5884 | // register pressure. |
| 5885 | Register table_base = temps.AcquireX(); |
| 5886 | // Load jump offset from the table. |
| 5887 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5888 | Register jump_offset = temp_w; |
| 5889 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5890 | |
| 5891 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5892 | Register target_address = table_base; |
| 5893 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5894 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5895 | } |
| 5896 | } |
| 5897 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5898 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 5899 | HInstruction* instruction, |
| 5900 | Location out, |
| 5901 | uint32_t offset, |
| 5902 | Location maybe_temp, |
| 5903 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5904 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5905 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5906 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5907 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5908 | if (kUseBakerReadBarrier) { |
| 5909 | // Load with fast path based Baker's read barrier. |
| 5910 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5911 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5912 | out, |
| 5913 | out_reg, |
| 5914 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5915 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5916 | /* needs_null_check */ false, |
| 5917 | /* use_load_acquire */ false); |
| 5918 | } else { |
| 5919 | // Load with slow path based read barrier. |
| 5920 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5921 | // in the following move operation, as we will need it for the |
| 5922 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5923 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5924 | __ Mov(temp_reg, out_reg); |
| 5925 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5926 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5927 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5928 | } |
| 5929 | } else { |
| 5930 | // Plain load with no read barrier. |
| 5931 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5932 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5933 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5934 | } |
| 5935 | } |
| 5936 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5937 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 5938 | HInstruction* instruction, |
| 5939 | Location out, |
| 5940 | Location obj, |
| 5941 | uint32_t offset, |
| 5942 | Location maybe_temp, |
| 5943 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5944 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5945 | Register out_reg = RegisterFrom(out, type); |
| 5946 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5947 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5948 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5949 | if (kUseBakerReadBarrier) { |
| 5950 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5951 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5952 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5953 | out, |
| 5954 | obj_reg, |
| 5955 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5956 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5957 | /* needs_null_check */ false, |
| 5958 | /* use_load_acquire */ false); |
| 5959 | } else { |
| 5960 | // Load with slow path based read barrier. |
| 5961 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5962 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5963 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5964 | } |
| 5965 | } else { |
| 5966 | // Plain load with no read barrier. |
| 5967 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5968 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5969 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5970 | } |
| 5971 | } |
| 5972 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5973 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad( |
| 5974 | HInstruction* instruction, |
| 5975 | Location root, |
| 5976 | Register obj, |
| 5977 | uint32_t offset, |
| 5978 | vixl::aarch64::Label* fixup_label, |
| 5979 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5980 | DCHECK(fixup_label == nullptr || offset == 0u); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5981 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5982 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5983 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5984 | if (kUseBakerReadBarrier) { |
| 5985 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5986 | // Baker's read barrier are used. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5987 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 5988 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 5989 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 5990 | // the Marking Register) to decide whether we need to enter |
| 5991 | // the slow path to mark the GC root. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5992 | // |
| 5993 | // We use link-time generated thunks for the slow path. That thunk |
| 5994 | // checks the reference and jumps to the entrypoint if needed. |
| 5995 | // |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5996 | // lr = &return_address; |
| 5997 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 5998 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 5999 | // goto gc_root_thunk<root_reg>(lr) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6000 | // } |
| 6001 | // return_address: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6002 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6003 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6004 | DCHECK(temps.IsAvailable(ip0)); |
| 6005 | DCHECK(temps.IsAvailable(ip1)); |
| 6006 | temps.Exclude(ip0, ip1); |
| 6007 | uint32_t custom_data = |
| 6008 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
| 6009 | vixl::aarch64::Label* cbnz_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6010 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6011 | EmissionCheckScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6012 | vixl::aarch64::Label return_address; |
| 6013 | __ adr(lr, &return_address); |
| 6014 | if (fixup_label != nullptr) { |
| 6015 | __ Bind(fixup_label); |
| 6016 | } |
| 6017 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6018 | "GC root LDR must be 2 instruction (8B) before the return address label."); |
| 6019 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6020 | __ Bind(cbnz_label); |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6021 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6022 | __ Bind(&return_address); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6023 | } else { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6024 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6025 | // the Marking Register) to decide whether we need to enter |
| 6026 | // the slow path to mark the GC root. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6027 | // |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6028 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6029 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6030 | // // Slow path. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6031 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6032 | // root = entrypoint(root); // root = ReadBarrier::Mark(root); // Entry point call. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6033 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6034 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6035 | // Slow path marking the GC root `root`. The entrypoint will |
| 6036 | // be loaded by the slow path code. |
| 6037 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6038 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathARM64(instruction, root); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6039 | codegen_->AddSlowPath(slow_path); |
| 6040 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6041 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6042 | if (fixup_label == nullptr) { |
| 6043 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6044 | } else { |
| 6045 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
| 6046 | } |
| 6047 | static_assert( |
| 6048 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6049 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6050 | "have different sizes."); |
| 6051 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6052 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6053 | "have different sizes."); |
| 6054 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6055 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6056 | __ Bind(slow_path->GetExitLabel()); |
| 6057 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6058 | } else { |
| 6059 | // GC root loaded through a slow path for read barriers other |
| 6060 | // than Baker's. |
| 6061 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6062 | if (fixup_label == nullptr) { |
| 6063 | __ Add(root_reg.X(), obj.X(), offset); |
| 6064 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6065 | codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6066 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6067 | // /* mirror::Object* */ root = root->Read() |
| 6068 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6069 | } |
| 6070 | } else { |
| 6071 | // Plain GC root load with no read barrier. |
| 6072 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6073 | if (fixup_label == nullptr) { |
| 6074 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6075 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6076 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6077 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6078 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6079 | // do not have to unpoison `root_reg` here. |
| 6080 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6081 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6082 | } |
| 6083 | |
| 6084 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6085 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6086 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6087 | uint32_t offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6088 | Location maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6089 | bool needs_null_check, |
| 6090 | bool use_load_acquire) { |
| 6091 | DCHECK(kEmitCompilerReadBarrier); |
| 6092 | DCHECK(kUseBakerReadBarrier); |
| 6093 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6094 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6095 | !use_load_acquire && |
| 6096 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6097 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6098 | // Marking Register) to decide whether we need to enter the slow |
| 6099 | // path to mark the reference. Then, in the slow path, check the |
| 6100 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6101 | // decide whether to mark `ref` or not. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6102 | // |
| 6103 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6104 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6105 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6106 | // |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6107 | // lr = &gray_return_address; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6108 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6109 | // goto field_thunk<holder_reg, base_reg>(lr) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6110 | // } |
| 6111 | // not_gray_return_address: |
| 6112 | // // Original reference load. If the offset is too large to fit |
| 6113 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6114 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6115 | // gray_return_address: |
| 6116 | |
| 6117 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6118 | Register base = obj; |
| 6119 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6120 | DCHECK(maybe_temp.IsRegister()); |
| 6121 | base = WRegisterFrom(maybe_temp); |
| 6122 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6123 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6124 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 6125 | } |
| 6126 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6127 | DCHECK(temps.IsAvailable(ip0)); |
| 6128 | DCHECK(temps.IsAvailable(ip1)); |
| 6129 | temps.Exclude(ip0, ip1); |
| 6130 | uint32_t custom_data = linker::Arm64RelativePatcher::EncodeBakerReadBarrierFieldData( |
| 6131 | base.GetCode(), |
| 6132 | obj.GetCode()); |
| 6133 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6134 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6135 | { |
| 6136 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6137 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6138 | vixl::aarch64::Label return_address; |
| 6139 | __ adr(lr, &return_address); |
| 6140 | __ Bind(cbnz_label); |
| 6141 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6142 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6143 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6144 | " 2 instructions (8B) for heap poisoning."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6145 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6146 | __ ldr(ref_reg, MemOperand(base.X(), offset)); |
| 6147 | if (needs_null_check) { |
| 6148 | MaybeRecordImplicitNullCheck(instruction); |
| 6149 | } |
| 6150 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6151 | __ Bind(&return_address); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6152 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6153 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6154 | return; |
| 6155 | } |
| 6156 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6157 | // /* HeapReference<Object> */ ref = *(obj + offset) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6158 | Register temp = WRegisterFrom(maybe_temp); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6159 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6160 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6161 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6162 | ref, |
| 6163 | obj, |
| 6164 | offset, |
| 6165 | no_index, |
| 6166 | no_scale_factor, |
| 6167 | temp, |
| 6168 | needs_null_check, |
| 6169 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6170 | } |
| 6171 | |
| 6172 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6173 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6174 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6175 | uint32_t data_offset, |
| 6176 | Location index, |
| 6177 | Register temp, |
| 6178 | bool needs_null_check) { |
| 6179 | DCHECK(kEmitCompilerReadBarrier); |
| 6180 | DCHECK(kUseBakerReadBarrier); |
| 6181 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6182 | static_assert( |
| 6183 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6184 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6185 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6186 | |
| 6187 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6188 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6189 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6190 | // Marking Register) to decide whether we need to enter the slow |
| 6191 | // path to mark the reference. Then, in the slow path, check the |
| 6192 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6193 | // decide whether to mark `ref` or not. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6194 | // |
| 6195 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6196 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6197 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6198 | // |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6199 | // lr = &gray_return_address; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6200 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6201 | // goto array_thunk<base_reg>(lr) |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6202 | // } |
| 6203 | // not_gray_return_address: |
| 6204 | // // Original reference load. If the offset is too large to fit |
| 6205 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6206 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6207 | // gray_return_address: |
| 6208 | |
| 6209 | DCHECK(index.IsValid()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6210 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 6211 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6212 | |
| 6213 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6214 | DCHECK(temps.IsAvailable(ip0)); |
| 6215 | DCHECK(temps.IsAvailable(ip1)); |
| 6216 | temps.Exclude(ip0, ip1); |
| 6217 | uint32_t custom_data = |
| 6218 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierArrayData(temp.GetCode()); |
| 6219 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6220 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6221 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6222 | { |
| 6223 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6224 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6225 | vixl::aarch64::Label return_address; |
| 6226 | __ adr(lr, &return_address); |
| 6227 | __ Bind(cbnz_label); |
| 6228 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6229 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6230 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6231 | " 2 instructions (8B) for heap poisoning."); |
| 6232 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6233 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6234 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6235 | __ Bind(&return_address); |
| 6236 | } |
| 6237 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6238 | return; |
| 6239 | } |
| 6240 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6241 | // Array cells are never volatile variables, therefore array loads |
| 6242 | // never use Load-Acquire instructions on ARM64. |
| 6243 | const bool use_load_acquire = false; |
| 6244 | |
| 6245 | // /* HeapReference<Object> */ ref = |
| 6246 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6247 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6248 | ref, |
| 6249 | obj, |
| 6250 | data_offset, |
| 6251 | index, |
| 6252 | scale_factor, |
| 6253 | temp, |
| 6254 | needs_null_check, |
| 6255 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6256 | } |
| 6257 | |
| 6258 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6259 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6260 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6261 | uint32_t offset, |
| 6262 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6263 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6264 | Register temp, |
| 6265 | bool needs_null_check, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6266 | bool use_load_acquire) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6267 | DCHECK(kEmitCompilerReadBarrier); |
| 6268 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6269 | // If we are emitting an array load, we should not be using a |
| 6270 | // Load Acquire instruction. In other words: |
| 6271 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6272 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6273 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6274 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6275 | // Marking Register) to decide whether we need to enter the slow |
| 6276 | // path to mark the reference. Then, in the slow path, check the |
| 6277 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6278 | // decide whether to mark `ref` or not. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6279 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6280 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6281 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6282 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6283 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6284 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 6285 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6286 | // if (is_gray) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6287 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6288 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6289 | // } |
| 6290 | // } else { |
| 6291 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6292 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6293 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6294 | // Slow path marking the object `ref` when the GC is marking. The |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6295 | // entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6296 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6297 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierSlowPathARM64( |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6298 | instruction, |
| 6299 | ref, |
| 6300 | obj, |
| 6301 | offset, |
| 6302 | index, |
| 6303 | scale_factor, |
| 6304 | needs_null_check, |
| 6305 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6306 | temp); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6307 | AddSlowPath(slow_path); |
| 6308 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6309 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6310 | // Fast path: the GC is not marking: just load the reference. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6311 | GenerateRawReferenceLoad( |
| 6312 | 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] | 6313 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6314 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6315 | } |
| 6316 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6317 | void CodeGeneratorARM64::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 6318 | Location ref, |
| 6319 | Register obj, |
| 6320 | Location field_offset, |
| 6321 | Register temp, |
| 6322 | bool needs_null_check, |
| 6323 | bool use_load_acquire) { |
| 6324 | DCHECK(kEmitCompilerReadBarrier); |
| 6325 | DCHECK(kUseBakerReadBarrier); |
| 6326 | // If we are emitting an array load, we should not be using a |
| 6327 | // Load Acquire instruction. In other words: |
| 6328 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6329 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
| 6330 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6331 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6332 | // Marking Register) to decide whether we need to enter the slow |
| 6333 | // path to update the reference field within `obj`. Then, in the |
| 6334 | // slow path, check the gray bit in the lock word of the reference's |
| 6335 | // holder (`obj`) to decide whether to mark `ref` and update the |
| 6336 | // field or not. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6337 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6338 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6339 | // // Slow path. |
| 6340 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6341 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6342 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
| 6343 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6344 | // if (is_gray) { |
| 6345 | // old_ref = ref; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6346 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6347 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6348 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 6349 | // } |
| 6350 | // } |
| 6351 | |
| 6352 | // Slow path updating the object reference at address `obj + field_offset` |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6353 | // 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] | 6354 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6355 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6356 | instruction, |
| 6357 | ref, |
| 6358 | obj, |
| 6359 | /* offset */ 0u, |
| 6360 | /* index */ field_offset, |
| 6361 | /* scale_factor */ 0u /* "times 1" */, |
| 6362 | needs_null_check, |
| 6363 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6364 | temp); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6365 | AddSlowPath(slow_path); |
| 6366 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6367 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6368 | // Fast path: the GC is not marking: nothing to do (the field is |
| 6369 | // up-to-date, and we don't need to load the reference). |
| 6370 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6371 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6372 | } |
| 6373 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6374 | void CodeGeneratorARM64::GenerateRawReferenceLoad(HInstruction* instruction, |
| 6375 | Location ref, |
| 6376 | Register obj, |
| 6377 | uint32_t offset, |
| 6378 | Location index, |
| 6379 | size_t scale_factor, |
| 6380 | bool needs_null_check, |
| 6381 | bool use_load_acquire) { |
| 6382 | DCHECK(obj.IsW()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6383 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6384 | Register ref_reg = RegisterFrom(ref, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6385 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6386 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 6387 | // that no pools are emitted between the load (macro) instruction |
| 6388 | // and MaybeRecordImplicitNullCheck. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6389 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6390 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6391 | // Load types involving an "index": ArrayGet, |
| 6392 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6393 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6394 | if (use_load_acquire) { |
| 6395 | // UnsafeGetObjectVolatile intrinsic case. |
| 6396 | // Register `index` is not an index in an object array, but an |
| 6397 | // offset to an object reference field within object `obj`. |
| 6398 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 6399 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 6400 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 6401 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6402 | DCHECK_EQ(offset, 0u); |
| 6403 | DCHECK_EQ(scale_factor, 0u); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6404 | DCHECK_EQ(needs_null_check, false); |
| 6405 | // /* HeapReference<mirror::Object> */ ref = *(obj + index) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6406 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 6407 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6408 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6409 | // ArrayGet and UnsafeGetObject and UnsafeCASObject intrinsics cases. |
| 6410 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6411 | if (index.IsConstant()) { |
| 6412 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6413 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6414 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6415 | if (needs_null_check) { |
| 6416 | MaybeRecordImplicitNullCheck(instruction); |
| 6417 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6418 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6419 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6420 | Register temp = temps.AcquireW(); |
| 6421 | __ Add(temp, obj, offset); |
| 6422 | { |
| 6423 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6424 | Load(type, ref_reg, HeapOperand(temp, XRegisterFrom(index), LSL, scale_factor)); |
| 6425 | if (needs_null_check) { |
| 6426 | MaybeRecordImplicitNullCheck(instruction); |
| 6427 | } |
| 6428 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6429 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6430 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6431 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6432 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6433 | MemOperand field = HeapOperand(obj, offset); |
| 6434 | if (use_load_acquire) { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6435 | // Implicit null checks are handled by CodeGeneratorARM64::LoadAcquire. |
| 6436 | LoadAcquire(instruction, ref_reg, field, needs_null_check); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6437 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6438 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6439 | Load(type, ref_reg, field); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6440 | if (needs_null_check) { |
| 6441 | MaybeRecordImplicitNullCheck(instruction); |
| 6442 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6443 | } |
| 6444 | } |
| 6445 | |
| 6446 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6447 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6448 | } |
| 6449 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6450 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6451 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6452 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6453 | // The following condition is a run-time one; it is executed after the |
| 6454 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6455 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6456 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6457 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6458 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6459 | } |
| 6460 | } |
| 6461 | } |
| 6462 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6463 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6464 | Location out, |
| 6465 | Location ref, |
| 6466 | Location obj, |
| 6467 | uint32_t offset, |
| 6468 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6469 | DCHECK(kEmitCompilerReadBarrier); |
| 6470 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6471 | // Insert a slow path based read barrier *after* the reference load. |
| 6472 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6473 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6474 | // reference will be carried out by the runtime within the slow |
| 6475 | // path. |
| 6476 | // |
| 6477 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6478 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6479 | // not used by the artReadBarrierSlow entry point. |
| 6480 | // |
| 6481 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6482 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6483 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6484 | AddSlowPath(slow_path); |
| 6485 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6486 | __ B(slow_path->GetEntryLabel()); |
| 6487 | __ Bind(slow_path->GetExitLabel()); |
| 6488 | } |
| 6489 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6490 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6491 | Location out, |
| 6492 | Location ref, |
| 6493 | Location obj, |
| 6494 | uint32_t offset, |
| 6495 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6496 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6497 | // Baker's read barriers shall be handled by the fast path |
| 6498 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6499 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6500 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6501 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6502 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6503 | } else if (kPoisonHeapReferences) { |
| 6504 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6505 | } |
| 6506 | } |
| 6507 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6508 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6509 | Location out, |
| 6510 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6511 | DCHECK(kEmitCompilerReadBarrier); |
| 6512 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6513 | // Insert a slow path based read barrier *after* the GC root load. |
| 6514 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6515 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6516 | // not need to do anything special for this here. |
| 6517 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6518 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6519 | AddSlowPath(slow_path); |
| 6520 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6521 | __ B(slow_path->GetEntryLabel()); |
| 6522 | __ Bind(slow_path->GetExitLabel()); |
| 6523 | } |
| 6524 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6525 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6526 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6527 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6528 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6529 | locations->SetOut(Location::RequiresRegister()); |
| 6530 | } |
| 6531 | |
| 6532 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6533 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6534 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6535 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6536 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6537 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6538 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6539 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6540 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6541 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6542 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6543 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6544 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6545 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6546 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6547 | } |
| 6548 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6549 | static void PatchJitRootUse(uint8_t* code, |
| 6550 | const uint8_t* roots_data, |
| 6551 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6552 | uint64_t index_in_table) { |
| 6553 | uint32_t literal_offset = literal->GetOffset(); |
| 6554 | uintptr_t address = |
| 6555 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6556 | uint8_t* data = code + literal_offset; |
| 6557 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6558 | } |
| 6559 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6560 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6561 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6562 | const StringReference& string_reference = entry.first; |
| 6563 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6564 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6565 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6566 | } |
| 6567 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6568 | const TypeReference& type_reference = entry.first; |
| 6569 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6570 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6571 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6572 | } |
| 6573 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6574 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6575 | #undef __ |
| 6576 | #undef QUICK_ENTRY_POINT |
| 6577 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6578 | } // namespace arm64 |
| 6579 | } // namespace art |