Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm64.h" |
| 18 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 19 | #include "arch/arm64/asm_support_arm64.h" |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 20 | #include "arch/arm64/instruction_set_features_arm64.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 21 | #include "art_method.h" |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 22 | #include "base/bit_utils.h" |
| 23 | #include "base/bit_utils_iterator.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 24 | #include "class_table.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 25 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 26 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 27 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 28 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 29 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 30 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 31 | #include "heap_poisoning.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 32 | #include "intrinsics.h" |
| 33 | #include "intrinsics_arm64.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 34 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 35 | #include "lock_word.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 36 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 37 | #include "mirror/class-inl.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 38 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 39 | #include "thread.h" |
| 40 | #include "utils/arm64/assembler_arm64.h" |
| 41 | #include "utils/assembler.h" |
| 42 | #include "utils/stack_checks.h" |
| 43 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 44 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 45 | using vixl::ExactAssemblyScope; |
| 46 | using vixl::CodeBufferCheckScope; |
| 47 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 48 | |
| 49 | #ifdef __ |
| 50 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 51 | #endif |
| 52 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 53 | namespace art { |
| 54 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 55 | template<class MirrorType> |
| 56 | class GcRoot; |
| 57 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 58 | namespace arm64 { |
| 59 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 60 | using helpers::ARM64EncodableConstantOrRegister; |
| 61 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 62 | using helpers::CPURegisterFrom; |
| 63 | using helpers::DRegisterFrom; |
| 64 | using helpers::FPRegisterFrom; |
| 65 | using helpers::HeapOperand; |
| 66 | using helpers::HeapOperandFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 67 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 68 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 70 | using helpers::InputRegisterAt; |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 71 | using helpers::Int64FromLocation; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 72 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 73 | using helpers::LocationFrom; |
| 74 | using helpers::OperandFromMemOperand; |
| 75 | using helpers::OutputCPURegister; |
| 76 | using helpers::OutputFPRegister; |
| 77 | using helpers::OutputRegister; |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 78 | using helpers::QRegisterFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 79 | using helpers::RegisterFrom; |
| 80 | using helpers::StackOperandFrom; |
| 81 | using helpers::VIXLRegCodeFromART; |
| 82 | using helpers::WRegisterFrom; |
| 83 | using helpers::XRegisterFrom; |
| 84 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 85 | // 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] | 86 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 87 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 88 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 89 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 90 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 91 | // offset < 16KiB. For offsets >= 16KiB, the load shall be emitted as two or more instructions. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 92 | // For the Baker read barrier implementation using link-time generated thunks we need to split |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 93 | // the offset explicitly. |
| 94 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 95 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 96 | inline Condition ARM64Condition(IfCondition cond) { |
| 97 | switch (cond) { |
| 98 | case kCondEQ: return eq; |
| 99 | case kCondNE: return ne; |
| 100 | case kCondLT: return lt; |
| 101 | case kCondLE: return le; |
| 102 | case kCondGT: return gt; |
| 103 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 104 | case kCondB: return lo; |
| 105 | case kCondBE: return ls; |
| 106 | case kCondA: return hi; |
| 107 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 108 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 109 | LOG(FATAL) << "Unreachable"; |
| 110 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 113 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 114 | // The ARM64 condition codes can express all the necessary branches, see the |
| 115 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 116 | // There is no dex instruction or HIR that would need the missing conditions |
| 117 | // "equal or unordered" or "not equal". |
| 118 | switch (cond) { |
| 119 | case kCondEQ: return eq; |
| 120 | case kCondNE: return ne /* unordered */; |
| 121 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 122 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 123 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 124 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 125 | default: |
| 126 | LOG(FATAL) << "UNREACHABLE"; |
| 127 | UNREACHABLE(); |
| 128 | } |
| 129 | } |
| 130 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 131 | Location ARM64ReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 132 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 133 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 134 | // but we use the exact registers for clarity. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 135 | if (return_type == DataType::Type::kFloat32) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 136 | return LocationFrom(s0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 137 | } else if (return_type == DataType::Type::kFloat64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 138 | return LocationFrom(d0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 139 | } else if (return_type == DataType::Type::kInt64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 140 | return LocationFrom(x0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 141 | } else if (return_type == DataType::Type::kVoid) { |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 142 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 143 | } else { |
| 144 | return LocationFrom(w0); |
| 145 | } |
| 146 | } |
| 147 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 148 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 149 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 152 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 153 | InvokeRuntimeCallingConvention calling_convention; |
| 154 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 155 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 156 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 157 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 158 | DataType::Type::kReference).GetCode()); |
| 159 | return caller_saves; |
| 160 | } |
| 161 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 162 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 163 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 164 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 165 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 166 | // Calculate memory accessing operand for save/restore live registers. |
| 167 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 168 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 169 | int64_t spill_offset, |
| 170 | bool is_save) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 171 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 172 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 173 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 174 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 175 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 176 | codegen->GetNumberOfFloatingPointRegisters())); |
| 177 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 178 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 179 | unsigned v_reg_size = codegen->GetGraph()->HasSIMD() ? kQRegSize : kDRegSize; |
| 180 | CPURegList fp_list = CPURegList(CPURegister::kVRegister, v_reg_size, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 181 | |
| 182 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 183 | UseScratchRegisterScope temps(masm); |
| 184 | |
| 185 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 186 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 187 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 188 | int64_t reg_size = kXRegSizeInBytes; |
| 189 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 190 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 191 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 192 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 193 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 194 | // to compute the base address(float point registers spill base address). |
| 195 | Register new_base = temps.AcquireSameSizeAs(base); |
| 196 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 197 | base = new_base; |
| 198 | spill_offset = -core_spill_size; |
| 199 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 200 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 201 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 202 | } |
| 203 | |
| 204 | if (is_save) { |
| 205 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 206 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 207 | } else { |
| 208 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 209 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 214 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 215 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 216 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 217 | // If the register holds an object, update the stack mask. |
| 218 | if (locations->RegisterContainsObject(i)) { |
| 219 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 220 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 221 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 222 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 223 | saved_core_stack_offsets_[i] = stack_offset; |
| 224 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 225 | } |
| 226 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 227 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 228 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 229 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 230 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 231 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 232 | stack_offset += kDRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 233 | } |
| 234 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 235 | SaveRestoreLiveRegistersHelper(codegen, |
| 236 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 237 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 238 | } |
| 239 | |
| 240 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
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(), false /* is_save */); |
| 244 | } |
| 245 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 246 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 247 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 248 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 249 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 250 | void EmitNativeCode(CodeGenerator* codegen) override { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 251 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 252 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 253 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 254 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 255 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 256 | // Live registers will be restored in the catch block if caught. |
| 257 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 258 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 259 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 260 | // move resolver. |
| 261 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 262 | codegen->EmitParallelMoves(locations->InAt(0), |
| 263 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 264 | DataType::Type::kInt32, |
| 265 | locations->InAt(1), |
| 266 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 267 | DataType::Type::kInt32); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 268 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 269 | ? kQuickThrowStringBounds |
| 270 | : kQuickThrowArrayBounds; |
| 271 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 272 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 273 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 274 | } |
| 275 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 276 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 277 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 278 | const char* GetDescription() const override { return "BoundsCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 279 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 280 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 281 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 282 | }; |
| 283 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 284 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 285 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 286 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 287 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 288 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 289 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 290 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 291 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 292 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 295 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 296 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 297 | const char* GetDescription() const override { return "DivZeroCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 298 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 299 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 300 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 301 | }; |
| 302 | |
| 303 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 304 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 305 | LoadClassSlowPathARM64(HLoadClass* cls, HInstruction* at) |
| 306 | : SlowPathCodeARM64(at), cls_(cls) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 307 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 308 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 311 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 312 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 313 | Location out = locations->Out(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 314 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 315 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 316 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 317 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 318 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 319 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 320 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 321 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 322 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 323 | if (must_resolve_type) { |
| 324 | DCHECK(IsSameDexFile(cls_->GetDexFile(), arm64_codegen->GetGraph()->GetDexFile())); |
| 325 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 326 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 327 | arm64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 328 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 329 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 330 | } else { |
| 331 | DCHECK(must_do_clinit); |
| 332 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 333 | arm64_codegen->MoveLocation(LocationFrom(calling_convention.GetRegisterAt(0)), |
| 334 | source, |
| 335 | cls_->GetType()); |
| 336 | } |
| 337 | if (must_do_clinit) { |
| 338 | arm64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 339 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
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 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 352 | const char* GetDescription() const override { return "LoadClassSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 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 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 359 | }; |
| 360 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 361 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 362 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 363 | explicit LoadStringSlowPathARM64(HLoadString* instruction) |
| 364 | : SlowPathCodeARM64(instruction) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 365 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 366 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 367 | LocationSummary* locations = instruction_->GetLocations(); |
| 368 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 369 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 370 | |
| 371 | __ Bind(GetEntryLabel()); |
| 372 | SaveLiveRegisters(codegen, locations); |
| 373 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 374 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 375 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 376 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 377 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 378 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 379 | DataType::Type type = instruction_->GetType(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 380 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 381 | |
| 382 | RestoreLiveRegisters(codegen, locations); |
| 383 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 384 | __ B(GetExitLabel()); |
| 385 | } |
| 386 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 387 | const char* GetDescription() const override { return "LoadStringSlowPathARM64"; } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 388 | |
| 389 | private: |
| 390 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 391 | }; |
| 392 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 393 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 394 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 395 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 396 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 397 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 398 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 399 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 400 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 401 | // Live registers will be restored in the catch block if caught. |
| 402 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 403 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 404 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 405 | instruction_, |
| 406 | instruction_->GetDexPc(), |
| 407 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 408 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 409 | } |
| 410 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 411 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 412 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 413 | const char* GetDescription() const override { return "NullCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 414 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 415 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 416 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 417 | }; |
| 418 | |
| 419 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 420 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 421 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 422 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 423 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 424 | void EmitNativeCode(CodeGenerator* codegen) override { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 425 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 426 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 427 | __ Bind(GetEntryLabel()); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 428 | SaveLiveRegisters(codegen, locations); // Only saves live 128-bit regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 429 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 430 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 431 | RestoreLiveRegisters(codegen, locations); // Only restores live 128-bit regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 432 | if (successor_ == nullptr) { |
| 433 | __ B(GetReturnLabel()); |
| 434 | } else { |
| 435 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 436 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 437 | } |
| 438 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 439 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 440 | DCHECK(successor_ == nullptr); |
| 441 | return &return_label_; |
| 442 | } |
| 443 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 444 | HBasicBlock* GetSuccessor() const { |
| 445 | return successor_; |
| 446 | } |
| 447 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 448 | const char* GetDescription() const override { return "SuspendCheckSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 449 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 450 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 451 | // If not null, the block to branch to after the suspend check. |
| 452 | HBasicBlock* const successor_; |
| 453 | |
| 454 | // 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] | 455 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 456 | |
| 457 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 458 | }; |
| 459 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 460 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 461 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 462 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 463 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 464 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 465 | void EmitNativeCode(CodeGenerator* codegen) override { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 466 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 467 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 468 | DCHECK(instruction_->IsCheckCast() |
| 469 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 470 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 471 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 472 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 473 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 474 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 475 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 476 | SaveLiveRegisters(codegen, locations); |
| 477 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 478 | |
| 479 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 480 | // move resolver. |
| 481 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 482 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 483 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 484 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 485 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 486 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 487 | DataType::Type::kReference); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 488 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 489 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 490 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 491 | DataType::Type ret_type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 492 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 493 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 494 | } else { |
| 495 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 496 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 497 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 500 | if (!is_fatal_) { |
| 501 | RestoreLiveRegisters(codegen, locations); |
| 502 | __ B(GetExitLabel()); |
| 503 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 506 | const char* GetDescription() const override { return "TypeCheckSlowPathARM64"; } |
| 507 | bool IsFatal() const override { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 508 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 509 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 510 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 511 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 512 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 513 | }; |
| 514 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 515 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 516 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 517 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 518 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 519 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 520 | void EmitNativeCode(CodeGenerator* codegen) override { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 521 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 522 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 523 | LocationSummary* locations = instruction_->GetLocations(); |
| 524 | SaveLiveRegisters(codegen, locations); |
| 525 | InvokeRuntimeCallingConvention calling_convention; |
| 526 | __ Mov(calling_convention.GetRegisterAt(0), |
| 527 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 528 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 529 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 532 | const char* GetDescription() const override { return "DeoptimizationSlowPathARM64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 533 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 534 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 535 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 536 | }; |
| 537 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 538 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 539 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 540 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 541 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 542 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 543 | LocationSummary* locations = instruction_->GetLocations(); |
| 544 | __ Bind(GetEntryLabel()); |
| 545 | SaveLiveRegisters(codegen, locations); |
| 546 | |
| 547 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 548 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 549 | parallel_move.AddMove( |
| 550 | locations->InAt(0), |
| 551 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 552 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 553 | nullptr); |
| 554 | parallel_move.AddMove( |
| 555 | locations->InAt(1), |
| 556 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 557 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 558 | nullptr); |
| 559 | parallel_move.AddMove( |
| 560 | locations->InAt(2), |
| 561 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 562 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 563 | nullptr); |
| 564 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 565 | |
| 566 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 567 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 568 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 569 | RestoreLiveRegisters(codegen, locations); |
| 570 | __ B(GetExitLabel()); |
| 571 | } |
| 572 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 573 | const char* GetDescription() const override { return "ArraySetSlowPathARM64"; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 574 | |
| 575 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 576 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 577 | }; |
| 578 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 579 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 580 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 581 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 582 | |
| 583 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 584 | // 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] | 585 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 586 | num_entries * sizeof(int32_t), |
| 587 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 588 | |
| 589 | __ Bind(&table_start_); |
| 590 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 591 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 592 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 593 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 594 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 595 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 596 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 597 | Literal<int32_t> literal(jump_offset); |
| 598 | __ place(&literal); |
| 599 | } |
| 600 | } |
| 601 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 602 | // Slow path generating a read barrier for a heap reference. |
| 603 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 604 | public: |
| 605 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 606 | Location out, |
| 607 | Location ref, |
| 608 | Location obj, |
| 609 | uint32_t offset, |
| 610 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 611 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 612 | out_(out), |
| 613 | ref_(ref), |
| 614 | obj_(obj), |
| 615 | offset_(offset), |
| 616 | index_(index) { |
| 617 | DCHECK(kEmitCompilerReadBarrier); |
| 618 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 619 | // has been overwritten by (or after) the heap object reference load |
| 620 | // to be instrumented, e.g.: |
| 621 | // |
| 622 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 623 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 624 | // |
| 625 | // In that case, we have lost the information about the original |
| 626 | // object, and the emitted read barrier cannot work properly. |
| 627 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 628 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 629 | } |
| 630 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 631 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 632 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 633 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 634 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 635 | DCHECK(locations->CanCall()); |
| 636 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 637 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 638 | instruction_->IsStaticFieldGet() || |
| 639 | instruction_->IsArrayGet() || |
| 640 | instruction_->IsInstanceOf() || |
| 641 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 642 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 643 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 644 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 645 | // The read barrier instrumentation of object ArrayGet |
| 646 | // instructions does not support the HIntermediateAddress |
| 647 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 648 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 649 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 650 | |
| 651 | __ Bind(GetEntryLabel()); |
| 652 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 653 | SaveLiveRegisters(codegen, locations); |
| 654 | |
| 655 | // We may have to change the index's value, but as `index_` is a |
| 656 | // constant member (like other "inputs" of this slow path), |
| 657 | // introduce a copy of it, `index`. |
| 658 | Location index = index_; |
| 659 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 660 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 661 | if (instruction_->IsArrayGet()) { |
| 662 | // Compute the actual memory offset and store it in `index`. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 663 | Register index_reg = RegisterFrom(index_, DataType::Type::kInt32); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 664 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 665 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 666 | // We are about to change the value of `index_reg` (see the |
| 667 | // calls to vixl::MacroAssembler::Lsl and |
| 668 | // vixl::MacroAssembler::Mov below), but it has |
| 669 | // not been saved by the previous call to |
| 670 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 671 | // callee-save register -- |
| 672 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 673 | // callee-save registers, as it has been designed with the |
| 674 | // assumption that callee-save registers are supposed to be |
| 675 | // handled by the called function. So, as a callee-save |
| 676 | // register, `index_reg` _would_ eventually be saved onto |
| 677 | // the stack, but it would be too late: we would have |
| 678 | // changed its value earlier. Therefore, we manually save |
| 679 | // it here into another freely available register, |
| 680 | // `free_reg`, chosen of course among the caller-save |
| 681 | // registers (as a callee-save `free_reg` register would |
| 682 | // exhibit the same problem). |
| 683 | // |
| 684 | // Note we could have requested a temporary register from |
| 685 | // the register allocator instead; but we prefer not to, as |
| 686 | // this is a slow path, and we know we can find a |
| 687 | // caller-save register that is available. |
| 688 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 689 | __ Mov(free_reg.W(), index_reg); |
| 690 | index_reg = free_reg; |
| 691 | index = LocationFrom(index_reg); |
| 692 | } else { |
| 693 | // The initial register stored in `index_` has already been |
| 694 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 695 | // (as it is not a callee-save register), so we can freely |
| 696 | // use it. |
| 697 | } |
| 698 | // Shifting the index value contained in `index_reg` by the scale |
| 699 | // factor (2) cannot overflow in practice, as the runtime is |
| 700 | // unable to allocate object arrays with a size larger than |
| 701 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 702 | __ Lsl(index_reg, index_reg, DataType::SizeShift(type)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 703 | static_assert( |
| 704 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 705 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 706 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 707 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 708 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 709 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 710 | // (as in the case of ArrayGet), as it is actually an offset |
| 711 | // to an object field within an object. |
| 712 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 713 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 714 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 715 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 716 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 717 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 718 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | |
| 722 | // We're moving two or three locations to locations that could |
| 723 | // overlap, so we need a parallel move resolver. |
| 724 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 725 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 726 | parallel_move.AddMove(ref_, |
| 727 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 728 | type, |
| 729 | nullptr); |
| 730 | parallel_move.AddMove(obj_, |
| 731 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 732 | type, |
| 733 | nullptr); |
| 734 | if (index.IsValid()) { |
| 735 | parallel_move.AddMove(index, |
| 736 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 737 | DataType::Type::kInt32, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 738 | nullptr); |
| 739 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 740 | } else { |
| 741 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 742 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 743 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 744 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 745 | instruction_, |
| 746 | instruction_->GetDexPc(), |
| 747 | this); |
| 748 | CheckEntrypointTypes< |
| 749 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 750 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 751 | |
| 752 | RestoreLiveRegisters(codegen, locations); |
| 753 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 754 | __ B(GetExitLabel()); |
| 755 | } |
| 756 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 757 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 758 | |
| 759 | private: |
| 760 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 761 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 762 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 763 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 764 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 765 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 766 | } |
| 767 | } |
| 768 | // We shall never fail to find a free caller-save register, as |
| 769 | // there are more than two core caller-save registers on ARM64 |
| 770 | // (meaning it is possible to find one which is different from |
| 771 | // `ref` and `obj`). |
| 772 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 773 | LOG(FATAL) << "Could not find a free register"; |
| 774 | UNREACHABLE(); |
| 775 | } |
| 776 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 777 | const Location out_; |
| 778 | const Location ref_; |
| 779 | const Location obj_; |
| 780 | const uint32_t offset_; |
| 781 | // An additional location containing an index to an array. |
| 782 | // Only used for HArrayGet and the UnsafeGetObject & |
| 783 | // UnsafeGetObjectVolatile intrinsics. |
| 784 | const Location index_; |
| 785 | |
| 786 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 787 | }; |
| 788 | |
| 789 | // Slow path generating a read barrier for a GC root. |
| 790 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 791 | public: |
| 792 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 793 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 794 | DCHECK(kEmitCompilerReadBarrier); |
| 795 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 796 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 797 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 798 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 799 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 800 | DCHECK(locations->CanCall()); |
| 801 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 802 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 803 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 804 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 805 | |
| 806 | __ Bind(GetEntryLabel()); |
| 807 | SaveLiveRegisters(codegen, locations); |
| 808 | |
| 809 | InvokeRuntimeCallingConvention calling_convention; |
| 810 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 811 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 812 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 813 | // thus we need a 64-bit move here, and we cannot use |
| 814 | // |
| 815 | // arm64_codegen->MoveLocation( |
| 816 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 817 | // root_, |
| 818 | // type); |
| 819 | // |
| 820 | // 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] | 821 | // reference type (`DataType::Type::kReference`). |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 822 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 823 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 824 | instruction_, |
| 825 | instruction_->GetDexPc(), |
| 826 | this); |
| 827 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 828 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 829 | |
| 830 | RestoreLiveRegisters(codegen, locations); |
| 831 | __ B(GetExitLabel()); |
| 832 | } |
| 833 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 834 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathARM64"; } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 835 | |
| 836 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 837 | const Location out_; |
| 838 | const Location root_; |
| 839 | |
| 840 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 841 | }; |
| 842 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 843 | #undef __ |
| 844 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 845 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 846 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 847 | if (type == DataType::Type::kVoid) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 848 | LOG(FATAL) << "Unreachable type " << type; |
| 849 | } |
| 850 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 851 | if (DataType::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 852 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 853 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 854 | } else if (!DataType::IsFloatingPointType(type) && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 855 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 856 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 857 | } else { |
| 858 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 859 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 860 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 861 | } |
| 862 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 863 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 864 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 865 | return next_location; |
| 866 | } |
| 867 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 868 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 869 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 870 | } |
| 871 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 872 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 873 | const CompilerOptions& compiler_options, |
| 874 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 875 | : CodeGenerator(graph, |
| 876 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 877 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 878 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 879 | callee_saved_core_registers.GetList(), |
| 880 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 881 | compiler_options, |
| 882 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 883 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 884 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 885 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 886 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 887 | move_resolver_(graph->GetAllocator(), this), |
| 888 | assembler_(graph->GetAllocator()), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 889 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 890 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 891 | uint64_literals_(std::less<uint64_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 892 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 893 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 894 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 895 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 896 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 897 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 898 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 899 | boot_image_intrinsic_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 900 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 901 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 902 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 903 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 904 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 905 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 906 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 907 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 908 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 909 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 910 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 911 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 912 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 913 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 914 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 915 | jump_table->EmitTable(this); |
| 916 | } |
| 917 | } |
| 918 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 919 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 920 | EmitJumpTables(); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 921 | |
| 922 | // Emit JIT baker read barrier slow paths. |
| 923 | DCHECK(Runtime::Current()->UseJitCompilation() || jit_baker_read_barrier_slow_paths_.empty()); |
| 924 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 925 | uint32_t encoded_data = entry.first; |
| 926 | vixl::aarch64::Label* slow_path_entry = &entry.second.label; |
| 927 | __ Bind(slow_path_entry); |
| 928 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name */ nullptr); |
| 929 | } |
| 930 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 931 | // Ensure we emit the literal pool. |
| 932 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 933 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 934 | CodeGenerator::Finalize(allocator); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 935 | |
| 936 | // Verify Baker read barrier linker patches. |
| 937 | if (kIsDebugBuild) { |
| 938 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 939 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 940 | DCHECK(info.label.IsBound()); |
| 941 | uint32_t literal_offset = info.label.GetLocation(); |
| 942 | DCHECK_ALIGNED(literal_offset, 4u); |
| 943 | |
| 944 | auto GetInsn = [&code](uint32_t offset) { |
| 945 | DCHECK_ALIGNED(offset, 4u); |
| 946 | return |
| 947 | (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 948 | (static_cast<uint32_t>(code[offset + 1]) << 8) + |
| 949 | (static_cast<uint32_t>(code[offset + 2]) << 16)+ |
| 950 | (static_cast<uint32_t>(code[offset + 3]) << 24); |
| 951 | }; |
| 952 | |
| 953 | const uint32_t encoded_data = info.custom_data; |
| 954 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 955 | // Check that the next instruction matches the expected LDR. |
| 956 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 957 | case BakerReadBarrierKind::kField: |
| 958 | case BakerReadBarrierKind::kAcquire: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 959 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 960 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 961 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 962 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 963 | if (kind == BakerReadBarrierKind::kField) { |
| 964 | // LDR (immediate) with correct base_reg. |
| 965 | CHECK_EQ(next_insn & 0xffc003e0u, 0xb9400000u | (base_reg << 5)); |
| 966 | } else { |
| 967 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 968 | // LDAR with correct base_reg. |
| 969 | CHECK_EQ(next_insn & 0xffffffe0u, 0x88dffc00u | (base_reg << 5)); |
| 970 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 971 | break; |
| 972 | } |
| 973 | case BakerReadBarrierKind::kArray: { |
| 974 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 975 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 976 | // LDR (register) with the correct base_reg, size=10 (32-bit), option=011 (extend = LSL), |
| 977 | // and S=1 (shift amount = 2 for 32-bit version), i.e. LDR Wt, [Xn, Xm, LSL #2]. |
| 978 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 979 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 980 | CHECK_EQ(next_insn & 0xffe0ffe0u, 0xb8607800u | (base_reg << 5)); |
| 981 | CheckValidReg((next_insn >> 16) & 0x1f); // Check index register |
| 982 | break; |
| 983 | } |
| 984 | case BakerReadBarrierKind::kGcRoot: { |
| 985 | DCHECK_GE(literal_offset, 4u); |
| 986 | uint32_t prev_insn = GetInsn(literal_offset - 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 987 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 988 | // Usually LDR (immediate) with correct root_reg but |
| 989 | // we may have a "MOV marked, old_value" for UnsafeCASObject. |
| 990 | if ((prev_insn & 0xffe0ffff) != (0x2a0003e0 | root_reg)) { // MOV? |
| 991 | CHECK_EQ(prev_insn & 0xffc0001fu, 0xb9400000u | root_reg); // LDR? |
| 992 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 993 | break; |
| 994 | } |
| 995 | default: |
| 996 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 997 | UNREACHABLE(); |
| 998 | } |
| 999 | } |
| 1000 | } |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1003 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1004 | // Note: There are 6 kinds of moves: |
| 1005 | // 1. constant -> GPR/FPR (non-cycle) |
| 1006 | // 2. constant -> stack (non-cycle) |
| 1007 | // 3. GPR/FPR -> GPR/FPR |
| 1008 | // 4. GPR/FPR -> stack |
| 1009 | // 5. stack -> GPR/FPR |
| 1010 | // 6. stack -> stack (non-cycle) |
| 1011 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1012 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1013 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1014 | // dependency. |
| 1015 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1016 | } |
| 1017 | |
| 1018 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1019 | vixl_temps_.Close(); |
| 1020 | } |
| 1021 | |
| 1022 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1023 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1024 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1025 | || kind == Location::kSIMDStackSlot); |
| 1026 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1027 | ? Location::kFpuRegister |
| 1028 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1029 | Location scratch = GetScratchLocation(kind); |
| 1030 | if (!scratch.Equals(Location::NoLocation())) { |
| 1031 | return scratch; |
| 1032 | } |
| 1033 | // Allocate from VIXL temp registers. |
| 1034 | if (kind == Location::kRegister) { |
| 1035 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1036 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1037 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1038 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1039 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1040 | : vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1041 | } |
| 1042 | AddScratchLocation(scratch); |
| 1043 | return scratch; |
| 1044 | } |
| 1045 | |
| 1046 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1047 | if (loc.IsRegister()) { |
| 1048 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1049 | } else { |
| 1050 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1051 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1052 | } |
| 1053 | RemoveScratchLocation(loc); |
| 1054 | } |
| 1055 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1056 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1057 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1058 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1061 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1062 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1063 | __ Bind(&frame_entry_label_); |
| 1064 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1065 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1066 | UseScratchRegisterScope temps(masm); |
| 1067 | Register temp = temps.AcquireX(); |
| 1068 | __ Ldrh(temp, MemOperand(kArtMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1069 | __ Add(temp, temp, 1); |
| 1070 | __ Strh(temp, MemOperand(kArtMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1071 | } |
| 1072 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1073 | bool do_overflow_check = |
| 1074 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1075 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1076 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1077 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1078 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1079 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1080 | { |
| 1081 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1082 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1083 | kInstructionSize, |
| 1084 | CodeBufferCheckScope::kExactSize); |
| 1085 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1086 | RecordPcInfo(nullptr, 0); |
| 1087 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1088 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1089 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1090 | if (!HasEmptyFrame()) { |
| 1091 | int frame_size = GetFrameSize(); |
| 1092 | // Stack layout: |
| 1093 | // sp[frame_size - 8] : lr. |
| 1094 | // ... : other preserved core registers. |
| 1095 | // ... : other preserved fp registers. |
| 1096 | // ... : reserved frame space. |
| 1097 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1098 | |
| 1099 | // Save the current method if we need it. Note that we do not |
| 1100 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1101 | // in the SSA graph. |
| 1102 | if (RequiresCurrentMethod()) { |
| 1103 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1104 | } else { |
| 1105 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1106 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1107 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1108 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1109 | frame_size - GetCoreSpillSize()); |
| 1110 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1111 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1112 | |
| 1113 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1114 | // Initialize should_deoptimize flag to 0. |
| 1115 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1116 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1117 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1118 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 1119 | |
| 1120 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1124 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1125 | if (!HasEmptyFrame()) { |
| 1126 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1127 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1128 | frame_size - FrameEntrySpillSize()); |
| 1129 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1130 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1131 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1132 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1133 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1134 | __ Ret(); |
| 1135 | GetAssembler()->cfi().RestoreState(); |
| 1136 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1137 | } |
| 1138 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1139 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1140 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1141 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1142 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1143 | } |
| 1144 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1145 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1146 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1147 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1148 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1149 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1150 | } |
| 1151 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1152 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1153 | __ Bind(GetLabelOf(block)); |
| 1154 | } |
| 1155 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1156 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1157 | DCHECK(location.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1158 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1159 | } |
| 1160 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1161 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1162 | if (location.IsRegister()) { |
| 1163 | locations->AddTemp(location); |
| 1164 | } else { |
| 1165 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1166 | } |
| 1167 | } |
| 1168 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1169 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1170 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1171 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1172 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1173 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1174 | if (value_can_be_null) { |
| 1175 | __ Cbz(value, &done); |
| 1176 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1177 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1178 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1179 | // Calculate the offset (in the card table) of the card corresponding to |
| 1180 | // `object`. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1181 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 1182 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 1183 | // `object`'s card. |
| 1184 | // |
| 1185 | // Register `card` contains the address of the card table. Note that the card |
| 1186 | // table's base is biased during its creation so that it always starts at an |
| 1187 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 1188 | // art::gc::accounting::CardTable::Create). Therefore the STRB instruction |
| 1189 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 1190 | // (located at `card + object >> kCardShift`). |
| 1191 | // |
| 1192 | // This dual use of the value in register `card` (1. to calculate the location |
| 1193 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 1194 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1195 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1196 | if (value_can_be_null) { |
| 1197 | __ Bind(&done); |
| 1198 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1199 | } |
| 1200 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1201 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1202 | // Blocked core registers: |
| 1203 | // lr : Runtime reserved. |
| 1204 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1205 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1206 | // ip1 : VIXL core temp. |
| 1207 | // ip0 : VIXL core temp. |
Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1208 | // x18 : Platform register. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1209 | // |
| 1210 | // Blocked fp registers: |
| 1211 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1212 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1213 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1214 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1215 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1216 | } |
Peter Collingbourne | bd8e10c | 2018-04-12 16:39:55 -0700 | [diff] [blame] | 1217 | blocked_core_registers_[X18] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1218 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1219 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1220 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1221 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1222 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1223 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1224 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1225 | // Stubs do not save callee-save floating point registers. If the graph |
| 1226 | // is debuggable, we need to deal with these registers differently. For |
| 1227 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1228 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1229 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1230 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1231 | } |
| 1232 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1233 | } |
| 1234 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1235 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1236 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1237 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1238 | return kArm64WordSize; |
| 1239 | } |
| 1240 | |
| 1241 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1242 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1243 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1244 | return kArm64WordSize; |
| 1245 | } |
| 1246 | |
| 1247 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1248 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1249 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1250 | return kArm64WordSize; |
| 1251 | } |
| 1252 | |
| 1253 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1254 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1255 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1256 | return kArm64WordSize; |
| 1257 | } |
| 1258 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1259 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1260 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1264 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1265 | } |
| 1266 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1267 | const Arm64InstructionSetFeatures& CodeGeneratorARM64::GetInstructionSetFeatures() const { |
| 1268 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArm64InstructionSetFeatures(); |
| 1269 | } |
| 1270 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1271 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1272 | if (constant->IsIntConstant()) { |
| 1273 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1274 | } else if (constant->IsLongConstant()) { |
| 1275 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1276 | } else if (constant->IsNullConstant()) { |
| 1277 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1278 | } else if (constant->IsFloatConstant()) { |
| 1279 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1280 | } else { |
| 1281 | DCHECK(constant->IsDoubleConstant()); |
| 1282 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1283 | } |
| 1284 | } |
| 1285 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1286 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1287 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1288 | DCHECK(constant.IsConstant()); |
| 1289 | HConstant* cst = constant.GetConstant(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1290 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1291 | // 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] | 1292 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1293 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1294 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1295 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1298 | // Allocate a scratch register from the VIXL pool, querying first |
| 1299 | // the floating-point register pool, and then the core register |
| 1300 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1301 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1302 | // using a different allocation strategy. |
| 1303 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1304 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1305 | int size_in_bits) { |
| 1306 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1307 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1308 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1309 | } |
| 1310 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1311 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1312 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1313 | DataType::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1314 | if (source.Equals(destination)) { |
| 1315 | return; |
| 1316 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1317 | |
| 1318 | // A valid move can always be inferred from the destination and source |
| 1319 | // locations. When moving from and to a register, the argument type can be |
| 1320 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1321 | // checks the coherency of the locations and the type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1322 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1323 | |
| 1324 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1325 | if (unspecified_type) { |
| 1326 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1327 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1328 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1329 | || src_cst->IsFloatConstant() |
| 1330 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1331 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1332 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1333 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1334 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1335 | // type is appropriate. Else the source is a register, and since the |
| 1336 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1337 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1338 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1339 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1340 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1341 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1342 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1343 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1344 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1345 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1346 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1347 | } else if (source.IsSIMDStackSlot()) { |
| 1348 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1349 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1350 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1351 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1352 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1353 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1354 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1355 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1356 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1357 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1358 | ? DataType::Type::kInt64 |
| 1359 | : DataType::Type::kInt32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1360 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1361 | } |
| 1362 | } else { |
| 1363 | DCHECK(source.IsFpuRegister()); |
| 1364 | if (destination.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1365 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1366 | ? DataType::Type::kFloat64 |
| 1367 | : DataType::Type::kFloat32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1368 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1369 | } else { |
| 1370 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1371 | if (GetGraph()->HasSIMD()) { |
| 1372 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1373 | } else { |
| 1374 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1375 | } |
| 1376 | } |
| 1377 | } |
| 1378 | } else if (destination.IsSIMDStackSlot()) { |
| 1379 | if (source.IsFpuRegister()) { |
| 1380 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1381 | } else { |
| 1382 | DCHECK(source.IsSIMDStackSlot()); |
| 1383 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1384 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1385 | Register temp = temps.AcquireX(); |
| 1386 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1387 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1388 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1389 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1390 | } else { |
| 1391 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1392 | __ Ldr(temp, StackOperandFrom(source)); |
| 1393 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1394 | } |
| 1395 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1396 | } else { // The destination is not a register. It must be a stack slot. |
| 1397 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1398 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1399 | if (unspecified_type) { |
| 1400 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1401 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1402 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1403 | dst_type = |
| 1404 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1405 | } |
| 1406 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1407 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1408 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1409 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1410 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1411 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1412 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1413 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1414 | HConstant* src_cst = source.GetConstant(); |
| 1415 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1416 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1417 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1418 | ? Register(xzr) |
| 1419 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1420 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1421 | if (src_cst->IsIntConstant()) { |
| 1422 | temp = temps.AcquireW(); |
| 1423 | } else if (src_cst->IsLongConstant()) { |
| 1424 | temp = temps.AcquireX(); |
| 1425 | } else if (src_cst->IsFloatConstant()) { |
| 1426 | temp = temps.AcquireS(); |
| 1427 | } else { |
| 1428 | DCHECK(src_cst->IsDoubleConstant()); |
| 1429 | temp = temps.AcquireD(); |
| 1430 | } |
| 1431 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1432 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1433 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1434 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1435 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1436 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1437 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1438 | // Use any scratch register (a core or a floating-point one) |
| 1439 | // from VIXL scratch register pools as a temporary. |
| 1440 | // |
| 1441 | // We used to only use the FP scratch register pool, but in some |
| 1442 | // rare cases the only register from this pool (D31) would |
| 1443 | // already be used (e.g. within a ParallelMove instruction, when |
| 1444 | // a move is blocked by a another move requiring a scratch FP |
| 1445 | // register, which would reserve D31). To prevent this issue, we |
| 1446 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1447 | // |
| 1448 | // 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] | 1449 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1450 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1451 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1452 | // allocates core scratch registers first. |
| 1453 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1454 | GetVIXLAssembler(), |
| 1455 | &temps, |
| 1456 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1457 | __ Ldr(temp, StackOperandFrom(source)); |
| 1458 | __ Str(temp, StackOperandFrom(destination)); |
| 1459 | } |
| 1460 | } |
| 1461 | } |
| 1462 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1463 | void CodeGeneratorARM64::Load(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1464 | CPURegister dst, |
| 1465 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1466 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1467 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1468 | case DataType::Type::kUint8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1469 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1470 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1471 | case DataType::Type::kInt8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1472 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1473 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1474 | case DataType::Type::kUint16: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1475 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1476 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1477 | case DataType::Type::kInt16: |
| 1478 | __ Ldrsh(Register(dst), src); |
| 1479 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1480 | case DataType::Type::kInt32: |
| 1481 | case DataType::Type::kReference: |
| 1482 | case DataType::Type::kInt64: |
| 1483 | case DataType::Type::kFloat32: |
| 1484 | case DataType::Type::kFloat64: |
| 1485 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1486 | __ Ldr(dst, src); |
| 1487 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1488 | case DataType::Type::kUint32: |
| 1489 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1490 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1491 | LOG(FATAL) << "Unreachable type " << type; |
| 1492 | } |
| 1493 | } |
| 1494 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1495 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1496 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1497 | const MemOperand& src, |
| 1498 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1499 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1500 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1501 | Register temp_base = temps.AcquireX(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1502 | DataType::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1503 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1504 | DCHECK(!src.IsPreIndex()); |
| 1505 | DCHECK(!src.IsPostIndex()); |
| 1506 | |
| 1507 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1508 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1509 | { |
| 1510 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1511 | MemOperand base = MemOperand(temp_base); |
| 1512 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1513 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1514 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1515 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1516 | { |
| 1517 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1518 | __ ldarb(Register(dst), base); |
| 1519 | if (needs_null_check) { |
| 1520 | MaybeRecordImplicitNullCheck(instruction); |
| 1521 | } |
| 1522 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1523 | if (type == DataType::Type::kInt8) { |
| 1524 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1525 | } |
| 1526 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1527 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1528 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1529 | { |
| 1530 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1531 | __ ldarh(Register(dst), base); |
| 1532 | if (needs_null_check) { |
| 1533 | MaybeRecordImplicitNullCheck(instruction); |
| 1534 | } |
| 1535 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1536 | if (type == DataType::Type::kInt16) { |
| 1537 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 1538 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1539 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1540 | case DataType::Type::kInt32: |
| 1541 | case DataType::Type::kReference: |
| 1542 | case DataType::Type::kInt64: |
| 1543 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1544 | { |
| 1545 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1546 | __ ldar(Register(dst), base); |
| 1547 | if (needs_null_check) { |
| 1548 | MaybeRecordImplicitNullCheck(instruction); |
| 1549 | } |
| 1550 | } |
| 1551 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1552 | case DataType::Type::kFloat32: |
| 1553 | case DataType::Type::kFloat64: { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1554 | DCHECK(dst.IsFPRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1555 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1556 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1557 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1558 | { |
| 1559 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1560 | __ ldar(temp, base); |
| 1561 | if (needs_null_check) { |
| 1562 | MaybeRecordImplicitNullCheck(instruction); |
| 1563 | } |
| 1564 | } |
| 1565 | __ Fmov(FPRegister(dst), temp); |
| 1566 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1567 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1568 | case DataType::Type::kUint32: |
| 1569 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1570 | case DataType::Type::kVoid: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1571 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1572 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1573 | } |
| 1574 | } |
| 1575 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1576 | void CodeGeneratorARM64::Store(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1577 | CPURegister src, |
| 1578 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1579 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1580 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1581 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1582 | case DataType::Type::kInt8: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1583 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1584 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1585 | case DataType::Type::kUint16: |
| 1586 | case DataType::Type::kInt16: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1587 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1588 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1589 | case DataType::Type::kInt32: |
| 1590 | case DataType::Type::kReference: |
| 1591 | case DataType::Type::kInt64: |
| 1592 | case DataType::Type::kFloat32: |
| 1593 | case DataType::Type::kFloat64: |
| 1594 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1595 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1596 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1597 | case DataType::Type::kUint32: |
| 1598 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1599 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1600 | LOG(FATAL) << "Unreachable type " << type; |
| 1601 | } |
| 1602 | } |
| 1603 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1604 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1605 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1606 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1607 | const MemOperand& dst, |
| 1608 | bool needs_null_check) { |
| 1609 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1610 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1611 | Register temp_base = temps.AcquireX(); |
| 1612 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1613 | DCHECK(!dst.IsPreIndex()); |
| 1614 | DCHECK(!dst.IsPostIndex()); |
| 1615 | |
| 1616 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1617 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1618 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1619 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1620 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1621 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1622 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1623 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1624 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1625 | { |
| 1626 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1627 | __ stlrb(Register(src), base); |
| 1628 | if (needs_null_check) { |
| 1629 | MaybeRecordImplicitNullCheck(instruction); |
| 1630 | } |
| 1631 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1632 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1633 | case DataType::Type::kUint16: |
| 1634 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1635 | { |
| 1636 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1637 | __ stlrh(Register(src), base); |
| 1638 | if (needs_null_check) { |
| 1639 | MaybeRecordImplicitNullCheck(instruction); |
| 1640 | } |
| 1641 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1642 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1643 | case DataType::Type::kInt32: |
| 1644 | case DataType::Type::kReference: |
| 1645 | case DataType::Type::kInt64: |
| 1646 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1647 | { |
| 1648 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1649 | __ stlr(Register(src), base); |
| 1650 | if (needs_null_check) { |
| 1651 | MaybeRecordImplicitNullCheck(instruction); |
| 1652 | } |
| 1653 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1654 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1655 | case DataType::Type::kFloat32: |
| 1656 | case DataType::Type::kFloat64: { |
| 1657 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1658 | Register temp_src; |
| 1659 | if (src.IsZero()) { |
| 1660 | // The zero register is used to avoid synthesizing zero constants. |
| 1661 | temp_src = Register(src); |
| 1662 | } else { |
| 1663 | DCHECK(src.IsFPRegister()); |
| 1664 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 1665 | __ Fmov(temp_src, FPRegister(src)); |
| 1666 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1667 | { |
| 1668 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1669 | __ stlr(temp_src, base); |
| 1670 | if (needs_null_check) { |
| 1671 | MaybeRecordImplicitNullCheck(instruction); |
| 1672 | } |
| 1673 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1674 | break; |
| 1675 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1676 | case DataType::Type::kUint32: |
| 1677 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1678 | case DataType::Type::kVoid: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1679 | LOG(FATAL) << "Unreachable type " << type; |
| 1680 | } |
| 1681 | } |
| 1682 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1683 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1684 | HInstruction* instruction, |
| 1685 | uint32_t dex_pc, |
| 1686 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1687 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1688 | |
| 1689 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 1690 | { |
| 1691 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 1692 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1693 | __ blr(lr); |
| 1694 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1695 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1696 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1697 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1700 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1701 | HInstruction* instruction, |
| 1702 | SlowPathCode* slow_path) { |
| 1703 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1704 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 1705 | __ Blr(lr); |
| 1706 | } |
| 1707 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1708 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1709 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1710 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1711 | Register temp = temps.AcquireW(); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1712 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 1713 | const size_t status_byte_offset = |
| 1714 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 1715 | constexpr uint32_t shifted_initialized_value = |
| 1716 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1717 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1718 | // 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] | 1719 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1720 | __ Add(temp, class_reg, status_byte_offset); |
Igor Murashkin | 86083f7 | 2017-10-27 10:59:04 -0700 | [diff] [blame] | 1721 | __ Ldarb(temp, HeapOperand(temp)); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 1722 | __ Cmp(temp, shifted_initialized_value); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 1723 | __ B(lo, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1724 | __ Bind(slow_path->GetExitLabel()); |
| 1725 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1726 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 1727 | void InstructionCodeGeneratorARM64::GenerateBitstringTypeCheckCompare( |
| 1728 | HTypeCheckInstruction* check, vixl::aarch64::Register temp) { |
| 1729 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 1730 | uint32_t mask = check->GetBitstringMask(); |
| 1731 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 1732 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 1733 | |
| 1734 | if (mask_bits == 16u) { |
| 1735 | // Load only the bitstring part of the status word. |
| 1736 | __ Ldrh(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1737 | } else { |
| 1738 | // /* uint32_t */ temp = temp->status_ |
| 1739 | __ Ldr(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 1740 | // Extract the bitstring bits. |
| 1741 | __ Ubfx(temp, temp, 0, mask_bits); |
| 1742 | } |
| 1743 | // Compare the bitstring bits to `path_to_root`. |
| 1744 | __ Cmp(temp, path_to_root); |
| 1745 | } |
| 1746 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1747 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1748 | BarrierType type = BarrierAll; |
| 1749 | |
| 1750 | switch (kind) { |
| 1751 | case MemBarrierKind::kAnyAny: |
| 1752 | case MemBarrierKind::kAnyStore: { |
| 1753 | type = BarrierAll; |
| 1754 | break; |
| 1755 | } |
| 1756 | case MemBarrierKind::kLoadAny: { |
| 1757 | type = BarrierReads; |
| 1758 | break; |
| 1759 | } |
| 1760 | case MemBarrierKind::kStoreStore: { |
| 1761 | type = BarrierWrites; |
| 1762 | break; |
| 1763 | } |
| 1764 | default: |
| 1765 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 1766 | } |
| 1767 | __ Dmb(InnerShareable, type); |
| 1768 | } |
| 1769 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1770 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1771 | HBasicBlock* successor) { |
| 1772 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1773 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 1774 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1775 | slow_path = |
| 1776 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1777 | instruction->SetSlowPath(slow_path); |
| 1778 | codegen_->AddSlowPath(slow_path); |
| 1779 | if (successor != nullptr) { |
| 1780 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 1781 | } |
| 1782 | } else { |
| 1783 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 1784 | } |
| 1785 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1786 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 1787 | Register temp = temps.AcquireW(); |
| 1788 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1789 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1790 | if (successor == nullptr) { |
| 1791 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 1792 | __ Bind(slow_path->GetReturnLabel()); |
| 1793 | } else { |
| 1794 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 1795 | __ B(slow_path->GetEntryLabel()); |
| 1796 | // slow_path will return to GetLabelOf(successor). |
| 1797 | } |
| 1798 | } |
| 1799 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1800 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 1801 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1802 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1803 | assembler_(codegen->GetAssembler()), |
| 1804 | codegen_(codegen) {} |
| 1805 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1806 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1807 | DCHECK_EQ(instr->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1808 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1809 | DataType::Type type = instr->GetResultType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1810 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1811 | case DataType::Type::kInt32: |
| 1812 | case DataType::Type::kInt64: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1813 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 1814 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 1815 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1816 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1817 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1818 | case DataType::Type::kFloat32: |
| 1819 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1820 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1821 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1822 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1823 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1824 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1825 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1826 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1827 | } |
| 1828 | } |
| 1829 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1830 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 1831 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1832 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 1833 | |
| 1834 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1835 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1836 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1837 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 1838 | object_field_get_with_read_barrier |
| 1839 | ? LocationSummary::kCallOnSlowPath |
| 1840 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1841 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1842 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 1843 | // We need a temporary register for the read barrier load in |
| 1844 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 1845 | // only if the field is volatile or the offset is too big. |
| 1846 | if (field_info.IsVolatile() || |
| 1847 | field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 1848 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1849 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1850 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1851 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1852 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1853 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1854 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1855 | // The output overlaps for an object field get when read barriers |
| 1856 | // are enabled: we do not want the load to overwrite the object's |
| 1857 | // location, as we need it to emit the read barrier. |
| 1858 | locations->SetOut( |
| 1859 | Location::RequiresRegister(), |
| 1860 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1861 | } |
| 1862 | } |
| 1863 | |
| 1864 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 1865 | const FieldInfo& field_info) { |
| 1866 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1867 | LocationSummary* locations = instruction->GetLocations(); |
| 1868 | Location base_loc = locations->InAt(0); |
| 1869 | Location out = locations->Out(); |
| 1870 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 1871 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 1872 | DataType::Type load_type = instruction->GetType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1873 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1874 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1875 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 1876 | load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1877 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1878 | // /* HeapReference<Object> */ out = *(base + offset) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1879 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1880 | Location maybe_temp = |
| 1881 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1882 | // Note that potential implicit null checks are handled in this |
| 1883 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 1884 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1885 | instruction, |
| 1886 | out, |
| 1887 | base, |
| 1888 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1889 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1890 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1891 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1892 | } else { |
| 1893 | // General case. |
| 1894 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1895 | // Note that a potential implicit null check is handled in this |
| 1896 | // CodeGeneratorARM64::LoadAcquire call. |
| 1897 | // NB: LoadAcquire will record the pc info if needed. |
| 1898 | codegen_->LoadAcquire( |
| 1899 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1900 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1901 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1902 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 1903 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1904 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1905 | } |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 1906 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1907 | // If read barriers are enabled, emit read barriers other than |
| 1908 | // Baker's using a slow path (and also unpoison the loaded |
| 1909 | // reference, if heap poisoning is enabled). |
| 1910 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 1911 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1912 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 1916 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1917 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1918 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1919 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 1920 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1921 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1922 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1923 | } else { |
| 1924 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1929 | const FieldInfo& field_info, |
| 1930 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1931 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 1932 | |
| 1933 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 1934 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1935 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1936 | Offset offset = field_info.GetFieldOffset(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1937 | DataType::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1938 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1939 | { |
| 1940 | // We use a block to end the scratch scope before the write barrier, thus |
| 1941 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 1942 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1943 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1944 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1945 | DCHECK(value.IsW()); |
| 1946 | Register temp = temps.AcquireW(); |
| 1947 | __ Mov(temp, value.W()); |
| 1948 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 1949 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1950 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1951 | |
| 1952 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1953 | codegen_->StoreRelease( |
| 1954 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1955 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1956 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1957 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1958 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 1959 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 1960 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1964 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 1965 | } |
| 1966 | } |
| 1967 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1968 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1969 | DataType::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1970 | |
| 1971 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1972 | case DataType::Type::kInt32: |
| 1973 | case DataType::Type::kInt64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1974 | Register dst = OutputRegister(instr); |
| 1975 | Register lhs = InputRegisterAt(instr, 0); |
| 1976 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1977 | if (instr->IsAdd()) { |
| 1978 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1979 | } else if (instr->IsAnd()) { |
| 1980 | __ And(dst, lhs, rhs); |
| 1981 | } else if (instr->IsOr()) { |
| 1982 | __ Orr(dst, lhs, rhs); |
| 1983 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1984 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1985 | } else if (instr->IsRor()) { |
| 1986 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1987 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1988 | __ Ror(dst, lhs, shift); |
| 1989 | } else { |
| 1990 | // Ensure shift distance is in the same size register as the result. If |
| 1991 | // we are rotating a long and the shift comes in a w register originally, |
| 1992 | // we don't need to sxtw for use as an x since the shift distances are |
| 1993 | // all & reg_bits - 1. |
| 1994 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 1995 | } |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 1996 | } else if (instr->IsMin() || instr->IsMax()) { |
| 1997 | __ Cmp(lhs, rhs); |
| 1998 | __ Csel(dst, lhs, rhs, instr->IsMin() ? lt : gt); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1999 | } else { |
| 2000 | DCHECK(instr->IsXor()); |
| 2001 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2002 | } |
| 2003 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2004 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2005 | case DataType::Type::kFloat32: |
| 2006 | case DataType::Type::kFloat64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2007 | FPRegister dst = OutputFPRegister(instr); |
| 2008 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2009 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2010 | if (instr->IsAdd()) { |
| 2011 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2012 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2013 | __ Fsub(dst, lhs, rhs); |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2014 | } else if (instr->IsMin()) { |
| 2015 | __ Fmin(dst, lhs, rhs); |
| 2016 | } else if (instr->IsMax()) { |
| 2017 | __ Fmax(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2018 | } else { |
| 2019 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2020 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2021 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2022 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2023 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2024 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2025 | } |
| 2026 | } |
| 2027 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2028 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2029 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2030 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2031 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2032 | DataType::Type type = instr->GetResultType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2033 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2034 | case DataType::Type::kInt32: |
| 2035 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2036 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2037 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2038 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2039 | break; |
| 2040 | } |
| 2041 | default: |
| 2042 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2043 | } |
| 2044 | } |
| 2045 | |
| 2046 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2047 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2048 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2049 | DataType::Type type = instr->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2050 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2051 | case DataType::Type::kInt32: |
| 2052 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2053 | Register dst = OutputRegister(instr); |
| 2054 | Register lhs = InputRegisterAt(instr, 0); |
| 2055 | Operand rhs = InputOperandAt(instr, 1); |
| 2056 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2057 | uint32_t shift_value = rhs.GetImmediate() & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2058 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2059 | if (instr->IsShl()) { |
| 2060 | __ Lsl(dst, lhs, shift_value); |
| 2061 | } else if (instr->IsShr()) { |
| 2062 | __ Asr(dst, lhs, shift_value); |
| 2063 | } else { |
| 2064 | __ Lsr(dst, lhs, shift_value); |
| 2065 | } |
| 2066 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2067 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2068 | |
| 2069 | if (instr->IsShl()) { |
| 2070 | __ Lsl(dst, lhs, rhs_reg); |
| 2071 | } else if (instr->IsShr()) { |
| 2072 | __ Asr(dst, lhs, rhs_reg); |
| 2073 | } else { |
| 2074 | __ Lsr(dst, lhs, rhs_reg); |
| 2075 | } |
| 2076 | } |
| 2077 | break; |
| 2078 | } |
| 2079 | default: |
| 2080 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2081 | } |
| 2082 | } |
| 2083 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2084 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2085 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2089 | HandleBinaryOp(instruction); |
| 2090 | } |
| 2091 | |
| 2092 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2093 | HandleBinaryOp(instruction); |
| 2094 | } |
| 2095 | |
| 2096 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2097 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2098 | } |
| 2099 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2100 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2101 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2102 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2103 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2104 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2105 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2106 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2107 | } |
| 2108 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2109 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2110 | Register dst = OutputRegister(instr); |
| 2111 | Register lhs = InputRegisterAt(instr, 0); |
| 2112 | Register rhs = InputRegisterAt(instr, 1); |
| 2113 | |
| 2114 | switch (instr->GetOpKind()) { |
| 2115 | case HInstruction::kAnd: |
| 2116 | __ Bic(dst, lhs, rhs); |
| 2117 | break; |
| 2118 | case HInstruction::kOr: |
| 2119 | __ Orn(dst, lhs, rhs); |
| 2120 | break; |
| 2121 | case HInstruction::kXor: |
| 2122 | __ Eon(dst, lhs, rhs); |
| 2123 | break; |
| 2124 | default: |
| 2125 | LOG(FATAL) << "Unreachable"; |
| 2126 | } |
| 2127 | } |
| 2128 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2129 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2130 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2131 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2132 | instruction->GetType() == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2133 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2134 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2135 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2136 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2137 | } else { |
| 2138 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2139 | } |
| 2140 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2141 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2142 | } |
| 2143 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2144 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2145 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2146 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2147 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2148 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2149 | Register out = OutputRegister(instruction); |
| 2150 | Register left; |
| 2151 | if (kind != HInstruction::kNeg) { |
| 2152 | left = InputRegisterAt(instruction, 0); |
| 2153 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2154 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2155 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2156 | // conversion) can have a different type from the current instruction's type, |
| 2157 | // so we manually indicate the type. |
| 2158 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2159 | Operand right_operand(0); |
| 2160 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2161 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2162 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2163 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2164 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2165 | right_operand = Operand(right_reg, |
| 2166 | helpers::ShiftFromOpKind(op_kind), |
| 2167 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | // Logical binary operations do not support extension operations in the |
| 2171 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2172 | // the extension as a separate instruction. |
| 2173 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2174 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2175 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2176 | kind != HInstruction::kNeg)); |
| 2177 | switch (kind) { |
| 2178 | case HInstruction::kAdd: |
| 2179 | __ Add(out, left, right_operand); |
| 2180 | break; |
| 2181 | case HInstruction::kAnd: |
| 2182 | __ And(out, left, right_operand); |
| 2183 | break; |
| 2184 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2185 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2186 | __ Neg(out, right_operand); |
| 2187 | break; |
| 2188 | case HInstruction::kOr: |
| 2189 | __ Orr(out, left, right_operand); |
| 2190 | break; |
| 2191 | case HInstruction::kSub: |
| 2192 | __ Sub(out, left, right_operand); |
| 2193 | break; |
| 2194 | case HInstruction::kXor: |
| 2195 | __ Eor(out, left, right_operand); |
| 2196 | break; |
| 2197 | default: |
| 2198 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2199 | UNREACHABLE(); |
| 2200 | } |
| 2201 | } |
| 2202 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2203 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2204 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2205 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2206 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2207 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2208 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2209 | } |
| 2210 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2211 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2212 | __ Add(OutputRegister(instruction), |
| 2213 | InputRegisterAt(instruction, 0), |
| 2214 | Operand(InputOperandAt(instruction, 1))); |
| 2215 | } |
| 2216 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2217 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2218 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2219 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2220 | |
| 2221 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2222 | |
| 2223 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2224 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2225 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2226 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2227 | // loop. |
| 2228 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2229 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2230 | : Location::RequiresRegister()); |
| 2231 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2232 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2233 | } |
| 2234 | |
| 2235 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2236 | HIntermediateAddressIndex* instruction) { |
| 2237 | Register index_reg = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2238 | uint32_t shift = Int64FromLocation(instruction->GetLocations()->InAt(2)); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2239 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2240 | |
| 2241 | if (shift == 0) { |
| 2242 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2243 | } else { |
| 2244 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2245 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2246 | } |
| 2247 | } |
| 2248 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2249 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2250 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2251 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2252 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2253 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2254 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2255 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2256 | // Don't allocate register for Mneg instruction. |
| 2257 | } else { |
| 2258 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2259 | Location::RequiresRegister()); |
| 2260 | } |
| 2261 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2262 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2263 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2264 | } |
| 2265 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2266 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2267 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2268 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2269 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2270 | |
| 2271 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2272 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2273 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2274 | if (instr->GetType() == DataType::Type::kInt64 && |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2275 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2276 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2277 | vixl::aarch64::Instruction* prev = |
| 2278 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2279 | if (prev->IsLoadOrStore()) { |
| 2280 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2281 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2282 | __ nop(); |
| 2283 | } |
| 2284 | } |
| 2285 | |
| 2286 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2287 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2288 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2289 | } else { |
| 2290 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2291 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2292 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2293 | __ Mneg(res, mul_left, mul_right); |
| 2294 | } else { |
| 2295 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2296 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2297 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2298 | } |
| 2299 | } |
| 2300 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2301 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2302 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2303 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2304 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2305 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2306 | object_array_get_with_read_barrier |
| 2307 | ? LocationSummary::kCallOnSlowPath |
| 2308 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2309 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2310 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2311 | if (instruction->GetIndex()->IsConstant()) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2312 | // Array loads with constant index are treated as field loads. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2313 | // We need a temporary register for the read barrier load in |
| 2314 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2315 | // only if the offset is too big. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2316 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2317 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2318 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2319 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2320 | locations->AddTemp(FixedTempLocation()); |
| 2321 | } |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2322 | } else if (!instruction->GetArray()->IsIntermediateAddress()) { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2323 | // We need a non-scratch temporary for the array data pointer in |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2324 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier() for the case with no |
| 2325 | // intermediate address. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2326 | locations->AddTemp(Location::RequiresRegister()); |
| 2327 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2328 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2329 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2330 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2331 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2332 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2333 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2334 | // The output overlaps in the case of an object array get with |
| 2335 | // read barriers enabled: we do not want the move to overwrite the |
| 2336 | // array's location, as we need it to emit the read barrier. |
| 2337 | locations->SetOut( |
| 2338 | Location::RequiresRegister(), |
| 2339 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2340 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2344 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2345 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2346 | LocationSummary* locations = instruction->GetLocations(); |
| 2347 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2348 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2349 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2350 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2351 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2352 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2353 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2354 | |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2355 | // The non-Baker read barrier instrumentation of object ArrayGet instructions |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2356 | // does not support the HIntermediateAddress instruction. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2357 | DCHECK(!((type == DataType::Type::kReference) && |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2358 | instruction->GetArray()->IsIntermediateAddress() && |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2359 | kEmitCompilerReadBarrier && |
| 2360 | !kUseBakerReadBarrier)); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2361 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2362 | if (type == DataType::Type::kReference && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2363 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2364 | // Note that a potential implicit null check is handled in the |
| 2365 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2366 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2367 | if (index.IsConstant()) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2368 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2369 | // Array load with a constant index can be treated as a field load. |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2370 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2371 | Location maybe_temp = |
| 2372 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2373 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2374 | out, |
| 2375 | obj.W(), |
| 2376 | offset, |
| 2377 | maybe_temp, |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2378 | /* needs_null_check */ false, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2379 | /* use_load_acquire */ false); |
| 2380 | } else { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2381 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2382 | instruction, out, obj.W(), offset, index, /* needs_null_check */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2383 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2384 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2385 | // General case. |
| 2386 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2387 | Register length; |
| 2388 | if (maybe_compressed_char_at) { |
| 2389 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2390 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2391 | { |
| 2392 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2393 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2394 | |
| 2395 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2396 | DCHECK_LT(count_offset, offset); |
| 2397 | int64_t adjusted_offset = |
| 2398 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2399 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2400 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2401 | } else { |
| 2402 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2403 | } |
| 2404 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2405 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2406 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2407 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2408 | if (maybe_compressed_char_at) { |
| 2409 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2410 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2411 | "Expecting 0=compressed, 1=uncompressed"); |
| 2412 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2413 | __ Ldrb(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2414 | HeapOperand(obj, offset + Int64FromLocation(index))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2415 | __ B(&done); |
| 2416 | __ Bind(&uncompressed_load); |
| 2417 | __ Ldrh(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2418 | HeapOperand(obj, offset + (Int64FromLocation(index) << 1))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2419 | __ Bind(&done); |
| 2420 | } else { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2421 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2422 | source = HeapOperand(obj, offset); |
| 2423 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2424 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2425 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2426 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2427 | // We do not need to compute the intermediate address from the array: the |
| 2428 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2429 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2430 | if (kIsDebugBuild) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2431 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2432 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2433 | } |
| 2434 | temp = obj; |
| 2435 | } else { |
| 2436 | __ Add(temp, obj, offset); |
| 2437 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2438 | if (maybe_compressed_char_at) { |
| 2439 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2440 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2441 | "Expecting 0=compressed, 1=uncompressed"); |
| 2442 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2443 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2444 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2445 | __ B(&done); |
| 2446 | __ Bind(&uncompressed_load); |
| 2447 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2448 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2449 | __ Bind(&done); |
| 2450 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2451 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2452 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2453 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2454 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2455 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2456 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2457 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2458 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2459 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2460 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2461 | if (type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2462 | static_assert( |
| 2463 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2464 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2465 | Location obj_loc = locations->InAt(0); |
| 2466 | if (index.IsConstant()) { |
| 2467 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2468 | } else { |
| 2469 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2470 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2471 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2472 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2473 | } |
| 2474 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2475 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2476 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2477 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2478 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2482 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2483 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2484 | { |
| 2485 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2486 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2487 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2488 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2489 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2490 | // Mask out compression flag from String's array length. |
| 2491 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2492 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2493 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2494 | } |
| 2495 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2496 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2497 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2498 | |
| 2499 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2500 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2501 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2502 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2503 | LocationSummary::kCallOnSlowPath : |
| 2504 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2505 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2506 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2507 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2508 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2509 | } else if (DataType::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2510 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2511 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2512 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2513 | } |
| 2514 | } |
| 2515 | |
| 2516 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2517 | DataType::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2518 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2519 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2520 | bool needs_write_barrier = |
| 2521 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2522 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2523 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2524 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2525 | CPURegister source = value; |
| 2526 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2527 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2528 | MemOperand destination = HeapOperand(array); |
| 2529 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2530 | |
| 2531 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2532 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2533 | if (index.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2534 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2535 | destination = HeapOperand(array, offset); |
| 2536 | } else { |
| 2537 | UseScratchRegisterScope temps(masm); |
| 2538 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2539 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2540 | // We do not need to compute the intermediate address from the array: the |
| 2541 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2542 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2543 | if (kIsDebugBuild) { |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 2544 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 2545 | DCHECK(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2546 | } |
| 2547 | temp = array; |
| 2548 | } else { |
| 2549 | __ Add(temp, array, offset); |
| 2550 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2551 | destination = HeapOperand(temp, |
| 2552 | XRegisterFrom(index), |
| 2553 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2554 | DataType::SizeShift(value_type)); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2555 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2556 | { |
| 2557 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2558 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2559 | codegen_->Store(value_type, value, destination); |
| 2560 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2561 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2562 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2563 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2564 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2565 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2566 | { |
| 2567 | // We use a block to end the scratch scope before the write barrier, thus |
| 2568 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2569 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2570 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2571 | if (index.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2572 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2573 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2574 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2575 | destination = HeapOperand(temp, |
| 2576 | XRegisterFrom(index), |
| 2577 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2578 | DataType::SizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2579 | } |
| 2580 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2581 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2582 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2583 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2584 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2585 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2586 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2587 | codegen_->AddSlowPath(slow_path); |
| 2588 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2589 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2590 | __ Cbnz(Register(value), &non_zero); |
| 2591 | if (!index.IsConstant()) { |
| 2592 | __ Add(temp, array, offset); |
| 2593 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2594 | { |
| 2595 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 2596 | // emitted. |
| 2597 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2598 | __ Str(wzr, destination); |
| 2599 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2600 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2601 | __ B(&done); |
| 2602 | __ Bind(&non_zero); |
| 2603 | } |
| 2604 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2605 | // Note that when Baker read barriers are enabled, the type |
| 2606 | // checks are performed without read barriers. This is fine, |
| 2607 | // even in the case where a class object is in the from-space |
| 2608 | // after the flip, as a comparison involving such a type would |
| 2609 | // not produce a false positive; it may of course produce a |
| 2610 | // false negative, in which case we would take the ArraySet |
| 2611 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2612 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2613 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 2614 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2615 | { |
| 2616 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2617 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2618 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 2619 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2620 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2621 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2622 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2623 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 2624 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 2625 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 2626 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 2627 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 2628 | // nor `temp2`, as we are comparing two poisoned references. |
| 2629 | __ Cmp(temp, temp2); |
| 2630 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 2631 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2632 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 2633 | vixl::aarch64::Label do_put; |
| 2634 | __ B(eq, &do_put); |
| 2635 | // If heap poisoning is enabled, the `temp` reference has |
| 2636 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2637 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 2638 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 2639 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 2640 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 2641 | // If heap poisoning is enabled, no need to unpoison |
| 2642 | // `temp`, as we are comparing against null below. |
| 2643 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2644 | __ Bind(&do_put); |
| 2645 | } else { |
| 2646 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2647 | } |
| 2648 | } |
| 2649 | |
| 2650 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2651 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2652 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 2653 | __ Mov(temp2, value.W()); |
| 2654 | GetAssembler()->PoisonHeapReference(temp2); |
| 2655 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | if (!index.IsConstant()) { |
| 2659 | __ Add(temp, array, offset); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 2660 | } else { |
| 2661 | // We no longer need the `temp` here so release it as the store below may |
| 2662 | // need a scratch register (if the constant index makes the offset too large) |
| 2663 | // and the poisoned `source` could be using the other scratch register. |
| 2664 | temps.Release(temp); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2665 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2666 | { |
| 2667 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2668 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2669 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2670 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2671 | if (!may_need_runtime_call_for_type_check) { |
| 2672 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2673 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2674 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2675 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2676 | |
| 2677 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 2678 | |
| 2679 | if (done.IsLinked()) { |
| 2680 | __ Bind(&done); |
| 2681 | } |
| 2682 | |
| 2683 | if (slow_path != nullptr) { |
| 2684 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2685 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2686 | } |
| 2687 | } |
| 2688 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2689 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2690 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2691 | InvokeRuntimeCallingConvention calling_convention; |
| 2692 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 2693 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 2694 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2695 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 2696 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 2700 | BoundsCheckSlowPathARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2701 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2702 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2703 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 2704 | __ B(slow_path->GetEntryLabel(), hs); |
| 2705 | } |
| 2706 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2707 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2708 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2709 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2710 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2711 | if (check->HasUses()) { |
| 2712 | locations->SetOut(Location::SameAsFirstInput()); |
| 2713 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 2714 | // Rely on the type initialization to save everything we need. |
| 2715 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 2719 | // We assume the class is not null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 2720 | SlowPathCodeARM64* slow_path = |
| 2721 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(check->GetLoadClass(), check); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2722 | codegen_->AddSlowPath(slow_path); |
| 2723 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 2724 | } |
| 2725 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2726 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 2727 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 2728 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 2729 | } |
| 2730 | |
| 2731 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 2732 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 2733 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 2734 | if (rhs_loc.IsConstant()) { |
| 2735 | // 0.0 is the only immediate that can be encoded directly in |
| 2736 | // an FCMP instruction. |
| 2737 | // |
| 2738 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 2739 | // specify that in a floating-point comparison, positive zero |
| 2740 | // and negative zero are considered equal, so we can use the |
| 2741 | // literal 0.0 for both cases here. |
| 2742 | // |
| 2743 | // Note however that some methods (Float.equal, Float.compare, |
| 2744 | // Float.compareTo, Double.equal, Double.compare, |
| 2745 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 2746 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 2747 | // -0.0. So if we ever translate calls to these methods into a |
| 2748 | // HCompare instruction, we must handle the -0.0 case with |
| 2749 | // care here. |
| 2750 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 2751 | __ Fcmp(lhs_reg, 0.0); |
| 2752 | } else { |
| 2753 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 2754 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2755 | } |
| 2756 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2757 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2758 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2759 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2760 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2761 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2762 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2763 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2764 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2765 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2766 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2767 | case DataType::Type::kInt32: |
| 2768 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2769 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2770 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2771 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2772 | break; |
| 2773 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2774 | case DataType::Type::kFloat32: |
| 2775 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2776 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2777 | locations->SetInAt(1, |
| 2778 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 2779 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 2780 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2781 | locations->SetOut(Location::RequiresRegister()); |
| 2782 | break; |
| 2783 | } |
| 2784 | default: |
| 2785 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 2786 | } |
| 2787 | } |
| 2788 | |
| 2789 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2790 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2791 | |
| 2792 | // 0 if: left == right |
| 2793 | // 1 if: left > right |
| 2794 | // -1 if: left < right |
| 2795 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2796 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2797 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2798 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2799 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2800 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2801 | case DataType::Type::kInt32: |
| 2802 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2803 | Register result = OutputRegister(compare); |
| 2804 | Register left = InputRegisterAt(compare, 0); |
| 2805 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2806 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2807 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 2808 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2809 | break; |
| 2810 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2811 | case DataType::Type::kFloat32: |
| 2812 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2813 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2814 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2815 | __ Cset(result, ne); |
| 2816 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2817 | break; |
| 2818 | } |
| 2819 | default: |
| 2820 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 2821 | } |
| 2822 | } |
| 2823 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2824 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2825 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2826 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2827 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2828 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2829 | locations->SetInAt(1, |
| 2830 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 2831 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 2832 | : Location::RequiresFpuRegister()); |
| 2833 | } else { |
| 2834 | // Integer cases. |
| 2835 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2836 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 2837 | } |
| 2838 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2839 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2840 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2841 | } |
| 2842 | } |
| 2843 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2844 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2845 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2846 | return; |
| 2847 | } |
| 2848 | |
| 2849 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2850 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2851 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2852 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2853 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2854 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2855 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2856 | } else { |
| 2857 | // Integer cases. |
| 2858 | Register lhs = InputRegisterAt(instruction, 0); |
| 2859 | Operand rhs = InputOperandAt(instruction, 1); |
| 2860 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2861 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 2862 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 2866 | M(Equal) \ |
| 2867 | M(NotEqual) \ |
| 2868 | M(LessThan) \ |
| 2869 | M(LessThanOrEqual) \ |
| 2870 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2871 | M(GreaterThanOrEqual) \ |
| 2872 | M(Below) \ |
| 2873 | M(BelowOrEqual) \ |
| 2874 | M(Above) \ |
| 2875 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2876 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2877 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 2878 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2879 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2880 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2881 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 2882 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 2883 | void InstructionCodeGeneratorARM64::GenerateIntDivForPower2Denom(HDiv* instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2884 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 2885 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 2886 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 2887 | |
| 2888 | Register out = OutputRegister(instruction); |
| 2889 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 2890 | |
| 2891 | if (abs_imm == 2) { |
| 2892 | int bits = DataType::Size(instruction->GetResultType()) * kBitsPerByte; |
| 2893 | __ Add(out, dividend, Operand(dividend, LSR, bits - 1)); |
| 2894 | } else { |
| 2895 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2896 | Register temp = temps.AcquireSameSizeAs(out); |
| 2897 | __ Add(temp, dividend, abs_imm - 1); |
| 2898 | __ Cmp(dividend, 0); |
| 2899 | __ Csel(out, temp, dividend, lt); |
| 2900 | } |
| 2901 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2902 | int ctz_imm = CTZ(abs_imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 2903 | if (imm > 0) { |
| 2904 | __ Asr(out, out, ctz_imm); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2905 | } else { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 2906 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2907 | } |
| 2908 | } |
| 2909 | |
| 2910 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2911 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2912 | |
| 2913 | LocationSummary* locations = instruction->GetLocations(); |
| 2914 | Location second = locations->InAt(1); |
| 2915 | DCHECK(second.IsConstant()); |
| 2916 | |
| 2917 | Register out = OutputRegister(instruction); |
| 2918 | Register dividend = InputRegisterAt(instruction, 0); |
| 2919 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 2920 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2921 | DataType::Type type = instruction->GetResultType(); |
| 2922 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2923 | |
| 2924 | int64_t magic; |
| 2925 | int shift; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2926 | CalculateMagicAndShiftForDivRem( |
| 2927 | imm, type == DataType::Type::kInt64 /* is_long */, &magic, &shift); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2928 | |
| 2929 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2930 | Register temp = temps.AcquireSameSizeAs(out); |
| 2931 | |
| 2932 | // temp = get_high(dividend * magic) |
| 2933 | __ Mov(temp, magic); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2934 | if (type == DataType::Type::kInt64) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2935 | __ Smulh(temp, dividend, temp); |
| 2936 | } else { |
| 2937 | __ Smull(temp.X(), dividend, temp); |
| 2938 | __ Lsr(temp.X(), temp.X(), 32); |
| 2939 | } |
| 2940 | |
| 2941 | if (imm > 0 && magic < 0) { |
| 2942 | __ Add(temp, temp, dividend); |
| 2943 | } else if (imm < 0 && magic > 0) { |
| 2944 | __ Sub(temp, temp, dividend); |
| 2945 | } |
| 2946 | |
| 2947 | if (shift != 0) { |
| 2948 | __ Asr(temp, temp, shift); |
| 2949 | } |
| 2950 | |
| 2951 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2952 | __ Sub(out, temp, Operand(temp, ASR, type == DataType::Type::kInt64 ? 63 : 31)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2953 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2954 | __ Sub(temp, temp, Operand(temp, ASR, type == DataType::Type::kInt64 ? 63 : 31)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2955 | // TODO: Strength reduction for msub. |
| 2956 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 2957 | __ Mov(temp_imm, imm); |
| 2958 | __ Msub(out, temp, temp_imm, dividend); |
| 2959 | } |
| 2960 | } |
| 2961 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 2962 | void InstructionCodeGeneratorARM64::GenerateIntDivForConstDenom(HDiv *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2963 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2964 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 2965 | if (imm == 0) { |
| 2966 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2967 | return; |
| 2968 | } |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2969 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 2970 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 2971 | GenerateIntDivForPower2Denom(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2972 | } else { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 2973 | // Cases imm == -1 or imm == 1 are handled by InstructionSimplifier. |
| 2974 | DCHECK(imm < -2 || imm > 2) << imm; |
| 2975 | GenerateDivRemWithAnyConstant(instruction); |
| 2976 | } |
| 2977 | } |
| 2978 | |
| 2979 | void InstructionCodeGeneratorARM64::GenerateIntDiv(HDiv *instruction) { |
| 2980 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 2981 | << instruction->GetResultType(); |
| 2982 | |
| 2983 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 2984 | GenerateIntDivForConstDenom(instruction); |
| 2985 | } else { |
| 2986 | Register out = OutputRegister(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2987 | Register dividend = InputRegisterAt(instruction, 0); |
| 2988 | Register divisor = InputRegisterAt(instruction, 1); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 2989 | __ Sdiv(out, dividend, divisor); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 2990 | } |
| 2991 | } |
| 2992 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2993 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 2994 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2995 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2996 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2997 | case DataType::Type::kInt32: |
| 2998 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2999 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3000 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3001 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3002 | break; |
| 3003 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3004 | case DataType::Type::kFloat32: |
| 3005 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3006 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3007 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3008 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3009 | break; |
| 3010 | |
| 3011 | default: |
| 3012 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3013 | } |
| 3014 | } |
| 3015 | |
| 3016 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3017 | DataType::Type type = div->GetResultType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3018 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3019 | case DataType::Type::kInt32: |
| 3020 | case DataType::Type::kInt64: |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3021 | GenerateIntDiv(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3022 | break; |
| 3023 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3024 | case DataType::Type::kFloat32: |
| 3025 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3026 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3027 | break; |
| 3028 | |
| 3029 | default: |
| 3030 | LOG(FATAL) << "Unexpected div type " << type; |
| 3031 | } |
| 3032 | } |
| 3033 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3034 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3035 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3036 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3040 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3041 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3042 | codegen_->AddSlowPath(slow_path); |
| 3043 | Location value = instruction->GetLocations()->InAt(0); |
| 3044 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3045 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3046 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3047 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3048 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame^] | 3049 | UNREACHABLE(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3050 | } |
| 3051 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3052 | if (value.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3053 | int64_t divisor = Int64FromLocation(value); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3054 | if (divisor == 0) { |
| 3055 | __ B(slow_path->GetEntryLabel()); |
| 3056 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3057 | // A division by a non-null constant is valid. We don't need to perform |
| 3058 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3059 | } |
| 3060 | } else { |
| 3061 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3062 | } |
| 3063 | } |
| 3064 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3065 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3066 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3067 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3068 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3069 | } |
| 3070 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3071 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3072 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3073 | // Will be generated at use site. |
| 3074 | } |
| 3075 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3076 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3077 | exit->SetLocations(nullptr); |
| 3078 | } |
| 3079 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3080 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3081 | } |
| 3082 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3083 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3084 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3085 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3086 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3087 | } |
| 3088 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3089 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3090 | // Will be generated at use site. |
| 3091 | } |
| 3092 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3093 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3094 | if (successor->IsExitBlock()) { |
| 3095 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3096 | return; // no code needed |
| 3097 | } |
| 3098 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3099 | HBasicBlock* block = got->GetBlock(); |
| 3100 | HInstruction* previous = got->GetPrevious(); |
| 3101 | HLoopInformation* info = block->GetLoopInformation(); |
| 3102 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3103 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 3104 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 3105 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3106 | Register temp1 = temps.AcquireX(); |
| 3107 | Register temp2 = temps.AcquireX(); |
| 3108 | __ Ldr(temp1, MemOperand(sp, 0)); |
| 3109 | __ Ldrh(temp2, MemOperand(temp1, ArtMethod::HotnessCountOffset().Int32Value())); |
| 3110 | __ Add(temp2, temp2, 1); |
| 3111 | __ Strh(temp2, MemOperand(temp1, ArtMethod::HotnessCountOffset().Int32Value())); |
| 3112 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3113 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3114 | return; |
| 3115 | } |
| 3116 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3117 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 3118 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3119 | } |
| 3120 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3121 | __ B(codegen_->GetLabelOf(successor)); |
| 3122 | } |
| 3123 | } |
| 3124 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3125 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3126 | got->SetLocations(nullptr); |
| 3127 | } |
| 3128 | |
| 3129 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3130 | HandleGoto(got, got->GetSuccessor()); |
| 3131 | } |
| 3132 | |
| 3133 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3134 | try_boundary->SetLocations(nullptr); |
| 3135 | } |
| 3136 | |
| 3137 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3138 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3139 | if (!successor->IsExitBlock()) { |
| 3140 | HandleGoto(try_boundary, successor); |
| 3141 | } |
| 3142 | } |
| 3143 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3144 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3145 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3146 | vixl::aarch64::Label* true_target, |
| 3147 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3148 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3149 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3150 | if (true_target == nullptr && false_target == nullptr) { |
| 3151 | // Nothing to do. The code always falls through. |
| 3152 | return; |
| 3153 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3154 | // Constant condition, statically compared against "true" (integer value 1). |
| 3155 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3156 | if (true_target != nullptr) { |
| 3157 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3158 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3159 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3160 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3161 | if (false_target != nullptr) { |
| 3162 | __ B(false_target); |
| 3163 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3164 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3165 | return; |
| 3166 | } |
| 3167 | |
| 3168 | // The following code generates these patterns: |
| 3169 | // (1) true_target == nullptr && false_target != nullptr |
| 3170 | // - opposite condition true => branch to false_target |
| 3171 | // (2) true_target != nullptr && false_target == nullptr |
| 3172 | // - condition true => branch to true_target |
| 3173 | // (3) true_target != nullptr && false_target != nullptr |
| 3174 | // - condition true => branch to true_target |
| 3175 | // - branch to false_target |
| 3176 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3177 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3178 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3179 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3180 | if (true_target == nullptr) { |
| 3181 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3182 | } else { |
| 3183 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3184 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3185 | } else { |
| 3186 | // The condition instruction has not been materialized, use its inputs as |
| 3187 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3188 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3189 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3190 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3191 | if (DataType::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3192 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3193 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3194 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3195 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3196 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3197 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3198 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3199 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3200 | // Integer cases. |
| 3201 | Register lhs = InputRegisterAt(condition, 0); |
| 3202 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3203 | |
| 3204 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3205 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3206 | if (true_target == nullptr) { |
| 3207 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3208 | non_fallthrough_target = false_target; |
| 3209 | } else { |
| 3210 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3211 | non_fallthrough_target = true_target; |
| 3212 | } |
| 3213 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3214 | 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] | 3215 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3216 | switch (arm64_cond) { |
| 3217 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3218 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3219 | break; |
| 3220 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3221 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3222 | break; |
| 3223 | case lt: |
| 3224 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3225 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3226 | break; |
| 3227 | case ge: |
| 3228 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3229 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3230 | break; |
| 3231 | default: |
| 3232 | // Without the `static_cast` the compiler throws an error for |
| 3233 | // `-Werror=sign-promo`. |
| 3234 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3235 | } |
| 3236 | } else { |
| 3237 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3238 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3239 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3240 | } |
| 3241 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3242 | |
| 3243 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3244 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3245 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3246 | __ B(false_target); |
| 3247 | } |
| 3248 | } |
| 3249 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3250 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3251 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3252 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3253 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3254 | } |
| 3255 | } |
| 3256 | |
| 3257 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3258 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3259 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3260 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3261 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3262 | true_target = nullptr; |
| 3263 | } |
| 3264 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3265 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3266 | false_target = nullptr; |
| 3267 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3268 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3272 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3273 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3274 | InvokeRuntimeCallingConvention calling_convention; |
| 3275 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3276 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3277 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3278 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3279 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3280 | } |
| 3281 | } |
| 3282 | |
| 3283 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3284 | SlowPathCodeARM64* slow_path = |
| 3285 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3286 | GenerateTestAndBranch(deoptimize, |
| 3287 | /* condition_input_index */ 0, |
| 3288 | slow_path->GetEntryLabel(), |
| 3289 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3290 | } |
| 3291 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3292 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3293 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3294 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3295 | locations->SetOut(Location::RequiresRegister()); |
| 3296 | } |
| 3297 | |
| 3298 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3299 | __ Ldr(OutputRegister(flag), |
| 3300 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3301 | } |
| 3302 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3303 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3304 | return condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3305 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3306 | } |
| 3307 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3308 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3309 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3310 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3311 | : ARM64Condition(cond); |
| 3312 | } |
| 3313 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3314 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3315 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3316 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3317 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3318 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3319 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3320 | } else { |
| 3321 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3322 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3323 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3324 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3325 | // Ask VIXL whether we should synthesize constants in registers. |
| 3326 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3327 | Operand true_op = is_true_value_constant ? |
| 3328 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3329 | Operand false_op = is_false_value_constant ? |
| 3330 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3331 | bool true_value_in_register = false; |
| 3332 | bool false_value_in_register = false; |
| 3333 | MacroAssembler::GetCselSynthesisInformation( |
| 3334 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3335 | true_value_in_register |= !is_true_value_constant; |
| 3336 | false_value_in_register |= !is_false_value_constant; |
| 3337 | |
| 3338 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3339 | : Location::ConstantLocation(cst_true_value)); |
| 3340 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3341 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3342 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3343 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3344 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3345 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3346 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3347 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3348 | } |
| 3349 | |
| 3350 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3351 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3352 | Condition csel_cond; |
| 3353 | |
| 3354 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3355 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3356 | // Use the condition flags set by the previous instruction. |
| 3357 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3358 | } else { |
| 3359 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3360 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3361 | } |
| 3362 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3363 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3364 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3365 | } else { |
| 3366 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3367 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3368 | } |
| 3369 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3370 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3371 | __ Fcsel(OutputFPRegister(select), |
| 3372 | InputFPRegisterAt(select, 1), |
| 3373 | InputFPRegisterAt(select, 0), |
| 3374 | csel_cond); |
| 3375 | } else { |
| 3376 | __ Csel(OutputRegister(select), |
| 3377 | InputOperandAt(select, 1), |
| 3378 | InputOperandAt(select, 0), |
| 3379 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3380 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3381 | } |
| 3382 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3383 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3384 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3385 | } |
| 3386 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3387 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3388 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3389 | } |
| 3390 | |
| 3391 | void CodeGeneratorARM64::GenerateNop() { |
| 3392 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3393 | } |
| 3394 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3395 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3396 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3400 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3404 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3405 | } |
| 3406 | |
| 3407 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3408 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3409 | } |
| 3410 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3411 | // Temp is used for read barrier. |
| 3412 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3413 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3414 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3415 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3416 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3417 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3418 | return 1; |
| 3419 | } |
| 3420 | return 0; |
| 3421 | } |
| 3422 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3423 | // 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] | 3424 | // interface pointer, one for loading the current interface. |
| 3425 | // The other checks have one temp for loading the object's class. |
| 3426 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3427 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3428 | return 3; |
| 3429 | } |
| 3430 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3431 | } |
| 3432 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3433 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3434 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3435 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3436 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3437 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3438 | case TypeCheckKind::kExactCheck: |
| 3439 | case TypeCheckKind::kAbstractClassCheck: |
| 3440 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3441 | case TypeCheckKind::kArrayObjectCheck: { |
| 3442 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 3443 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 3444 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3445 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3446 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3447 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3448 | case TypeCheckKind::kUnresolvedCheck: |
| 3449 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3450 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3451 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3452 | case TypeCheckKind::kBitstringCheck: |
| 3453 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3454 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3455 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3456 | LocationSummary* locations = |
| 3457 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3458 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3459 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3460 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3461 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3462 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3463 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3464 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3465 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3466 | } else { |
| 3467 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3468 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3469 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3470 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3471 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3472 | // Add temps if necessary for read barriers. |
| 3473 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3477 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3478 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3479 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3480 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3481 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 3482 | ? Register() |
| 3483 | : InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3484 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3485 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3486 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3487 | DCHECK_LE(num_temps, 1u); |
| 3488 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3489 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3490 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3491 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3492 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3493 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3494 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3495 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3496 | |
| 3497 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3498 | // Avoid null check if we know `obj` is not null. |
| 3499 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3500 | __ Cbz(obj, &zero); |
| 3501 | } |
| 3502 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3503 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3504 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3505 | ReadBarrierOption read_barrier_option = |
| 3506 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3507 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3508 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3509 | out_loc, |
| 3510 | obj_loc, |
| 3511 | class_offset, |
| 3512 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3513 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3514 | __ Cmp(out, cls); |
| 3515 | __ Cset(out, eq); |
| 3516 | if (zero.IsLinked()) { |
| 3517 | __ B(&done); |
| 3518 | } |
| 3519 | break; |
| 3520 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3521 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3522 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3523 | ReadBarrierOption read_barrier_option = |
| 3524 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3525 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3526 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3527 | out_loc, |
| 3528 | obj_loc, |
| 3529 | class_offset, |
| 3530 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3531 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3532 | // If the class is abstract, we eagerly fetch the super class of the |
| 3533 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3534 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3535 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3536 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3537 | GenerateReferenceLoadOneRegister(instruction, |
| 3538 | out_loc, |
| 3539 | super_offset, |
| 3540 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3541 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3542 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3543 | __ Cbz(out, &done); |
| 3544 | __ Cmp(out, cls); |
| 3545 | __ B(ne, &loop); |
| 3546 | __ Mov(out, 1); |
| 3547 | if (zero.IsLinked()) { |
| 3548 | __ B(&done); |
| 3549 | } |
| 3550 | break; |
| 3551 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3552 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3553 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3554 | ReadBarrierOption read_barrier_option = |
| 3555 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3556 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3557 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3558 | out_loc, |
| 3559 | obj_loc, |
| 3560 | class_offset, |
| 3561 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3562 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3563 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3564 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3565 | __ Bind(&loop); |
| 3566 | __ Cmp(out, cls); |
| 3567 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3568 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3569 | GenerateReferenceLoadOneRegister(instruction, |
| 3570 | out_loc, |
| 3571 | super_offset, |
| 3572 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3573 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3574 | __ Cbnz(out, &loop); |
| 3575 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3576 | __ B(&done); |
| 3577 | __ Bind(&success); |
| 3578 | __ Mov(out, 1); |
| 3579 | if (zero.IsLinked()) { |
| 3580 | __ B(&done); |
| 3581 | } |
| 3582 | break; |
| 3583 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3584 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3585 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3586 | ReadBarrierOption read_barrier_option = |
| 3587 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3588 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3589 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3590 | out_loc, |
| 3591 | obj_loc, |
| 3592 | class_offset, |
| 3593 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3594 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3595 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3596 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3597 | __ Cmp(out, cls); |
| 3598 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3599 | // 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] | 3600 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3601 | GenerateReferenceLoadOneRegister(instruction, |
| 3602 | out_loc, |
| 3603 | component_offset, |
| 3604 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3605 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3606 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3607 | __ Cbz(out, &done); |
| 3608 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 3609 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 3610 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3611 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3612 | __ Mov(out, 1); |
| 3613 | __ B(&done); |
| 3614 | break; |
| 3615 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3616 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3617 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3618 | // No read barrier since the slow path will retry upon failure. |
| 3619 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3620 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3621 | out_loc, |
| 3622 | obj_loc, |
| 3623 | class_offset, |
| 3624 | maybe_temp_loc, |
| 3625 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3626 | __ Cmp(out, cls); |
| 3627 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3628 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 3629 | instruction, /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3630 | codegen_->AddSlowPath(slow_path); |
| 3631 | __ B(ne, slow_path->GetEntryLabel()); |
| 3632 | __ Mov(out, 1); |
| 3633 | if (zero.IsLinked()) { |
| 3634 | __ B(&done); |
| 3635 | } |
| 3636 | break; |
| 3637 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3638 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3639 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3640 | case TypeCheckKind::kInterfaceCheck: { |
| 3641 | // Note that we indeed only call on slow path, but we always go |
| 3642 | // into the slow path for the unresolved and interface check |
| 3643 | // cases. |
| 3644 | // |
| 3645 | // We cannot directly call the InstanceofNonTrivial runtime |
| 3646 | // entry point without resorting to a type checking slow path |
| 3647 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 3648 | // require to assign fixed registers for the inputs of this |
| 3649 | // HInstanceOf instruction (following the runtime calling |
| 3650 | // convention), which might be cluttered by the potential first |
| 3651 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3652 | // |
| 3653 | // TODO: Introduce a new runtime entry point taking the object |
| 3654 | // to test (instead of its class) as argument, and let it deal |
| 3655 | // with the read barrier issues. This will let us refactor this |
| 3656 | // case of the `switch` code as it was previously (with a direct |
| 3657 | // call to the runtime not using a type checking slow path). |
| 3658 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3659 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3660 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 3661 | instruction, /* is_fatal */ false); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3662 | codegen_->AddSlowPath(slow_path); |
| 3663 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3664 | if (zero.IsLinked()) { |
| 3665 | __ B(&done); |
| 3666 | } |
| 3667 | break; |
| 3668 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3669 | |
| 3670 | case TypeCheckKind::kBitstringCheck: { |
| 3671 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3672 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3673 | out_loc, |
| 3674 | obj_loc, |
| 3675 | class_offset, |
| 3676 | maybe_temp_loc, |
| 3677 | kWithoutReadBarrier); |
| 3678 | |
| 3679 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 3680 | __ Cset(out, eq); |
| 3681 | if (zero.IsLinked()) { |
| 3682 | __ B(&done); |
| 3683 | } |
| 3684 | break; |
| 3685 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3686 | } |
| 3687 | |
| 3688 | if (zero.IsLinked()) { |
| 3689 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3690 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3691 | } |
| 3692 | |
| 3693 | if (done.IsLinked()) { |
| 3694 | __ Bind(&done); |
| 3695 | } |
| 3696 | |
| 3697 | if (slow_path != nullptr) { |
| 3698 | __ Bind(slow_path->GetExitLabel()); |
| 3699 | } |
| 3700 | } |
| 3701 | |
| 3702 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3703 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3704 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3705 | LocationSummary* locations = |
| 3706 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3707 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3708 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3709 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3710 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3711 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3712 | } else { |
| 3713 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3714 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3715 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 3716 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3717 | } |
| 3718 | |
| 3719 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3720 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3721 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3722 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3723 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3724 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 3725 | ? Register() |
| 3726 | : InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3727 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 3728 | DCHECK_GE(num_temps, 1u); |
| 3729 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3730 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3731 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 3732 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3733 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3734 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3735 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3736 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3737 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 3738 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 3739 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 3740 | const uint32_t object_array_data_offset = |
| 3741 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3742 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3743 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3744 | SlowPathCodeARM64* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3745 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 3746 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3747 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3748 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3749 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3750 | // Avoid null check if we know obj is not null. |
| 3751 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3752 | __ Cbz(obj, &done); |
| 3753 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3754 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3755 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3756 | case TypeCheckKind::kExactCheck: |
| 3757 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3758 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3759 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3760 | temp_loc, |
| 3761 | obj_loc, |
| 3762 | class_offset, |
| 3763 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3764 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3765 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3766 | __ Cmp(temp, cls); |
| 3767 | // Jump to slow path for throwing the exception or doing a |
| 3768 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3769 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3770 | break; |
| 3771 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3772 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3773 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3774 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3775 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3776 | temp_loc, |
| 3777 | obj_loc, |
| 3778 | class_offset, |
| 3779 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3780 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3781 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3782 | // If the class is abstract, we eagerly fetch the super class of the |
| 3783 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3784 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3785 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3786 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3787 | GenerateReferenceLoadOneRegister(instruction, |
| 3788 | temp_loc, |
| 3789 | super_offset, |
| 3790 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3791 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3792 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3793 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 3794 | // exception. |
| 3795 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 3796 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3797 | __ Cmp(temp, cls); |
| 3798 | __ B(ne, &loop); |
| 3799 | break; |
| 3800 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3801 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3802 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3803 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3804 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3805 | temp_loc, |
| 3806 | obj_loc, |
| 3807 | class_offset, |
| 3808 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3809 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3810 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3811 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3812 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3813 | __ Bind(&loop); |
| 3814 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3815 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3816 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3817 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3818 | GenerateReferenceLoadOneRegister(instruction, |
| 3819 | temp_loc, |
| 3820 | super_offset, |
| 3821 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3822 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3823 | |
| 3824 | // If the class reference currently in `temp` is not null, jump |
| 3825 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3826 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3827 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3828 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3829 | break; |
| 3830 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3831 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3832 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3833 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3834 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3835 | temp_loc, |
| 3836 | obj_loc, |
| 3837 | class_offset, |
| 3838 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3839 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3840 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 3841 | // Do an exact check. |
| 3842 | __ Cmp(temp, cls); |
| 3843 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3844 | |
| 3845 | // 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] | 3846 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3847 | GenerateReferenceLoadOneRegister(instruction, |
| 3848 | temp_loc, |
| 3849 | component_offset, |
| 3850 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3851 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3852 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3853 | // If the component type is null, jump to the slow path to throw the exception. |
| 3854 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 3855 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 3856 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3857 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 3858 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 3859 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3860 | break; |
| 3861 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3862 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 3863 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3864 | // 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] | 3865 | // |
| 3866 | // We cannot directly call the CheckCast runtime entry point |
| 3867 | // without resorting to a type checking slow path here (i.e. by |
| 3868 | // calling InvokeRuntime directly), as it would require to |
| 3869 | // assign fixed registers for the inputs of this HInstanceOf |
| 3870 | // instruction (following the runtime calling convention), which |
| 3871 | // might be cluttered by the potential first read barrier |
| 3872 | // emission at the beginning of this method. |
| 3873 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3874 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3875 | case TypeCheckKind::kInterfaceCheck: { |
| 3876 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3877 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3878 | temp_loc, |
| 3879 | obj_loc, |
| 3880 | class_offset, |
| 3881 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3882 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3883 | |
| 3884 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 3885 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3886 | temp_loc, |
| 3887 | temp_loc, |
| 3888 | iftable_offset, |
| 3889 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3890 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 3891 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3892 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 3893 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3894 | vixl::aarch64::Label start_loop; |
| 3895 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 3896 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3897 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 3898 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3899 | // Go to next interface. |
| 3900 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 3901 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 3902 | // Compare the classes and continue the loop if they do not match. |
| 3903 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 3904 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3905 | break; |
| 3906 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3907 | |
| 3908 | case TypeCheckKind::kBitstringCheck: { |
| 3909 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 3910 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3911 | temp_loc, |
| 3912 | obj_loc, |
| 3913 | class_offset, |
| 3914 | maybe_temp2_loc, |
| 3915 | kWithoutReadBarrier); |
| 3916 | |
| 3917 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 3918 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 3919 | break; |
| 3920 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3921 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 3922 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3923 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3924 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3925 | } |
| 3926 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3927 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3928 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3929 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3930 | } |
| 3931 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3932 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3933 | // Will be generated at use site. |
| 3934 | } |
| 3935 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3936 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3937 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3938 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3939 | } |
| 3940 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3941 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3942 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3943 | } |
| 3944 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3945 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3946 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3947 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3948 | // the method_idx. |
| 3949 | HandleInvoke(invoke); |
| 3950 | } |
| 3951 | |
| 3952 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3953 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 3954 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3955 | } |
| 3956 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3957 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3958 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3959 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3960 | } |
| 3961 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3962 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3963 | HandleInvoke(invoke); |
| 3964 | } |
| 3965 | |
| 3966 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3967 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3968 | LocationSummary* locations = invoke->GetLocations(); |
| 3969 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3970 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3971 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3972 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3973 | |
| 3974 | // The register ip1 is required to be used for the hidden argument in |
| 3975 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 3976 | MacroAssembler* masm = GetVIXLAssembler(); |
| 3977 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3978 | scratch_scope.Exclude(ip1); |
| 3979 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 3980 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3981 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3982 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3983 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3984 | { |
| 3985 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3986 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 3987 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 3988 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3989 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3990 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3991 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3992 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3993 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3994 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3995 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3996 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3997 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3998 | // emit a read barrier for the previous class reference load. |
| 3999 | // However this is not required in practice, as this is an |
| 4000 | // intermediate/temporary reference and because the current |
| 4001 | // concurrent copying collector keeps the from-space memory |
| 4002 | // intact/accessible until the end of the marking phase (the |
| 4003 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4004 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4005 | __ Ldr(temp, |
| 4006 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4007 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4008 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4009 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4010 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4011 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4012 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4013 | |
| 4014 | { |
| 4015 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4016 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4017 | |
| 4018 | // lr(); |
| 4019 | __ blr(lr); |
| 4020 | DCHECK(!codegen_->IsLeafMethod()); |
| 4021 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4022 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4023 | |
| 4024 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4025 | } |
| 4026 | |
| 4027 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4028 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4029 | if (intrinsic.TryDispatch(invoke)) { |
| 4030 | return; |
| 4031 | } |
| 4032 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4033 | HandleInvoke(invoke); |
| 4034 | } |
| 4035 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4036 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4037 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4038 | // art::PrepareForRegisterAllocation. |
| 4039 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4040 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4041 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4042 | if (intrinsic.TryDispatch(invoke)) { |
| 4043 | return; |
| 4044 | } |
| 4045 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4046 | HandleInvoke(invoke); |
| 4047 | } |
| 4048 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4049 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4050 | if (invoke->GetLocations()->Intrinsified()) { |
| 4051 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4052 | intrinsic.Dispatch(invoke); |
| 4053 | return true; |
| 4054 | } |
| 4055 | return false; |
| 4056 | } |
| 4057 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4058 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4059 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4060 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4061 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4062 | return desired_dispatch_info; |
| 4063 | } |
| 4064 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4065 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4066 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4067 | // 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] | 4068 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4069 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4070 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4071 | uint32_t offset = |
| 4072 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4073 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4074 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4075 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4076 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4077 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4078 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4079 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4080 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4081 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4082 | // Add ADRP with its PC-relative method patch. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4083 | vixl::aarch64::Label* adrp_label = NewBootImageMethodPatch(invoke->GetTargetMethod()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4084 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4085 | // Add ADD with its PC-relative method patch. |
| 4086 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4087 | NewBootImageMethodPatch(invoke->GetTargetMethod(), adrp_label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4088 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4089 | break; |
| 4090 | } |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4091 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4092 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4093 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4094 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_offset); |
| 4095 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4096 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| 4097 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| 4098 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 4099 | EmitLdrOffsetPlaceholder(ldr_label, WRegisterFrom(temp), XRegisterFrom(temp)); |
| 4100 | break; |
| 4101 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4102 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4103 | // Add ADRP with its PC-relative .bss entry patch. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4104 | MethodReference target_method(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4105 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(target_method); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4106 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4107 | // Add LDR with its PC-relative .bss entry patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4108 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4109 | NewMethodBssEntryPatch(target_method, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4110 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4111 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4112 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4113 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 4114 | // Load method address from literal pool. |
| 4115 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
| 4116 | break; |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4117 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4118 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4119 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4120 | } |
| 4121 | } |
| 4122 | |
| 4123 | switch (invoke->GetCodePtrLocation()) { |
| 4124 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4125 | { |
| 4126 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4127 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4128 | kInstructionSize, |
| 4129 | CodeBufferCheckScope::kExactSize); |
| 4130 | __ bl(&frame_entry_label_); |
| 4131 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4132 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4133 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4134 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4135 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4136 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4137 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4138 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4139 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4140 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4141 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4142 | kInstructionSize, |
| 4143 | CodeBufferCheckScope::kExactSize); |
| 4144 | // lr() |
| 4145 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4146 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4147 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4148 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4149 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4150 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4151 | DCHECK(!IsLeafMethod()); |
| 4152 | } |
| 4153 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4154 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4155 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4156 | // Use the calling convention instead of the location of the receiver, as |
| 4157 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4158 | // slow path, the arguments have been moved to the right place, so here we are |
| 4159 | // guaranteed that the receiver is the first register of the calling convention. |
| 4160 | InvokeDexCallingConvention calling_convention; |
| 4161 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4162 | Register temp = XRegisterFrom(temp_in); |
| 4163 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4164 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4165 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4166 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4167 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4168 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4169 | |
| 4170 | { |
| 4171 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4172 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4173 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4174 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4175 | MaybeRecordImplicitNullCheck(invoke); |
| 4176 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4177 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4178 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4179 | // intermediate/temporary reference and because the current |
| 4180 | // concurrent copying collector keeps the from-space memory |
| 4181 | // intact/accessible until the end of the marking phase (the |
| 4182 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4183 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4184 | // temp = temp->GetMethodAt(method_offset); |
| 4185 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4186 | // lr = temp->GetEntryPoint(); |
| 4187 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4188 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4189 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4190 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4191 | // lr(); |
| 4192 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4193 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4194 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4195 | } |
| 4196 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4197 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4198 | HandleInvoke(invoke); |
| 4199 | } |
| 4200 | |
| 4201 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4202 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4203 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4204 | } |
| 4205 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4206 | void LocationsBuilderARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4207 | HandleInvoke(invoke); |
| 4208 | } |
| 4209 | |
| 4210 | void InstructionCodeGeneratorARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4211 | codegen_->GenerateInvokeCustomCall(invoke); |
| 4212 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| 4213 | } |
| 4214 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4215 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageIntrinsicPatch( |
| 4216 | uint32_t intrinsic_data, |
| 4217 | vixl::aarch64::Label* adrp_label) { |
| 4218 | return NewPcRelativePatch( |
| 4219 | /* dex_file */ nullptr, intrinsic_data, adrp_label, &boot_image_intrinsic_patches_); |
| 4220 | } |
| 4221 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4222 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageRelRoPatch( |
| 4223 | uint32_t boot_image_offset, |
| 4224 | vixl::aarch64::Label* adrp_label) { |
| 4225 | return NewPcRelativePatch( |
| 4226 | /* dex_file */ nullptr, boot_image_offset, adrp_label, &boot_image_method_patches_); |
| 4227 | } |
| 4228 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4229 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageMethodPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4230 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4231 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4232 | return NewPcRelativePatch( |
| 4233 | target_method.dex_file, target_method.index, adrp_label, &boot_image_method_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4234 | } |
| 4235 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4236 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4237 | MethodReference target_method, |
| 4238 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4239 | return NewPcRelativePatch( |
| 4240 | target_method.dex_file, target_method.index, adrp_label, &method_bss_entry_patches_); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4241 | } |
| 4242 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4243 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageTypePatch( |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4244 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4245 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4246 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4247 | return NewPcRelativePatch(&dex_file, type_index.index_, adrp_label, &boot_image_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4248 | } |
| 4249 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4250 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4251 | const DexFile& dex_file, |
| 4252 | dex::TypeIndex type_index, |
| 4253 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4254 | return NewPcRelativePatch(&dex_file, type_index.index_, adrp_label, &type_bss_entry_patches_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4255 | } |
| 4256 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4257 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageStringPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4258 | const DexFile& dex_file, |
| 4259 | dex::StringIndex string_index, |
| 4260 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4261 | return NewPcRelativePatch( |
| 4262 | &dex_file, string_index.index_, adrp_label, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4263 | } |
| 4264 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4265 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4266 | const DexFile& dex_file, |
| 4267 | dex::StringIndex string_index, |
| 4268 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4269 | return NewPcRelativePatch(&dex_file, string_index.index_, adrp_label, &string_bss_entry_patches_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4270 | } |
| 4271 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 4272 | void CodeGeneratorARM64::EmitBakerReadBarrierCbnz(uint32_t custom_data) { |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 4273 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 4274 | if (Runtime::Current()->UseJitCompilation()) { |
| 4275 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 4276 | vixl::aarch64::Label* slow_path_entry = &it->second.label; |
| 4277 | __ cbnz(mr, slow_path_entry); |
| 4278 | } else { |
| 4279 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4280 | vixl::aarch64::Label* cbnz_label = &baker_read_barrier_patches_.back().label; |
| 4281 | __ bind(cbnz_label); |
| 4282 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 4283 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4284 | } |
| 4285 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4286 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4287 | const DexFile* dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4288 | uint32_t offset_or_index, |
| 4289 | vixl::aarch64::Label* adrp_label, |
| 4290 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4291 | // Add a patch entry and return the label. |
| 4292 | patches->emplace_back(dex_file, offset_or_index); |
| 4293 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4294 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4295 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4296 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4297 | return label; |
| 4298 | } |
| 4299 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4300 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4301 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4302 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4303 | } |
| 4304 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4305 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4306 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4307 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4308 | return jit_string_patches_.GetOrCreate( |
| 4309 | StringReference(&dex_file, string_index), |
| 4310 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4311 | } |
| 4312 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4313 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4314 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4315 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4316 | return jit_class_patches_.GetOrCreate( |
| 4317 | TypeReference(&dex_file, type_index), |
| 4318 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4319 | } |
| 4320 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4321 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4322 | vixl::aarch64::Register reg) { |
| 4323 | DCHECK(reg.IsX()); |
| 4324 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4325 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4326 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4327 | } |
| 4328 | |
| 4329 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4330 | vixl::aarch64::Register out, |
| 4331 | vixl::aarch64::Register base) { |
| 4332 | DCHECK(out.IsX()); |
| 4333 | DCHECK(base.IsX()); |
| 4334 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4335 | __ Bind(fixup_label); |
| 4336 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4337 | } |
| 4338 | |
| 4339 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4340 | vixl::aarch64::Register out, |
| 4341 | vixl::aarch64::Register base) { |
| 4342 | DCHECK(base.IsX()); |
| 4343 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4344 | __ Bind(fixup_label); |
| 4345 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4346 | } |
| 4347 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4348 | void CodeGeneratorARM64::LoadBootImageAddress(vixl::aarch64::Register reg, |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4349 | uint32_t boot_image_reference) { |
| 4350 | if (GetCompilerOptions().IsBootImage()) { |
| 4351 | // Add ADRP with its PC-relative type patch. |
| 4352 | vixl::aarch64::Label* adrp_label = NewBootImageIntrinsicPatch(boot_image_reference); |
| 4353 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4354 | // Add ADD with its PC-relative type patch. |
| 4355 | vixl::aarch64::Label* add_label = NewBootImageIntrinsicPatch(boot_image_reference, adrp_label); |
| 4356 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 4357 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4358 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4359 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4360 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4361 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4362 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_reference, adrp_label); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4363 | EmitLdrOffsetPlaceholder(ldr_label, reg.W(), reg.X()); |
| 4364 | } else { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4365 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4366 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 4367 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4368 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4369 | __ Ldr(reg.W(), DeduplicateBootImageAddressLiteral(reinterpret_cast<uintptr_t>(address))); |
| 4370 | } |
| 4371 | } |
| 4372 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4373 | void CodeGeneratorARM64::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 4374 | uint32_t boot_image_offset) { |
| 4375 | DCHECK(invoke->IsStatic()); |
| 4376 | InvokeRuntimeCallingConvention calling_convention; |
| 4377 | Register argument = calling_convention.GetRegisterAt(0); |
| 4378 | if (GetCompilerOptions().IsBootImage()) { |
| 4379 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 4380 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 4381 | MethodReference target_method = invoke->GetTargetMethod(); |
| 4382 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 4383 | // Add ADRP with its PC-relative type patch. |
| 4384 | vixl::aarch64::Label* adrp_label = NewBootImageTypePatch(*target_method.dex_file, type_idx); |
| 4385 | EmitAdrpPlaceholder(adrp_label, argument.X()); |
| 4386 | // Add ADD with its PC-relative type patch. |
| 4387 | vixl::aarch64::Label* add_label = |
| 4388 | NewBootImageTypePatch(*target_method.dex_file, type_idx, adrp_label); |
| 4389 | EmitAddPlaceholder(add_label, argument.X(), argument.X()); |
| 4390 | } else { |
| 4391 | LoadBootImageAddress(argument, boot_image_offset); |
| 4392 | } |
| 4393 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 4394 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4395 | } |
| 4396 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4397 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4398 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4399 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4400 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4401 | for (const PcRelativePatchInfo& info : infos) { |
| 4402 | linker_patches->push_back(Factory(info.label.GetLocation(), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4403 | info.target_dex_file, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4404 | info.pc_insn_label->GetLocation(), |
| 4405 | info.offset_or_index)); |
| 4406 | } |
| 4407 | } |
| 4408 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4409 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 4410 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 4411 | const DexFile* target_dex_file, |
| 4412 | uint32_t pc_insn_offset, |
| 4413 | uint32_t boot_image_offset) { |
| 4414 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 4415 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4416 | } |
| 4417 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4418 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4419 | DCHECK(linker_patches->empty()); |
| 4420 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4421 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4422 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4423 | boot_image_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4424 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4425 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4426 | string_bss_entry_patches_.size() + |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4427 | boot_image_intrinsic_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4428 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4429 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4430 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4431 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4432 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4433 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4434 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4435 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4436 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4437 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 4438 | boot_image_intrinsic_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4439 | } else { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4440 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4441 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4442 | DCHECK(boot_image_type_patches_.empty()); |
| 4443 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4444 | DCHECK(boot_image_intrinsic_patches_.empty()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4445 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4446 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4447 | method_bss_entry_patches_, linker_patches); |
| 4448 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4449 | type_bss_entry_patches_, linker_patches); |
| 4450 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4451 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4452 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4453 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 4454 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4455 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4456 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4457 | } |
| 4458 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4459 | bool CodeGeneratorARM64::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
| 4460 | return patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
| 4461 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 4462 | } |
| 4463 | |
| 4464 | void CodeGeneratorARM64::EmitThunkCode(const linker::LinkerPatch& patch, |
| 4465 | /*out*/ ArenaVector<uint8_t>* code, |
| 4466 | /*out*/ std::string* debug_name) { |
| 4467 | Arm64Assembler assembler(GetGraph()->GetAllocator()); |
| 4468 | switch (patch.GetType()) { |
| 4469 | case linker::LinkerPatch::Type::kCallRelative: { |
| 4470 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 4471 | // to the generic JNI and interpreter trampolines. |
| 4472 | Offset offset(ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4473 | kArm64PointerSize).Int32Value()); |
| 4474 | assembler.JumpTo(ManagedRegister(arm64::X0), offset, ManagedRegister(arm64::IP0)); |
| 4475 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 4476 | *debug_name = "MethodCallThunk"; |
| 4477 | } |
| 4478 | break; |
| 4479 | } |
| 4480 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| 4481 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 4482 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 4483 | break; |
| 4484 | } |
| 4485 | default: |
| 4486 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 4487 | UNREACHABLE(); |
| 4488 | } |
| 4489 | |
| 4490 | // Ensure we emit the literal pool if any. |
| 4491 | assembler.FinalizeCode(); |
| 4492 | code->resize(assembler.CodeSize()); |
| 4493 | MemoryRegion code_region(code->data(), code->size()); |
| 4494 | assembler.FinalizeInstructions(code_region); |
| 4495 | } |
| 4496 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4497 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4498 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4499 | value, |
| 4500 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4501 | } |
| 4502 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4503 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4504 | return uint64_literals_.GetOrCreate( |
| 4505 | value, |
| 4506 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4507 | } |
| 4508 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4509 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4510 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4511 | // art::PrepareForRegisterAllocation. |
| 4512 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4513 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4514 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4515 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4516 | return; |
| 4517 | } |
| 4518 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4519 | { |
| 4520 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4521 | // are no pools emitted. |
| 4522 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4523 | LocationSummary* locations = invoke->GetLocations(); |
| 4524 | codegen_->GenerateStaticOrDirectCall( |
| 4525 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| 4526 | } |
| 4527 | |
| 4528 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4529 | } |
| 4530 | |
| 4531 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4532 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4533 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4534 | return; |
| 4535 | } |
| 4536 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4537 | { |
| 4538 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4539 | // are no pools emitted. |
| 4540 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4541 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 4542 | DCHECK(!codegen_->IsLeafMethod()); |
| 4543 | } |
| 4544 | |
| 4545 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4546 | } |
| 4547 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4548 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4549 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4550 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4551 | case HLoadClass::LoadKind::kInvalid: |
| 4552 | LOG(FATAL) << "UNREACHABLE"; |
| 4553 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4554 | case HLoadClass::LoadKind::kReferrersClass: |
| 4555 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4556 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4557 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4558 | case HLoadClass::LoadKind::kBssEntry: |
| 4559 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4560 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4561 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4562 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4563 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4564 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4565 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4566 | break; |
| 4567 | } |
| 4568 | return desired_class_load_kind; |
| 4569 | } |
| 4570 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4571 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4572 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4573 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4574 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4575 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4576 | cls, |
| 4577 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4578 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4579 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4580 | return; |
| 4581 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4582 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4583 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4584 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4585 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4586 | ? LocationSummary::kCallOnSlowPath |
| 4587 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4588 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4589 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4590 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4591 | } |
| 4592 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4593 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4594 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4595 | } |
| 4596 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4597 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 4598 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4599 | // Rely on the type resolution or initialization and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 4600 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4601 | } else { |
| 4602 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4603 | } |
| 4604 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4605 | } |
| 4606 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4607 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4608 | // move. |
| 4609 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4610 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4611 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4612 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4613 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4614 | return; |
| 4615 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4616 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4617 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4618 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4619 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4620 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4621 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4622 | ? kWithoutReadBarrier |
| 4623 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4624 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4625 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4626 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4627 | DCHECK(!cls->CanCallRuntime()); |
| 4628 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4629 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4630 | Register current_method = InputRegisterAt(cls, 0); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4631 | codegen_->GenerateGcRootFieldLoad(cls, |
| 4632 | out_loc, |
| 4633 | current_method, |
| 4634 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 4635 | /* fixup_label */ nullptr, |
| 4636 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4637 | break; |
| 4638 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4639 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4640 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4641 | // Add ADRP with its PC-relative type patch. |
| 4642 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4643 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4644 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4645 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4646 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4647 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4648 | codegen_->NewBootImageTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4649 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4650 | break; |
| 4651 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4652 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4653 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4654 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls); |
| 4655 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 4656 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4657 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4658 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4659 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4660 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4661 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4662 | break; |
| 4663 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4664 | case HLoadClass::LoadKind::kBssEntry: { |
| 4665 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 4666 | const DexFile& dex_file = cls->GetDexFile(); |
| 4667 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 4668 | vixl::aarch64::Register temp = XRegisterFrom(out_loc); |
| 4669 | vixl::aarch64::Label* adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 4670 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4671 | // Add LDR with its PC-relative Class .bss entry patch. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4672 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 4673 | codegen_->NewBssEntryTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4674 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4675 | codegen_->GenerateGcRootFieldLoad(cls, |
| 4676 | out_loc, |
| 4677 | temp, |
| 4678 | /* offset placeholder */ 0u, |
| 4679 | ldr_label, |
| 4680 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4681 | generate_null_check = true; |
| 4682 | break; |
| 4683 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4684 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 4685 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 4686 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 4687 | DCHECK_NE(address, 0u); |
| 4688 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 4689 | break; |
| 4690 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4691 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 4692 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 4693 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4694 | cls->GetClass())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4695 | codegen_->GenerateGcRootFieldLoad(cls, |
| 4696 | out_loc, |
| 4697 | out.X(), |
| 4698 | /* offset */ 0, |
| 4699 | /* fixup_label */ nullptr, |
| 4700 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4701 | break; |
| 4702 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4703 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4704 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4705 | LOG(FATAL) << "UNREACHABLE"; |
| 4706 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4707 | } |
| 4708 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4709 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 4710 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4711 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 4712 | SlowPathCodeARM64* slow_path = |
| 4713 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4714 | codegen_->AddSlowPath(slow_path); |
| 4715 | if (generate_null_check) { |
| 4716 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4717 | } |
| 4718 | if (cls->MustGenerateClinitCheck()) { |
| 4719 | GenerateClassInitializationCheck(slow_path, out); |
| 4720 | } else { |
| 4721 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4722 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4723 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4724 | } |
| 4725 | } |
| 4726 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 4727 | void LocationsBuilderARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 4728 | InvokeRuntimeCallingConvention calling_convention; |
| 4729 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 4730 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 4731 | } |
| 4732 | |
| 4733 | void InstructionCodeGeneratorARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 4734 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 4735 | } |
| 4736 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 4737 | void LocationsBuilderARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 4738 | InvokeRuntimeCallingConvention calling_convention; |
| 4739 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 4740 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 4741 | } |
| 4742 | |
| 4743 | void InstructionCodeGeneratorARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 4744 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 4745 | } |
| 4746 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4747 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4748 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4749 | } |
| 4750 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4751 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 4752 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4753 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4754 | locations->SetOut(Location::RequiresRegister()); |
| 4755 | } |
| 4756 | |
| 4757 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4758 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 4759 | } |
| 4760 | |
| 4761 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4762 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4763 | } |
| 4764 | |
| 4765 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4766 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4767 | } |
| 4768 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4769 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 4770 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4771 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4772 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4773 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4774 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 4775 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4776 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4777 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4778 | case HLoadString::LoadKind::kJitTableAddress: |
| 4779 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4780 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4781 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4782 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4783 | } |
| 4784 | return desired_string_load_kind; |
| 4785 | } |
| 4786 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4787 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4788 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4789 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4790 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4791 | InvokeRuntimeCallingConvention calling_convention; |
| 4792 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 4793 | } else { |
| 4794 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4795 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 4796 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4797 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 4798 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4799 | } else { |
| 4800 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4801 | } |
| 4802 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4803 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4804 | } |
| 4805 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4806 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4807 | // move. |
| 4808 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4809 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4810 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4811 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4812 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4813 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4814 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4815 | // Add ADRP with its PC-relative String patch. |
| 4816 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4817 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4818 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4819 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4820 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4821 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4822 | codegen_->NewBootImageStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4823 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4824 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4825 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4826 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4827 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4828 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 4829 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(load); |
| 4830 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4831 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4832 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4833 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4834 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4835 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 4836 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4837 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4838 | case HLoadString::LoadKind::kBssEntry: { |
| 4839 | // Add ADRP with its PC-relative String .bss entry patch. |
| 4840 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4841 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4842 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 4843 | Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4844 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4845 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4846 | // Add LDR with its PC-relative String .bss entry patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4847 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4848 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4849 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4850 | codegen_->GenerateGcRootFieldLoad(load, |
| 4851 | out_loc, |
| 4852 | temp, |
| 4853 | /* offset placeholder */ 0u, |
| 4854 | ldr_label, |
| 4855 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4856 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 4857 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4858 | codegen_->AddSlowPath(slow_path); |
| 4859 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 4860 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4861 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4862 | return; |
| 4863 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4864 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 4865 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 4866 | DCHECK_NE(address, 0u); |
| 4867 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 4868 | return; |
| 4869 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4870 | case HLoadString::LoadKind::kJitTableAddress: { |
| 4871 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4872 | load->GetStringIndex(), |
| 4873 | load->GetString())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4874 | codegen_->GenerateGcRootFieldLoad(load, |
| 4875 | out_loc, |
| 4876 | out.X(), |
| 4877 | /* offset */ 0, |
| 4878 | /* fixup_label */ nullptr, |
| 4879 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4880 | return; |
| 4881 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4882 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4883 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4884 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4885 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 4886 | // 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] | 4887 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 4888 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 4889 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 4890 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 4891 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4892 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4893 | } |
| 4894 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4895 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4896 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4897 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4898 | } |
| 4899 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4900 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4901 | // Will be generated at use site. |
| 4902 | } |
| 4903 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4904 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4905 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4906 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4907 | InvokeRuntimeCallingConvention calling_convention; |
| 4908 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4909 | } |
| 4910 | |
| 4911 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4912 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 4913 | instruction, |
| 4914 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4915 | if (instruction->IsEnter()) { |
| 4916 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 4917 | } else { |
| 4918 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 4919 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4920 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4921 | } |
| 4922 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4923 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 4924 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4925 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4926 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4927 | case DataType::Type::kInt32: |
| 4928 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4929 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4930 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 4931 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4932 | break; |
| 4933 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4934 | case DataType::Type::kFloat32: |
| 4935 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4936 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4937 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4938 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4939 | break; |
| 4940 | |
| 4941 | default: |
| 4942 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4943 | } |
| 4944 | } |
| 4945 | |
| 4946 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 4947 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4948 | case DataType::Type::kInt32: |
| 4949 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4950 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4951 | break; |
| 4952 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4953 | case DataType::Type::kFloat32: |
| 4954 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 4955 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 4956 | break; |
| 4957 | |
| 4958 | default: |
| 4959 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4960 | } |
| 4961 | } |
| 4962 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4963 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 4964 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4965 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4966 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4967 | case DataType::Type::kInt32: |
| 4968 | case DataType::Type::kInt64: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 4969 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4970 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4971 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4972 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4973 | case DataType::Type::kFloat32: |
| 4974 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4975 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4976 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4977 | break; |
| 4978 | |
| 4979 | default: |
| 4980 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4981 | } |
| 4982 | } |
| 4983 | |
| 4984 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 4985 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4986 | case DataType::Type::kInt32: |
| 4987 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4988 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 4989 | break; |
| 4990 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4991 | case DataType::Type::kFloat32: |
| 4992 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4993 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 4994 | break; |
| 4995 | |
| 4996 | default: |
| 4997 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 4998 | } |
| 4999 | } |
| 5000 | |
| 5001 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5002 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5003 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5004 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5005 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5006 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5007 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5008 | } |
| 5009 | |
| 5010 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5011 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5012 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5013 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5014 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5015 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5016 | } |
| 5017 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5018 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5019 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5020 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5021 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5022 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5023 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5027 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5028 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5029 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5030 | } |
| 5031 | |
| 5032 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5033 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5034 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5035 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5036 | } |
| 5037 | |
| 5038 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5039 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5040 | case DataType::Type::kInt32: |
| 5041 | case DataType::Type::kInt64: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5042 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5043 | break; |
| 5044 | |
| 5045 | default: |
| 5046 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5047 | } |
| 5048 | } |
| 5049 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5050 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5051 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5052 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5053 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5054 | } |
| 5055 | |
| 5056 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5057 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5058 | } |
| 5059 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5060 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5061 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5062 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5063 | } |
| 5064 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5065 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5066 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5067 | return; |
| 5068 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5069 | { |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 5070 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5071 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5072 | Location obj = instruction->GetLocations()->InAt(0); |
| 5073 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5074 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5075 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5076 | } |
| 5077 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5078 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5079 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5080 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5081 | |
| 5082 | LocationSummary* locations = instruction->GetLocations(); |
| 5083 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5084 | |
| 5085 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5086 | } |
| 5087 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5088 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5089 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5090 | } |
| 5091 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5092 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5093 | HandleBinaryOp(instruction); |
| 5094 | } |
| 5095 | |
| 5096 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5097 | HandleBinaryOp(instruction); |
| 5098 | } |
| 5099 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5100 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5101 | LOG(FATAL) << "Unreachable"; |
| 5102 | } |
| 5103 | |
| 5104 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5105 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5106 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5107 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5108 | // The back edge will generate the suspend check. |
| 5109 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5110 | } |
| 5111 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5112 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5113 | } |
| 5114 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5115 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5116 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5117 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5118 | if (location.IsStackSlot()) { |
| 5119 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5120 | } else if (location.IsDoubleStackSlot()) { |
| 5121 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5122 | } |
| 5123 | locations->SetOut(location); |
| 5124 | } |
| 5125 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5126 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5127 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5128 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5129 | } |
| 5130 | |
| 5131 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5132 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5133 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5134 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5135 | } |
| 5136 | |
| 5137 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5138 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5139 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5140 | } |
| 5141 | |
| 5142 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5143 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5144 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5145 | locations->SetInAt(i, Location::Any()); |
| 5146 | } |
| 5147 | locations->SetOut(Location::Any()); |
| 5148 | } |
| 5149 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5150 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5151 | LOG(FATAL) << "Unreachable"; |
| 5152 | } |
| 5153 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5154 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5155 | DataType::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5156 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5157 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5158 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5159 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5160 | |
| 5161 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5162 | case DataType::Type::kInt32: |
| 5163 | case DataType::Type::kInt64: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5164 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5165 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5166 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5167 | break; |
| 5168 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5169 | case DataType::Type::kFloat32: |
| 5170 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5171 | InvokeRuntimeCallingConvention calling_convention; |
| 5172 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5173 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5174 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5175 | |
| 5176 | break; |
| 5177 | } |
| 5178 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5179 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5180 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5181 | } |
| 5182 | } |
| 5183 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5184 | void InstructionCodeGeneratorARM64::GenerateIntRemForPower2Denom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5185 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5186 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 5187 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 5188 | |
| 5189 | Register out = OutputRegister(instruction); |
| 5190 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5191 | |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5192 | if (abs_imm == 2) { |
| 5193 | __ Cmp(dividend, 0); |
| 5194 | __ And(out, dividend, 1); |
| 5195 | __ Csneg(out, out, out, ge); |
| 5196 | } else { |
| 5197 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5198 | Register temp = temps.AcquireSameSizeAs(out); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5199 | |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5200 | __ Negs(temp, dividend); |
| 5201 | __ And(out, dividend, abs_imm - 1); |
| 5202 | __ And(temp, temp, abs_imm - 1); |
| 5203 | __ Csneg(out, out, temp, mi); |
| 5204 | } |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5205 | } |
| 5206 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5207 | void InstructionCodeGeneratorARM64::GenerateIntRemForConstDenom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5208 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5209 | |
| 5210 | if (imm == 0) { |
| 5211 | // Do not generate anything. |
| 5212 | // DivZeroCheck would prevent any code to be executed. |
| 5213 | return; |
| 5214 | } |
| 5215 | |
Evgeny Astigeevich | f58dc65 | 2018-06-25 17:54:07 +0100 | [diff] [blame] | 5216 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 5217 | // Cases imm == -1 or imm == 1 are handled in constant folding by |
| 5218 | // InstructionWithAbsorbingInputSimplifier. |
| 5219 | // If the cases have survided till code generation they are handled in |
| 5220 | // GenerateIntRemForPower2Denom becauses -1 and 1 are the power of 2 (2^0). |
| 5221 | // The correct code is generated for them, just more instructions. |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5222 | GenerateIntRemForPower2Denom(instruction); |
| 5223 | } else { |
| 5224 | DCHECK(imm < -2 || imm > 2) << imm; |
| 5225 | GenerateDivRemWithAnyConstant(instruction); |
| 5226 | } |
| 5227 | } |
| 5228 | |
| 5229 | void InstructionCodeGeneratorARM64::GenerateIntRem(HRem* instruction) { |
| 5230 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 5231 | << instruction->GetResultType(); |
| 5232 | |
| 5233 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 5234 | GenerateIntRemForConstDenom(instruction); |
| 5235 | } else { |
| 5236 | Register out = OutputRegister(instruction); |
| 5237 | Register dividend = InputRegisterAt(instruction, 0); |
| 5238 | Register divisor = InputRegisterAt(instruction, 1); |
| 5239 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5240 | Register temp = temps.AcquireSameSizeAs(out); |
| 5241 | __ Sdiv(temp, dividend, divisor); |
| 5242 | __ Msub(out, temp, divisor, dividend); |
| 5243 | } |
| 5244 | } |
| 5245 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5246 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5247 | DataType::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5248 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5249 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5250 | case DataType::Type::kInt32: |
| 5251 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5252 | GenerateIntRem(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5253 | break; |
| 5254 | } |
| 5255 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5256 | case DataType::Type::kFloat32: |
| 5257 | case DataType::Type::kFloat64: { |
| 5258 | QuickEntrypointEnum entrypoint = |
| 5259 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5260 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5261 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5262 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5263 | } else { |
| 5264 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5265 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5266 | break; |
| 5267 | } |
| 5268 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5269 | default: |
| 5270 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5271 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5272 | } |
| 5273 | } |
| 5274 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5275 | void LocationsBuilderARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5276 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5277 | } |
| 5278 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5279 | void InstructionCodeGeneratorARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5280 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5281 | } |
| 5282 | |
| 5283 | void LocationsBuilderARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5284 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5285 | } |
| 5286 | |
| 5287 | void InstructionCodeGeneratorARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5288 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5289 | } |
| 5290 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5291 | void LocationsBuilderARM64::VisitAbs(HAbs* abs) { |
| 5292 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 5293 | switch (abs->GetResultType()) { |
| 5294 | case DataType::Type::kInt32: |
| 5295 | case DataType::Type::kInt64: |
| 5296 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5297 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5298 | break; |
| 5299 | case DataType::Type::kFloat32: |
| 5300 | case DataType::Type::kFloat64: |
| 5301 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5302 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5303 | break; |
| 5304 | default: |
| 5305 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5306 | } |
| 5307 | } |
| 5308 | |
| 5309 | void InstructionCodeGeneratorARM64::VisitAbs(HAbs* abs) { |
| 5310 | switch (abs->GetResultType()) { |
| 5311 | case DataType::Type::kInt32: |
| 5312 | case DataType::Type::kInt64: { |
| 5313 | Register in_reg = InputRegisterAt(abs, 0); |
| 5314 | Register out_reg = OutputRegister(abs); |
| 5315 | __ Cmp(in_reg, Operand(0)); |
| 5316 | __ Cneg(out_reg, in_reg, lt); |
| 5317 | break; |
| 5318 | } |
| 5319 | case DataType::Type::kFloat32: |
| 5320 | case DataType::Type::kFloat64: { |
| 5321 | FPRegister in_reg = InputFPRegisterAt(abs, 0); |
| 5322 | FPRegister out_reg = OutputFPRegister(abs); |
| 5323 | __ Fabs(out_reg, in_reg); |
| 5324 | break; |
| 5325 | } |
| 5326 | default: |
| 5327 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5328 | } |
| 5329 | } |
| 5330 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5331 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5332 | constructor_fence->SetLocations(nullptr); |
| 5333 | } |
| 5334 | |
| 5335 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5336 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5337 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5338 | } |
| 5339 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5340 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5341 | memory_barrier->SetLocations(nullptr); |
| 5342 | } |
| 5343 | |
| 5344 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5345 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5346 | } |
| 5347 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5348 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5349 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5350 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5351 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5352 | } |
| 5353 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5354 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5355 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5356 | } |
| 5357 | |
| 5358 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5359 | instruction->SetLocations(nullptr); |
| 5360 | } |
| 5361 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5362 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5363 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5364 | } |
| 5365 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5366 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5367 | HandleBinaryOp(ror); |
| 5368 | } |
| 5369 | |
| 5370 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5371 | HandleBinaryOp(ror); |
| 5372 | } |
| 5373 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5374 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5375 | HandleShift(shl); |
| 5376 | } |
| 5377 | |
| 5378 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5379 | HandleShift(shl); |
| 5380 | } |
| 5381 | |
| 5382 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5383 | HandleShift(shr); |
| 5384 | } |
| 5385 | |
| 5386 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5387 | HandleShift(shr); |
| 5388 | } |
| 5389 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5390 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5391 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5392 | } |
| 5393 | |
| 5394 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5395 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5396 | } |
| 5397 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5398 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5399 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5400 | } |
| 5401 | |
| 5402 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5403 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5404 | } |
| 5405 | |
| 5406 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5407 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5408 | } |
| 5409 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5410 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5411 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5412 | } |
| 5413 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5414 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5415 | HUnresolvedInstanceFieldGet* instruction) { |
| 5416 | FieldAccessCallingConventionARM64 calling_convention; |
| 5417 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5418 | instruction, instruction->GetFieldType(), calling_convention); |
| 5419 | } |
| 5420 | |
| 5421 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5422 | HUnresolvedInstanceFieldGet* instruction) { |
| 5423 | FieldAccessCallingConventionARM64 calling_convention; |
| 5424 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5425 | instruction->GetFieldType(), |
| 5426 | instruction->GetFieldIndex(), |
| 5427 | instruction->GetDexPc(), |
| 5428 | calling_convention); |
| 5429 | } |
| 5430 | |
| 5431 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5432 | HUnresolvedInstanceFieldSet* instruction) { |
| 5433 | FieldAccessCallingConventionARM64 calling_convention; |
| 5434 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5435 | instruction, instruction->GetFieldType(), calling_convention); |
| 5436 | } |
| 5437 | |
| 5438 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5439 | HUnresolvedInstanceFieldSet* instruction) { |
| 5440 | FieldAccessCallingConventionARM64 calling_convention; |
| 5441 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5442 | instruction->GetFieldType(), |
| 5443 | instruction->GetFieldIndex(), |
| 5444 | instruction->GetDexPc(), |
| 5445 | calling_convention); |
| 5446 | } |
| 5447 | |
| 5448 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5449 | HUnresolvedStaticFieldGet* instruction) { |
| 5450 | FieldAccessCallingConventionARM64 calling_convention; |
| 5451 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5452 | instruction, instruction->GetFieldType(), calling_convention); |
| 5453 | } |
| 5454 | |
| 5455 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5456 | HUnresolvedStaticFieldGet* instruction) { |
| 5457 | FieldAccessCallingConventionARM64 calling_convention; |
| 5458 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5459 | instruction->GetFieldType(), |
| 5460 | instruction->GetFieldIndex(), |
| 5461 | instruction->GetDexPc(), |
| 5462 | calling_convention); |
| 5463 | } |
| 5464 | |
| 5465 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5466 | HUnresolvedStaticFieldSet* instruction) { |
| 5467 | FieldAccessCallingConventionARM64 calling_convention; |
| 5468 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5469 | instruction, instruction->GetFieldType(), calling_convention); |
| 5470 | } |
| 5471 | |
| 5472 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5473 | HUnresolvedStaticFieldSet* instruction) { |
| 5474 | FieldAccessCallingConventionARM64 calling_convention; |
| 5475 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5476 | instruction->GetFieldType(), |
| 5477 | instruction->GetFieldIndex(), |
| 5478 | instruction->GetDexPc(), |
| 5479 | calling_convention); |
| 5480 | } |
| 5481 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5482 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5483 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5484 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5485 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5486 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5487 | // registers in full width (since the runtime only saves/restores lower part). |
| 5488 | locations->SetCustomSlowPathCallerSaves( |
| 5489 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5490 | } |
| 5491 | |
| 5492 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5493 | HBasicBlock* block = instruction->GetBlock(); |
| 5494 | if (block->GetLoopInformation() != nullptr) { |
| 5495 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5496 | // The back edge will generate the suspend check. |
| 5497 | return; |
| 5498 | } |
| 5499 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5500 | // The goto will generate the suspend check. |
| 5501 | return; |
| 5502 | } |
| 5503 | GenerateSuspendCheck(instruction, nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5504 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5505 | } |
| 5506 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5507 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5508 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5509 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5510 | InvokeRuntimeCallingConvention calling_convention; |
| 5511 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5512 | } |
| 5513 | |
| 5514 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5515 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5516 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5517 | } |
| 5518 | |
| 5519 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5520 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5521 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5522 | DataType::Type input_type = conversion->GetInputType(); |
| 5523 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5524 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5525 | << input_type << " -> " << result_type; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5526 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 5527 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5528 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5529 | } |
| 5530 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5531 | if (DataType::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5532 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5533 | } else { |
| 5534 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5535 | } |
| 5536 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5537 | if (DataType::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5538 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5539 | } else { |
| 5540 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5541 | } |
| 5542 | } |
| 5543 | |
| 5544 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5545 | DataType::Type result_type = conversion->GetResultType(); |
| 5546 | DataType::Type input_type = conversion->GetInputType(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5547 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5548 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5549 | << input_type << " -> " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5550 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5551 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 5552 | int result_size = DataType::Size(result_type); |
| 5553 | int input_size = DataType::Size(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5554 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5555 | Register output = OutputRegister(conversion); |
| 5556 | Register source = InputRegisterAt(conversion, 0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5557 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5558 | // 'int' values are used directly as W registers, discarding the top |
| 5559 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5560 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5561 | // top 32 bits of the target register. We theoretically could leave those |
| 5562 | // bits unchanged, but we would have to make sure that no code uses a |
| 5563 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5564 | // zero. |
| 5565 | __ Mov(output.W(), source.W()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5566 | } else if (DataType::IsUnsignedType(result_type) || |
| 5567 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 5568 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5569 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5570 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5571 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5572 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5573 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5574 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 5575 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5576 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5577 | } else if (DataType::IsFloatingPointType(result_type) && |
| 5578 | DataType::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5579 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5580 | } else { |
| 5581 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5582 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5583 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5584 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5585 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5586 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5587 | HandleShift(ushr); |
| 5588 | } |
| 5589 | |
| 5590 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5591 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5592 | } |
| 5593 | |
| 5594 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5595 | HandleBinaryOp(instruction); |
| 5596 | } |
| 5597 | |
| 5598 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5599 | HandleBinaryOp(instruction); |
| 5600 | } |
| 5601 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5602 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5603 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5604 | LOG(FATAL) << "Unreachable"; |
| 5605 | } |
| 5606 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5607 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5608 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5609 | LOG(FATAL) << "Unreachable"; |
| 5610 | } |
| 5611 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5612 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5613 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5614 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5615 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5616 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5617 | } |
| 5618 | |
| 5619 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5620 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5621 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5622 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5623 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5624 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5625 | // 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] | 5626 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5627 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5628 | // make sure we don't emit it if the target may run out of range. |
| 5629 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5630 | // ranges and emit the tables only as required. |
| 5631 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5632 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5633 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5634 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5635 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5636 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5637 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5638 | Register temp = temps.AcquireW(); |
| 5639 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5640 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5641 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5642 | // Jump to successors[0] if value == lower_bound. |
| 5643 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5644 | int32_t last_index = 0; |
| 5645 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5646 | __ Subs(temp, temp, Operand(2)); |
| 5647 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5648 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5649 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5650 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5651 | } |
| 5652 | if (num_entries - last_index == 2) { |
| 5653 | // The last missing case_value. |
| 5654 | __ Cmp(temp, Operand(1)); |
| 5655 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5656 | } |
| 5657 | |
| 5658 | // And the default for any other value. |
| 5659 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5660 | __ B(codegen_->GetLabelOf(default_block)); |
| 5661 | } |
| 5662 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5663 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5664 | |
| 5665 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5666 | |
| 5667 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5668 | // registers, we are free to block one. |
| 5669 | Register temp_w = temps.AcquireW(); |
| 5670 | Register index; |
| 5671 | // Remove the bias. |
| 5672 | if (lower_bound != 0) { |
| 5673 | index = temp_w; |
| 5674 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5675 | } else { |
| 5676 | index = value_reg; |
| 5677 | } |
| 5678 | |
| 5679 | // Jump to default block if index is out of the range. |
| 5680 | __ Cmp(index, Operand(num_entries)); |
| 5681 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5682 | |
| 5683 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5684 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5685 | // register pressure. |
| 5686 | Register table_base = temps.AcquireX(); |
| 5687 | // Load jump offset from the table. |
| 5688 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5689 | Register jump_offset = temp_w; |
| 5690 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5691 | |
| 5692 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5693 | Register target_address = table_base; |
| 5694 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5695 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5696 | } |
| 5697 | } |
| 5698 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5699 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 5700 | HInstruction* instruction, |
| 5701 | Location out, |
| 5702 | uint32_t offset, |
| 5703 | Location maybe_temp, |
| 5704 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5705 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5706 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5707 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5708 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5709 | if (kUseBakerReadBarrier) { |
| 5710 | // Load with fast path based Baker's read barrier. |
| 5711 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5712 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5713 | out, |
| 5714 | out_reg, |
| 5715 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5716 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5717 | /* needs_null_check */ false, |
| 5718 | /* use_load_acquire */ false); |
| 5719 | } else { |
| 5720 | // Load with slow path based read barrier. |
| 5721 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5722 | // in the following move operation, as we will need it for the |
| 5723 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5724 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5725 | __ Mov(temp_reg, out_reg); |
| 5726 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5727 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5728 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5729 | } |
| 5730 | } else { |
| 5731 | // Plain load with no read barrier. |
| 5732 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5733 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5734 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5735 | } |
| 5736 | } |
| 5737 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5738 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 5739 | HInstruction* instruction, |
| 5740 | Location out, |
| 5741 | Location obj, |
| 5742 | uint32_t offset, |
| 5743 | Location maybe_temp, |
| 5744 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5745 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5746 | Register out_reg = RegisterFrom(out, type); |
| 5747 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5748 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5749 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5750 | if (kUseBakerReadBarrier) { |
| 5751 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5752 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5753 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5754 | out, |
| 5755 | obj_reg, |
| 5756 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5757 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5758 | /* needs_null_check */ false, |
| 5759 | /* use_load_acquire */ false); |
| 5760 | } else { |
| 5761 | // Load with slow path based read barrier. |
| 5762 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5763 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5764 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5765 | } |
| 5766 | } else { |
| 5767 | // Plain load with no read barrier. |
| 5768 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5769 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5770 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5771 | } |
| 5772 | } |
| 5773 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5774 | void CodeGeneratorARM64::GenerateGcRootFieldLoad( |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5775 | HInstruction* instruction, |
| 5776 | Location root, |
| 5777 | Register obj, |
| 5778 | uint32_t offset, |
| 5779 | vixl::aarch64::Label* fixup_label, |
| 5780 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5781 | DCHECK(fixup_label == nullptr || offset == 0u); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5782 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5783 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5784 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5785 | if (kUseBakerReadBarrier) { |
| 5786 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5787 | // Baker's read barrier are used. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5788 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 5789 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 5790 | // the Marking Register) to decide whether we need to enter |
| 5791 | // the slow path to mark the GC root. |
| 5792 | // |
| 5793 | // We use shared thunks for the slow path; shared within the method |
| 5794 | // for JIT, across methods for AOT. That thunk checks the reference |
| 5795 | // and jumps to the entrypoint if needed. |
| 5796 | // |
| 5797 | // lr = &return_address; |
| 5798 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5799 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 5800 | // goto gc_root_thunk<root_reg>(lr) |
| 5801 | // } |
| 5802 | // return_address: |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5803 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 5804 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5805 | DCHECK(temps.IsAvailable(ip0)); |
| 5806 | DCHECK(temps.IsAvailable(ip1)); |
| 5807 | temps.Exclude(ip0, ip1); |
| 5808 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5809 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 5810 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 5811 | vixl::aarch64::Label return_address; |
| 5812 | __ adr(lr, &return_address); |
| 5813 | if (fixup_label != nullptr) { |
| 5814 | __ bind(fixup_label); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5815 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 5816 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 5817 | "GC root LDR must be 2 instructions (8B) before the return address label."); |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 5818 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 5819 | EmitBakerReadBarrierCbnz(custom_data); |
| 5820 | __ bind(&return_address); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5821 | } else { |
| 5822 | // GC root loaded through a slow path for read barriers other |
| 5823 | // than Baker's. |
| 5824 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5825 | if (fixup_label == nullptr) { |
| 5826 | __ Add(root_reg.X(), obj.X(), offset); |
| 5827 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5828 | EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5829 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5830 | // /* mirror::Object* */ root = root->Read() |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5831 | GenerateReadBarrierForRootSlow(instruction, root, root); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5832 | } |
| 5833 | } else { |
| 5834 | // Plain GC root load with no read barrier. |
| 5835 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5836 | if (fixup_label == nullptr) { |
| 5837 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 5838 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5839 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5840 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5841 | // Note that GC roots are not affected by heap poisoning, thus we |
| 5842 | // do not have to unpoison `root_reg` here. |
| 5843 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5844 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5845 | } |
| 5846 | |
Vladimir Marko | 94796f8 | 2018-08-08 15:15:33 +0100 | [diff] [blame] | 5847 | void CodeGeneratorARM64::GenerateUnsafeCasOldValueMovWithBakerReadBarrier( |
| 5848 | vixl::aarch64::Register marked, |
| 5849 | vixl::aarch64::Register old_value) { |
| 5850 | DCHECK(kEmitCompilerReadBarrier); |
| 5851 | DCHECK(kUseBakerReadBarrier); |
| 5852 | |
| 5853 | // Similar to the Baker RB path in GenerateGcRootFieldLoad(), with a MOV instead of LDR. |
| 5854 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(marked.GetCode()); |
| 5855 | |
| 5856 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 5857 | vixl::aarch64::Label return_address; |
| 5858 | __ adr(lr, &return_address); |
| 5859 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 5860 | "GC root LDR must be 2 instructions (8B) before the return address label."); |
| 5861 | __ mov(marked, old_value); |
| 5862 | EmitBakerReadBarrierCbnz(custom_data); |
| 5863 | __ bind(&return_address); |
| 5864 | } |
| 5865 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5866 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5867 | Location ref, |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 5868 | vixl::aarch64::Register obj, |
| 5869 | const vixl::aarch64::MemOperand& src, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5870 | bool needs_null_check, |
| 5871 | bool use_load_acquire) { |
| 5872 | DCHECK(kEmitCompilerReadBarrier); |
| 5873 | DCHECK(kUseBakerReadBarrier); |
| 5874 | |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 5875 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 5876 | // Marking Register) to decide whether we need to enter the slow |
| 5877 | // path to mark the reference. Then, in the slow path, check the |
| 5878 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 5879 | // decide whether to mark `ref` or not. |
| 5880 | // |
| 5881 | // We use shared thunks for the slow path; shared within the method |
| 5882 | // for JIT, across methods for AOT. That thunk checks the holder |
| 5883 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 5884 | // it creates a fake dependency and returns to the LDR instruction. |
| 5885 | // |
| 5886 | // lr = &gray_return_address; |
| 5887 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 5888 | // goto field_thunk<holder_reg, base_reg, use_load_acquire>(lr) |
| 5889 | // } |
| 5890 | // not_gray_return_address: |
| 5891 | // // Original reference load. If the offset is too large to fit |
| 5892 | // // into LDR, we use an adjusted base register here. |
| 5893 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 5894 | // gray_return_address: |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5895 | |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 5896 | DCHECK(src.GetAddrMode() == vixl::aarch64::Offset); |
| 5897 | DCHECK_ALIGNED(src.GetOffset(), sizeof(mirror::HeapReference<mirror::Object>)); |
| 5898 | |
| 5899 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5900 | DCHECK(temps.IsAvailable(ip0)); |
| 5901 | DCHECK(temps.IsAvailable(ip1)); |
| 5902 | temps.Exclude(ip0, ip1); |
| 5903 | uint32_t custom_data = use_load_acquire |
| 5904 | ? EncodeBakerReadBarrierAcquireData(src.GetBaseRegister().GetCode(), obj.GetCode()) |
| 5905 | : EncodeBakerReadBarrierFieldData(src.GetBaseRegister().GetCode(), obj.GetCode()); |
| 5906 | |
| 5907 | { |
| 5908 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5909 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 5910 | vixl::aarch64::Label return_address; |
| 5911 | __ adr(lr, &return_address); |
| 5912 | EmitBakerReadBarrierCbnz(custom_data); |
| 5913 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 5914 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 5915 | " 2 instructions (8B) for heap poisoning."); |
| 5916 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 5917 | if (use_load_acquire) { |
| 5918 | DCHECK_EQ(src.GetOffset(), 0); |
| 5919 | __ ldar(ref_reg, src); |
| 5920 | } else { |
| 5921 | __ ldr(ref_reg, src); |
| 5922 | } |
| 5923 | if (needs_null_check) { |
| 5924 | MaybeRecordImplicitNullCheck(instruction); |
| 5925 | } |
| 5926 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 5927 | // macro instructions disallowed in ExactAssemblyScope. |
| 5928 | if (kPoisonHeapReferences) { |
| 5929 | __ neg(ref_reg, Operand(ref_reg)); |
| 5930 | } |
| 5931 | __ bind(&return_address); |
| 5932 | } |
| 5933 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
| 5934 | } |
| 5935 | |
| 5936 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 5937 | Location ref, |
| 5938 | Register obj, |
| 5939 | uint32_t offset, |
| 5940 | Location maybe_temp, |
| 5941 | bool needs_null_check, |
| 5942 | bool use_load_acquire) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 5943 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 5944 | Register base = obj; |
| 5945 | if (use_load_acquire) { |
| 5946 | DCHECK(maybe_temp.IsRegister()); |
| 5947 | base = WRegisterFrom(maybe_temp); |
| 5948 | __ Add(base, obj, offset); |
| 5949 | offset = 0u; |
| 5950 | } else if (offset >= kReferenceLoadMinFarOffset) { |
| 5951 | DCHECK(maybe_temp.IsRegister()); |
| 5952 | base = WRegisterFrom(maybe_temp); |
| 5953 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 5954 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 5955 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5956 | } |
Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 5957 | MemOperand src(base.X(), offset); |
| 5958 | GenerateFieldLoadWithBakerReadBarrier( |
| 5959 | instruction, ref, obj, src, needs_null_check, use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5960 | } |
| 5961 | |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 5962 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HArrayGet* instruction, |
| 5963 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5964 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5965 | uint32_t data_offset, |
| 5966 | Location index, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5967 | bool needs_null_check) { |
| 5968 | DCHECK(kEmitCompilerReadBarrier); |
| 5969 | DCHECK(kUseBakerReadBarrier); |
| 5970 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 5971 | static_assert( |
| 5972 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5973 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5974 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 5975 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 5976 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 5977 | // Marking Register) to decide whether we need to enter the slow |
| 5978 | // path to mark the reference. Then, in the slow path, check the |
| 5979 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 5980 | // decide whether to mark `ref` or not. |
| 5981 | // |
| 5982 | // We use shared thunks for the slow path; shared within the method |
| 5983 | // for JIT, across methods for AOT. That thunk checks the holder |
| 5984 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 5985 | // it creates a fake dependency and returns to the LDR instruction. |
| 5986 | // |
| 5987 | // lr = &gray_return_address; |
| 5988 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 5989 | // goto array_thunk<base_reg>(lr) |
| 5990 | // } |
| 5991 | // not_gray_return_address: |
| 5992 | // // Original reference load. If the offset is too large to fit |
| 5993 | // // into LDR, we use an adjusted base register here. |
| 5994 | // HeapReference<mirror::Object> reference = data[index]; |
| 5995 | // gray_return_address: |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 5996 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 5997 | DCHECK(index.IsValid()); |
| 5998 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 5999 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6000 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6001 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6002 | DCHECK(temps.IsAvailable(ip0)); |
| 6003 | DCHECK(temps.IsAvailable(ip1)); |
| 6004 | temps.Exclude(ip0, ip1); |
Artem Serov | 0806f58 | 2018-10-11 20:14:20 +0100 | [diff] [blame] | 6005 | |
| 6006 | Register temp; |
| 6007 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 6008 | // We do not need to compute the intermediate address from the array: the |
| 6009 | // input instruction has done it already. See the comment in |
| 6010 | // `TryExtractArrayAccessAddress()`. |
| 6011 | if (kIsDebugBuild) { |
| 6012 | HIntermediateAddress* interm_addr = instruction->GetArray()->AsIntermediateAddress(); |
| 6013 | DCHECK_EQ(interm_addr->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 6014 | } |
| 6015 | temp = obj; |
| 6016 | } else { |
| 6017 | temp = WRegisterFrom(instruction->GetLocations()->GetTemp(0)); |
| 6018 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
| 6019 | } |
| 6020 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6021 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(temp.GetCode()); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6022 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6023 | { |
| 6024 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6025 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6026 | vixl::aarch64::Label return_address; |
| 6027 | __ adr(lr, &return_address); |
| 6028 | EmitBakerReadBarrierCbnz(custom_data); |
| 6029 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6030 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6031 | " 2 instructions (8B) for heap poisoning."); |
| 6032 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6033 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6034 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6035 | // macro instructions disallowed in ExactAssemblyScope. |
| 6036 | if (kPoisonHeapReferences) { |
| 6037 | __ neg(ref_reg, Operand(ref_reg)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6038 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6039 | __ bind(&return_address); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6040 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6041 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6042 | } |
| 6043 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6044 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6045 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6046 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6047 | // The following condition is a run-time one; it is executed after the |
| 6048 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6049 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6050 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6051 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6052 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6053 | } |
| 6054 | } |
| 6055 | } |
| 6056 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6057 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6058 | Location out, |
| 6059 | Location ref, |
| 6060 | Location obj, |
| 6061 | uint32_t offset, |
| 6062 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6063 | DCHECK(kEmitCompilerReadBarrier); |
| 6064 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6065 | // Insert a slow path based read barrier *after* the reference load. |
| 6066 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6067 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6068 | // reference will be carried out by the runtime within the slow |
| 6069 | // path. |
| 6070 | // |
| 6071 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6072 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6073 | // not used by the artReadBarrierSlow entry point. |
| 6074 | // |
| 6075 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6076 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6077 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6078 | AddSlowPath(slow_path); |
| 6079 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6080 | __ B(slow_path->GetEntryLabel()); |
| 6081 | __ Bind(slow_path->GetExitLabel()); |
| 6082 | } |
| 6083 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6084 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6085 | Location out, |
| 6086 | Location ref, |
| 6087 | Location obj, |
| 6088 | uint32_t offset, |
| 6089 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6090 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6091 | // Baker's read barriers shall be handled by the fast path |
| 6092 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6093 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6094 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6095 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6096 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6097 | } else if (kPoisonHeapReferences) { |
| 6098 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6099 | } |
| 6100 | } |
| 6101 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6102 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6103 | Location out, |
| 6104 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6105 | DCHECK(kEmitCompilerReadBarrier); |
| 6106 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6107 | // Insert a slow path based read barrier *after* the GC root load. |
| 6108 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6109 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6110 | // not need to do anything special for this here. |
| 6111 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6112 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6113 | AddSlowPath(slow_path); |
| 6114 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6115 | __ B(slow_path->GetEntryLabel()); |
| 6116 | __ Bind(slow_path->GetExitLabel()); |
| 6117 | } |
| 6118 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6119 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6120 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6121 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6122 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6123 | locations->SetOut(Location::RequiresRegister()); |
| 6124 | } |
| 6125 | |
| 6126 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6127 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6128 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6129 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6130 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6131 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6132 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6133 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6134 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6135 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6136 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6137 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6138 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6139 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6140 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6141 | } |
| 6142 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6143 | static void PatchJitRootUse(uint8_t* code, |
| 6144 | const uint8_t* roots_data, |
| 6145 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6146 | uint64_t index_in_table) { |
| 6147 | uint32_t literal_offset = literal->GetOffset(); |
| 6148 | uintptr_t address = |
| 6149 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6150 | uint8_t* data = code + literal_offset; |
| 6151 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6152 | } |
| 6153 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6154 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6155 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6156 | const StringReference& string_reference = entry.first; |
| 6157 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6158 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6159 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6160 | } |
| 6161 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6162 | const TypeReference& type_reference = entry.first; |
| 6163 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6164 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6165 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6166 | } |
| 6167 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6168 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6169 | #undef __ |
| 6170 | #undef QUICK_ENTRY_POINT |
| 6171 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6172 | #define __ assembler.GetVIXLAssembler()-> |
| 6173 | |
| 6174 | static void EmitGrayCheckAndFastPath(arm64::Arm64Assembler& assembler, |
| 6175 | vixl::aarch64::Register base_reg, |
| 6176 | vixl::aarch64::MemOperand& lock_word, |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6177 | vixl::aarch64::Label* slow_path, |
| 6178 | vixl::aarch64::Label* throw_npe = nullptr) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6179 | // Load the lock word containing the rb_state. |
| 6180 | __ Ldr(ip0.W(), lock_word); |
| 6181 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
Roland Levillain | 14e5a29 | 2018-06-28 12:00:56 +0100 | [diff] [blame] | 6182 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6183 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 6184 | __ Tbnz(ip0.W(), LockWord::kReadBarrierStateShift, slow_path); |
| 6185 | static_assert( |
| 6186 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET, |
| 6187 | "Field and array LDR offsets must be the same to reuse the same code."); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6188 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 6189 | if (throw_npe != nullptr) { |
| 6190 | __ Bind(throw_npe); |
| 6191 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6192 | // Adjust the return address back to the LDR (1 instruction; 2 for heap poisoning). |
| 6193 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6194 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6195 | " 2 instructions (8B) for heap poisoning."); |
| 6196 | __ Add(lr, lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6197 | // Introduce a dependency on the lock_word including rb_state, |
| 6198 | // to prevent load-load reordering, and without using |
| 6199 | // a memory barrier (which would be more expensive). |
| 6200 | __ Add(base_reg, base_reg, Operand(ip0, LSR, 32)); |
| 6201 | __ Br(lr); // And return back to the function. |
| 6202 | // Note: The fake dependency is unnecessary for the slow path. |
| 6203 | } |
| 6204 | |
| 6205 | // Load the read barrier introspection entrypoint in register `entrypoint`. |
| 6206 | static void LoadReadBarrierMarkIntrospectionEntrypoint(arm64::Arm64Assembler& assembler, |
| 6207 | vixl::aarch64::Register entrypoint) { |
| 6208 | // entrypoint = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6209 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6210 | const int32_t entry_point_offset = |
| 6211 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6212 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| 6213 | } |
| 6214 | |
| 6215 | void CodeGeneratorARM64::CompileBakerReadBarrierThunk(Arm64Assembler& assembler, |
| 6216 | uint32_t encoded_data, |
| 6217 | /*out*/ std::string* debug_name) { |
| 6218 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 6219 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6220 | case BakerReadBarrierKind::kField: |
| 6221 | case BakerReadBarrierKind::kAcquire: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6222 | auto base_reg = |
| 6223 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6224 | CheckValidReg(base_reg.GetCode()); |
| 6225 | auto holder_reg = |
| 6226 | Register::GetXRegFromCode(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6227 | CheckValidReg(holder_reg.GetCode()); |
| 6228 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6229 | temps.Exclude(ip0, ip1); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6230 | // If base_reg differs from holder_reg, the offset was too large and we must have emitted |
| 6231 | // an explicit null check before the load. Otherwise, for implicit null checks, we need to |
| 6232 | // null-check the holder as we do not necessarily do that check before going to the thunk. |
| 6233 | vixl::aarch64::Label throw_npe_label; |
| 6234 | vixl::aarch64::Label* throw_npe = nullptr; |
| 6235 | if (GetCompilerOptions().GetImplicitNullChecks() && holder_reg.Is(base_reg)) { |
| 6236 | throw_npe = &throw_npe_label; |
| 6237 | __ Cbz(holder_reg.W(), throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6238 | } |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6239 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 6240 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 6241 | // to load the reference and call the entrypoint that performs further checks on the |
| 6242 | // reference and marks it if needed. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6243 | vixl::aarch64::Label slow_path; |
| 6244 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6245 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6246 | __ Bind(&slow_path); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6247 | if (kind == BakerReadBarrierKind::kField) { |
| 6248 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6249 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (immediate) unsigned offset. |
| 6250 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6251 | __ Ubfx(ip0.W(), ip0.W(), 10, 12); // Extract the offset. |
| 6252 | __ Ldr(ip0.W(), MemOperand(base_reg, ip0, LSL, 2)); // Load the reference. |
| 6253 | } else { |
| 6254 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 6255 | DCHECK(!base_reg.Is(holder_reg)); |
| 6256 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6257 | __ Ldar(ip0.W(), MemOperand(base_reg)); |
| 6258 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6259 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 6260 | __ Br(ip1); // Jump to the entrypoint. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6261 | break; |
| 6262 | } |
| 6263 | case BakerReadBarrierKind::kArray: { |
| 6264 | auto base_reg = |
| 6265 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6266 | CheckValidReg(base_reg.GetCode()); |
| 6267 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6268 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6269 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6270 | temps.Exclude(ip0, ip1); |
| 6271 | vixl::aarch64::Label slow_path; |
| 6272 | int32_t data_offset = |
| 6273 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 6274 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 6275 | DCHECK_LT(lock_word.GetOffset(), 0); |
| 6276 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path); |
| 6277 | __ Bind(&slow_path); |
| 6278 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| 6279 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (register) unsigned offset. |
| 6280 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6281 | __ Ubfx(ip0, ip0, 16, 6); // Extract the index register, plus 32 (bit 21 is set). |
| 6282 | __ Bfi(ip1, ip0, 3, 6); // Insert ip0 to the entrypoint address to create |
| 6283 | // a switch case target based on the index register. |
| 6284 | __ Mov(ip0, base_reg); // Move the base register to ip0. |
| 6285 | __ Br(ip1); // Jump to the entrypoint's array switch case. |
| 6286 | break; |
| 6287 | } |
| 6288 | case BakerReadBarrierKind::kGcRoot: { |
| 6289 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 6290 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 6291 | // otherwise return the reference (or the extracted forwarding address). |
| 6292 | // There is no gray bit check for GC roots. |
| 6293 | auto root_reg = |
| 6294 | Register::GetWRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6295 | CheckValidReg(root_reg.GetCode()); |
| 6296 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6297 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6298 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6299 | temps.Exclude(ip0, ip1); |
| 6300 | vixl::aarch64::Label return_label, not_marked, forwarding_address; |
| 6301 | __ Cbz(root_reg, &return_label); |
| 6302 | MemOperand lock_word(root_reg.X(), mirror::Object::MonitorOffset().Int32Value()); |
| 6303 | __ Ldr(ip0.W(), lock_word); |
| 6304 | __ Tbz(ip0.W(), LockWord::kMarkBitStateShift, ¬_marked); |
| 6305 | __ Bind(&return_label); |
| 6306 | __ Br(lr); |
| 6307 | __ Bind(¬_marked); |
| 6308 | __ Tst(ip0.W(), Operand(ip0.W(), LSL, 1)); |
| 6309 | __ B(&forwarding_address, mi); |
| 6310 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6311 | // Adjust the art_quick_read_barrier_mark_introspection address in IP1 to |
| 6312 | // art_quick_read_barrier_mark_introspection_gc_roots. |
| 6313 | __ Add(ip1, ip1, Operand(BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET)); |
| 6314 | __ Mov(ip0.W(), root_reg); |
| 6315 | __ Br(ip1); |
| 6316 | __ Bind(&forwarding_address); |
| 6317 | __ Lsl(root_reg, ip0.W(), LockWord::kForwardingAddressShift); |
| 6318 | __ Br(lr); |
| 6319 | break; |
| 6320 | } |
| 6321 | default: |
| 6322 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 6323 | UNREACHABLE(); |
| 6324 | } |
| 6325 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6326 | // For JIT, the slow path is considered part of the compiled method, |
| 6327 | // so JIT should pass null as `debug_name`. Tests may not have a runtime. |
| 6328 | DCHECK(Runtime::Current() == nullptr || |
| 6329 | !Runtime::Current()->UseJitCompilation() || |
| 6330 | debug_name == nullptr); |
| 6331 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6332 | std::ostringstream oss; |
| 6333 | oss << "BakerReadBarrierThunk"; |
| 6334 | switch (kind) { |
| 6335 | case BakerReadBarrierKind::kField: |
| 6336 | oss << "Field_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 6337 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 6338 | break; |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame] | 6339 | case BakerReadBarrierKind::kAcquire: |
| 6340 | oss << "Acquire_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 6341 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 6342 | break; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6343 | case BakerReadBarrierKind::kArray: |
| 6344 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6345 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6346 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6347 | break; |
| 6348 | case BakerReadBarrierKind::kGcRoot: |
| 6349 | oss << "GcRoot_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6350 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6351 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6352 | break; |
| 6353 | } |
| 6354 | *debug_name = oss.str(); |
| 6355 | } |
| 6356 | } |
| 6357 | |
| 6358 | #undef __ |
| 6359 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6360 | } // namespace arm64 |
| 6361 | } // namespace art |