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 | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 314 | bool do_clinit) |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 315 | : SlowPathCodeARM64(at), |
| 316 | cls_(cls), |
| 317 | dex_pc_(dex_pc), |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 318 | do_clinit_(do_clinit) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 319 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 320 | } |
| 321 | |
| 322 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 323 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 324 | Location out = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 325 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 326 | |
| 327 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 328 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 329 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 330 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 331 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 332 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 333 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 334 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 335 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 336 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 337 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 338 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 339 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 340 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 341 | |
| 342 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 343 | if (out.IsValid()) { |
| 344 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 345 | DataType::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 346 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 347 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 348 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 349 | __ B(GetExitLabel()); |
| 350 | } |
| 351 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 352 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 353 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 354 | private: |
| 355 | // The class this slow path will load. |
| 356 | HLoadClass* const cls_; |
| 357 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 358 | // The dex PC of `at_`. |
| 359 | const uint32_t dex_pc_; |
| 360 | |
| 361 | // Whether to initialize the class. |
| 362 | const bool do_clinit_; |
| 363 | |
| 364 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 365 | }; |
| 366 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 367 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 368 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 369 | explicit LoadStringSlowPathARM64(HLoadString* instruction) |
| 370 | : SlowPathCodeARM64(instruction) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 371 | |
| 372 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 373 | LocationSummary* locations = instruction_->GetLocations(); |
| 374 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 375 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 376 | |
| 377 | __ Bind(GetEntryLabel()); |
| 378 | SaveLiveRegisters(codegen, locations); |
| 379 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 380 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 381 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 382 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 383 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 384 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 385 | DataType::Type type = instruction_->GetType(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 386 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 387 | |
| 388 | RestoreLiveRegisters(codegen, locations); |
| 389 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 390 | __ B(GetExitLabel()); |
| 391 | } |
| 392 | |
| 393 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 394 | |
| 395 | private: |
| 396 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 397 | }; |
| 398 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 399 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 400 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 401 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 402 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 403 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 404 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 405 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 406 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 407 | // Live registers will be restored in the catch block if caught. |
| 408 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 409 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 410 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 411 | instruction_, |
| 412 | instruction_->GetDexPc(), |
| 413 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 414 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 415 | } |
| 416 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 417 | bool IsFatal() const OVERRIDE { return true; } |
| 418 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 419 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 420 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 421 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 422 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 423 | }; |
| 424 | |
| 425 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 426 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 427 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 428 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 429 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 430 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 431 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 432 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 433 | __ Bind(GetEntryLabel()); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 434 | SaveLiveRegisters(codegen, locations); // Only saves live 128-bit regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 435 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 436 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 437 | RestoreLiveRegisters(codegen, locations); // Only restores live 128-bit regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 438 | if (successor_ == nullptr) { |
| 439 | __ B(GetReturnLabel()); |
| 440 | } else { |
| 441 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 442 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 443 | } |
| 444 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 445 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 446 | DCHECK(successor_ == nullptr); |
| 447 | return &return_label_; |
| 448 | } |
| 449 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 450 | HBasicBlock* GetSuccessor() const { |
| 451 | return successor_; |
| 452 | } |
| 453 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 454 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 455 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 456 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 457 | // If not null, the block to branch to after the suspend check. |
| 458 | HBasicBlock* const successor_; |
| 459 | |
| 460 | // If `successor_` is null, the label to branch to after the suspend check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 461 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 462 | |
| 463 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 464 | }; |
| 465 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 466 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 467 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 468 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 469 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 470 | |
| 471 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 472 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 473 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 474 | DCHECK(instruction_->IsCheckCast() |
| 475 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 476 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 477 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 478 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 479 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 480 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 481 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 482 | SaveLiveRegisters(codegen, locations); |
| 483 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 484 | |
| 485 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 486 | // move resolver. |
| 487 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 488 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 489 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 490 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 491 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 492 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 493 | DataType::Type::kReference); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 494 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 495 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 496 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 497 | DataType::Type ret_type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 498 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 499 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 500 | } else { |
| 501 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 502 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 503 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 506 | if (!is_fatal_) { |
| 507 | RestoreLiveRegisters(codegen, locations); |
| 508 | __ B(GetExitLabel()); |
| 509 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 512 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 513 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 514 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 515 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 516 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 517 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 518 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 519 | }; |
| 520 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 521 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 522 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 523 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 524 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 525 | |
| 526 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 527 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 528 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 529 | LocationSummary* locations = instruction_->GetLocations(); |
| 530 | SaveLiveRegisters(codegen, locations); |
| 531 | InvokeRuntimeCallingConvention calling_convention; |
| 532 | __ Mov(calling_convention.GetRegisterAt(0), |
| 533 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 534 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 535 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 538 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 539 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 540 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 541 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 542 | }; |
| 543 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 544 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 545 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 546 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 547 | |
| 548 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 549 | LocationSummary* locations = instruction_->GetLocations(); |
| 550 | __ Bind(GetEntryLabel()); |
| 551 | SaveLiveRegisters(codegen, locations); |
| 552 | |
| 553 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 554 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 555 | parallel_move.AddMove( |
| 556 | locations->InAt(0), |
| 557 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 558 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 559 | nullptr); |
| 560 | parallel_move.AddMove( |
| 561 | locations->InAt(1), |
| 562 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 563 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 564 | nullptr); |
| 565 | parallel_move.AddMove( |
| 566 | locations->InAt(2), |
| 567 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 568 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 569 | nullptr); |
| 570 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 571 | |
| 572 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 573 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 574 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 575 | RestoreLiveRegisters(codegen, locations); |
| 576 | __ B(GetExitLabel()); |
| 577 | } |
| 578 | |
| 579 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 580 | |
| 581 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 582 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 583 | }; |
| 584 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 585 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 586 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 587 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 588 | |
| 589 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 590 | // underlying code buffer and we have generated the jump table with right size. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 591 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 592 | num_entries * sizeof(int32_t), |
| 593 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 594 | |
| 595 | __ Bind(&table_start_); |
| 596 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 597 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 598 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 599 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 600 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 601 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 602 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 603 | Literal<int32_t> literal(jump_offset); |
| 604 | __ place(&literal); |
| 605 | } |
| 606 | } |
| 607 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 608 | // Abstract base class for read barrier slow paths marking a reference |
| 609 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 610 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 611 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 612 | // barrier marking runtime entry point to be invoked or an empty |
| 613 | // location; in the latter case, the read barrier marking runtime |
| 614 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 615 | class ReadBarrierMarkSlowPathBaseARM64 : public SlowPathCodeARM64 { |
| 616 | protected: |
| 617 | ReadBarrierMarkSlowPathBaseARM64(HInstruction* instruction, Location ref, Location entrypoint) |
| 618 | : SlowPathCodeARM64(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 619 | DCHECK(kEmitCompilerReadBarrier); |
| 620 | } |
| 621 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 622 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM64"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 623 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 624 | // Generate assembly code calling the read barrier marking runtime |
| 625 | // entry point (ReadBarrierMarkRegX). |
| 626 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 627 | // No need to save live registers; it's taken care of by the |
| 628 | // entrypoint. Also, there is no need to update the stack mask, |
| 629 | // as this runtime call will not trigger a garbage collection. |
| 630 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 631 | DCHECK_NE(ref_.reg(), LR); |
| 632 | DCHECK_NE(ref_.reg(), WSP); |
| 633 | DCHECK_NE(ref_.reg(), WZR); |
| 634 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 635 | // as a temporary, it cannot be the entry point's input/output. |
| 636 | DCHECK_NE(ref_.reg(), IP0); |
| 637 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 638 | // "Compact" slow path, saving two moves. |
| 639 | // |
| 640 | // Instead of using the standard runtime calling convention (input |
| 641 | // and output in W0): |
| 642 | // |
| 643 | // W0 <- ref |
| 644 | // W0 <- ReadBarrierMark(W0) |
| 645 | // ref <- W0 |
| 646 | // |
| 647 | // we just use rX (the register containing `ref`) as input and output |
| 648 | // of a dedicated entrypoint: |
| 649 | // |
| 650 | // rX <- ReadBarrierMarkRegX(rX) |
| 651 | // |
| 652 | if (entrypoint_.IsValid()) { |
| 653 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 654 | __ Blr(XRegisterFrom(entrypoint_)); |
| 655 | } else { |
| 656 | // Entrypoint is not already loaded, load from the thread. |
| 657 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 658 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 659 | // This runtime call does not require a stack map. |
| 660 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | // The location (register) of the marked object reference. |
| 665 | const Location ref_; |
| 666 | |
| 667 | // The location of the entrypoint if it is already loaded. |
| 668 | const Location entrypoint_; |
| 669 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 670 | private: |
| 671 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM64); |
| 672 | }; |
| 673 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 674 | // Slow path marking an object reference `ref` during a read |
| 675 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 676 | // reference does not get updated by this slow path after marking. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 677 | // |
| 678 | // This means that after the execution of this slow path, `ref` will |
| 679 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 680 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 681 | // probably still be a from-space reference (unless it gets updated by |
| 682 | // another thread, or if another thread installed another object |
| 683 | // reference (different from `ref`) in `obj.field`). |
| 684 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 685 | // Argument `entrypoint` must be a register location holding the read |
| 686 | // barrier marking runtime entry point to be invoked or an empty |
| 687 | // location; in the latter case, the read barrier marking runtime |
| 688 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 689 | class ReadBarrierMarkSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 690 | public: |
| 691 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 692 | Location ref, |
| 693 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 694 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 695 | DCHECK(kEmitCompilerReadBarrier); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 699 | |
| 700 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 701 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 702 | DCHECK(locations->CanCall()); |
| 703 | DCHECK(ref_.IsRegister()) << ref_; |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 704 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 705 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 706 | << "Unexpected instruction in read barrier marking slow path: " |
| 707 | << instruction_->DebugName(); |
| 708 | |
| 709 | __ Bind(GetEntryLabel()); |
| 710 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 711 | __ B(GetExitLabel()); |
| 712 | } |
| 713 | |
| 714 | private: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 715 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 716 | }; |
| 717 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 718 | // Slow path loading `obj`'s lock word, loading a reference from |
| 719 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 720 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 721 | // read barrier). The field `obj.field` in the object `obj` holding |
| 722 | // this reference does not get updated by this slow path after marking |
| 723 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 724 | // below for that). |
| 725 | // |
| 726 | // This means that after the execution of this slow path, `ref` will |
| 727 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 728 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 729 | // probably still be a from-space reference (unless it gets updated by |
| 730 | // another thread, or if another thread installed another object |
| 731 | // reference (different from `ref`) in `obj.field`). |
| 732 | // |
| 733 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 734 | // barrier marking runtime entry point to be invoked or an empty |
| 735 | // location; in the latter case, the read barrier marking runtime |
| 736 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 737 | class LoadReferenceWithBakerReadBarrierSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
| 738 | public: |
| 739 | LoadReferenceWithBakerReadBarrierSlowPathARM64(HInstruction* instruction, |
| 740 | Location ref, |
| 741 | Register obj, |
| 742 | uint32_t offset, |
| 743 | Location index, |
| 744 | size_t scale_factor, |
| 745 | bool needs_null_check, |
| 746 | bool use_load_acquire, |
| 747 | Register temp, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 748 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 749 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
| 750 | obj_(obj), |
| 751 | offset_(offset), |
| 752 | index_(index), |
| 753 | scale_factor_(scale_factor), |
| 754 | needs_null_check_(needs_null_check), |
| 755 | use_load_acquire_(use_load_acquire), |
| 756 | temp_(temp) { |
| 757 | DCHECK(kEmitCompilerReadBarrier); |
| 758 | DCHECK(kUseBakerReadBarrier); |
| 759 | } |
| 760 | |
| 761 | const char* GetDescription() const OVERRIDE { |
| 762 | return "LoadReferenceWithBakerReadBarrierSlowPathARM64"; |
| 763 | } |
| 764 | |
| 765 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 766 | LocationSummary* locations = instruction_->GetLocations(); |
| 767 | DCHECK(locations->CanCall()); |
| 768 | DCHECK(ref_.IsRegister()) << ref_; |
| 769 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 770 | DCHECK(obj_.IsW()); |
| 771 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 772 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 773 | instruction_->IsStaticFieldGet() || |
| 774 | instruction_->IsArrayGet() || |
| 775 | instruction_->IsArraySet() || |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 776 | instruction_->IsInstanceOf() || |
| 777 | instruction_->IsCheckCast() || |
| 778 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 779 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 780 | << "Unexpected instruction in read barrier marking slow path: " |
| 781 | << instruction_->DebugName(); |
| 782 | // The read barrier instrumentation of object ArrayGet |
| 783 | // instructions does not support the HIntermediateAddress |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 784 | // instruction. |
| 785 | DCHECK(!(instruction_->IsArrayGet() && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 786 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 787 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 788 | // Temporary register `temp_`, used to store the lock word, must |
| 789 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 790 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 791 | // need the lock word to still be in `temp_` after the reference |
| 792 | // load. |
| 793 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 794 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
| 795 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 796 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 797 | |
| 798 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 799 | // inserted after the original load. However, in fast path based |
| 800 | // Baker's read barriers, we need to perform the load of |
| 801 | // mirror::Object::monitor_ *before* the original reference load. |
| 802 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 803 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 804 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 805 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 806 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 807 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 808 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 809 | // if (is_gray) { |
| 810 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 811 | // } |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 812 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 813 | // Note: the original implementation in ReadBarrier::Barrier is |
| 814 | // slightly more complex as it performs additional checks that we do |
| 815 | // not do here for performance reasons. |
| 816 | |
| 817 | // /* int32_t */ monitor = obj->monitor_ |
| 818 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 819 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 820 | if (needs_null_check_) { |
| 821 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 822 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 823 | // /* LockWord */ lock_word = LockWord(monitor) |
| 824 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 825 | "art::LockWord and int32_t have different sizes."); |
| 826 | |
| 827 | // Introduce a dependency on the lock_word including rb_state, |
| 828 | // to prevent load-load reordering, and without using |
| 829 | // a memory barrier (which would be more expensive). |
| 830 | // `obj` is unchanged by this operation, but its value now depends |
| 831 | // on `temp`. |
| 832 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 833 | |
| 834 | // The actual reference load. |
| 835 | // A possible implicit null check has already been handled above. |
| 836 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 837 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 838 | ref_, |
| 839 | obj_, |
| 840 | offset_, |
| 841 | index_, |
| 842 | scale_factor_, |
| 843 | /* needs_null_check */ false, |
| 844 | use_load_acquire_); |
| 845 | |
| 846 | // Mark the object `ref` when `obj` is gray. |
| 847 | // |
| 848 | // if (rb_state == ReadBarrier::GrayState()) |
| 849 | // ref = ReadBarrier::Mark(ref); |
| 850 | // |
| 851 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 852 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 853 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 854 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 855 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 856 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 857 | __ B(GetExitLabel()); |
| 858 | } |
| 859 | |
| 860 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 861 | // The register containing the object holding the marked object reference field. |
| 862 | Register obj_; |
| 863 | // The offset, index and scale factor to access the reference in `obj_`. |
| 864 | uint32_t offset_; |
| 865 | Location index_; |
| 866 | size_t scale_factor_; |
| 867 | // Is a null check required? |
| 868 | bool needs_null_check_; |
| 869 | // Should this reference load use Load-Acquire semantics? |
| 870 | bool use_load_acquire_; |
| 871 | // A temporary register used to hold the lock word of `obj_`. |
| 872 | Register temp_; |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 873 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 874 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM64); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 875 | }; |
| 876 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 877 | // Slow path loading `obj`'s lock word, loading a reference from |
| 878 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 879 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 880 | // read barrier). If needed, this slow path also atomically updates |
| 881 | // the field `obj.field` in the object `obj` holding this reference |
| 882 | // after marking (contrary to |
| 883 | // LoadReferenceWithBakerReadBarrierSlowPathARM64 above, which never |
| 884 | // tries to update `obj.field`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 885 | // |
| 886 | // This means that after the execution of this slow path, both `ref` |
| 887 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 888 | // hold the same to-space reference (unless another thread installed |
| 889 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 890 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 891 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 892 | // barrier marking runtime entry point to be invoked or an empty |
| 893 | // location; in the latter case, the read barrier marking runtime |
| 894 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 895 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 896 | : public ReadBarrierMarkSlowPathBaseARM64 { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 897 | public: |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 898 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 899 | HInstruction* instruction, |
| 900 | Location ref, |
| 901 | Register obj, |
| 902 | uint32_t offset, |
| 903 | Location index, |
| 904 | size_t scale_factor, |
| 905 | bool needs_null_check, |
| 906 | bool use_load_acquire, |
| 907 | Register temp, |
| 908 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 909 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 910 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 911 | offset_(offset), |
| 912 | index_(index), |
| 913 | scale_factor_(scale_factor), |
| 914 | needs_null_check_(needs_null_check), |
| 915 | use_load_acquire_(use_load_acquire), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 916 | temp_(temp) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 917 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 918 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 922 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64"; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 926 | LocationSummary* locations = instruction_->GetLocations(); |
| 927 | Register ref_reg = WRegisterFrom(ref_); |
| 928 | DCHECK(locations->CanCall()); |
| 929 | DCHECK(ref_.IsRegister()) << ref_; |
| 930 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 931 | DCHECK(obj_.IsW()); |
| 932 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
| 933 | |
| 934 | // This slow path is only used by the UnsafeCASObject intrinsic at the moment. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 935 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 936 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 937 | << instruction_->DebugName(); |
| 938 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 939 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 940 | DCHECK_EQ(offset_, 0u); |
| 941 | DCHECK_EQ(scale_factor_, 0u); |
| 942 | DCHECK_EQ(use_load_acquire_, false); |
| 943 | // The location of the offset of the marked reference field within `obj_`. |
| 944 | Location field_offset = index_; |
| 945 | DCHECK(field_offset.IsRegister()) << field_offset; |
| 946 | |
| 947 | // Temporary register `temp_`, used to store the lock word, must |
| 948 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 949 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 950 | // need the lock word to still be in `temp_` after the reference |
| 951 | // load. |
| 952 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 953 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 954 | |
| 955 | __ Bind(GetEntryLabel()); |
| 956 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 957 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM64's: |
| 958 | // |
| 959 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 960 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 961 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 962 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 963 | // if (is_gray) { |
| 964 | // old_ref = ref; |
| 965 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 966 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 967 | // } |
| 968 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 969 | // /* int32_t */ monitor = obj->monitor_ |
| 970 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 971 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 972 | if (needs_null_check_) { |
| 973 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 974 | } |
| 975 | // /* LockWord */ lock_word = LockWord(monitor) |
| 976 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 977 | "art::LockWord and int32_t have different sizes."); |
| 978 | |
| 979 | // Introduce a dependency on the lock_word including rb_state, |
| 980 | // to prevent load-load reordering, and without using |
| 981 | // a memory barrier (which would be more expensive). |
| 982 | // `obj` is unchanged by this operation, but its value now depends |
| 983 | // on `temp`. |
| 984 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 985 | |
| 986 | // The actual reference load. |
| 987 | // A possible implicit null check has already been handled above. |
| 988 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 989 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 990 | ref_, |
| 991 | obj_, |
| 992 | offset_, |
| 993 | index_, |
| 994 | scale_factor_, |
| 995 | /* needs_null_check */ false, |
| 996 | use_load_acquire_); |
| 997 | |
| 998 | // Mark the object `ref` when `obj` is gray. |
| 999 | // |
| 1000 | // if (rb_state == ReadBarrier::GrayState()) |
| 1001 | // ref = ReadBarrier::Mark(ref); |
| 1002 | // |
| 1003 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 1004 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1005 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1006 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 1007 | |
| 1008 | // Save the old value of the reference before marking it. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1009 | // Note that we cannot use IP to save the old reference, as IP is |
| 1010 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1011 | // need the old reference after the call to that entry point. |
| 1012 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1013 | __ Mov(temp_.W(), ref_reg); |
| 1014 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1015 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1016 | |
| 1017 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1018 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1019 | // |
| 1020 | // Note that this field could also hold a different object, if |
| 1021 | // another thread had concurrently changed it. In that case, the |
| 1022 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 1023 | // (CAS) operation below would abort the CAS, leaving the field |
| 1024 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1025 | __ Cmp(temp_.W(), ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1026 | __ B(eq, GetExitLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1027 | |
| 1028 | // Update the the holder's field atomically. This may fail if |
| 1029 | // mutator updates before us, but it's OK. This is achieved |
| 1030 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1031 | // memory synchronization ordering, where the expected value is |
| 1032 | // the old reference and the desired value is the new reference. |
| 1033 | |
| 1034 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 1035 | UseScratchRegisterScope temps(masm); |
| 1036 | |
| 1037 | // Convenience aliases. |
| 1038 | Register base = obj_.W(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1039 | Register offset = XRegisterFrom(field_offset); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1040 | Register expected = temp_.W(); |
| 1041 | Register value = ref_reg; |
| 1042 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1043 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 1044 | |
| 1045 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1046 | |
| 1047 | if (kPoisonHeapReferences) { |
| 1048 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1049 | if (value.Is(expected)) { |
| 1050 | // Do not poison `value`, as it is the same register as |
| 1051 | // `expected`, which has just been poisoned. |
| 1052 | } else { |
| 1053 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | // do { |
| 1058 | // tmp_value = [tmp_ptr] - expected; |
| 1059 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1060 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1061 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1062 | __ Bind(&loop_head); |
| 1063 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 1064 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1065 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1066 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 1067 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1068 | __ B(&exit_loop); |
| 1069 | __ Bind(&comparison_failed); |
| 1070 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1071 | __ Bind(&exit_loop); |
| 1072 | |
| 1073 | if (kPoisonHeapReferences) { |
| 1074 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1075 | if (value.Is(expected)) { |
| 1076 | // Do not unpoison `value`, as it is the same register as |
| 1077 | // `expected`, which has just been unpoisoned. |
| 1078 | } else { |
| 1079 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1080 | } |
| 1081 | } |
| 1082 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1083 | __ B(GetExitLabel()); |
| 1084 | } |
| 1085 | |
| 1086 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1087 | // The register containing the object holding the marked object reference field. |
| 1088 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1089 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1090 | uint32_t offset_; |
| 1091 | Location index_; |
| 1092 | size_t scale_factor_; |
| 1093 | // Is a null check required? |
| 1094 | bool needs_null_check_; |
| 1095 | // Should this reference load use Load-Acquire semantics? |
| 1096 | bool use_load_acquire_; |
| 1097 | // A temporary register used to hold the lock word of `obj_`; and |
| 1098 | // also to hold the original reference value, when the reference is |
| 1099 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1100 | const Register temp_; |
| 1101 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1102 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1103 | }; |
| 1104 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1105 | // Slow path generating a read barrier for a heap reference. |
| 1106 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 1107 | public: |
| 1108 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 1109 | Location out, |
| 1110 | Location ref, |
| 1111 | Location obj, |
| 1112 | uint32_t offset, |
| 1113 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1114 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1115 | out_(out), |
| 1116 | ref_(ref), |
| 1117 | obj_(obj), |
| 1118 | offset_(offset), |
| 1119 | index_(index) { |
| 1120 | DCHECK(kEmitCompilerReadBarrier); |
| 1121 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1122 | // has been overwritten by (or after) the heap object reference load |
| 1123 | // to be instrumented, e.g.: |
| 1124 | // |
| 1125 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1126 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1127 | // |
| 1128 | // In that case, we have lost the information about the original |
| 1129 | // object, and the emitted read barrier cannot work properly. |
| 1130 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1131 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1132 | } |
| 1133 | |
| 1134 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1135 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1136 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1137 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1138 | DCHECK(locations->CanCall()); |
| 1139 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1140 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1141 | instruction_->IsStaticFieldGet() || |
| 1142 | instruction_->IsArrayGet() || |
| 1143 | instruction_->IsInstanceOf() || |
| 1144 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1145 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1146 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1147 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1148 | // The read barrier instrumentation of object ArrayGet |
| 1149 | // instructions does not support the HIntermediateAddress |
| 1150 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1151 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1152 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1153 | |
| 1154 | __ Bind(GetEntryLabel()); |
| 1155 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1156 | SaveLiveRegisters(codegen, locations); |
| 1157 | |
| 1158 | // We may have to change the index's value, but as `index_` is a |
| 1159 | // constant member (like other "inputs" of this slow path), |
| 1160 | // introduce a copy of it, `index`. |
| 1161 | Location index = index_; |
| 1162 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1163 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1164 | if (instruction_->IsArrayGet()) { |
| 1165 | // Compute the actual memory offset and store it in `index`. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1166 | Register index_reg = RegisterFrom(index_, DataType::Type::kInt32); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1167 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 1168 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 1169 | // We are about to change the value of `index_reg` (see the |
| 1170 | // calls to vixl::MacroAssembler::Lsl and |
| 1171 | // vixl::MacroAssembler::Mov below), but it has |
| 1172 | // not been saved by the previous call to |
| 1173 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1174 | // callee-save register -- |
| 1175 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1176 | // callee-save registers, as it has been designed with the |
| 1177 | // assumption that callee-save registers are supposed to be |
| 1178 | // handled by the called function. So, as a callee-save |
| 1179 | // register, `index_reg` _would_ eventually be saved onto |
| 1180 | // the stack, but it would be too late: we would have |
| 1181 | // changed its value earlier. Therefore, we manually save |
| 1182 | // it here into another freely available register, |
| 1183 | // `free_reg`, chosen of course among the caller-save |
| 1184 | // registers (as a callee-save `free_reg` register would |
| 1185 | // exhibit the same problem). |
| 1186 | // |
| 1187 | // Note we could have requested a temporary register from |
| 1188 | // the register allocator instead; but we prefer not to, as |
| 1189 | // this is a slow path, and we know we can find a |
| 1190 | // caller-save register that is available. |
| 1191 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1192 | __ Mov(free_reg.W(), index_reg); |
| 1193 | index_reg = free_reg; |
| 1194 | index = LocationFrom(index_reg); |
| 1195 | } else { |
| 1196 | // The initial register stored in `index_` has already been |
| 1197 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1198 | // (as it is not a callee-save register), so we can freely |
| 1199 | // use it. |
| 1200 | } |
| 1201 | // Shifting the index value contained in `index_reg` by the scale |
| 1202 | // factor (2) cannot overflow in practice, as the runtime is |
| 1203 | // unable to allocate object arrays with a size larger than |
| 1204 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1205 | __ Lsl(index_reg, index_reg, DataType::SizeShift(type)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1206 | static_assert( |
| 1207 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1208 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1209 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1210 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1211 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1212 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1213 | // (as in the case of ArrayGet), as it is actually an offset |
| 1214 | // to an object field within an object. |
| 1215 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1216 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1217 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1218 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1219 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1220 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1221 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | // We're moving two or three locations to locations that could |
| 1226 | // overlap, so we need a parallel move resolver. |
| 1227 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1228 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1229 | parallel_move.AddMove(ref_, |
| 1230 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1231 | type, |
| 1232 | nullptr); |
| 1233 | parallel_move.AddMove(obj_, |
| 1234 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1235 | type, |
| 1236 | nullptr); |
| 1237 | if (index.IsValid()) { |
| 1238 | parallel_move.AddMove(index, |
| 1239 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1240 | DataType::Type::kInt32, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1241 | nullptr); |
| 1242 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1243 | } else { |
| 1244 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1245 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1246 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1247 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1248 | instruction_, |
| 1249 | instruction_->GetDexPc(), |
| 1250 | this); |
| 1251 | CheckEntrypointTypes< |
| 1252 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1253 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1254 | |
| 1255 | RestoreLiveRegisters(codegen, locations); |
| 1256 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1257 | __ B(GetExitLabel()); |
| 1258 | } |
| 1259 | |
| 1260 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1261 | |
| 1262 | private: |
| 1263 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1264 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1265 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1266 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1267 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1268 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1269 | } |
| 1270 | } |
| 1271 | // We shall never fail to find a free caller-save register, as |
| 1272 | // there are more than two core caller-save registers on ARM64 |
| 1273 | // (meaning it is possible to find one which is different from |
| 1274 | // `ref` and `obj`). |
| 1275 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1276 | LOG(FATAL) << "Could not find a free register"; |
| 1277 | UNREACHABLE(); |
| 1278 | } |
| 1279 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1280 | const Location out_; |
| 1281 | const Location ref_; |
| 1282 | const Location obj_; |
| 1283 | const uint32_t offset_; |
| 1284 | // An additional location containing an index to an array. |
| 1285 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1286 | // UnsafeGetObjectVolatile intrinsics. |
| 1287 | const Location index_; |
| 1288 | |
| 1289 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1290 | }; |
| 1291 | |
| 1292 | // Slow path generating a read barrier for a GC root. |
| 1293 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1294 | public: |
| 1295 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1296 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1297 | DCHECK(kEmitCompilerReadBarrier); |
| 1298 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1299 | |
| 1300 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1301 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1302 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1303 | DCHECK(locations->CanCall()); |
| 1304 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1305 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1306 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1307 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1308 | |
| 1309 | __ Bind(GetEntryLabel()); |
| 1310 | SaveLiveRegisters(codegen, locations); |
| 1311 | |
| 1312 | InvokeRuntimeCallingConvention calling_convention; |
| 1313 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1314 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1315 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1316 | // thus we need a 64-bit move here, and we cannot use |
| 1317 | // |
| 1318 | // arm64_codegen->MoveLocation( |
| 1319 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1320 | // root_, |
| 1321 | // type); |
| 1322 | // |
| 1323 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1324 | // reference type (`DataType::Type::kReference`). |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1325 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1326 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1327 | instruction_, |
| 1328 | instruction_->GetDexPc(), |
| 1329 | this); |
| 1330 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1331 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1332 | |
| 1333 | RestoreLiveRegisters(codegen, locations); |
| 1334 | __ B(GetExitLabel()); |
| 1335 | } |
| 1336 | |
| 1337 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1338 | |
| 1339 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1340 | const Location out_; |
| 1341 | const Location root_; |
| 1342 | |
| 1343 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1344 | }; |
| 1345 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1346 | #undef __ |
| 1347 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1348 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1349 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1350 | if (type == DataType::Type::kVoid) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1351 | LOG(FATAL) << "Unreachable type " << type; |
| 1352 | } |
| 1353 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1354 | if (DataType::IsFloatingPointType(type) && |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1355 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1356 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1357 | } else if (!DataType::IsFloatingPointType(type) && |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1358 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 1359 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1360 | } else { |
| 1361 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1362 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1363 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1364 | } |
| 1365 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1366 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1367 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1368 | return next_location; |
| 1369 | } |
| 1370 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1371 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1372 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1373 | } |
| 1374 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1375 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1376 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1377 | const CompilerOptions& compiler_options, |
| 1378 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1379 | : CodeGenerator(graph, |
| 1380 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1381 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1382 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1383 | callee_saved_core_registers.GetList(), |
| 1384 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1385 | compiler_options, |
| 1386 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1387 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1388 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1389 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1390 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1391 | move_resolver_(graph->GetAllocator(), this), |
| 1392 | assembler_(graph->GetAllocator()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1393 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1394 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1395 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1396 | uint64_literals_(std::less<uint64_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1397 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1398 | pc_relative_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1399 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1400 | pc_relative_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1401 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1402 | pc_relative_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1403 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1404 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1405 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1406 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1407 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1408 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1409 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1410 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1411 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1412 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1413 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1414 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1415 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1416 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1417 | jump_table->EmitTable(this); |
| 1418 | } |
| 1419 | } |
| 1420 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1421 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1422 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1423 | // Ensure we emit the literal pool. |
| 1424 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1425 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1426 | CodeGenerator::Finalize(allocator); |
| 1427 | } |
| 1428 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1429 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1430 | // Note: There are 6 kinds of moves: |
| 1431 | // 1. constant -> GPR/FPR (non-cycle) |
| 1432 | // 2. constant -> stack (non-cycle) |
| 1433 | // 3. GPR/FPR -> GPR/FPR |
| 1434 | // 4. GPR/FPR -> stack |
| 1435 | // 5. stack -> GPR/FPR |
| 1436 | // 6. stack -> stack (non-cycle) |
| 1437 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1438 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1439 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1440 | // dependency. |
| 1441 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1442 | } |
| 1443 | |
| 1444 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1445 | vixl_temps_.Close(); |
| 1446 | } |
| 1447 | |
| 1448 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1449 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1450 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1451 | || kind == Location::kSIMDStackSlot); |
| 1452 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1453 | ? Location::kFpuRegister |
| 1454 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1455 | Location scratch = GetScratchLocation(kind); |
| 1456 | if (!scratch.Equals(Location::NoLocation())) { |
| 1457 | return scratch; |
| 1458 | } |
| 1459 | // Allocate from VIXL temp registers. |
| 1460 | if (kind == Location::kRegister) { |
| 1461 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1462 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1463 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1464 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1465 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1466 | : vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1467 | } |
| 1468 | AddScratchLocation(scratch); |
| 1469 | return scratch; |
| 1470 | } |
| 1471 | |
| 1472 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1473 | if (loc.IsRegister()) { |
| 1474 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1475 | } else { |
| 1476 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1477 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1478 | } |
| 1479 | RemoveScratchLocation(loc); |
| 1480 | } |
| 1481 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1482 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1483 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1484 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1487 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1488 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1489 | __ Bind(&frame_entry_label_); |
| 1490 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1491 | bool do_overflow_check = |
| 1492 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1493 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1494 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1495 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1496 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1497 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1498 | { |
| 1499 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1500 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1501 | kInstructionSize, |
| 1502 | CodeBufferCheckScope::kExactSize); |
| 1503 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1504 | RecordPcInfo(nullptr, 0); |
| 1505 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1506 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1507 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1508 | if (!HasEmptyFrame()) { |
| 1509 | int frame_size = GetFrameSize(); |
| 1510 | // Stack layout: |
| 1511 | // sp[frame_size - 8] : lr. |
| 1512 | // ... : other preserved core registers. |
| 1513 | // ... : other preserved fp registers. |
| 1514 | // ... : reserved frame space. |
| 1515 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1516 | |
| 1517 | // Save the current method if we need it. Note that we do not |
| 1518 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1519 | // in the SSA graph. |
| 1520 | if (RequiresCurrentMethod()) { |
| 1521 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1522 | } else { |
| 1523 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1524 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1525 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1526 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1527 | frame_size - GetCoreSpillSize()); |
| 1528 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1529 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1530 | |
| 1531 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1532 | // Initialize should_deoptimize flag to 0. |
| 1533 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1534 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1535 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1536 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 1537 | |
| 1538 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1542 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1543 | if (!HasEmptyFrame()) { |
| 1544 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1545 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1546 | frame_size - FrameEntrySpillSize()); |
| 1547 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1548 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1549 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1550 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1551 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1552 | __ Ret(); |
| 1553 | GetAssembler()->cfi().RestoreState(); |
| 1554 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1555 | } |
| 1556 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1557 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1558 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1559 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1560 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1561 | } |
| 1562 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1563 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1564 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1565 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1566 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1567 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1568 | } |
| 1569 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1570 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1571 | __ Bind(GetLabelOf(block)); |
| 1572 | } |
| 1573 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1574 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1575 | DCHECK(location.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1576 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1577 | } |
| 1578 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1579 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1580 | if (location.IsRegister()) { |
| 1581 | locations->AddTemp(location); |
| 1582 | } else { |
| 1583 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1584 | } |
| 1585 | } |
| 1586 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1587 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1588 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1589 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1590 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1591 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1592 | if (value_can_be_null) { |
| 1593 | __ Cbz(value, &done); |
| 1594 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1595 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1596 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1597 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1598 | if (value_can_be_null) { |
| 1599 | __ Bind(&done); |
| 1600 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1601 | } |
| 1602 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1603 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1604 | // Blocked core registers: |
| 1605 | // lr : Runtime reserved. |
| 1606 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1607 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1608 | // ip1 : VIXL core temp. |
| 1609 | // ip0 : VIXL core temp. |
| 1610 | // |
| 1611 | // Blocked fp registers: |
| 1612 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1613 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1614 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1615 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1616 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1617 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1618 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1619 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1620 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1621 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1622 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1623 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1624 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1625 | // Stubs do not save callee-save floating point registers. If the graph |
| 1626 | // is debuggable, we need to deal with these registers differently. For |
| 1627 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1628 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1629 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1630 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1631 | } |
| 1632 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1633 | } |
| 1634 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1635 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1636 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1637 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1638 | return kArm64WordSize; |
| 1639 | } |
| 1640 | |
| 1641 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1642 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1643 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1644 | return kArm64WordSize; |
| 1645 | } |
| 1646 | |
| 1647 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1648 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1649 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1650 | return kArm64WordSize; |
| 1651 | } |
| 1652 | |
| 1653 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1654 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1655 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1656 | return kArm64WordSize; |
| 1657 | } |
| 1658 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1659 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1660 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1664 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1665 | } |
| 1666 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1667 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1668 | if (constant->IsIntConstant()) { |
| 1669 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1670 | } else if (constant->IsLongConstant()) { |
| 1671 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1672 | } else if (constant->IsNullConstant()) { |
| 1673 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1674 | } else if (constant->IsFloatConstant()) { |
| 1675 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1676 | } else { |
| 1677 | DCHECK(constant->IsDoubleConstant()); |
| 1678 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1679 | } |
| 1680 | } |
| 1681 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1682 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1683 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1684 | DCHECK(constant.IsConstant()); |
| 1685 | HConstant* cst = constant.GetConstant(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1686 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1687 | // 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] | 1688 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1689 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1690 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1691 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1692 | } |
| 1693 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1694 | // Allocate a scratch register from the VIXL pool, querying first |
| 1695 | // the floating-point register pool, and then the core register |
| 1696 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1697 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1698 | // using a different allocation strategy. |
| 1699 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1700 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1701 | int size_in_bits) { |
| 1702 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1703 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1704 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1705 | } |
| 1706 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1707 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1708 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1709 | DataType::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1710 | if (source.Equals(destination)) { |
| 1711 | return; |
| 1712 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1713 | |
| 1714 | // A valid move can always be inferred from the destination and source |
| 1715 | // locations. When moving from and to a register, the argument type can be |
| 1716 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1717 | // checks the coherency of the locations and the type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1718 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1719 | |
| 1720 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1721 | if (unspecified_type) { |
| 1722 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1723 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1724 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1725 | || src_cst->IsFloatConstant() |
| 1726 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1727 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1728 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1729 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1730 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1731 | // type is appropriate. Else the source is a register, and since the |
| 1732 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1733 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1734 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1735 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1736 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1737 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1738 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1739 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1740 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1741 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1742 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1743 | } else if (source.IsSIMDStackSlot()) { |
| 1744 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1745 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1746 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1747 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1748 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1749 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1750 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1751 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1752 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1753 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1754 | ? DataType::Type::kInt64 |
| 1755 | : DataType::Type::kInt32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1756 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1757 | } |
| 1758 | } else { |
| 1759 | DCHECK(source.IsFpuRegister()); |
| 1760 | if (destination.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1761 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1762 | ? DataType::Type::kFloat64 |
| 1763 | : DataType::Type::kFloat32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1764 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1765 | } else { |
| 1766 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1767 | if (GetGraph()->HasSIMD()) { |
| 1768 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1769 | } else { |
| 1770 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1771 | } |
| 1772 | } |
| 1773 | } |
| 1774 | } else if (destination.IsSIMDStackSlot()) { |
| 1775 | if (source.IsFpuRegister()) { |
| 1776 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1777 | } else { |
| 1778 | DCHECK(source.IsSIMDStackSlot()); |
| 1779 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1780 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1781 | Register temp = temps.AcquireX(); |
| 1782 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1783 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1784 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1785 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1786 | } else { |
| 1787 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1788 | __ Ldr(temp, StackOperandFrom(source)); |
| 1789 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1790 | } |
| 1791 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1792 | } else { // The destination is not a register. It must be a stack slot. |
| 1793 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1794 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1795 | if (unspecified_type) { |
| 1796 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1797 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1798 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1799 | dst_type = |
| 1800 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1801 | } |
| 1802 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1803 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1804 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1805 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1806 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1807 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1808 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1809 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1810 | HConstant* src_cst = source.GetConstant(); |
| 1811 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1812 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1813 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1814 | ? Register(xzr) |
| 1815 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1816 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1817 | if (src_cst->IsIntConstant()) { |
| 1818 | temp = temps.AcquireW(); |
| 1819 | } else if (src_cst->IsLongConstant()) { |
| 1820 | temp = temps.AcquireX(); |
| 1821 | } else if (src_cst->IsFloatConstant()) { |
| 1822 | temp = temps.AcquireS(); |
| 1823 | } else { |
| 1824 | DCHECK(src_cst->IsDoubleConstant()); |
| 1825 | temp = temps.AcquireD(); |
| 1826 | } |
| 1827 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1828 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1829 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1830 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1831 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1832 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1833 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1834 | // Use any scratch register (a core or a floating-point one) |
| 1835 | // from VIXL scratch register pools as a temporary. |
| 1836 | // |
| 1837 | // We used to only use the FP scratch register pool, but in some |
| 1838 | // rare cases the only register from this pool (D31) would |
| 1839 | // already be used (e.g. within a ParallelMove instruction, when |
| 1840 | // a move is blocked by a another move requiring a scratch FP |
| 1841 | // register, which would reserve D31). To prevent this issue, we |
| 1842 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1843 | // |
| 1844 | // 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] | 1845 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1846 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1847 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1848 | // allocates core scratch registers first. |
| 1849 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1850 | GetVIXLAssembler(), |
| 1851 | &temps, |
| 1852 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1853 | __ Ldr(temp, StackOperandFrom(source)); |
| 1854 | __ Str(temp, StackOperandFrom(destination)); |
| 1855 | } |
| 1856 | } |
| 1857 | } |
| 1858 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1859 | void CodeGeneratorARM64::Load(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1860 | CPURegister dst, |
| 1861 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1862 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1863 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1864 | case DataType::Type::kUint8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1865 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1866 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1867 | case DataType::Type::kInt8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1868 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1869 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1870 | case DataType::Type::kUint16: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1871 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1872 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1873 | case DataType::Type::kInt16: |
| 1874 | __ Ldrsh(Register(dst), src); |
| 1875 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1876 | case DataType::Type::kInt32: |
| 1877 | case DataType::Type::kReference: |
| 1878 | case DataType::Type::kInt64: |
| 1879 | case DataType::Type::kFloat32: |
| 1880 | case DataType::Type::kFloat64: |
| 1881 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1882 | __ Ldr(dst, src); |
| 1883 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1884 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1885 | LOG(FATAL) << "Unreachable type " << type; |
| 1886 | } |
| 1887 | } |
| 1888 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1889 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1890 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1891 | const MemOperand& src, |
| 1892 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1893 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1894 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1895 | Register temp_base = temps.AcquireX(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1896 | DataType::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1897 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1898 | DCHECK(!src.IsPreIndex()); |
| 1899 | DCHECK(!src.IsPostIndex()); |
| 1900 | |
| 1901 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1902 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1903 | { |
| 1904 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1905 | MemOperand base = MemOperand(temp_base); |
| 1906 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1907 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1908 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1909 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1910 | { |
| 1911 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1912 | __ ldarb(Register(dst), base); |
| 1913 | if (needs_null_check) { |
| 1914 | MaybeRecordImplicitNullCheck(instruction); |
| 1915 | } |
| 1916 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1917 | if (type == DataType::Type::kInt8) { |
| 1918 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1919 | } |
| 1920 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1921 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1922 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1923 | { |
| 1924 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1925 | __ ldarh(Register(dst), base); |
| 1926 | if (needs_null_check) { |
| 1927 | MaybeRecordImplicitNullCheck(instruction); |
| 1928 | } |
| 1929 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1930 | if (type == DataType::Type::kInt16) { |
| 1931 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 1932 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1933 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1934 | case DataType::Type::kInt32: |
| 1935 | case DataType::Type::kReference: |
| 1936 | case DataType::Type::kInt64: |
| 1937 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1938 | { |
| 1939 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1940 | __ ldar(Register(dst), base); |
| 1941 | if (needs_null_check) { |
| 1942 | MaybeRecordImplicitNullCheck(instruction); |
| 1943 | } |
| 1944 | } |
| 1945 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1946 | case DataType::Type::kFloat32: |
| 1947 | case DataType::Type::kFloat64: { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1948 | DCHECK(dst.IsFPRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1949 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1950 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1951 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1952 | { |
| 1953 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1954 | __ ldar(temp, base); |
| 1955 | if (needs_null_check) { |
| 1956 | MaybeRecordImplicitNullCheck(instruction); |
| 1957 | } |
| 1958 | } |
| 1959 | __ Fmov(FPRegister(dst), temp); |
| 1960 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1961 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1962 | case DataType::Type::kVoid: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1963 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1964 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1965 | } |
| 1966 | } |
| 1967 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1968 | void CodeGeneratorARM64::Store(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1969 | CPURegister src, |
| 1970 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1971 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1972 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1973 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1974 | case DataType::Type::kInt8: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1975 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1976 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1977 | case DataType::Type::kUint16: |
| 1978 | case DataType::Type::kInt16: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1979 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1980 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1981 | case DataType::Type::kInt32: |
| 1982 | case DataType::Type::kReference: |
| 1983 | case DataType::Type::kInt64: |
| 1984 | case DataType::Type::kFloat32: |
| 1985 | case DataType::Type::kFloat64: |
| 1986 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1987 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1988 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1989 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1990 | LOG(FATAL) << "Unreachable type " << type; |
| 1991 | } |
| 1992 | } |
| 1993 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1994 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1995 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1996 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1997 | const MemOperand& dst, |
| 1998 | bool needs_null_check) { |
| 1999 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2000 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2001 | Register temp_base = temps.AcquireX(); |
| 2002 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2003 | DCHECK(!dst.IsPreIndex()); |
| 2004 | DCHECK(!dst.IsPostIndex()); |
| 2005 | |
| 2006 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2007 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2008 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2009 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2010 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2011 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2012 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2013 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2014 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2015 | { |
| 2016 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2017 | __ stlrb(Register(src), base); |
| 2018 | if (needs_null_check) { |
| 2019 | MaybeRecordImplicitNullCheck(instruction); |
| 2020 | } |
| 2021 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2022 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2023 | case DataType::Type::kUint16: |
| 2024 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2025 | { |
| 2026 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2027 | __ stlrh(Register(src), base); |
| 2028 | if (needs_null_check) { |
| 2029 | MaybeRecordImplicitNullCheck(instruction); |
| 2030 | } |
| 2031 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2032 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2033 | case DataType::Type::kInt32: |
| 2034 | case DataType::Type::kReference: |
| 2035 | case DataType::Type::kInt64: |
| 2036 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2037 | { |
| 2038 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2039 | __ stlr(Register(src), base); |
| 2040 | if (needs_null_check) { |
| 2041 | MaybeRecordImplicitNullCheck(instruction); |
| 2042 | } |
| 2043 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2044 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2045 | case DataType::Type::kFloat32: |
| 2046 | case DataType::Type::kFloat64: { |
| 2047 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2048 | Register temp_src; |
| 2049 | if (src.IsZero()) { |
| 2050 | // The zero register is used to avoid synthesizing zero constants. |
| 2051 | temp_src = Register(src); |
| 2052 | } else { |
| 2053 | DCHECK(src.IsFPRegister()); |
| 2054 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2055 | __ Fmov(temp_src, FPRegister(src)); |
| 2056 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2057 | { |
| 2058 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2059 | __ stlr(temp_src, base); |
| 2060 | if (needs_null_check) { |
| 2061 | MaybeRecordImplicitNullCheck(instruction); |
| 2062 | } |
| 2063 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2064 | break; |
| 2065 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2066 | case DataType::Type::kVoid: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2067 | LOG(FATAL) << "Unreachable type " << type; |
| 2068 | } |
| 2069 | } |
| 2070 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2071 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2072 | HInstruction* instruction, |
| 2073 | uint32_t dex_pc, |
| 2074 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2075 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2076 | |
| 2077 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 2078 | { |
| 2079 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 2080 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2081 | __ blr(lr); |
| 2082 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2083 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2084 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2085 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2088 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2089 | HInstruction* instruction, |
| 2090 | SlowPathCode* slow_path) { |
| 2091 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2092 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2093 | __ Blr(lr); |
| 2094 | } |
| 2095 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2096 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2097 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2098 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2099 | Register temp = temps.AcquireW(); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2100 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 2101 | const size_t status_byte_offset = |
| 2102 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 2103 | constexpr uint32_t shifted_initialized_value = |
| 2104 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2105 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2106 | // 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] | 2107 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2108 | __ Add(temp, class_reg, status_byte_offset); |
Igor Murashkin | 86083f7 | 2017-10-27 10:59:04 -0700 | [diff] [blame] | 2109 | __ Ldarb(temp, HeapOperand(temp)); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2110 | __ Cmp(temp, shifted_initialized_value); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 2111 | __ B(lo, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2112 | __ Bind(slow_path->GetExitLabel()); |
| 2113 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2114 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2115 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2116 | BarrierType type = BarrierAll; |
| 2117 | |
| 2118 | switch (kind) { |
| 2119 | case MemBarrierKind::kAnyAny: |
| 2120 | case MemBarrierKind::kAnyStore: { |
| 2121 | type = BarrierAll; |
| 2122 | break; |
| 2123 | } |
| 2124 | case MemBarrierKind::kLoadAny: { |
| 2125 | type = BarrierReads; |
| 2126 | break; |
| 2127 | } |
| 2128 | case MemBarrierKind::kStoreStore: { |
| 2129 | type = BarrierWrites; |
| 2130 | break; |
| 2131 | } |
| 2132 | default: |
| 2133 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2134 | } |
| 2135 | __ Dmb(InnerShareable, type); |
| 2136 | } |
| 2137 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2138 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2139 | HBasicBlock* successor) { |
| 2140 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2141 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2142 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2143 | slow_path = |
| 2144 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2145 | instruction->SetSlowPath(slow_path); |
| 2146 | codegen_->AddSlowPath(slow_path); |
| 2147 | if (successor != nullptr) { |
| 2148 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2149 | } |
| 2150 | } else { |
| 2151 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2152 | } |
| 2153 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2154 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2155 | Register temp = temps.AcquireW(); |
| 2156 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2157 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2158 | if (successor == nullptr) { |
| 2159 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2160 | __ Bind(slow_path->GetReturnLabel()); |
| 2161 | } else { |
| 2162 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 2163 | __ B(slow_path->GetEntryLabel()); |
| 2164 | // slow_path will return to GetLabelOf(successor). |
| 2165 | } |
| 2166 | } |
| 2167 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2168 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2169 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2170 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2171 | assembler_(codegen->GetAssembler()), |
| 2172 | codegen_(codegen) {} |
| 2173 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2174 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2175 | DCHECK_EQ(instr->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2176 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2177 | DataType::Type type = instr->GetResultType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2178 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2179 | case DataType::Type::kInt32: |
| 2180 | case DataType::Type::kInt64: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2181 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2182 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2183 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2184 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2185 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2186 | case DataType::Type::kFloat32: |
| 2187 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2188 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2189 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2190 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2191 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2192 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2193 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2194 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2195 | } |
| 2196 | } |
| 2197 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2198 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2199 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2200 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2201 | |
| 2202 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2203 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2204 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2205 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2206 | object_field_get_with_read_barrier |
| 2207 | ? LocationSummary::kCallOnSlowPath |
| 2208 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2209 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2210 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2211 | // We need a temporary register for the read barrier marking slow |
| 2212 | // path in CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2213 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2214 | !Runtime::Current()->UseJitCompilation() && |
| 2215 | !field_info.IsVolatile()) { |
| 2216 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2217 | // non-volatile loads we need a temporary only if the offset is too big. |
| 2218 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2219 | locations->AddTemp(FixedTempLocation()); |
| 2220 | } |
| 2221 | } else { |
| 2222 | locations->AddTemp(Location::RequiresRegister()); |
| 2223 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2224 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2225 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2226 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2227 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2228 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2229 | // The output overlaps for an object field get when read barriers |
| 2230 | // are enabled: we do not want the load to overwrite the object's |
| 2231 | // location, as we need it to emit the read barrier. |
| 2232 | locations->SetOut( |
| 2233 | Location::RequiresRegister(), |
| 2234 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2239 | const FieldInfo& field_info) { |
| 2240 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2241 | LocationSummary* locations = instruction->GetLocations(); |
| 2242 | Location base_loc = locations->InAt(0); |
| 2243 | Location out = locations->Out(); |
| 2244 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2245 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 2246 | DataType::Type load_type = instruction->GetType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2247 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2248 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2249 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2250 | load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2251 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2252 | // /* HeapReference<Object> */ out = *(base + offset) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2253 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2254 | Location maybe_temp = |
| 2255 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2256 | // Note that potential implicit null checks are handled in this |
| 2257 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2258 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2259 | instruction, |
| 2260 | out, |
| 2261 | base, |
| 2262 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2263 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2264 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2265 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2266 | } else { |
| 2267 | // General case. |
| 2268 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2269 | // Note that a potential implicit null check is handled in this |
| 2270 | // CodeGeneratorARM64::LoadAcquire call. |
| 2271 | // NB: LoadAcquire will record the pc info if needed. |
| 2272 | codegen_->LoadAcquire( |
| 2273 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2274 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2275 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2276 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2277 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2278 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2279 | } |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2280 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2281 | // If read barriers are enabled, emit read barriers other than |
| 2282 | // Baker's using a slow path (and also unpoison the loaded |
| 2283 | // reference, if heap poisoning is enabled). |
| 2284 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2285 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2286 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2290 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2291 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2292 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2293 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2294 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2295 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2296 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2297 | } else { |
| 2298 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2299 | } |
| 2300 | } |
| 2301 | |
| 2302 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2303 | const FieldInfo& field_info, |
| 2304 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2305 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2306 | |
| 2307 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2308 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2309 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2310 | Offset offset = field_info.GetFieldOffset(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2311 | DataType::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2312 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2313 | { |
| 2314 | // We use a block to end the scratch scope before the write barrier, thus |
| 2315 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2316 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2317 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2318 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2319 | DCHECK(value.IsW()); |
| 2320 | Register temp = temps.AcquireW(); |
| 2321 | __ Mov(temp, value.W()); |
| 2322 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2323 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2324 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2325 | |
| 2326 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2327 | codegen_->StoreRelease( |
| 2328 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2329 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2330 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2331 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2332 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2333 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2334 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2338 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2339 | } |
| 2340 | } |
| 2341 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2342 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2343 | DataType::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2344 | |
| 2345 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2346 | case DataType::Type::kInt32: |
| 2347 | case DataType::Type::kInt64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2348 | Register dst = OutputRegister(instr); |
| 2349 | Register lhs = InputRegisterAt(instr, 0); |
| 2350 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2351 | if (instr->IsAdd()) { |
| 2352 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2353 | } else if (instr->IsAnd()) { |
| 2354 | __ And(dst, lhs, rhs); |
| 2355 | } else if (instr->IsOr()) { |
| 2356 | __ Orr(dst, lhs, rhs); |
| 2357 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2358 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2359 | } else if (instr->IsRor()) { |
| 2360 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2361 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2362 | __ Ror(dst, lhs, shift); |
| 2363 | } else { |
| 2364 | // Ensure shift distance is in the same size register as the result. If |
| 2365 | // we are rotating a long and the shift comes in a w register originally, |
| 2366 | // we don't need to sxtw for use as an x since the shift distances are |
| 2367 | // all & reg_bits - 1. |
| 2368 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2369 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2370 | } else { |
| 2371 | DCHECK(instr->IsXor()); |
| 2372 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2373 | } |
| 2374 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2375 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2376 | case DataType::Type::kFloat32: |
| 2377 | case DataType::Type::kFloat64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2378 | FPRegister dst = OutputFPRegister(instr); |
| 2379 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2380 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2381 | if (instr->IsAdd()) { |
| 2382 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2383 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2384 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2385 | } else { |
| 2386 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2387 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2388 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2389 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2390 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2391 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2392 | } |
| 2393 | } |
| 2394 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2395 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2396 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2397 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2398 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2399 | DataType::Type type = instr->GetResultType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2400 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2401 | case DataType::Type::kInt32: |
| 2402 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2403 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2404 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2405 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2406 | break; |
| 2407 | } |
| 2408 | default: |
| 2409 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2410 | } |
| 2411 | } |
| 2412 | |
| 2413 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2414 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2415 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2416 | DataType::Type type = instr->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2417 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2418 | case DataType::Type::kInt32: |
| 2419 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2420 | Register dst = OutputRegister(instr); |
| 2421 | Register lhs = InputRegisterAt(instr, 0); |
| 2422 | Operand rhs = InputOperandAt(instr, 1); |
| 2423 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2424 | uint32_t shift_value = rhs.GetImmediate() & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2425 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2426 | if (instr->IsShl()) { |
| 2427 | __ Lsl(dst, lhs, shift_value); |
| 2428 | } else if (instr->IsShr()) { |
| 2429 | __ Asr(dst, lhs, shift_value); |
| 2430 | } else { |
| 2431 | __ Lsr(dst, lhs, shift_value); |
| 2432 | } |
| 2433 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2434 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2435 | |
| 2436 | if (instr->IsShl()) { |
| 2437 | __ Lsl(dst, lhs, rhs_reg); |
| 2438 | } else if (instr->IsShr()) { |
| 2439 | __ Asr(dst, lhs, rhs_reg); |
| 2440 | } else { |
| 2441 | __ Lsr(dst, lhs, rhs_reg); |
| 2442 | } |
| 2443 | } |
| 2444 | break; |
| 2445 | } |
| 2446 | default: |
| 2447 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2448 | } |
| 2449 | } |
| 2450 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2451 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2452 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2453 | } |
| 2454 | |
| 2455 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2456 | HandleBinaryOp(instruction); |
| 2457 | } |
| 2458 | |
| 2459 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2460 | HandleBinaryOp(instruction); |
| 2461 | } |
| 2462 | |
| 2463 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2464 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2465 | } |
| 2466 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2467 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2468 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2469 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2470 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2471 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2472 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2473 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2474 | } |
| 2475 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2476 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2477 | Register dst = OutputRegister(instr); |
| 2478 | Register lhs = InputRegisterAt(instr, 0); |
| 2479 | Register rhs = InputRegisterAt(instr, 1); |
| 2480 | |
| 2481 | switch (instr->GetOpKind()) { |
| 2482 | case HInstruction::kAnd: |
| 2483 | __ Bic(dst, lhs, rhs); |
| 2484 | break; |
| 2485 | case HInstruction::kOr: |
| 2486 | __ Orn(dst, lhs, rhs); |
| 2487 | break; |
| 2488 | case HInstruction::kXor: |
| 2489 | __ Eon(dst, lhs, rhs); |
| 2490 | break; |
| 2491 | default: |
| 2492 | LOG(FATAL) << "Unreachable"; |
| 2493 | } |
| 2494 | } |
| 2495 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2496 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2497 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2498 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2499 | instruction->GetType() == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2500 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2501 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2502 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2503 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2504 | } else { |
| 2505 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2506 | } |
| 2507 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2508 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2509 | } |
| 2510 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2511 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2512 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2513 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2514 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2515 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2516 | Register out = OutputRegister(instruction); |
| 2517 | Register left; |
| 2518 | if (kind != HInstruction::kNeg) { |
| 2519 | left = InputRegisterAt(instruction, 0); |
| 2520 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2521 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2522 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2523 | // conversion) can have a different type from the current instruction's type, |
| 2524 | // so we manually indicate the type. |
| 2525 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2526 | Operand right_operand(0); |
| 2527 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2528 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2529 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2530 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2531 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2532 | right_operand = Operand(right_reg, |
| 2533 | helpers::ShiftFromOpKind(op_kind), |
| 2534 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | // Logical binary operations do not support extension operations in the |
| 2538 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2539 | // the extension as a separate instruction. |
| 2540 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2541 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2542 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2543 | kind != HInstruction::kNeg)); |
| 2544 | switch (kind) { |
| 2545 | case HInstruction::kAdd: |
| 2546 | __ Add(out, left, right_operand); |
| 2547 | break; |
| 2548 | case HInstruction::kAnd: |
| 2549 | __ And(out, left, right_operand); |
| 2550 | break; |
| 2551 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2552 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2553 | __ Neg(out, right_operand); |
| 2554 | break; |
| 2555 | case HInstruction::kOr: |
| 2556 | __ Orr(out, left, right_operand); |
| 2557 | break; |
| 2558 | case HInstruction::kSub: |
| 2559 | __ Sub(out, left, right_operand); |
| 2560 | break; |
| 2561 | case HInstruction::kXor: |
| 2562 | __ Eor(out, left, right_operand); |
| 2563 | break; |
| 2564 | default: |
| 2565 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2566 | UNREACHABLE(); |
| 2567 | } |
| 2568 | } |
| 2569 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2570 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2571 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2572 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2573 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2574 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2575 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2576 | } |
| 2577 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2578 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2579 | __ Add(OutputRegister(instruction), |
| 2580 | InputRegisterAt(instruction, 0), |
| 2581 | Operand(InputOperandAt(instruction, 1))); |
| 2582 | } |
| 2583 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2584 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2585 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2586 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2587 | |
| 2588 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2589 | |
| 2590 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2591 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2592 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2593 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2594 | // loop. |
| 2595 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2596 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2597 | : Location::RequiresRegister()); |
| 2598 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2599 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2600 | } |
| 2601 | |
| 2602 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2603 | HIntermediateAddressIndex* instruction) { |
| 2604 | Register index_reg = InputRegisterAt(instruction, 0); |
| 2605 | uint32_t shift = Int64ConstantFrom(instruction->GetLocations()->InAt(2)); |
| 2606 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2607 | |
| 2608 | if (shift == 0) { |
| 2609 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2610 | } else { |
| 2611 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2612 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2613 | } |
| 2614 | } |
| 2615 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2616 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2617 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2618 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2619 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2620 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2621 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2622 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2623 | // Don't allocate register for Mneg instruction. |
| 2624 | } else { |
| 2625 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2626 | Location::RequiresRegister()); |
| 2627 | } |
| 2628 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2629 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2630 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2631 | } |
| 2632 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2633 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2634 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2635 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2636 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2637 | |
| 2638 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2639 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2640 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2641 | if (instr->GetType() == DataType::Type::kInt64 && |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2642 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2643 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2644 | vixl::aarch64::Instruction* prev = |
| 2645 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2646 | if (prev->IsLoadOrStore()) { |
| 2647 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2648 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2649 | __ nop(); |
| 2650 | } |
| 2651 | } |
| 2652 | |
| 2653 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2654 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2655 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2656 | } else { |
| 2657 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2658 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2659 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2660 | __ Mneg(res, mul_left, mul_right); |
| 2661 | } else { |
| 2662 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2663 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2664 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2665 | } |
| 2666 | } |
| 2667 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2668 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2669 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2670 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2671 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2672 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2673 | object_array_get_with_read_barrier |
| 2674 | ? LocationSummary::kCallOnSlowPath |
| 2675 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2676 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2677 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 2678 | // We need a temporary register for the read barrier marking slow |
| 2679 | // path in CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2680 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2681 | !Runtime::Current()->UseJitCompilation() && |
| 2682 | instruction->GetIndex()->IsConstant()) { |
| 2683 | // Array loads with constant index are treated as field loads. |
| 2684 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2685 | // constant index loads we need a temporary only if the offset is too big. |
| 2686 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2687 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2688 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2689 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2690 | locations->AddTemp(FixedTempLocation()); |
| 2691 | } |
| 2692 | } else { |
| 2693 | locations->AddTemp(Location::RequiresRegister()); |
| 2694 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2695 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2696 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2697 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2698 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2699 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2700 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2701 | // The output overlaps in the case of an object array get with |
| 2702 | // read barriers enabled: we do not want the move to overwrite the |
| 2703 | // array's location, as we need it to emit the read barrier. |
| 2704 | locations->SetOut( |
| 2705 | Location::RequiresRegister(), |
| 2706 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2707 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2711 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2712 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2713 | LocationSummary* locations = instruction->GetLocations(); |
| 2714 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2715 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2716 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2717 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2718 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2719 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2720 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2721 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2722 | // The read barrier instrumentation of object ArrayGet instructions |
| 2723 | // does not support the HIntermediateAddress instruction. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2724 | DCHECK(!((type == DataType::Type::kReference) && |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2725 | instruction->GetArray()->IsIntermediateAddress() && |
| 2726 | kEmitCompilerReadBarrier)); |
| 2727 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2728 | if (type == DataType::Type::kReference && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2729 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2730 | // Note that a potential implicit null check is handled in the |
| 2731 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2732 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2733 | if (index.IsConstant()) { |
| 2734 | // 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] | 2735 | offset += Int64ConstantFrom(index) << DataType::SizeShift(type); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2736 | Location maybe_temp = |
| 2737 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2738 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2739 | out, |
| 2740 | obj.W(), |
| 2741 | offset, |
| 2742 | maybe_temp, |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2743 | /* needs_null_check */ false, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2744 | /* use_load_acquire */ false); |
| 2745 | } else { |
| 2746 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
| 2747 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2748 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2749 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2750 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2751 | // General case. |
| 2752 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2753 | Register length; |
| 2754 | if (maybe_compressed_char_at) { |
| 2755 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2756 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2757 | { |
| 2758 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2759 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2760 | |
| 2761 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2762 | DCHECK_LT(count_offset, offset); |
| 2763 | int64_t adjusted_offset = |
| 2764 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2765 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2766 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2767 | } else { |
| 2768 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2769 | } |
| 2770 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2771 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2772 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2773 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2774 | if (maybe_compressed_char_at) { |
| 2775 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2776 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2777 | "Expecting 0=compressed, 1=uncompressed"); |
| 2778 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2779 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2780 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2781 | __ B(&done); |
| 2782 | __ Bind(&uncompressed_load); |
| 2783 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2784 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2785 | __ Bind(&done); |
| 2786 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2787 | offset += Int64ConstantFrom(index) << DataType::SizeShift(type); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2788 | source = HeapOperand(obj, offset); |
| 2789 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2790 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2791 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2792 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2793 | // We do not need to compute the intermediate address from the array: the |
| 2794 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2795 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2796 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2797 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2798 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2799 | } |
| 2800 | temp = obj; |
| 2801 | } else { |
| 2802 | __ Add(temp, obj, offset); |
| 2803 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2804 | if (maybe_compressed_char_at) { |
| 2805 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2806 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2807 | "Expecting 0=compressed, 1=uncompressed"); |
| 2808 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2809 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2810 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2811 | __ B(&done); |
| 2812 | __ Bind(&uncompressed_load); |
| 2813 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2814 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2815 | __ Bind(&done); |
| 2816 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2817 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2818 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2819 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2820 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2821 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2822 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2823 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2824 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2825 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2826 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2827 | if (type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2828 | static_assert( |
| 2829 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2830 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2831 | Location obj_loc = locations->InAt(0); |
| 2832 | if (index.IsConstant()) { |
| 2833 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2834 | } else { |
| 2835 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2836 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2837 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2838 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2839 | } |
| 2840 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2841 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2842 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2843 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2844 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2848 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2849 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2850 | { |
| 2851 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2852 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2853 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2854 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2855 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2856 | // Mask out compression flag from String's array length. |
| 2857 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2858 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2859 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2860 | } |
| 2861 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2862 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2863 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2864 | |
| 2865 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2866 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2867 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2868 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2869 | LocationSummary::kCallOnSlowPath : |
| 2870 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2871 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2872 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2873 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2874 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2875 | } else if (DataType::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2876 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2877 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2878 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2879 | } |
| 2880 | } |
| 2881 | |
| 2882 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2883 | DataType::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2884 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2885 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2886 | bool needs_write_barrier = |
| 2887 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2888 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2889 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2890 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2891 | CPURegister source = value; |
| 2892 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2893 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2894 | MemOperand destination = HeapOperand(array); |
| 2895 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2896 | |
| 2897 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2898 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2899 | if (index.IsConstant()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2900 | offset += Int64ConstantFrom(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2901 | destination = HeapOperand(array, offset); |
| 2902 | } else { |
| 2903 | UseScratchRegisterScope temps(masm); |
| 2904 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2905 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2906 | // We do not need to compute the intermediate address from the array: the |
| 2907 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2908 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2909 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2910 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2911 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2912 | } |
| 2913 | temp = array; |
| 2914 | } else { |
| 2915 | __ Add(temp, array, offset); |
| 2916 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2917 | destination = HeapOperand(temp, |
| 2918 | XRegisterFrom(index), |
| 2919 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2920 | DataType::SizeShift(value_type)); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2921 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2922 | { |
| 2923 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2924 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2925 | codegen_->Store(value_type, value, destination); |
| 2926 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2927 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2928 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2929 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2930 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2931 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2932 | { |
| 2933 | // We use a block to end the scratch scope before the write barrier, thus |
| 2934 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2935 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2936 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2937 | if (index.IsConstant()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2938 | offset += Int64ConstantFrom(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2939 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2940 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2941 | destination = HeapOperand(temp, |
| 2942 | XRegisterFrom(index), |
| 2943 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2944 | DataType::SizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2945 | } |
| 2946 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2947 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2948 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2949 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2950 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2951 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2952 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2953 | codegen_->AddSlowPath(slow_path); |
| 2954 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2955 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2956 | __ Cbnz(Register(value), &non_zero); |
| 2957 | if (!index.IsConstant()) { |
| 2958 | __ Add(temp, array, offset); |
| 2959 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2960 | { |
| 2961 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 2962 | // emitted. |
| 2963 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2964 | __ Str(wzr, destination); |
| 2965 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2966 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2967 | __ B(&done); |
| 2968 | __ Bind(&non_zero); |
| 2969 | } |
| 2970 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2971 | // Note that when Baker read barriers are enabled, the type |
| 2972 | // checks are performed without read barriers. This is fine, |
| 2973 | // even in the case where a class object is in the from-space |
| 2974 | // after the flip, as a comparison involving such a type would |
| 2975 | // not produce a false positive; it may of course produce a |
| 2976 | // false negative, in which case we would take the ArraySet |
| 2977 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2978 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2979 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2980 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2981 | { |
| 2982 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2983 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2984 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2985 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2986 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2987 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2988 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2989 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2990 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2991 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2992 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2993 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2994 | // nor `temp2`, as we are comparing two poisoned references. |
| 2995 | __ Cmp(temp, temp2); |
| 2996 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2997 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2998 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2999 | vixl::aarch64::Label do_put; |
| 3000 | __ B(eq, &do_put); |
| 3001 | // If heap poisoning is enabled, the `temp` reference has |
| 3002 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3003 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3004 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3005 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 3006 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 3007 | // If heap poisoning is enabled, no need to unpoison |
| 3008 | // `temp`, as we are comparing against null below. |
| 3009 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 3010 | __ Bind(&do_put); |
| 3011 | } else { |
| 3012 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3013 | } |
| 3014 | } |
| 3015 | |
| 3016 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3017 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3018 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3019 | __ Mov(temp2, value.W()); |
| 3020 | GetAssembler()->PoisonHeapReference(temp2); |
| 3021 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | if (!index.IsConstant()) { |
| 3025 | __ Add(temp, array, offset); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 3026 | } else { |
| 3027 | // We no longer need the `temp` here so release it as the store below may |
| 3028 | // need a scratch register (if the constant index makes the offset too large) |
| 3029 | // and the poisoned `source` could be using the other scratch register. |
| 3030 | temps.Release(temp); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3031 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3032 | { |
| 3033 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3034 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3035 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3036 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3037 | if (!may_need_runtime_call_for_type_check) { |
| 3038 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3039 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3040 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3041 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3042 | |
| 3043 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 3044 | |
| 3045 | if (done.IsLinked()) { |
| 3046 | __ Bind(&done); |
| 3047 | } |
| 3048 | |
| 3049 | if (slow_path != nullptr) { |
| 3050 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3051 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3052 | } |
| 3053 | } |
| 3054 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3055 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3056 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3057 | InvokeRuntimeCallingConvention calling_convention; |
| 3058 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3059 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 3060 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3061 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 3062 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3063 | } |
| 3064 | |
| 3065 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3066 | BoundsCheckSlowPathARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3067 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3068 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3069 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 3070 | __ B(slow_path->GetEntryLabel(), hs); |
| 3071 | } |
| 3072 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3073 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3074 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3075 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3076 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3077 | if (check->HasUses()) { |
| 3078 | locations->SetOut(Location::SameAsFirstInput()); |
| 3079 | } |
| 3080 | } |
| 3081 | |
| 3082 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3083 | // We assume the class is not null. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3084 | SlowPathCodeARM64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64( |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3085 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 3086 | codegen_->AddSlowPath(slow_path); |
| 3087 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3088 | } |
| 3089 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3090 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3091 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3092 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3093 | } |
| 3094 | |
| 3095 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 3096 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 3097 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3098 | if (rhs_loc.IsConstant()) { |
| 3099 | // 0.0 is the only immediate that can be encoded directly in |
| 3100 | // an FCMP instruction. |
| 3101 | // |
| 3102 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3103 | // specify that in a floating-point comparison, positive zero |
| 3104 | // and negative zero are considered equal, so we can use the |
| 3105 | // literal 0.0 for both cases here. |
| 3106 | // |
| 3107 | // Note however that some methods (Float.equal, Float.compare, |
| 3108 | // Float.compareTo, Double.equal, Double.compare, |
| 3109 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3110 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3111 | // -0.0. So if we ever translate calls to these methods into a |
| 3112 | // HCompare instruction, we must handle the -0.0 case with |
| 3113 | // care here. |
| 3114 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3115 | __ Fcmp(lhs_reg, 0.0); |
| 3116 | } else { |
| 3117 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3118 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3119 | } |
| 3120 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3121 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3122 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3123 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3124 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3125 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3126 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3127 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3128 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3129 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3130 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3131 | case DataType::Type::kInt32: |
| 3132 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3133 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3134 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3135 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3136 | break; |
| 3137 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3138 | case DataType::Type::kFloat32: |
| 3139 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3140 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3141 | locations->SetInAt(1, |
| 3142 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3143 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3144 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3145 | locations->SetOut(Location::RequiresRegister()); |
| 3146 | break; |
| 3147 | } |
| 3148 | default: |
| 3149 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3154 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3155 | |
| 3156 | // 0 if: left == right |
| 3157 | // 1 if: left > right |
| 3158 | // -1 if: left < right |
| 3159 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3160 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3161 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3162 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3163 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3164 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3165 | case DataType::Type::kInt32: |
| 3166 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3167 | Register result = OutputRegister(compare); |
| 3168 | Register left = InputRegisterAt(compare, 0); |
| 3169 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3170 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3171 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3172 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3173 | break; |
| 3174 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3175 | case DataType::Type::kFloat32: |
| 3176 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3177 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3178 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3179 | __ Cset(result, ne); |
| 3180 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3181 | break; |
| 3182 | } |
| 3183 | default: |
| 3184 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3185 | } |
| 3186 | } |
| 3187 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3188 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3189 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3190 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3191 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3192 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3193 | locations->SetInAt(1, |
| 3194 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3195 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3196 | : Location::RequiresFpuRegister()); |
| 3197 | } else { |
| 3198 | // Integer cases. |
| 3199 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3200 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3201 | } |
| 3202 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3203 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3204 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3205 | } |
| 3206 | } |
| 3207 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3208 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3209 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3210 | return; |
| 3211 | } |
| 3212 | |
| 3213 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3214 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3215 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3216 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3217 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3218 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3219 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3220 | } else { |
| 3221 | // Integer cases. |
| 3222 | Register lhs = InputRegisterAt(instruction, 0); |
| 3223 | Operand rhs = InputOperandAt(instruction, 1); |
| 3224 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3225 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3226 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3230 | M(Equal) \ |
| 3231 | M(NotEqual) \ |
| 3232 | M(LessThan) \ |
| 3233 | M(LessThanOrEqual) \ |
| 3234 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3235 | M(GreaterThanOrEqual) \ |
| 3236 | M(Below) \ |
| 3237 | M(BelowOrEqual) \ |
| 3238 | M(Above) \ |
| 3239 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3240 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3241 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3242 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3243 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3244 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3245 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3246 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3247 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3248 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3249 | |
| 3250 | LocationSummary* locations = instruction->GetLocations(); |
| 3251 | Location second = locations->InAt(1); |
| 3252 | DCHECK(second.IsConstant()); |
| 3253 | |
| 3254 | Register out = OutputRegister(instruction); |
| 3255 | Register dividend = InputRegisterAt(instruction, 0); |
| 3256 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3257 | DCHECK(imm == 1 || imm == -1); |
| 3258 | |
| 3259 | if (instruction->IsRem()) { |
| 3260 | __ Mov(out, 0); |
| 3261 | } else { |
| 3262 | if (imm == 1) { |
| 3263 | __ Mov(out, dividend); |
| 3264 | } else { |
| 3265 | __ Neg(out, dividend); |
| 3266 | } |
| 3267 | } |
| 3268 | } |
| 3269 | |
| 3270 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3271 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3272 | |
| 3273 | LocationSummary* locations = instruction->GetLocations(); |
| 3274 | Location second = locations->InAt(1); |
| 3275 | DCHECK(second.IsConstant()); |
| 3276 | |
| 3277 | Register out = OutputRegister(instruction); |
| 3278 | Register dividend = InputRegisterAt(instruction, 0); |
| 3279 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3280 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3281 | int ctz_imm = CTZ(abs_imm); |
| 3282 | |
| 3283 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3284 | Register temp = temps.AcquireSameSizeAs(out); |
| 3285 | |
| 3286 | if (instruction->IsDiv()) { |
| 3287 | __ Add(temp, dividend, abs_imm - 1); |
| 3288 | __ Cmp(dividend, 0); |
| 3289 | __ Csel(out, temp, dividend, lt); |
| 3290 | if (imm > 0) { |
| 3291 | __ Asr(out, out, ctz_imm); |
| 3292 | } else { |
| 3293 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 3294 | } |
| 3295 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3296 | int bits = instruction->GetResultType() == DataType::Type::kInt32 ? 32 : 64; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3297 | __ Asr(temp, dividend, bits - 1); |
| 3298 | __ Lsr(temp, temp, bits - ctz_imm); |
| 3299 | __ Add(out, dividend, temp); |
| 3300 | __ And(out, out, abs_imm - 1); |
| 3301 | __ Sub(out, out, temp); |
| 3302 | } |
| 3303 | } |
| 3304 | |
| 3305 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3306 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3307 | |
| 3308 | LocationSummary* locations = instruction->GetLocations(); |
| 3309 | Location second = locations->InAt(1); |
| 3310 | DCHECK(second.IsConstant()); |
| 3311 | |
| 3312 | Register out = OutputRegister(instruction); |
| 3313 | Register dividend = InputRegisterAt(instruction, 0); |
| 3314 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3315 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3316 | DataType::Type type = instruction->GetResultType(); |
| 3317 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3318 | |
| 3319 | int64_t magic; |
| 3320 | int shift; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3321 | CalculateMagicAndShiftForDivRem( |
| 3322 | imm, type == DataType::Type::kInt64 /* is_long */, &magic, &shift); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3323 | |
| 3324 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3325 | Register temp = temps.AcquireSameSizeAs(out); |
| 3326 | |
| 3327 | // temp = get_high(dividend * magic) |
| 3328 | __ Mov(temp, magic); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3329 | if (type == DataType::Type::kInt64) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3330 | __ Smulh(temp, dividend, temp); |
| 3331 | } else { |
| 3332 | __ Smull(temp.X(), dividend, temp); |
| 3333 | __ Lsr(temp.X(), temp.X(), 32); |
| 3334 | } |
| 3335 | |
| 3336 | if (imm > 0 && magic < 0) { |
| 3337 | __ Add(temp, temp, dividend); |
| 3338 | } else if (imm < 0 && magic > 0) { |
| 3339 | __ Sub(temp, temp, dividend); |
| 3340 | } |
| 3341 | |
| 3342 | if (shift != 0) { |
| 3343 | __ Asr(temp, temp, shift); |
| 3344 | } |
| 3345 | |
| 3346 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3347 | __ Sub(out, temp, Operand(temp, ASR, type == DataType::Type::kInt64 ? 63 : 31)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3348 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3349 | __ Sub(temp, temp, Operand(temp, ASR, type == DataType::Type::kInt64 ? 63 : 31)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3350 | // TODO: Strength reduction for msub. |
| 3351 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3352 | __ Mov(temp_imm, imm); |
| 3353 | __ Msub(out, temp, temp_imm, dividend); |
| 3354 | } |
| 3355 | } |
| 3356 | |
| 3357 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3358 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3359 | DataType::Type type = instruction->GetResultType(); |
| 3360 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3361 | |
| 3362 | LocationSummary* locations = instruction->GetLocations(); |
| 3363 | Register out = OutputRegister(instruction); |
| 3364 | Location second = locations->InAt(1); |
| 3365 | |
| 3366 | if (second.IsConstant()) { |
| 3367 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3368 | |
| 3369 | if (imm == 0) { |
| 3370 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3371 | } else if (imm == 1 || imm == -1) { |
| 3372 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3373 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3374 | DivRemByPowerOfTwo(instruction); |
| 3375 | } else { |
| 3376 | DCHECK(imm <= -2 || imm >= 2); |
| 3377 | GenerateDivRemWithAnyConstant(instruction); |
| 3378 | } |
| 3379 | } else { |
| 3380 | Register dividend = InputRegisterAt(instruction, 0); |
| 3381 | Register divisor = InputRegisterAt(instruction, 1); |
| 3382 | if (instruction->IsDiv()) { |
| 3383 | __ Sdiv(out, dividend, divisor); |
| 3384 | } else { |
| 3385 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3386 | Register temp = temps.AcquireSameSizeAs(out); |
| 3387 | __ Sdiv(temp, dividend, divisor); |
| 3388 | __ Msub(out, temp, divisor, dividend); |
| 3389 | } |
| 3390 | } |
| 3391 | } |
| 3392 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3393 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3394 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3395 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3396 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3397 | case DataType::Type::kInt32: |
| 3398 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3399 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3400 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3401 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3402 | break; |
| 3403 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3404 | case DataType::Type::kFloat32: |
| 3405 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3406 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3407 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3408 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3409 | break; |
| 3410 | |
| 3411 | default: |
| 3412 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3413 | } |
| 3414 | } |
| 3415 | |
| 3416 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3417 | DataType::Type type = div->GetResultType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3418 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3419 | case DataType::Type::kInt32: |
| 3420 | case DataType::Type::kInt64: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3421 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3422 | break; |
| 3423 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3424 | case DataType::Type::kFloat32: |
| 3425 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3426 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3427 | break; |
| 3428 | |
| 3429 | default: |
| 3430 | LOG(FATAL) << "Unexpected div type " << type; |
| 3431 | } |
| 3432 | } |
| 3433 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3434 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3435 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3436 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3440 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3441 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3442 | codegen_->AddSlowPath(slow_path); |
| 3443 | Location value = instruction->GetLocations()->InAt(0); |
| 3444 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3445 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3446 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3447 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3448 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3449 | return; |
| 3450 | } |
| 3451 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3452 | if (value.IsConstant()) { |
| 3453 | int64_t divisor = Int64ConstantFrom(value); |
| 3454 | if (divisor == 0) { |
| 3455 | __ B(slow_path->GetEntryLabel()); |
| 3456 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3457 | // A division by a non-null constant is valid. We don't need to perform |
| 3458 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3459 | } |
| 3460 | } else { |
| 3461 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3462 | } |
| 3463 | } |
| 3464 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3465 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3466 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3467 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3468 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3469 | } |
| 3470 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3471 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3472 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3473 | // Will be generated at use site. |
| 3474 | } |
| 3475 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3476 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3477 | exit->SetLocations(nullptr); |
| 3478 | } |
| 3479 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3480 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3481 | } |
| 3482 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3483 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3484 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3485 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3486 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3487 | } |
| 3488 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3489 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3490 | // Will be generated at use site. |
| 3491 | } |
| 3492 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3493 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3494 | if (successor->IsExitBlock()) { |
| 3495 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3496 | return; // no code needed |
| 3497 | } |
| 3498 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3499 | HBasicBlock* block = got->GetBlock(); |
| 3500 | HInstruction* previous = got->GetPrevious(); |
| 3501 | HLoopInformation* info = block->GetLoopInformation(); |
| 3502 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3503 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3504 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3505 | return; |
| 3506 | } |
| 3507 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3508 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 3509 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3510 | } |
| 3511 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3512 | __ B(codegen_->GetLabelOf(successor)); |
| 3513 | } |
| 3514 | } |
| 3515 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3516 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3517 | got->SetLocations(nullptr); |
| 3518 | } |
| 3519 | |
| 3520 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3521 | HandleGoto(got, got->GetSuccessor()); |
| 3522 | } |
| 3523 | |
| 3524 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3525 | try_boundary->SetLocations(nullptr); |
| 3526 | } |
| 3527 | |
| 3528 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3529 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3530 | if (!successor->IsExitBlock()) { |
| 3531 | HandleGoto(try_boundary, successor); |
| 3532 | } |
| 3533 | } |
| 3534 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3535 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3536 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3537 | vixl::aarch64::Label* true_target, |
| 3538 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3539 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3540 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3541 | if (true_target == nullptr && false_target == nullptr) { |
| 3542 | // Nothing to do. The code always falls through. |
| 3543 | return; |
| 3544 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3545 | // Constant condition, statically compared against "true" (integer value 1). |
| 3546 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3547 | if (true_target != nullptr) { |
| 3548 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3549 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3550 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3551 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3552 | if (false_target != nullptr) { |
| 3553 | __ B(false_target); |
| 3554 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3555 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3556 | return; |
| 3557 | } |
| 3558 | |
| 3559 | // The following code generates these patterns: |
| 3560 | // (1) true_target == nullptr && false_target != nullptr |
| 3561 | // - opposite condition true => branch to false_target |
| 3562 | // (2) true_target != nullptr && false_target == nullptr |
| 3563 | // - condition true => branch to true_target |
| 3564 | // (3) true_target != nullptr && false_target != nullptr |
| 3565 | // - condition true => branch to true_target |
| 3566 | // - branch to false_target |
| 3567 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3568 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3569 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3570 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3571 | if (true_target == nullptr) { |
| 3572 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3573 | } else { |
| 3574 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3575 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3576 | } else { |
| 3577 | // The condition instruction has not been materialized, use its inputs as |
| 3578 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3579 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3580 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3581 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3582 | if (DataType::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3583 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3584 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3585 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3586 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3587 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3588 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3589 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3590 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3591 | // Integer cases. |
| 3592 | Register lhs = InputRegisterAt(condition, 0); |
| 3593 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3594 | |
| 3595 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3596 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3597 | if (true_target == nullptr) { |
| 3598 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3599 | non_fallthrough_target = false_target; |
| 3600 | } else { |
| 3601 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3602 | non_fallthrough_target = true_target; |
| 3603 | } |
| 3604 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3605 | 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] | 3606 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3607 | switch (arm64_cond) { |
| 3608 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3609 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3610 | break; |
| 3611 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3612 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3613 | break; |
| 3614 | case lt: |
| 3615 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3616 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3617 | break; |
| 3618 | case ge: |
| 3619 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3620 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3621 | break; |
| 3622 | default: |
| 3623 | // Without the `static_cast` the compiler throws an error for |
| 3624 | // `-Werror=sign-promo`. |
| 3625 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3626 | } |
| 3627 | } else { |
| 3628 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3629 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3630 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3631 | } |
| 3632 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3633 | |
| 3634 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3635 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3636 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3637 | __ B(false_target); |
| 3638 | } |
| 3639 | } |
| 3640 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3641 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3642 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3643 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3644 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3645 | } |
| 3646 | } |
| 3647 | |
| 3648 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3649 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3650 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3651 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3652 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3653 | true_target = nullptr; |
| 3654 | } |
| 3655 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3656 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3657 | false_target = nullptr; |
| 3658 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3659 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3663 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3664 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3665 | InvokeRuntimeCallingConvention calling_convention; |
| 3666 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3667 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3668 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3669 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3670 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3671 | } |
| 3672 | } |
| 3673 | |
| 3674 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3675 | SlowPathCodeARM64* slow_path = |
| 3676 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3677 | GenerateTestAndBranch(deoptimize, |
| 3678 | /* condition_input_index */ 0, |
| 3679 | slow_path->GetEntryLabel(), |
| 3680 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3681 | } |
| 3682 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3683 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3684 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3685 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3686 | locations->SetOut(Location::RequiresRegister()); |
| 3687 | } |
| 3688 | |
| 3689 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3690 | __ Ldr(OutputRegister(flag), |
| 3691 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3692 | } |
| 3693 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3694 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3695 | return condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3696 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3697 | } |
| 3698 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3699 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3700 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3701 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3702 | : ARM64Condition(cond); |
| 3703 | } |
| 3704 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3705 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3706 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3707 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3708 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3709 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3710 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3711 | } else { |
| 3712 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3713 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3714 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3715 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3716 | // Ask VIXL whether we should synthesize constants in registers. |
| 3717 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3718 | Operand true_op = is_true_value_constant ? |
| 3719 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3720 | Operand false_op = is_false_value_constant ? |
| 3721 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3722 | bool true_value_in_register = false; |
| 3723 | bool false_value_in_register = false; |
| 3724 | MacroAssembler::GetCselSynthesisInformation( |
| 3725 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3726 | true_value_in_register |= !is_true_value_constant; |
| 3727 | false_value_in_register |= !is_false_value_constant; |
| 3728 | |
| 3729 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3730 | : Location::ConstantLocation(cst_true_value)); |
| 3731 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3732 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3733 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3734 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3735 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3736 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3737 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3738 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3742 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3743 | Condition csel_cond; |
| 3744 | |
| 3745 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3746 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3747 | // Use the condition flags set by the previous instruction. |
| 3748 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3749 | } else { |
| 3750 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3751 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3752 | } |
| 3753 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3754 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3755 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3756 | } else { |
| 3757 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3758 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3759 | } |
| 3760 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3761 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3762 | __ Fcsel(OutputFPRegister(select), |
| 3763 | InputFPRegisterAt(select, 1), |
| 3764 | InputFPRegisterAt(select, 0), |
| 3765 | csel_cond); |
| 3766 | } else { |
| 3767 | __ Csel(OutputRegister(select), |
| 3768 | InputOperandAt(select, 1), |
| 3769 | InputOperandAt(select, 0), |
| 3770 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3771 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3772 | } |
| 3773 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3774 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3775 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3776 | } |
| 3777 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3778 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3779 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3780 | } |
| 3781 | |
| 3782 | void CodeGeneratorARM64::GenerateNop() { |
| 3783 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3784 | } |
| 3785 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3786 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3787 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3791 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3795 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3799 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3800 | } |
| 3801 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3802 | // Temp is used for read barrier. |
| 3803 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3804 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3805 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3806 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3807 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3808 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3809 | return 1; |
| 3810 | } |
| 3811 | return 0; |
| 3812 | } |
| 3813 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3814 | // 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] | 3815 | // interface pointer, one for loading the current interface. |
| 3816 | // The other checks have one temp for loading the object's class. |
| 3817 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3818 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3819 | return 3; |
| 3820 | } |
| 3821 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3822 | } |
| 3823 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3824 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3825 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3826 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3827 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3828 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3829 | case TypeCheckKind::kExactCheck: |
| 3830 | case TypeCheckKind::kAbstractClassCheck: |
| 3831 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3832 | case TypeCheckKind::kArrayObjectCheck: { |
| 3833 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 3834 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 3835 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3836 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3837 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3838 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3839 | case TypeCheckKind::kUnresolvedCheck: |
| 3840 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3841 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3842 | break; |
| 3843 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3844 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3845 | LocationSummary* locations = |
| 3846 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3847 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3848 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3849 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3850 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3851 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3852 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3853 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3854 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3855 | // Add temps if necessary for read barriers. |
| 3856 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3857 | } |
| 3858 | |
| 3859 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3860 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3861 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3862 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3863 | Register obj = InputRegisterAt(instruction, 0); |
| 3864 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3865 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3866 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3867 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3868 | DCHECK_LE(num_temps, 1u); |
| 3869 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3870 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3871 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3872 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3873 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3874 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3875 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3876 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3877 | |
| 3878 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3879 | // Avoid null check if we know `obj` is not null. |
| 3880 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3881 | __ Cbz(obj, &zero); |
| 3882 | } |
| 3883 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3884 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3885 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3886 | ReadBarrierOption read_barrier_option = |
| 3887 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3888 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3889 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3890 | out_loc, |
| 3891 | obj_loc, |
| 3892 | class_offset, |
| 3893 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3894 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3895 | __ Cmp(out, cls); |
| 3896 | __ Cset(out, eq); |
| 3897 | if (zero.IsLinked()) { |
| 3898 | __ B(&done); |
| 3899 | } |
| 3900 | break; |
| 3901 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3902 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3903 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3904 | ReadBarrierOption read_barrier_option = |
| 3905 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3906 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3907 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3908 | out_loc, |
| 3909 | obj_loc, |
| 3910 | class_offset, |
| 3911 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3912 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3913 | // If the class is abstract, we eagerly fetch the super class of the |
| 3914 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3915 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3916 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3917 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3918 | GenerateReferenceLoadOneRegister(instruction, |
| 3919 | out_loc, |
| 3920 | super_offset, |
| 3921 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3922 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3923 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3924 | __ Cbz(out, &done); |
| 3925 | __ Cmp(out, cls); |
| 3926 | __ B(ne, &loop); |
| 3927 | __ Mov(out, 1); |
| 3928 | if (zero.IsLinked()) { |
| 3929 | __ B(&done); |
| 3930 | } |
| 3931 | break; |
| 3932 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3933 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3934 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3935 | ReadBarrierOption read_barrier_option = |
| 3936 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3937 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3938 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3939 | out_loc, |
| 3940 | obj_loc, |
| 3941 | class_offset, |
| 3942 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3943 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3944 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3945 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3946 | __ Bind(&loop); |
| 3947 | __ Cmp(out, cls); |
| 3948 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3949 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3950 | GenerateReferenceLoadOneRegister(instruction, |
| 3951 | out_loc, |
| 3952 | super_offset, |
| 3953 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3954 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3955 | __ Cbnz(out, &loop); |
| 3956 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3957 | __ B(&done); |
| 3958 | __ Bind(&success); |
| 3959 | __ Mov(out, 1); |
| 3960 | if (zero.IsLinked()) { |
| 3961 | __ B(&done); |
| 3962 | } |
| 3963 | break; |
| 3964 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3965 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3966 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3967 | ReadBarrierOption read_barrier_option = |
| 3968 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3969 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3970 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3971 | out_loc, |
| 3972 | obj_loc, |
| 3973 | class_offset, |
| 3974 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3975 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3976 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3977 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3978 | __ Cmp(out, cls); |
| 3979 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3980 | // 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] | 3981 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3982 | GenerateReferenceLoadOneRegister(instruction, |
| 3983 | out_loc, |
| 3984 | component_offset, |
| 3985 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3986 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3987 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3988 | __ Cbz(out, &done); |
| 3989 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3990 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3991 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3992 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3993 | __ Mov(out, 1); |
| 3994 | __ B(&done); |
| 3995 | break; |
| 3996 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3997 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3998 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3999 | // No read barrier since the slow path will retry upon failure. |
| 4000 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4001 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4002 | out_loc, |
| 4003 | obj_loc, |
| 4004 | class_offset, |
| 4005 | maybe_temp_loc, |
| 4006 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4007 | __ Cmp(out, cls); |
| 4008 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4009 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4010 | instruction, /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4011 | codegen_->AddSlowPath(slow_path); |
| 4012 | __ B(ne, slow_path->GetEntryLabel()); |
| 4013 | __ Mov(out, 1); |
| 4014 | if (zero.IsLinked()) { |
| 4015 | __ B(&done); |
| 4016 | } |
| 4017 | break; |
| 4018 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4019 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4020 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4021 | case TypeCheckKind::kInterfaceCheck: { |
| 4022 | // Note that we indeed only call on slow path, but we always go |
| 4023 | // into the slow path for the unresolved and interface check |
| 4024 | // cases. |
| 4025 | // |
| 4026 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4027 | // entry point without resorting to a type checking slow path |
| 4028 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4029 | // require to assign fixed registers for the inputs of this |
| 4030 | // HInstanceOf instruction (following the runtime calling |
| 4031 | // convention), which might be cluttered by the potential first |
| 4032 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4033 | // |
| 4034 | // TODO: Introduce a new runtime entry point taking the object |
| 4035 | // to test (instead of its class) as argument, and let it deal |
| 4036 | // with the read barrier issues. This will let us refactor this |
| 4037 | // case of the `switch` code as it was previously (with a direct |
| 4038 | // call to the runtime not using a type checking slow path). |
| 4039 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4040 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4041 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4042 | instruction, /* is_fatal */ false); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4043 | codegen_->AddSlowPath(slow_path); |
| 4044 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4045 | if (zero.IsLinked()) { |
| 4046 | __ B(&done); |
| 4047 | } |
| 4048 | break; |
| 4049 | } |
| 4050 | } |
| 4051 | |
| 4052 | if (zero.IsLinked()) { |
| 4053 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4054 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4055 | } |
| 4056 | |
| 4057 | if (done.IsLinked()) { |
| 4058 | __ Bind(&done); |
| 4059 | } |
| 4060 | |
| 4061 | if (slow_path != nullptr) { |
| 4062 | __ Bind(slow_path->GetExitLabel()); |
| 4063 | } |
| 4064 | } |
| 4065 | |
| 4066 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4067 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4068 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4069 | LocationSummary* locations = |
| 4070 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4071 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4072 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4073 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4074 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4078 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4079 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4080 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4081 | Register obj = InputRegisterAt(instruction, 0); |
| 4082 | Register cls = InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4083 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4084 | DCHECK_GE(num_temps, 1u); |
| 4085 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4086 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4087 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4088 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4089 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4090 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4091 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4092 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4093 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4094 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4095 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4096 | const uint32_t object_array_data_offset = |
| 4097 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4098 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4099 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4100 | SlowPathCodeARM64* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4101 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4102 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4103 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4104 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4105 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4106 | // Avoid null check if we know obj is not null. |
| 4107 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4108 | __ Cbz(obj, &done); |
| 4109 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4110 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4111 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4112 | case TypeCheckKind::kExactCheck: |
| 4113 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4114 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4115 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4116 | temp_loc, |
| 4117 | obj_loc, |
| 4118 | class_offset, |
| 4119 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4120 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4121 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4122 | __ Cmp(temp, cls); |
| 4123 | // Jump to slow path for throwing the exception or doing a |
| 4124 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4125 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4126 | break; |
| 4127 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4128 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4129 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4130 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4131 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4132 | temp_loc, |
| 4133 | obj_loc, |
| 4134 | class_offset, |
| 4135 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4136 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4137 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4138 | // If the class is abstract, we eagerly fetch the super class of the |
| 4139 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4140 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4141 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4142 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4143 | GenerateReferenceLoadOneRegister(instruction, |
| 4144 | temp_loc, |
| 4145 | super_offset, |
| 4146 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4147 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4148 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4149 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4150 | // exception. |
| 4151 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4152 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4153 | __ Cmp(temp, cls); |
| 4154 | __ B(ne, &loop); |
| 4155 | break; |
| 4156 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4157 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4158 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4159 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4160 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4161 | temp_loc, |
| 4162 | obj_loc, |
| 4163 | class_offset, |
| 4164 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4165 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4166 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4167 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4168 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4169 | __ Bind(&loop); |
| 4170 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4171 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4172 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4173 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4174 | GenerateReferenceLoadOneRegister(instruction, |
| 4175 | temp_loc, |
| 4176 | super_offset, |
| 4177 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4178 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4179 | |
| 4180 | // If the class reference currently in `temp` is not null, jump |
| 4181 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4182 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4183 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4184 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4185 | break; |
| 4186 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4187 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4188 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4189 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4190 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4191 | temp_loc, |
| 4192 | obj_loc, |
| 4193 | class_offset, |
| 4194 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4195 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4196 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4197 | // Do an exact check. |
| 4198 | __ Cmp(temp, cls); |
| 4199 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4200 | |
| 4201 | // 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] | 4202 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4203 | GenerateReferenceLoadOneRegister(instruction, |
| 4204 | temp_loc, |
| 4205 | component_offset, |
| 4206 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4207 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4208 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4209 | // If the component type is null, jump to the slow path to throw the exception. |
| 4210 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4211 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4212 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4213 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4214 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4215 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4216 | break; |
| 4217 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4218 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4219 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4220 | // 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] | 4221 | // |
| 4222 | // We cannot directly call the CheckCast runtime entry point |
| 4223 | // without resorting to a type checking slow path here (i.e. by |
| 4224 | // calling InvokeRuntime directly), as it would require to |
| 4225 | // assign fixed registers for the inputs of this HInstanceOf |
| 4226 | // instruction (following the runtime calling convention), which |
| 4227 | // might be cluttered by the potential first read barrier |
| 4228 | // emission at the beginning of this method. |
| 4229 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4230 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4231 | case TypeCheckKind::kInterfaceCheck: { |
| 4232 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4233 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4234 | temp_loc, |
| 4235 | obj_loc, |
| 4236 | class_offset, |
| 4237 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4238 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4239 | |
| 4240 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4241 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4242 | temp_loc, |
| 4243 | temp_loc, |
| 4244 | iftable_offset, |
| 4245 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4246 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4247 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4248 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4249 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4250 | vixl::aarch64::Label start_loop; |
| 4251 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4252 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4253 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4254 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4255 | // Go to next interface. |
| 4256 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4257 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4258 | // Compare the classes and continue the loop if they do not match. |
| 4259 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4260 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4261 | break; |
| 4262 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4263 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4264 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4265 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4266 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4267 | } |
| 4268 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4269 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4270 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4271 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4272 | } |
| 4273 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4274 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4275 | // Will be generated at use site. |
| 4276 | } |
| 4277 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4278 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4279 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4280 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4281 | } |
| 4282 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4283 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4284 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4285 | } |
| 4286 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4287 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4288 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4289 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4290 | // the method_idx. |
| 4291 | HandleInvoke(invoke); |
| 4292 | } |
| 4293 | |
| 4294 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4295 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4296 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4297 | } |
| 4298 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4299 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4300 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4301 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4302 | } |
| 4303 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4304 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4305 | HandleInvoke(invoke); |
| 4306 | } |
| 4307 | |
| 4308 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4309 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4310 | LocationSummary* locations = invoke->GetLocations(); |
| 4311 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4312 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4313 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4314 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4315 | |
| 4316 | // The register ip1 is required to be used for the hidden argument in |
| 4317 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4318 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4319 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4320 | scratch_scope.Exclude(ip1); |
| 4321 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4322 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4323 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4324 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4325 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4326 | { |
| 4327 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4328 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4329 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4330 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4331 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4332 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4333 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4334 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4335 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4336 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4337 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4338 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4339 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4340 | // emit a read barrier for the previous class reference load. |
| 4341 | // However this is not required in practice, as this is an |
| 4342 | // intermediate/temporary reference and because the current |
| 4343 | // concurrent copying collector keeps the from-space memory |
| 4344 | // intact/accessible until the end of the marking phase (the |
| 4345 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4346 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4347 | __ Ldr(temp, |
| 4348 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4349 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4350 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4351 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4352 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4353 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4354 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4355 | |
| 4356 | { |
| 4357 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4358 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4359 | |
| 4360 | // lr(); |
| 4361 | __ blr(lr); |
| 4362 | DCHECK(!codegen_->IsLeafMethod()); |
| 4363 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4364 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4365 | |
| 4366 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4367 | } |
| 4368 | |
| 4369 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4370 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4371 | if (intrinsic.TryDispatch(invoke)) { |
| 4372 | return; |
| 4373 | } |
| 4374 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4375 | HandleInvoke(invoke); |
| 4376 | } |
| 4377 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4378 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4379 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4380 | // art::PrepareForRegisterAllocation. |
| 4381 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4382 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4383 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4384 | if (intrinsic.TryDispatch(invoke)) { |
| 4385 | return; |
| 4386 | } |
| 4387 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4388 | HandleInvoke(invoke); |
| 4389 | } |
| 4390 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4391 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4392 | if (invoke->GetLocations()->Intrinsified()) { |
| 4393 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4394 | intrinsic.Dispatch(invoke); |
| 4395 | return true; |
| 4396 | } |
| 4397 | return false; |
| 4398 | } |
| 4399 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4400 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4401 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4402 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4403 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4404 | return desired_dispatch_info; |
| 4405 | } |
| 4406 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4407 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4408 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4409 | // 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] | 4410 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4411 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4412 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4413 | uint32_t offset = |
| 4414 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4415 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4416 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4417 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4418 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4419 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4420 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4421 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4422 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4423 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4424 | // Add ADRP with its PC-relative method patch. |
| 4425 | vixl::aarch64::Label* adrp_label = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 4426 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4427 | // Add ADD with its PC-relative method patch. |
| 4428 | vixl::aarch64::Label* add_label = |
| 4429 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), adrp_label); |
| 4430 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4431 | break; |
| 4432 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4433 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4434 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4435 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4436 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4437 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4438 | // Add ADRP with its PC-relative DexCache access patch. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4439 | MethodReference target_method(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4440 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(target_method); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4441 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4442 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4443 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4444 | NewMethodBssEntryPatch(target_method, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4445 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4446 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4447 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4448 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4449 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4450 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4451 | } |
| 4452 | } |
| 4453 | |
| 4454 | switch (invoke->GetCodePtrLocation()) { |
| 4455 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4456 | { |
| 4457 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4458 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4459 | kInstructionSize, |
| 4460 | CodeBufferCheckScope::kExactSize); |
| 4461 | __ bl(&frame_entry_label_); |
| 4462 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4463 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4464 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4465 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4466 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4467 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4468 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4469 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4470 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4471 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4472 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4473 | kInstructionSize, |
| 4474 | CodeBufferCheckScope::kExactSize); |
| 4475 | // lr() |
| 4476 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4477 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4478 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4479 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4480 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4481 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4482 | DCHECK(!IsLeafMethod()); |
| 4483 | } |
| 4484 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4485 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4486 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4487 | // Use the calling convention instead of the location of the receiver, as |
| 4488 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4489 | // slow path, the arguments have been moved to the right place, so here we are |
| 4490 | // guaranteed that the receiver is the first register of the calling convention. |
| 4491 | InvokeDexCallingConvention calling_convention; |
| 4492 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4493 | Register temp = XRegisterFrom(temp_in); |
| 4494 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4495 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4496 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4497 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4498 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4499 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4500 | |
| 4501 | { |
| 4502 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4503 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4504 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4505 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4506 | MaybeRecordImplicitNullCheck(invoke); |
| 4507 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4508 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4509 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4510 | // intermediate/temporary reference and because the current |
| 4511 | // concurrent copying collector keeps the from-space memory |
| 4512 | // intact/accessible until the end of the marking phase (the |
| 4513 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4514 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4515 | // temp = temp->GetMethodAt(method_offset); |
| 4516 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4517 | // lr = temp->GetEntryPoint(); |
| 4518 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4519 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4520 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4521 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4522 | // lr(); |
| 4523 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4524 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4525 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4526 | } |
| 4527 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4528 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4529 | HandleInvoke(invoke); |
| 4530 | } |
| 4531 | |
| 4532 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4533 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4534 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4535 | } |
| 4536 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4537 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeMethodPatch( |
| 4538 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4539 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4540 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4541 | target_method.index, |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4542 | adrp_label, |
| 4543 | &pc_relative_method_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4544 | } |
| 4545 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4546 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4547 | MethodReference target_method, |
| 4548 | vixl::aarch64::Label* adrp_label) { |
| 4549 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4550 | target_method.index, |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4551 | adrp_label, |
| 4552 | &method_bss_entry_patches_); |
| 4553 | } |
| 4554 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4555 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 4556 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4557 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4558 | vixl::aarch64::Label* adrp_label) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4559 | 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] | 4560 | } |
| 4561 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4562 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4563 | const DexFile& dex_file, |
| 4564 | dex::TypeIndex type_index, |
| 4565 | vixl::aarch64::Label* adrp_label) { |
| 4566 | return NewPcRelativePatch(dex_file, type_index.index_, adrp_label, &type_bss_entry_patches_); |
| 4567 | } |
| 4568 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4569 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 4570 | const DexFile& dex_file, |
| 4571 | dex::StringIndex string_index, |
| 4572 | vixl::aarch64::Label* adrp_label) { |
| 4573 | return |
| 4574 | NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &pc_relative_string_patches_); |
| 4575 | } |
| 4576 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4577 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4578 | const DexFile& dex_file, |
| 4579 | dex::StringIndex string_index, |
| 4580 | vixl::aarch64::Label* adrp_label) { |
| 4581 | return NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &string_bss_entry_patches_); |
| 4582 | } |
| 4583 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4584 | vixl::aarch64::Label* CodeGeneratorARM64::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 4585 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4586 | return &baker_read_barrier_patches_.back().label; |
| 4587 | } |
| 4588 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4589 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 4590 | const DexFile& dex_file, |
| 4591 | uint32_t offset_or_index, |
| 4592 | vixl::aarch64::Label* adrp_label, |
| 4593 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4594 | // Add a patch entry and return the label. |
| 4595 | patches->emplace_back(dex_file, offset_or_index); |
| 4596 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4597 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4598 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4599 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4600 | return label; |
| 4601 | } |
| 4602 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4603 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4604 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4605 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4606 | } |
| 4607 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4608 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4609 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4610 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4611 | return jit_string_patches_.GetOrCreate( |
| 4612 | StringReference(&dex_file, string_index), |
| 4613 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4614 | } |
| 4615 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4616 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4617 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4618 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4619 | return jit_class_patches_.GetOrCreate( |
| 4620 | TypeReference(&dex_file, type_index), |
| 4621 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4622 | } |
| 4623 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4624 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4625 | vixl::aarch64::Register reg) { |
| 4626 | DCHECK(reg.IsX()); |
| 4627 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4628 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4629 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4633 | vixl::aarch64::Register out, |
| 4634 | vixl::aarch64::Register base) { |
| 4635 | DCHECK(out.IsX()); |
| 4636 | DCHECK(base.IsX()); |
| 4637 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4638 | __ Bind(fixup_label); |
| 4639 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4640 | } |
| 4641 | |
| 4642 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4643 | vixl::aarch64::Register out, |
| 4644 | vixl::aarch64::Register base) { |
| 4645 | DCHECK(base.IsX()); |
| 4646 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4647 | __ Bind(fixup_label); |
| 4648 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4649 | } |
| 4650 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4651 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4652 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4653 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4654 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4655 | for (const PcRelativePatchInfo& info : infos) { |
| 4656 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 4657 | &info.target_dex_file, |
| 4658 | info.pc_insn_label->GetLocation(), |
| 4659 | info.offset_or_index)); |
| 4660 | } |
| 4661 | } |
| 4662 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4663 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4664 | DCHECK(linker_patches->empty()); |
| 4665 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4666 | pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4667 | method_bss_entry_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4668 | pc_relative_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4669 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4670 | pc_relative_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4671 | string_bss_entry_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4672 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4673 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4674 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4675 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 4676 | pc_relative_method_patches_, linker_patches); |
| 4677 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 4678 | pc_relative_type_patches_, linker_patches); |
| 4679 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 4680 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4681 | } else { |
| 4682 | DCHECK(pc_relative_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4683 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 4684 | pc_relative_type_patches_, linker_patches); |
| 4685 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 4686 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4687 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4688 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4689 | method_bss_entry_patches_, linker_patches); |
| 4690 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4691 | type_bss_entry_patches_, linker_patches); |
| 4692 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4693 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4694 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4695 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 4696 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4697 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4698 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4699 | } |
| 4700 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4701 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4702 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4703 | value, |
| 4704 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4705 | } |
| 4706 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4707 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4708 | return uint64_literals_.GetOrCreate( |
| 4709 | value, |
| 4710 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4711 | } |
| 4712 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4713 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4714 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4715 | // art::PrepareForRegisterAllocation. |
| 4716 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4717 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4718 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4719 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4720 | return; |
| 4721 | } |
| 4722 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4723 | { |
| 4724 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4725 | // are no pools emitted. |
| 4726 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4727 | LocationSummary* locations = invoke->GetLocations(); |
| 4728 | codegen_->GenerateStaticOrDirectCall( |
| 4729 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| 4730 | } |
| 4731 | |
| 4732 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4736 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4737 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4738 | return; |
| 4739 | } |
| 4740 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4741 | { |
| 4742 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4743 | // are no pools emitted. |
| 4744 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4745 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 4746 | DCHECK(!codegen_->IsLeafMethod()); |
| 4747 | } |
| 4748 | |
| 4749 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4750 | } |
| 4751 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4752 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4753 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4754 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4755 | case HLoadClass::LoadKind::kInvalid: |
| 4756 | LOG(FATAL) << "UNREACHABLE"; |
| 4757 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4758 | case HLoadClass::LoadKind::kReferrersClass: |
| 4759 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4760 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4761 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4762 | case HLoadClass::LoadKind::kBssEntry: |
| 4763 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4764 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4765 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4766 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4767 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4768 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4769 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4770 | break; |
| 4771 | } |
| 4772 | return desired_class_load_kind; |
| 4773 | } |
| 4774 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4775 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4776 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4777 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4778 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4779 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4780 | cls, |
| 4781 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4782 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4783 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4784 | return; |
| 4785 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4786 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4787 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4788 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4789 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4790 | ? LocationSummary::kCallOnSlowPath |
| 4791 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4792 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4793 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4794 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4795 | } |
| 4796 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4797 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4798 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4799 | } |
| 4800 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4801 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 4802 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4803 | // Rely on the type resolution or initialization and marking to save everything we need. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4804 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4805 | InvokeRuntimeCallingConvention calling_convention; |
| 4806 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4807 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4808 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 4809 | DataType::Type::kReference).GetCode()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4810 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4811 | } else { |
| 4812 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4813 | } |
| 4814 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4815 | } |
| 4816 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4817 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4818 | // move. |
| 4819 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4820 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4821 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4822 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4823 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4824 | return; |
| 4825 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4826 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4827 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4828 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4829 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4830 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4831 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4832 | ? kWithoutReadBarrier |
| 4833 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4834 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4835 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4836 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4837 | DCHECK(!cls->CanCallRuntime()); |
| 4838 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4839 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4840 | Register current_method = InputRegisterAt(cls, 0); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4841 | GenerateGcRootFieldLoad(cls, |
| 4842 | out_loc, |
| 4843 | current_method, |
| 4844 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4845 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4846 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4847 | break; |
| 4848 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4849 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4850 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4851 | // Add ADRP with its PC-relative type patch. |
| 4852 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4853 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4854 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4855 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4856 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4857 | vixl::aarch64::Label* add_label = |
| 4858 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4859 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4860 | break; |
| 4861 | } |
| 4862 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4863 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4864 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 4865 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 4866 | DCHECK_NE(address, 0u); |
| 4867 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4868 | break; |
| 4869 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4870 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 4871 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 4872 | // Add ADRP with its PC-relative type patch. |
| 4873 | const DexFile& dex_file = cls->GetDexFile(); |
| 4874 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
| 4875 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
| 4876 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| 4877 | // Add LDR with its PC-relative type patch. |
| 4878 | vixl::aarch64::Label* ldr_label = |
| 4879 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
| 4880 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 4881 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 4882 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 4883 | ComputeModifiedUtf8Hash(dex_file.StringByTypeIdx(type_index))); |
| 4884 | if (masked_hash != 0) { |
| 4885 | __ Sub(out.W(), out.W(), Operand(masked_hash)); |
| 4886 | } |
| 4887 | break; |
| 4888 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4889 | case HLoadClass::LoadKind::kBssEntry: { |
| 4890 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 4891 | const DexFile& dex_file = cls->GetDexFile(); |
| 4892 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 4893 | vixl::aarch64::Register temp = XRegisterFrom(out_loc); |
| 4894 | vixl::aarch64::Label* adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 4895 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4896 | // Add LDR with its PC-relative Class patch. |
| 4897 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 4898 | codegen_->NewBssEntryTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4899 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 4900 | GenerateGcRootFieldLoad(cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4901 | out_loc, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 4902 | temp, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4903 | /* offset placeholder */ 0u, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4904 | ldr_label, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4905 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4906 | generate_null_check = true; |
| 4907 | break; |
| 4908 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4909 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 4910 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 4911 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4912 | cls->GetClass())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4913 | GenerateGcRootFieldLoad(cls, |
| 4914 | out_loc, |
| 4915 | out.X(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4916 | /* offset */ 0, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4917 | /* fixup_label */ nullptr, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4918 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4919 | break; |
| 4920 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4921 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4922 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4923 | LOG(FATAL) << "UNREACHABLE"; |
| 4924 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4925 | } |
| 4926 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4927 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 4928 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4929 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4930 | SlowPathCodeARM64* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64( |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 4931 | cls, cls, cls->GetDexPc(), do_clinit); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4932 | codegen_->AddSlowPath(slow_path); |
| 4933 | if (generate_null_check) { |
| 4934 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4935 | } |
| 4936 | if (cls->MustGenerateClinitCheck()) { |
| 4937 | GenerateClassInitializationCheck(slow_path, out); |
| 4938 | } else { |
| 4939 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4940 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4941 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4942 | } |
| 4943 | } |
| 4944 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4945 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4946 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4947 | } |
| 4948 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4949 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 4950 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4951 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4952 | locations->SetOut(Location::RequiresRegister()); |
| 4953 | } |
| 4954 | |
| 4955 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4956 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 4957 | } |
| 4958 | |
| 4959 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4960 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4961 | } |
| 4962 | |
| 4963 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4964 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4965 | } |
| 4966 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4967 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 4968 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4969 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4970 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4971 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4972 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4973 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4974 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4975 | case HLoadString::LoadKind::kJitTableAddress: |
| 4976 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4977 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4978 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4979 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4980 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4981 | } |
| 4982 | return desired_string_load_kind; |
| 4983 | } |
| 4984 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4985 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4986 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4987 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4988 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4989 | InvokeRuntimeCallingConvention calling_convention; |
| 4990 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 4991 | } else { |
| 4992 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4993 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 4994 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4995 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4996 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4997 | InvokeRuntimeCallingConvention calling_convention; |
| 4998 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4999 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5000 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 5001 | DataType::Type::kReference).GetCode()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5002 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5003 | } else { |
| 5004 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5005 | } |
| 5006 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5007 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5008 | } |
| 5009 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5010 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5011 | // move. |
| 5012 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5013 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5014 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5015 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5016 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5017 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5018 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5019 | // Add ADRP with its PC-relative String patch. |
| 5020 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5021 | const dex::StringIndex string_index = load->GetStringIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5022 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5023 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5024 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5025 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5026 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5027 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5028 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5029 | } |
| 5030 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5031 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5032 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5033 | DCHECK_NE(address, 0u); |
| 5034 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5035 | return; |
| 5036 | } |
| 5037 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 5038 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5039 | // Add ADRP with its PC-relative String patch. |
| 5040 | const DexFile& dex_file = load->GetDexFile(); |
| 5041 | const dex::StringIndex string_index = load->GetStringIndex(); |
| 5042 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
| 5043 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| 5044 | // Add LDR with its PC-relative String patch. |
| 5045 | vixl::aarch64::Label* ldr_label = |
| 5046 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
| 5047 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 5048 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5049 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5050 | case HLoadString::LoadKind::kBssEntry: { |
| 5051 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5052 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5053 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5054 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5055 | Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5056 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5057 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5058 | // Add LDR with its .bss entry String patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5059 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5060 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5061 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5062 | GenerateGcRootFieldLoad(load, |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5063 | out_loc, |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5064 | temp, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5065 | /* offset placeholder */ 0u, |
| 5066 | ldr_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5067 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5068 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5069 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5070 | codegen_->AddSlowPath(slow_path); |
| 5071 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5072 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5073 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5074 | return; |
| 5075 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5076 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5077 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5078 | load->GetStringIndex(), |
| 5079 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5080 | GenerateGcRootFieldLoad(load, |
| 5081 | out_loc, |
| 5082 | out.X(), |
| 5083 | /* offset */ 0, |
| 5084 | /* fixup_label */ nullptr, |
| 5085 | kCompilerReadBarrierOption); |
| 5086 | return; |
| 5087 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5088 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5089 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5090 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5091 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5092 | // 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] | 5093 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5094 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5095 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5096 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5097 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5098 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5099 | } |
| 5100 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5101 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5102 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5103 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5104 | } |
| 5105 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5106 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5107 | // Will be generated at use site. |
| 5108 | } |
| 5109 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5110 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5111 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5112 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5113 | InvokeRuntimeCallingConvention calling_convention; |
| 5114 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5115 | } |
| 5116 | |
| 5117 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5118 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5119 | instruction, |
| 5120 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5121 | if (instruction->IsEnter()) { |
| 5122 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5123 | } else { |
| 5124 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5125 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5126 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5127 | } |
| 5128 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5129 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5130 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5131 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5132 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5133 | case DataType::Type::kInt32: |
| 5134 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5135 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5136 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5137 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5138 | break; |
| 5139 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5140 | case DataType::Type::kFloat32: |
| 5141 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5142 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5143 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5144 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5145 | break; |
| 5146 | |
| 5147 | default: |
| 5148 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5149 | } |
| 5150 | } |
| 5151 | |
| 5152 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5153 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5154 | case DataType::Type::kInt32: |
| 5155 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5156 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5157 | break; |
| 5158 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5159 | case DataType::Type::kFloat32: |
| 5160 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5161 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5162 | break; |
| 5163 | |
| 5164 | default: |
| 5165 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5166 | } |
| 5167 | } |
| 5168 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5169 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5170 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5171 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5172 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5173 | case DataType::Type::kInt32: |
| 5174 | case DataType::Type::kInt64: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5175 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5176 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5177 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5178 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5179 | case DataType::Type::kFloat32: |
| 5180 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5181 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5182 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5183 | break; |
| 5184 | |
| 5185 | default: |
| 5186 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5187 | } |
| 5188 | } |
| 5189 | |
| 5190 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5191 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5192 | case DataType::Type::kInt32: |
| 5193 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5194 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5195 | break; |
| 5196 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5197 | case DataType::Type::kFloat32: |
| 5198 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5199 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5200 | break; |
| 5201 | |
| 5202 | default: |
| 5203 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5204 | } |
| 5205 | } |
| 5206 | |
| 5207 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5208 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5209 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5210 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5211 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5212 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5213 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5214 | } |
| 5215 | |
| 5216 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5217 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5218 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5219 | QuickEntrypointEnum entrypoint = |
| 5220 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5221 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5222 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5223 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5224 | } |
| 5225 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5226 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5227 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5228 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5229 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5230 | if (instruction->IsStringAlloc()) { |
| 5231 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 5232 | } else { |
| 5233 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5234 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5235 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5236 | } |
| 5237 | |
| 5238 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5239 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5240 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5241 | if (instruction->IsStringAlloc()) { |
| 5242 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5243 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5244 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5245 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 5246 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5247 | |
| 5248 | { |
| 5249 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 5250 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 5251 | kInstructionSize, |
| 5252 | CodeBufferCheckScope::kExactSize); |
| 5253 | __ blr(lr); |
| 5254 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5255 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5256 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5257 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5258 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5259 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5260 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5261 | } |
| 5262 | |
| 5263 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5264 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5265 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5266 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5267 | } |
| 5268 | |
| 5269 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5270 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5271 | case DataType::Type::kInt32: |
| 5272 | case DataType::Type::kInt64: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5273 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5274 | break; |
| 5275 | |
| 5276 | default: |
| 5277 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5278 | } |
| 5279 | } |
| 5280 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5281 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5282 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5283 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5284 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5285 | } |
| 5286 | |
| 5287 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5288 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5289 | } |
| 5290 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5291 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5292 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5293 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5294 | } |
| 5295 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5296 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5297 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5298 | return; |
| 5299 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5300 | { |
| 5301 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5302 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5303 | Location obj = instruction->GetLocations()->InAt(0); |
| 5304 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5305 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5306 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5307 | } |
| 5308 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5309 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5310 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5311 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5312 | |
| 5313 | LocationSummary* locations = instruction->GetLocations(); |
| 5314 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5315 | |
| 5316 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5317 | } |
| 5318 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5319 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5320 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5321 | } |
| 5322 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5323 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5324 | HandleBinaryOp(instruction); |
| 5325 | } |
| 5326 | |
| 5327 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5328 | HandleBinaryOp(instruction); |
| 5329 | } |
| 5330 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5331 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5332 | LOG(FATAL) << "Unreachable"; |
| 5333 | } |
| 5334 | |
| 5335 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5336 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5337 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5338 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5339 | // The back edge will generate the suspend check. |
| 5340 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5341 | } |
| 5342 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5343 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5344 | } |
| 5345 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5346 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5347 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5348 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5349 | if (location.IsStackSlot()) { |
| 5350 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5351 | } else if (location.IsDoubleStackSlot()) { |
| 5352 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5353 | } |
| 5354 | locations->SetOut(location); |
| 5355 | } |
| 5356 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5357 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5358 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5359 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5360 | } |
| 5361 | |
| 5362 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5363 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5364 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5365 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5369 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5370 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5371 | } |
| 5372 | |
| 5373 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5374 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5375 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5376 | locations->SetInAt(i, Location::Any()); |
| 5377 | } |
| 5378 | locations->SetOut(Location::Any()); |
| 5379 | } |
| 5380 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5381 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5382 | LOG(FATAL) << "Unreachable"; |
| 5383 | } |
| 5384 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5385 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5386 | DataType::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5387 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5388 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5389 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5390 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5391 | |
| 5392 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5393 | case DataType::Type::kInt32: |
| 5394 | case DataType::Type::kInt64: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5395 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5396 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5397 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5398 | break; |
| 5399 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5400 | case DataType::Type::kFloat32: |
| 5401 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5402 | InvokeRuntimeCallingConvention calling_convention; |
| 5403 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5404 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5405 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5406 | |
| 5407 | break; |
| 5408 | } |
| 5409 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5410 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5411 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5412 | } |
| 5413 | } |
| 5414 | |
| 5415 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5416 | DataType::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5417 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5418 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5419 | case DataType::Type::kInt32: |
| 5420 | case DataType::Type::kInt64: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5421 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5422 | break; |
| 5423 | } |
| 5424 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5425 | case DataType::Type::kFloat32: |
| 5426 | case DataType::Type::kFloat64: { |
| 5427 | QuickEntrypointEnum entrypoint = |
| 5428 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5429 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5430 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5431 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5432 | } else { |
| 5433 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5434 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5435 | break; |
| 5436 | } |
| 5437 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5438 | default: |
| 5439 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5440 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5441 | } |
| 5442 | } |
| 5443 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5444 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5445 | constructor_fence->SetLocations(nullptr); |
| 5446 | } |
| 5447 | |
| 5448 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5449 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5450 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5451 | } |
| 5452 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5453 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5454 | memory_barrier->SetLocations(nullptr); |
| 5455 | } |
| 5456 | |
| 5457 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5458 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5459 | } |
| 5460 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5461 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5462 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5463 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5464 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5465 | } |
| 5466 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5467 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5468 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5469 | } |
| 5470 | |
| 5471 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5472 | instruction->SetLocations(nullptr); |
| 5473 | } |
| 5474 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5475 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5476 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5477 | } |
| 5478 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5479 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5480 | HandleBinaryOp(ror); |
| 5481 | } |
| 5482 | |
| 5483 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5484 | HandleBinaryOp(ror); |
| 5485 | } |
| 5486 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5487 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5488 | HandleShift(shl); |
| 5489 | } |
| 5490 | |
| 5491 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5492 | HandleShift(shl); |
| 5493 | } |
| 5494 | |
| 5495 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5496 | HandleShift(shr); |
| 5497 | } |
| 5498 | |
| 5499 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5500 | HandleShift(shr); |
| 5501 | } |
| 5502 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5503 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5504 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5505 | } |
| 5506 | |
| 5507 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5508 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5509 | } |
| 5510 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5511 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5512 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5513 | } |
| 5514 | |
| 5515 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5516 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5517 | } |
| 5518 | |
| 5519 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5520 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5521 | } |
| 5522 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5523 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5524 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5525 | } |
| 5526 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5527 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5528 | HUnresolvedInstanceFieldGet* instruction) { |
| 5529 | FieldAccessCallingConventionARM64 calling_convention; |
| 5530 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5531 | instruction, instruction->GetFieldType(), calling_convention); |
| 5532 | } |
| 5533 | |
| 5534 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5535 | HUnresolvedInstanceFieldGet* instruction) { |
| 5536 | FieldAccessCallingConventionARM64 calling_convention; |
| 5537 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5538 | instruction->GetFieldType(), |
| 5539 | instruction->GetFieldIndex(), |
| 5540 | instruction->GetDexPc(), |
| 5541 | calling_convention); |
| 5542 | } |
| 5543 | |
| 5544 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5545 | HUnresolvedInstanceFieldSet* instruction) { |
| 5546 | FieldAccessCallingConventionARM64 calling_convention; |
| 5547 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5548 | instruction, instruction->GetFieldType(), calling_convention); |
| 5549 | } |
| 5550 | |
| 5551 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5552 | HUnresolvedInstanceFieldSet* instruction) { |
| 5553 | FieldAccessCallingConventionARM64 calling_convention; |
| 5554 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5555 | instruction->GetFieldType(), |
| 5556 | instruction->GetFieldIndex(), |
| 5557 | instruction->GetDexPc(), |
| 5558 | calling_convention); |
| 5559 | } |
| 5560 | |
| 5561 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5562 | HUnresolvedStaticFieldGet* instruction) { |
| 5563 | FieldAccessCallingConventionARM64 calling_convention; |
| 5564 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5565 | instruction, instruction->GetFieldType(), calling_convention); |
| 5566 | } |
| 5567 | |
| 5568 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5569 | HUnresolvedStaticFieldGet* instruction) { |
| 5570 | FieldAccessCallingConventionARM64 calling_convention; |
| 5571 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5572 | instruction->GetFieldType(), |
| 5573 | instruction->GetFieldIndex(), |
| 5574 | instruction->GetDexPc(), |
| 5575 | calling_convention); |
| 5576 | } |
| 5577 | |
| 5578 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5579 | HUnresolvedStaticFieldSet* instruction) { |
| 5580 | FieldAccessCallingConventionARM64 calling_convention; |
| 5581 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5582 | instruction, instruction->GetFieldType(), calling_convention); |
| 5583 | } |
| 5584 | |
| 5585 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5586 | HUnresolvedStaticFieldSet* instruction) { |
| 5587 | FieldAccessCallingConventionARM64 calling_convention; |
| 5588 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5589 | instruction->GetFieldType(), |
| 5590 | instruction->GetFieldIndex(), |
| 5591 | instruction->GetDexPc(), |
| 5592 | calling_convention); |
| 5593 | } |
| 5594 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5595 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5596 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5597 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5598 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5599 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5600 | // registers in full width (since the runtime only saves/restores lower part). |
| 5601 | locations->SetCustomSlowPathCallerSaves( |
| 5602 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5606 | HBasicBlock* block = instruction->GetBlock(); |
| 5607 | if (block->GetLoopInformation() != nullptr) { |
| 5608 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5609 | // The back edge will generate the suspend check. |
| 5610 | return; |
| 5611 | } |
| 5612 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5613 | // The goto will generate the suspend check. |
| 5614 | return; |
| 5615 | } |
| 5616 | GenerateSuspendCheck(instruction, nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5617 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5618 | } |
| 5619 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5620 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5621 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5622 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5623 | InvokeRuntimeCallingConvention calling_convention; |
| 5624 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5625 | } |
| 5626 | |
| 5627 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5628 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5629 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5630 | } |
| 5631 | |
| 5632 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5633 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5634 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5635 | DataType::Type input_type = conversion->GetInputType(); |
| 5636 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5637 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5638 | << input_type << " -> " << result_type; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5639 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 5640 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5641 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5642 | } |
| 5643 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5644 | if (DataType::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5645 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5646 | } else { |
| 5647 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5648 | } |
| 5649 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5650 | if (DataType::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5651 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5652 | } else { |
| 5653 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5654 | } |
| 5655 | } |
| 5656 | |
| 5657 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5658 | DataType::Type result_type = conversion->GetResultType(); |
| 5659 | DataType::Type input_type = conversion->GetInputType(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5660 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5661 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5662 | << input_type << " -> " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5663 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5664 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 5665 | int result_size = DataType::Size(result_type); |
| 5666 | int input_size = DataType::Size(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5667 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5668 | Register output = OutputRegister(conversion); |
| 5669 | Register source = InputRegisterAt(conversion, 0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5670 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5671 | // 'int' values are used directly as W registers, discarding the top |
| 5672 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5673 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5674 | // top 32 bits of the target register. We theoretically could leave those |
| 5675 | // bits unchanged, but we would have to make sure that no code uses a |
| 5676 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5677 | // zero. |
| 5678 | __ Mov(output.W(), source.W()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5679 | } else if (DataType::IsUnsignedType(result_type) || |
| 5680 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 5681 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5682 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5683 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5684 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5685 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5686 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5687 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 5688 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5689 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5690 | } else if (DataType::IsFloatingPointType(result_type) && |
| 5691 | DataType::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5692 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5693 | } else { |
| 5694 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5695 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5696 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5697 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5698 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5699 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5700 | HandleShift(ushr); |
| 5701 | } |
| 5702 | |
| 5703 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5704 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5705 | } |
| 5706 | |
| 5707 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5708 | HandleBinaryOp(instruction); |
| 5709 | } |
| 5710 | |
| 5711 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5712 | HandleBinaryOp(instruction); |
| 5713 | } |
| 5714 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5715 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5716 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5717 | LOG(FATAL) << "Unreachable"; |
| 5718 | } |
| 5719 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5720 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5721 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5722 | LOG(FATAL) << "Unreachable"; |
| 5723 | } |
| 5724 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5725 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5726 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5727 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5728 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5729 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5730 | } |
| 5731 | |
| 5732 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5733 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5734 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5735 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5736 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5737 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5738 | // 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] | 5739 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5740 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5741 | // make sure we don't emit it if the target may run out of range. |
| 5742 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5743 | // ranges and emit the tables only as required. |
| 5744 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5745 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5746 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5747 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5748 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5749 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5750 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5751 | Register temp = temps.AcquireW(); |
| 5752 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5753 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5754 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5755 | // Jump to successors[0] if value == lower_bound. |
| 5756 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5757 | int32_t last_index = 0; |
| 5758 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5759 | __ Subs(temp, temp, Operand(2)); |
| 5760 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5761 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5762 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5763 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5764 | } |
| 5765 | if (num_entries - last_index == 2) { |
| 5766 | // The last missing case_value. |
| 5767 | __ Cmp(temp, Operand(1)); |
| 5768 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5769 | } |
| 5770 | |
| 5771 | // And the default for any other value. |
| 5772 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5773 | __ B(codegen_->GetLabelOf(default_block)); |
| 5774 | } |
| 5775 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5776 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5777 | |
| 5778 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5779 | |
| 5780 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5781 | // registers, we are free to block one. |
| 5782 | Register temp_w = temps.AcquireW(); |
| 5783 | Register index; |
| 5784 | // Remove the bias. |
| 5785 | if (lower_bound != 0) { |
| 5786 | index = temp_w; |
| 5787 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5788 | } else { |
| 5789 | index = value_reg; |
| 5790 | } |
| 5791 | |
| 5792 | // Jump to default block if index is out of the range. |
| 5793 | __ Cmp(index, Operand(num_entries)); |
| 5794 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5795 | |
| 5796 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5797 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5798 | // register pressure. |
| 5799 | Register table_base = temps.AcquireX(); |
| 5800 | // Load jump offset from the table. |
| 5801 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5802 | Register jump_offset = temp_w; |
| 5803 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5804 | |
| 5805 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5806 | Register target_address = table_base; |
| 5807 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5808 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5809 | } |
| 5810 | } |
| 5811 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5812 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 5813 | HInstruction* instruction, |
| 5814 | Location out, |
| 5815 | uint32_t offset, |
| 5816 | Location maybe_temp, |
| 5817 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5818 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5819 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5820 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5821 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5822 | if (kUseBakerReadBarrier) { |
| 5823 | // Load with fast path based Baker's read barrier. |
| 5824 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5825 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5826 | out, |
| 5827 | out_reg, |
| 5828 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5829 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5830 | /* needs_null_check */ false, |
| 5831 | /* use_load_acquire */ false); |
| 5832 | } else { |
| 5833 | // Load with slow path based read barrier. |
| 5834 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5835 | // in the following move operation, as we will need it for the |
| 5836 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5837 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5838 | __ Mov(temp_reg, out_reg); |
| 5839 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5840 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5841 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5842 | } |
| 5843 | } else { |
| 5844 | // Plain load with no read barrier. |
| 5845 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5846 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5847 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5848 | } |
| 5849 | } |
| 5850 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5851 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 5852 | HInstruction* instruction, |
| 5853 | Location out, |
| 5854 | Location obj, |
| 5855 | uint32_t offset, |
| 5856 | Location maybe_temp, |
| 5857 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5858 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5859 | Register out_reg = RegisterFrom(out, type); |
| 5860 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5861 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5862 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5863 | if (kUseBakerReadBarrier) { |
| 5864 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5865 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5866 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5867 | out, |
| 5868 | obj_reg, |
| 5869 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5870 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5871 | /* needs_null_check */ false, |
| 5872 | /* use_load_acquire */ false); |
| 5873 | } else { |
| 5874 | // Load with slow path based read barrier. |
| 5875 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5876 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5877 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5878 | } |
| 5879 | } else { |
| 5880 | // Plain load with no read barrier. |
| 5881 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5882 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5883 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5884 | } |
| 5885 | } |
| 5886 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5887 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad( |
| 5888 | HInstruction* instruction, |
| 5889 | Location root, |
| 5890 | Register obj, |
| 5891 | uint32_t offset, |
| 5892 | vixl::aarch64::Label* fixup_label, |
| 5893 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5894 | DCHECK(fixup_label == nullptr || offset == 0u); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5895 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5896 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5897 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5898 | if (kUseBakerReadBarrier) { |
| 5899 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5900 | // Baker's read barrier are used. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5901 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 5902 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 5903 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 5904 | // the Marking Register) to decide whether we need to enter |
| 5905 | // the slow path to mark the GC root. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5906 | // |
| 5907 | // We use link-time generated thunks for the slow path. That thunk |
| 5908 | // checks the reference and jumps to the entrypoint if needed. |
| 5909 | // |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5910 | // lr = &return_address; |
| 5911 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 5912 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 5913 | // goto gc_root_thunk<root_reg>(lr) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5914 | // } |
| 5915 | // return_address: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5916 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5917 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5918 | DCHECK(temps.IsAvailable(ip0)); |
| 5919 | DCHECK(temps.IsAvailable(ip1)); |
| 5920 | temps.Exclude(ip0, ip1); |
| 5921 | uint32_t custom_data = |
| 5922 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
| 5923 | vixl::aarch64::Label* cbnz_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5924 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5925 | EmissionCheckScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 5926 | vixl::aarch64::Label return_address; |
| 5927 | __ adr(lr, &return_address); |
| 5928 | if (fixup_label != nullptr) { |
| 5929 | __ Bind(fixup_label); |
| 5930 | } |
| 5931 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 5932 | "GC root LDR must be 2 instruction (8B) before the return address label."); |
| 5933 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 5934 | __ Bind(cbnz_label); |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 5935 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5936 | __ Bind(&return_address); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5937 | } else { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 5938 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 5939 | // the Marking Register) to decide whether we need to enter |
| 5940 | // the slow path to mark the GC root. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5941 | // |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5942 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 5943 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5944 | // // Slow path. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 5945 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5946 | // root = entrypoint(root); // root = ReadBarrier::Mark(root); // Entry point call. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5947 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5948 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 5949 | // Slow path marking the GC root `root`. The entrypoint will |
| 5950 | // be loaded by the slow path code. |
| 5951 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5952 | new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathARM64(instruction, root); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5953 | codegen_->AddSlowPath(slow_path); |
| 5954 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5955 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 5956 | if (fixup_label == nullptr) { |
| 5957 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5958 | } else { |
| 5959 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
| 5960 | } |
| 5961 | static_assert( |
| 5962 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 5963 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 5964 | "have different sizes."); |
| 5965 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 5966 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 5967 | "have different sizes."); |
| 5968 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 5969 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5970 | __ Bind(slow_path->GetExitLabel()); |
| 5971 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5972 | } else { |
| 5973 | // GC root loaded through a slow path for read barriers other |
| 5974 | // than Baker's. |
| 5975 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5976 | if (fixup_label == nullptr) { |
| 5977 | __ Add(root_reg.X(), obj.X(), offset); |
| 5978 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5979 | codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5980 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5981 | // /* mirror::Object* */ root = root->Read() |
| 5982 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 5983 | } |
| 5984 | } else { |
| 5985 | // Plain GC root load with no read barrier. |
| 5986 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5987 | if (fixup_label == nullptr) { |
| 5988 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5989 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5990 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5991 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5992 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5993 | // do not have to unpoison `root_reg` here. |
| 5994 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5995 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5996 | } |
| 5997 | |
| 5998 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5999 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6000 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6001 | uint32_t offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6002 | Location maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6003 | bool needs_null_check, |
| 6004 | bool use_load_acquire) { |
| 6005 | DCHECK(kEmitCompilerReadBarrier); |
| 6006 | DCHECK(kUseBakerReadBarrier); |
| 6007 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6008 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6009 | !use_load_acquire && |
| 6010 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6011 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6012 | // Marking Register) to decide whether we need to enter the slow |
| 6013 | // path to mark the reference. Then, in the slow path, check the |
| 6014 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6015 | // decide whether to mark `ref` or not. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6016 | // |
| 6017 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6018 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6019 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6020 | // |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6021 | // lr = &gray_return_address; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6022 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6023 | // goto field_thunk<holder_reg, base_reg>(lr) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6024 | // } |
| 6025 | // not_gray_return_address: |
| 6026 | // // Original reference load. If the offset is too large to fit |
| 6027 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6028 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6029 | // gray_return_address: |
| 6030 | |
| 6031 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6032 | Register base = obj; |
| 6033 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6034 | DCHECK(maybe_temp.IsRegister()); |
| 6035 | base = WRegisterFrom(maybe_temp); |
| 6036 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6037 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6038 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 6039 | } |
| 6040 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6041 | DCHECK(temps.IsAvailable(ip0)); |
| 6042 | DCHECK(temps.IsAvailable(ip1)); |
| 6043 | temps.Exclude(ip0, ip1); |
| 6044 | uint32_t custom_data = linker::Arm64RelativePatcher::EncodeBakerReadBarrierFieldData( |
| 6045 | base.GetCode(), |
| 6046 | obj.GetCode()); |
| 6047 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6048 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6049 | { |
| 6050 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6051 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6052 | vixl::aarch64::Label return_address; |
| 6053 | __ adr(lr, &return_address); |
| 6054 | __ Bind(cbnz_label); |
| 6055 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6056 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6057 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6058 | " 2 instructions (8B) for heap poisoning."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6059 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6060 | __ ldr(ref_reg, MemOperand(base.X(), offset)); |
| 6061 | if (needs_null_check) { |
| 6062 | MaybeRecordImplicitNullCheck(instruction); |
| 6063 | } |
| 6064 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6065 | __ Bind(&return_address); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6066 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6067 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6068 | return; |
| 6069 | } |
| 6070 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6071 | // /* HeapReference<Object> */ ref = *(obj + offset) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6072 | Register temp = WRegisterFrom(maybe_temp); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6073 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6074 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6075 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6076 | ref, |
| 6077 | obj, |
| 6078 | offset, |
| 6079 | no_index, |
| 6080 | no_scale_factor, |
| 6081 | temp, |
| 6082 | needs_null_check, |
| 6083 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6084 | } |
| 6085 | |
| 6086 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6087 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6088 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6089 | uint32_t data_offset, |
| 6090 | Location index, |
| 6091 | Register temp, |
| 6092 | bool needs_null_check) { |
| 6093 | DCHECK(kEmitCompilerReadBarrier); |
| 6094 | DCHECK(kUseBakerReadBarrier); |
| 6095 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6096 | static_assert( |
| 6097 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6098 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6099 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6100 | |
| 6101 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6102 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6103 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6104 | // Marking Register) to decide whether we need to enter the slow |
| 6105 | // path to mark the reference. Then, in the slow path, check the |
| 6106 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6107 | // decide whether to mark `ref` or not. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6108 | // |
| 6109 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6110 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6111 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6112 | // |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6113 | // lr = &gray_return_address; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6114 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6115 | // goto array_thunk<base_reg>(lr) |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6116 | // } |
| 6117 | // not_gray_return_address: |
| 6118 | // // Original reference load. If the offset is too large to fit |
| 6119 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6120 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6121 | // gray_return_address: |
| 6122 | |
| 6123 | DCHECK(index.IsValid()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6124 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 6125 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6126 | |
| 6127 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6128 | DCHECK(temps.IsAvailable(ip0)); |
| 6129 | DCHECK(temps.IsAvailable(ip1)); |
| 6130 | temps.Exclude(ip0, ip1); |
| 6131 | uint32_t custom_data = |
| 6132 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierArrayData(temp.GetCode()); |
| 6133 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6134 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6135 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6136 | { |
| 6137 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6138 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6139 | vixl::aarch64::Label return_address; |
| 6140 | __ adr(lr, &return_address); |
| 6141 | __ Bind(cbnz_label); |
| 6142 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6143 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6144 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6145 | " 2 instructions (8B) for heap poisoning."); |
| 6146 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6147 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6148 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6149 | __ Bind(&return_address); |
| 6150 | } |
| 6151 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6152 | return; |
| 6153 | } |
| 6154 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6155 | // Array cells are never volatile variables, therefore array loads |
| 6156 | // never use Load-Acquire instructions on ARM64. |
| 6157 | const bool use_load_acquire = false; |
| 6158 | |
| 6159 | // /* HeapReference<Object> */ ref = |
| 6160 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6161 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6162 | ref, |
| 6163 | obj, |
| 6164 | data_offset, |
| 6165 | index, |
| 6166 | 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::GenerateReferenceLoadWithBakerReadBarrier(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 offset, |
| 6176 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6177 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6178 | Register temp, |
| 6179 | bool needs_null_check, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6180 | bool use_load_acquire) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6181 | DCHECK(kEmitCompilerReadBarrier); |
| 6182 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6183 | // If we are emitting an array load, we should not be using a |
| 6184 | // Load Acquire instruction. In other words: |
| 6185 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6186 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6187 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6188 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6189 | // Marking Register) to decide whether we need to enter the slow |
| 6190 | // path to mark the reference. Then, in the slow path, check the |
| 6191 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6192 | // decide whether to mark `ref` or not. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6193 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6194 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6195 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6196 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6197 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6198 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 6199 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6200 | // if (is_gray) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6201 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6202 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6203 | // } |
| 6204 | // } else { |
| 6205 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6206 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6207 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6208 | // Slow path marking the object `ref` when the GC is marking. The |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6209 | // entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6210 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6211 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierSlowPathARM64( |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6212 | instruction, |
| 6213 | ref, |
| 6214 | obj, |
| 6215 | offset, |
| 6216 | index, |
| 6217 | scale_factor, |
| 6218 | needs_null_check, |
| 6219 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6220 | temp); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6221 | AddSlowPath(slow_path); |
| 6222 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6223 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6224 | // Fast path: the GC is not marking: just load the reference. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6225 | GenerateRawReferenceLoad( |
| 6226 | 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] | 6227 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6228 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6229 | } |
| 6230 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6231 | void CodeGeneratorARM64::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 6232 | Location ref, |
| 6233 | Register obj, |
| 6234 | Location field_offset, |
| 6235 | Register temp, |
| 6236 | bool needs_null_check, |
| 6237 | bool use_load_acquire) { |
| 6238 | DCHECK(kEmitCompilerReadBarrier); |
| 6239 | DCHECK(kUseBakerReadBarrier); |
| 6240 | // If we are emitting an array load, we should not be using a |
| 6241 | // Load Acquire instruction. In other words: |
| 6242 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6243 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
| 6244 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6245 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6246 | // Marking Register) to decide whether we need to enter the slow |
| 6247 | // path to update the reference field within `obj`. Then, in the |
| 6248 | // slow path, check the gray bit in the lock word of the reference's |
| 6249 | // holder (`obj`) to decide whether to mark `ref` and update the |
| 6250 | // field or not. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6251 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6252 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6253 | // // Slow path. |
| 6254 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6255 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6256 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
| 6257 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6258 | // if (is_gray) { |
| 6259 | // old_ref = ref; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6260 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6261 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6262 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 6263 | // } |
| 6264 | // } |
| 6265 | |
| 6266 | // Slow path updating the object reference at address `obj + field_offset` |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6267 | // 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] | 6268 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6269 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6270 | instruction, |
| 6271 | ref, |
| 6272 | obj, |
| 6273 | /* offset */ 0u, |
| 6274 | /* index */ field_offset, |
| 6275 | /* scale_factor */ 0u /* "times 1" */, |
| 6276 | needs_null_check, |
| 6277 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6278 | temp); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6279 | AddSlowPath(slow_path); |
| 6280 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6281 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6282 | // Fast path: the GC is not marking: nothing to do (the field is |
| 6283 | // up-to-date, and we don't need to load the reference). |
| 6284 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6285 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6286 | } |
| 6287 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6288 | void CodeGeneratorARM64::GenerateRawReferenceLoad(HInstruction* instruction, |
| 6289 | Location ref, |
| 6290 | Register obj, |
| 6291 | uint32_t offset, |
| 6292 | Location index, |
| 6293 | size_t scale_factor, |
| 6294 | bool needs_null_check, |
| 6295 | bool use_load_acquire) { |
| 6296 | DCHECK(obj.IsW()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6297 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6298 | Register ref_reg = RegisterFrom(ref, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6299 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6300 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 6301 | // that no pools are emitted between the load (macro) instruction |
| 6302 | // and MaybeRecordImplicitNullCheck. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6303 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6304 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6305 | // Load types involving an "index": ArrayGet, |
| 6306 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6307 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6308 | if (use_load_acquire) { |
| 6309 | // UnsafeGetObjectVolatile intrinsic case. |
| 6310 | // Register `index` is not an index in an object array, but an |
| 6311 | // offset to an object reference field within object `obj`. |
| 6312 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 6313 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 6314 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 6315 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6316 | DCHECK_EQ(offset, 0u); |
| 6317 | DCHECK_EQ(scale_factor, 0u); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6318 | DCHECK_EQ(needs_null_check, false); |
| 6319 | // /* HeapReference<mirror::Object> */ ref = *(obj + index) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6320 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 6321 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6322 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6323 | // ArrayGet and UnsafeGetObject and UnsafeCASObject intrinsics cases. |
| 6324 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6325 | if (index.IsConstant()) { |
| 6326 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6327 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6328 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6329 | if (needs_null_check) { |
| 6330 | MaybeRecordImplicitNullCheck(instruction); |
| 6331 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6332 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6333 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6334 | Register temp = temps.AcquireW(); |
| 6335 | __ Add(temp, obj, offset); |
| 6336 | { |
| 6337 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6338 | Load(type, ref_reg, HeapOperand(temp, XRegisterFrom(index), LSL, scale_factor)); |
| 6339 | if (needs_null_check) { |
| 6340 | MaybeRecordImplicitNullCheck(instruction); |
| 6341 | } |
| 6342 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6343 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6344 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6345 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6346 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6347 | MemOperand field = HeapOperand(obj, offset); |
| 6348 | if (use_load_acquire) { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6349 | // Implicit null checks are handled by CodeGeneratorARM64::LoadAcquire. |
| 6350 | LoadAcquire(instruction, ref_reg, field, needs_null_check); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6351 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6352 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6353 | Load(type, ref_reg, field); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6354 | if (needs_null_check) { |
| 6355 | MaybeRecordImplicitNullCheck(instruction); |
| 6356 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6357 | } |
| 6358 | } |
| 6359 | |
| 6360 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6361 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6362 | } |
| 6363 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6364 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6365 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6366 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6367 | // The following condition is a run-time one; it is executed after the |
| 6368 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6369 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6370 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6371 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6372 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6373 | } |
| 6374 | } |
| 6375 | } |
| 6376 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6377 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6378 | Location out, |
| 6379 | Location ref, |
| 6380 | Location obj, |
| 6381 | uint32_t offset, |
| 6382 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6383 | DCHECK(kEmitCompilerReadBarrier); |
| 6384 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6385 | // Insert a slow path based read barrier *after* the reference load. |
| 6386 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6387 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6388 | // reference will be carried out by the runtime within the slow |
| 6389 | // path. |
| 6390 | // |
| 6391 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6392 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6393 | // not used by the artReadBarrierSlow entry point. |
| 6394 | // |
| 6395 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6396 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6397 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6398 | AddSlowPath(slow_path); |
| 6399 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6400 | __ B(slow_path->GetEntryLabel()); |
| 6401 | __ Bind(slow_path->GetExitLabel()); |
| 6402 | } |
| 6403 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6404 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6405 | Location out, |
| 6406 | Location ref, |
| 6407 | Location obj, |
| 6408 | uint32_t offset, |
| 6409 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6410 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6411 | // Baker's read barriers shall be handled by the fast path |
| 6412 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6413 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6414 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6415 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6416 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6417 | } else if (kPoisonHeapReferences) { |
| 6418 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6419 | } |
| 6420 | } |
| 6421 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6422 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6423 | Location out, |
| 6424 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6425 | DCHECK(kEmitCompilerReadBarrier); |
| 6426 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6427 | // Insert a slow path based read barrier *after* the GC root load. |
| 6428 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6429 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6430 | // not need to do anything special for this here. |
| 6431 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6432 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6433 | AddSlowPath(slow_path); |
| 6434 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6435 | __ B(slow_path->GetEntryLabel()); |
| 6436 | __ Bind(slow_path->GetExitLabel()); |
| 6437 | } |
| 6438 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6439 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6440 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6441 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6442 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6443 | locations->SetOut(Location::RequiresRegister()); |
| 6444 | } |
| 6445 | |
| 6446 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6447 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6448 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6449 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6450 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6451 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6452 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6453 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6454 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6455 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6456 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6457 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6458 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6459 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6460 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6461 | } |
| 6462 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6463 | static void PatchJitRootUse(uint8_t* code, |
| 6464 | const uint8_t* roots_data, |
| 6465 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6466 | uint64_t index_in_table) { |
| 6467 | uint32_t literal_offset = literal->GetOffset(); |
| 6468 | uintptr_t address = |
| 6469 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6470 | uint8_t* data = code + literal_offset; |
| 6471 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6472 | } |
| 6473 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6474 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6475 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6476 | const StringReference& string_reference = entry.first; |
| 6477 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6478 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6479 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6480 | } |
| 6481 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6482 | const TypeReference& type_reference = entry.first; |
| 6483 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6484 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6485 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6486 | } |
| 6487 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6488 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6489 | #undef __ |
| 6490 | #undef QUICK_ENTRY_POINT |
| 6491 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6492 | } // namespace arm64 |
| 6493 | } // namespace art |