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 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 96 | // Some instructions have special requirements for a temporary, for example |
| 97 | // LoadClass/kBssEntry and LoadString/kBssEntry for Baker read barrier require |
| 98 | // temp that's not an R0 (to avoid an extra move) and Baker read barrier field |
| 99 | // loads with large offsets need a fixed register to limit the number of link-time |
| 100 | // thunks we generate. For these and similar cases, we want to reserve a specific |
| 101 | // register that's neither callee-save nor an argument register. We choose x15. |
| 102 | inline Location FixedTempLocation() { |
| 103 | return Location::RegisterLocation(x15.GetCode()); |
| 104 | } |
| 105 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 106 | inline Condition ARM64Condition(IfCondition cond) { |
| 107 | switch (cond) { |
| 108 | case kCondEQ: return eq; |
| 109 | case kCondNE: return ne; |
| 110 | case kCondLT: return lt; |
| 111 | case kCondLE: return le; |
| 112 | case kCondGT: return gt; |
| 113 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 114 | case kCondB: return lo; |
| 115 | case kCondBE: return ls; |
| 116 | case kCondA: return hi; |
| 117 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 118 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 119 | LOG(FATAL) << "Unreachable"; |
| 120 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 121 | } |
| 122 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 123 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 124 | // The ARM64 condition codes can express all the necessary branches, see the |
| 125 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 126 | // There is no dex instruction or HIR that would need the missing conditions |
| 127 | // "equal or unordered" or "not equal". |
| 128 | switch (cond) { |
| 129 | case kCondEQ: return eq; |
| 130 | case kCondNE: return ne /* unordered */; |
| 131 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 132 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 133 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 134 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 135 | default: |
| 136 | LOG(FATAL) << "UNREACHABLE"; |
| 137 | UNREACHABLE(); |
| 138 | } |
| 139 | } |
| 140 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 141 | Location ARM64ReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 142 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 143 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 144 | // but we use the exact registers for clarity. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 145 | if (return_type == DataType::Type::kFloat32) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 146 | return LocationFrom(s0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 147 | } else if (return_type == DataType::Type::kFloat64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 148 | return LocationFrom(d0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 149 | } else if (return_type == DataType::Type::kInt64) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 150 | return LocationFrom(x0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 151 | } else if (return_type == DataType::Type::kVoid) { |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 152 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 153 | } else { |
| 154 | return LocationFrom(w0); |
| 155 | } |
| 156 | } |
| 157 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 158 | Location InvokeRuntimeCallingConvention::GetReturnLocation(DataType::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 159 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 160 | } |
| 161 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 162 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 163 | InvokeRuntimeCallingConvention calling_convention; |
| 164 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 165 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 166 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 167 | RegisterFrom(calling_convention.GetReturnLocation(DataType::Type::kReference), |
| 168 | DataType::Type::kReference).GetCode()); |
| 169 | return caller_saves; |
| 170 | } |
| 171 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 172 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 173 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 174 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 175 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 176 | // Calculate memory accessing operand for save/restore live registers. |
| 177 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 178 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 179 | int64_t spill_offset, |
| 180 | bool is_save) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 181 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 182 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 183 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 184 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 185 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 186 | codegen->GetNumberOfFloatingPointRegisters())); |
| 187 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 188 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 189 | unsigned v_reg_size = codegen->GetGraph()->HasSIMD() ? kQRegSize : kDRegSize; |
| 190 | CPURegList fp_list = CPURegList(CPURegister::kVRegister, v_reg_size, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 191 | |
| 192 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 193 | UseScratchRegisterScope temps(masm); |
| 194 | |
| 195 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 196 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 197 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 198 | int64_t reg_size = kXRegSizeInBytes; |
| 199 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 200 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 201 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 202 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 203 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 204 | // to compute the base address(float point registers spill base address). |
| 205 | Register new_base = temps.AcquireSameSizeAs(base); |
| 206 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 207 | base = new_base; |
| 208 | spill_offset = -core_spill_size; |
| 209 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 210 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 211 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 212 | } |
| 213 | |
| 214 | if (is_save) { |
| 215 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 216 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 217 | } else { |
| 218 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 219 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 224 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 225 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 226 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 227 | // If the register holds an object, update the stack mask. |
| 228 | if (locations->RegisterContainsObject(i)) { |
| 229 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 230 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 231 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 232 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 233 | saved_core_stack_offsets_[i] = stack_offset; |
| 234 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 235 | } |
| 236 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 237 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 238 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 239 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 240 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 241 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 242 | stack_offset += kDRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 243 | } |
| 244 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 245 | SaveRestoreLiveRegistersHelper(codegen, |
| 246 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 247 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 248 | } |
| 249 | |
| 250 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 251 | SaveRestoreLiveRegistersHelper(codegen, |
| 252 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 253 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 254 | } |
| 255 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 256 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 257 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 258 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 259 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 260 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 261 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 262 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 263 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 264 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 265 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 266 | // Live registers will be restored in the catch block if caught. |
| 267 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 268 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 269 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 270 | // move resolver. |
| 271 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 272 | codegen->EmitParallelMoves(locations->InAt(0), |
| 273 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 274 | DataType::Type::kInt32, |
| 275 | locations->InAt(1), |
| 276 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 277 | DataType::Type::kInt32); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 278 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 279 | ? kQuickThrowStringBounds |
| 280 | : kQuickThrowArrayBounds; |
| 281 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 282 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 283 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 284 | } |
| 285 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 286 | bool IsFatal() const OVERRIDE { return true; } |
| 287 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 288 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 289 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 290 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 291 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 292 | }; |
| 293 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 294 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 295 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 296 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 297 | |
| 298 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 299 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 300 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 301 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 302 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 305 | bool IsFatal() const OVERRIDE { return true; } |
| 306 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 307 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 308 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 309 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 310 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 311 | }; |
| 312 | |
| 313 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 314 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 315 | LoadClassSlowPathARM64(HLoadClass* cls, HInstruction* at) |
| 316 | : SlowPathCodeARM64(at), cls_(cls) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 317 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 318 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 322 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 323 | Location out = locations->Out(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 324 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 325 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 326 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 327 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 328 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 329 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 330 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 331 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 332 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 333 | if (must_resolve_type) { |
| 334 | DCHECK(IsSameDexFile(cls_->GetDexFile(), arm64_codegen->GetGraph()->GetDexFile())); |
| 335 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 336 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 337 | arm64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 338 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 339 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 340 | } else { |
| 341 | DCHECK(must_do_clinit); |
| 342 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 343 | arm64_codegen->MoveLocation(LocationFrom(calling_convention.GetRegisterAt(0)), |
| 344 | source, |
| 345 | cls_->GetType()); |
| 346 | } |
| 347 | if (must_do_clinit) { |
| 348 | arm64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 349 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 350 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 351 | |
| 352 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 353 | if (out.IsValid()) { |
| 354 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 355 | DataType::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 356 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 357 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 358 | RestoreLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 359 | __ B(GetExitLabel()); |
| 360 | } |
| 361 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 362 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 363 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 364 | private: |
| 365 | // The class this slow path will load. |
| 366 | HLoadClass* const cls_; |
| 367 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 368 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 369 | }; |
| 370 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 371 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 372 | public: |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 373 | explicit LoadStringSlowPathARM64(HLoadString* instruction) |
| 374 | : SlowPathCodeARM64(instruction) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 375 | |
| 376 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 377 | LocationSummary* locations = instruction_->GetLocations(); |
| 378 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 379 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 380 | |
| 381 | __ Bind(GetEntryLabel()); |
| 382 | SaveLiveRegisters(codegen, locations); |
| 383 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 384 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 385 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 386 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 387 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 388 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 389 | DataType::Type type = instruction_->GetType(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 390 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 391 | |
| 392 | RestoreLiveRegisters(codegen, locations); |
| 393 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 394 | __ B(GetExitLabel()); |
| 395 | } |
| 396 | |
| 397 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 398 | |
| 399 | private: |
| 400 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 401 | }; |
| 402 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 403 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 404 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 405 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 406 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 407 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 408 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 409 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 410 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 411 | // Live registers will be restored in the catch block if caught. |
| 412 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 413 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 414 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 415 | instruction_, |
| 416 | instruction_->GetDexPc(), |
| 417 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 418 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 419 | } |
| 420 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 421 | bool IsFatal() const OVERRIDE { return true; } |
| 422 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 423 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 424 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 425 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 426 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 427 | }; |
| 428 | |
| 429 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 430 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 431 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 432 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 433 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 434 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 435 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 436 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 437 | __ Bind(GetEntryLabel()); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 438 | SaveLiveRegisters(codegen, locations); // Only saves live 128-bit regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 439 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 440 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 441 | RestoreLiveRegisters(codegen, locations); // Only restores live 128-bit regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 442 | if (successor_ == nullptr) { |
| 443 | __ B(GetReturnLabel()); |
| 444 | } else { |
| 445 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 446 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 447 | } |
| 448 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 449 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 450 | DCHECK(successor_ == nullptr); |
| 451 | return &return_label_; |
| 452 | } |
| 453 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 454 | HBasicBlock* GetSuccessor() const { |
| 455 | return successor_; |
| 456 | } |
| 457 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 458 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 459 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 460 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 461 | // If not null, the block to branch to after the suspend check. |
| 462 | HBasicBlock* const successor_; |
| 463 | |
| 464 | // 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] | 465 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 466 | |
| 467 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 468 | }; |
| 469 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 470 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 471 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 472 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 473 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 474 | |
| 475 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 476 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 477 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 478 | DCHECK(instruction_->IsCheckCast() |
| 479 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 480 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 481 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 482 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 483 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 484 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 485 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 486 | SaveLiveRegisters(codegen, locations); |
| 487 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 488 | |
| 489 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 490 | // move resolver. |
| 491 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 492 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 493 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 494 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 495 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 496 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 497 | DataType::Type::kReference); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 498 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 499 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 500 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 501 | DataType::Type ret_type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 502 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 503 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 504 | } else { |
| 505 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 506 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 507 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 510 | if (!is_fatal_) { |
| 511 | RestoreLiveRegisters(codegen, locations); |
| 512 | __ B(GetExitLabel()); |
| 513 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 516 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 517 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 518 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 519 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 520 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 521 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 522 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 523 | }; |
| 524 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 525 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 526 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 527 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 528 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 529 | |
| 530 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 531 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 532 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 533 | LocationSummary* locations = instruction_->GetLocations(); |
| 534 | SaveLiveRegisters(codegen, locations); |
| 535 | InvokeRuntimeCallingConvention calling_convention; |
| 536 | __ Mov(calling_convention.GetRegisterAt(0), |
| 537 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 538 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 539 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 542 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 543 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 544 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 545 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 546 | }; |
| 547 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 548 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 549 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 550 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 551 | |
| 552 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 553 | LocationSummary* locations = instruction_->GetLocations(); |
| 554 | __ Bind(GetEntryLabel()); |
| 555 | SaveLiveRegisters(codegen, locations); |
| 556 | |
| 557 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 558 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 559 | parallel_move.AddMove( |
| 560 | locations->InAt(0), |
| 561 | LocationFrom(calling_convention.GetRegisterAt(0)), |
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 | parallel_move.AddMove( |
| 565 | locations->InAt(1), |
| 566 | LocationFrom(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 567 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 568 | nullptr); |
| 569 | parallel_move.AddMove( |
| 570 | locations->InAt(2), |
| 571 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 572 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 573 | nullptr); |
| 574 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 575 | |
| 576 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 577 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 578 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 579 | RestoreLiveRegisters(codegen, locations); |
| 580 | __ B(GetExitLabel()); |
| 581 | } |
| 582 | |
| 583 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 584 | |
| 585 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 586 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 587 | }; |
| 588 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 589 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 590 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 591 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 592 | |
| 593 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 594 | // 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] | 595 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 596 | num_entries * sizeof(int32_t), |
| 597 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 598 | |
| 599 | __ Bind(&table_start_); |
| 600 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 601 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 602 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 603 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 604 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 605 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 606 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 607 | Literal<int32_t> literal(jump_offset); |
| 608 | __ place(&literal); |
| 609 | } |
| 610 | } |
| 611 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 612 | // Abstract base class for read barrier slow paths marking a reference |
| 613 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 614 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 615 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 616 | // barrier marking runtime entry point to be invoked or an empty |
| 617 | // location; in the latter case, the read barrier marking runtime |
| 618 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 619 | class ReadBarrierMarkSlowPathBaseARM64 : public SlowPathCodeARM64 { |
| 620 | protected: |
| 621 | ReadBarrierMarkSlowPathBaseARM64(HInstruction* instruction, Location ref, Location entrypoint) |
| 622 | : SlowPathCodeARM64(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 623 | DCHECK(kEmitCompilerReadBarrier); |
| 624 | } |
| 625 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 626 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM64"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 627 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 628 | // Generate assembly code calling the read barrier marking runtime |
| 629 | // entry point (ReadBarrierMarkRegX). |
| 630 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 631 | // No need to save live registers; it's taken care of by the |
| 632 | // entrypoint. Also, there is no need to update the stack mask, |
| 633 | // as this runtime call will not trigger a garbage collection. |
| 634 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 635 | DCHECK_NE(ref_.reg(), LR); |
| 636 | DCHECK_NE(ref_.reg(), WSP); |
| 637 | DCHECK_NE(ref_.reg(), WZR); |
| 638 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 639 | // as a temporary, it cannot be the entry point's input/output. |
| 640 | DCHECK_NE(ref_.reg(), IP0); |
| 641 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 642 | // "Compact" slow path, saving two moves. |
| 643 | // |
| 644 | // Instead of using the standard runtime calling convention (input |
| 645 | // and output in W0): |
| 646 | // |
| 647 | // W0 <- ref |
| 648 | // W0 <- ReadBarrierMark(W0) |
| 649 | // ref <- W0 |
| 650 | // |
| 651 | // we just use rX (the register containing `ref`) as input and output |
| 652 | // of a dedicated entrypoint: |
| 653 | // |
| 654 | // rX <- ReadBarrierMarkRegX(rX) |
| 655 | // |
| 656 | if (entrypoint_.IsValid()) { |
| 657 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 658 | __ Blr(XRegisterFrom(entrypoint_)); |
| 659 | } else { |
| 660 | // Entrypoint is not already loaded, load from the thread. |
| 661 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 662 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 663 | // This runtime call does not require a stack map. |
| 664 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | // The location (register) of the marked object reference. |
| 669 | const Location ref_; |
| 670 | |
| 671 | // The location of the entrypoint if it is already loaded. |
| 672 | const Location entrypoint_; |
| 673 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 674 | private: |
| 675 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM64); |
| 676 | }; |
| 677 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 678 | // Slow path loading `obj`'s lock word, loading a reference from |
| 679 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 680 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 681 | // read barrier). The field `obj.field` in the object `obj` holding |
| 682 | // this reference does not get updated by this slow path after marking |
| 683 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 684 | // below for that). |
| 685 | // |
| 686 | // This means that after the execution of this slow path, `ref` will |
| 687 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 688 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 689 | // probably still be a from-space reference (unless it gets updated by |
| 690 | // another thread, or if another thread installed another object |
| 691 | // reference (different from `ref`) in `obj.field`). |
| 692 | // |
| 693 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 694 | // barrier marking runtime entry point to be invoked or an empty |
| 695 | // location; in the latter case, the read barrier marking runtime |
| 696 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 697 | class LoadReferenceWithBakerReadBarrierSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
| 698 | public: |
| 699 | LoadReferenceWithBakerReadBarrierSlowPathARM64(HInstruction* instruction, |
| 700 | Location ref, |
| 701 | Register obj, |
| 702 | uint32_t offset, |
| 703 | Location index, |
| 704 | size_t scale_factor, |
| 705 | bool needs_null_check, |
| 706 | bool use_load_acquire, |
| 707 | Register temp, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 708 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 709 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
| 710 | obj_(obj), |
| 711 | offset_(offset), |
| 712 | index_(index), |
| 713 | scale_factor_(scale_factor), |
| 714 | needs_null_check_(needs_null_check), |
| 715 | use_load_acquire_(use_load_acquire), |
| 716 | temp_(temp) { |
| 717 | DCHECK(kEmitCompilerReadBarrier); |
| 718 | DCHECK(kUseBakerReadBarrier); |
| 719 | } |
| 720 | |
| 721 | const char* GetDescription() const OVERRIDE { |
| 722 | return "LoadReferenceWithBakerReadBarrierSlowPathARM64"; |
| 723 | } |
| 724 | |
| 725 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 726 | LocationSummary* locations = instruction_->GetLocations(); |
| 727 | DCHECK(locations->CanCall()); |
| 728 | DCHECK(ref_.IsRegister()) << ref_; |
| 729 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 730 | DCHECK(obj_.IsW()); |
| 731 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 732 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 733 | instruction_->IsStaticFieldGet() || |
| 734 | instruction_->IsArrayGet() || |
| 735 | instruction_->IsArraySet() || |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 736 | instruction_->IsInstanceOf() || |
| 737 | instruction_->IsCheckCast() || |
| 738 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 739 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 740 | << "Unexpected instruction in read barrier marking slow path: " |
| 741 | << instruction_->DebugName(); |
| 742 | // The read barrier instrumentation of object ArrayGet |
| 743 | // instructions does not support the HIntermediateAddress |
| 744 | // instruction. |
| 745 | DCHECK(!(instruction_->IsArrayGet() && |
| 746 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 747 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 748 | // Temporary register `temp_`, used to store the lock word, must |
| 749 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 750 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 751 | // need the lock word to still be in `temp_` after the reference |
| 752 | // load. |
| 753 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 754 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
| 755 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 756 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 757 | |
| 758 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 759 | // inserted after the original load. However, in fast path based |
| 760 | // Baker's read barriers, we need to perform the load of |
| 761 | // mirror::Object::monitor_ *before* the original reference load. |
| 762 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 763 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 764 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 765 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 766 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 767 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 768 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 769 | // if (is_gray) { |
| 770 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 771 | // } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 772 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 773 | // Note: the original implementation in ReadBarrier::Barrier is |
| 774 | // slightly more complex as it performs additional checks that we do |
| 775 | // not do here for performance reasons. |
| 776 | |
| 777 | // /* int32_t */ monitor = obj->monitor_ |
| 778 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 779 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 780 | if (needs_null_check_) { |
| 781 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 782 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 783 | // /* LockWord */ lock_word = LockWord(monitor) |
| 784 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 785 | "art::LockWord and int32_t have different sizes."); |
| 786 | |
| 787 | // Introduce a dependency on the lock_word including rb_state, |
| 788 | // to prevent load-load reordering, and without using |
| 789 | // a memory barrier (which would be more expensive). |
| 790 | // `obj` is unchanged by this operation, but its value now depends |
| 791 | // on `temp`. |
| 792 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 793 | |
| 794 | // The actual reference load. |
| 795 | // A possible implicit null check has already been handled above. |
| 796 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 797 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 798 | ref_, |
| 799 | obj_, |
| 800 | offset_, |
| 801 | index_, |
| 802 | scale_factor_, |
| 803 | /* needs_null_check */ false, |
| 804 | use_load_acquire_); |
| 805 | |
| 806 | // Mark the object `ref` when `obj` is gray. |
| 807 | // |
| 808 | // if (rb_state == ReadBarrier::GrayState()) |
| 809 | // ref = ReadBarrier::Mark(ref); |
| 810 | // |
| 811 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 812 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 813 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 814 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 815 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 816 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 817 | __ B(GetExitLabel()); |
| 818 | } |
| 819 | |
| 820 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 821 | // The register containing the object holding the marked object reference field. |
| 822 | Register obj_; |
| 823 | // The offset, index and scale factor to access the reference in `obj_`. |
| 824 | uint32_t offset_; |
| 825 | Location index_; |
| 826 | size_t scale_factor_; |
| 827 | // Is a null check required? |
| 828 | bool needs_null_check_; |
| 829 | // Should this reference load use Load-Acquire semantics? |
| 830 | bool use_load_acquire_; |
| 831 | // A temporary register used to hold the lock word of `obj_`. |
| 832 | Register temp_; |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 833 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 834 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM64); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 835 | }; |
| 836 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 837 | // Slow path loading `obj`'s lock word, loading a reference from |
| 838 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 839 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 840 | // read barrier). If needed, this slow path also atomically updates |
| 841 | // the field `obj.field` in the object `obj` holding this reference |
| 842 | // after marking (contrary to |
| 843 | // LoadReferenceWithBakerReadBarrierSlowPathARM64 above, which never |
| 844 | // tries to update `obj.field`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 845 | // |
| 846 | // This means that after the execution of this slow path, both `ref` |
| 847 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 848 | // hold the same to-space reference (unless another thread installed |
| 849 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 850 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 851 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 852 | // barrier marking runtime entry point to be invoked or an empty |
| 853 | // location; in the latter case, the read barrier marking runtime |
| 854 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 855 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 856 | : public ReadBarrierMarkSlowPathBaseARM64 { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 857 | public: |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 858 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 859 | HInstruction* instruction, |
| 860 | Location ref, |
| 861 | Register obj, |
| 862 | uint32_t offset, |
| 863 | Location index, |
| 864 | size_t scale_factor, |
| 865 | bool needs_null_check, |
| 866 | bool use_load_acquire, |
| 867 | Register temp, |
| 868 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 869 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 870 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 871 | offset_(offset), |
| 872 | index_(index), |
| 873 | scale_factor_(scale_factor), |
| 874 | needs_null_check_(needs_null_check), |
| 875 | use_load_acquire_(use_load_acquire), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 876 | temp_(temp) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 877 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 878 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 882 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64"; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 886 | LocationSummary* locations = instruction_->GetLocations(); |
| 887 | Register ref_reg = WRegisterFrom(ref_); |
| 888 | DCHECK(locations->CanCall()); |
| 889 | DCHECK(ref_.IsRegister()) << ref_; |
| 890 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 891 | DCHECK(obj_.IsW()); |
| 892 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
| 893 | |
| 894 | // This slow path is only used by the UnsafeCASObject intrinsic at the moment. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 895 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 896 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 897 | << instruction_->DebugName(); |
| 898 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 899 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 900 | DCHECK_EQ(offset_, 0u); |
| 901 | DCHECK_EQ(scale_factor_, 0u); |
| 902 | DCHECK_EQ(use_load_acquire_, false); |
| 903 | // The location of the offset of the marked reference field within `obj_`. |
| 904 | Location field_offset = index_; |
| 905 | DCHECK(field_offset.IsRegister()) << field_offset; |
| 906 | |
| 907 | // Temporary register `temp_`, used to store the lock word, must |
| 908 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 909 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 910 | // need the lock word to still be in `temp_` after the reference |
| 911 | // load. |
| 912 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 913 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 914 | |
| 915 | __ Bind(GetEntryLabel()); |
| 916 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 917 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM64's: |
| 918 | // |
| 919 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 920 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 921 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 922 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 923 | // if (is_gray) { |
| 924 | // old_ref = ref; |
| 925 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 926 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 927 | // } |
| 928 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 929 | // /* int32_t */ monitor = obj->monitor_ |
| 930 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 931 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 932 | if (needs_null_check_) { |
| 933 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 934 | } |
| 935 | // /* LockWord */ lock_word = LockWord(monitor) |
| 936 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 937 | "art::LockWord and int32_t have different sizes."); |
| 938 | |
| 939 | // Introduce a dependency on the lock_word including rb_state, |
| 940 | // to prevent load-load reordering, and without using |
| 941 | // a memory barrier (which would be more expensive). |
| 942 | // `obj` is unchanged by this operation, but its value now depends |
| 943 | // on `temp`. |
| 944 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 945 | |
| 946 | // The actual reference load. |
| 947 | // A possible implicit null check has already been handled above. |
| 948 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 949 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 950 | ref_, |
| 951 | obj_, |
| 952 | offset_, |
| 953 | index_, |
| 954 | scale_factor_, |
| 955 | /* needs_null_check */ false, |
| 956 | use_load_acquire_); |
| 957 | |
| 958 | // Mark the object `ref` when `obj` is gray. |
| 959 | // |
| 960 | // if (rb_state == ReadBarrier::GrayState()) |
| 961 | // ref = ReadBarrier::Mark(ref); |
| 962 | // |
| 963 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 964 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 965 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 966 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 967 | |
| 968 | // Save the old value of the reference before marking it. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 969 | // Note that we cannot use IP to save the old reference, as IP is |
| 970 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 971 | // need the old reference after the call to that entry point. |
| 972 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 973 | __ Mov(temp_.W(), ref_reg); |
| 974 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 975 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 976 | |
| 977 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 978 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 979 | // |
| 980 | // Note that this field could also hold a different object, if |
| 981 | // another thread had concurrently changed it. In that case, the |
| 982 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 983 | // (CAS) operation below would abort the CAS, leaving the field |
| 984 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 985 | __ Cmp(temp_.W(), ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 986 | __ B(eq, GetExitLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 987 | |
| 988 | // Update the the holder's field atomically. This may fail if |
| 989 | // mutator updates before us, but it's OK. This is achieved |
| 990 | // using a strong compare-and-set (CAS) operation with relaxed |
| 991 | // memory synchronization ordering, where the expected value is |
| 992 | // the old reference and the desired value is the new reference. |
| 993 | |
| 994 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 995 | UseScratchRegisterScope temps(masm); |
| 996 | |
| 997 | // Convenience aliases. |
| 998 | Register base = obj_.W(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 999 | Register offset = XRegisterFrom(field_offset); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1000 | Register expected = temp_.W(); |
| 1001 | Register value = ref_reg; |
| 1002 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1003 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 1004 | |
| 1005 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1006 | |
| 1007 | if (kPoisonHeapReferences) { |
| 1008 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1009 | if (value.Is(expected)) { |
| 1010 | // Do not poison `value`, as it is the same register as |
| 1011 | // `expected`, which has just been poisoned. |
| 1012 | } else { |
| 1013 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | // do { |
| 1018 | // tmp_value = [tmp_ptr] - expected; |
| 1019 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1020 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1021 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1022 | __ Bind(&loop_head); |
| 1023 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 1024 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1025 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1026 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 1027 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1028 | __ B(&exit_loop); |
| 1029 | __ Bind(&comparison_failed); |
| 1030 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1031 | __ Bind(&exit_loop); |
| 1032 | |
| 1033 | if (kPoisonHeapReferences) { |
| 1034 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1035 | if (value.Is(expected)) { |
| 1036 | // Do not unpoison `value`, as it is the same register as |
| 1037 | // `expected`, which has just been unpoisoned. |
| 1038 | } else { |
| 1039 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1040 | } |
| 1041 | } |
| 1042 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1043 | __ B(GetExitLabel()); |
| 1044 | } |
| 1045 | |
| 1046 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1047 | // The register containing the object holding the marked object reference field. |
| 1048 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1049 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1050 | uint32_t offset_; |
| 1051 | Location index_; |
| 1052 | size_t scale_factor_; |
| 1053 | // Is a null check required? |
| 1054 | bool needs_null_check_; |
| 1055 | // Should this reference load use Load-Acquire semantics? |
| 1056 | bool use_load_acquire_; |
| 1057 | // A temporary register used to hold the lock word of `obj_`; and |
| 1058 | // also to hold the original reference value, when the reference is |
| 1059 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1060 | const Register temp_; |
| 1061 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1062 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1063 | }; |
| 1064 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1065 | // Slow path generating a read barrier for a heap reference. |
| 1066 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 1067 | public: |
| 1068 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 1069 | Location out, |
| 1070 | Location ref, |
| 1071 | Location obj, |
| 1072 | uint32_t offset, |
| 1073 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1074 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1075 | out_(out), |
| 1076 | ref_(ref), |
| 1077 | obj_(obj), |
| 1078 | offset_(offset), |
| 1079 | index_(index) { |
| 1080 | DCHECK(kEmitCompilerReadBarrier); |
| 1081 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1082 | // has been overwritten by (or after) the heap object reference load |
| 1083 | // to be instrumented, e.g.: |
| 1084 | // |
| 1085 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1086 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1087 | // |
| 1088 | // In that case, we have lost the information about the original |
| 1089 | // object, and the emitted read barrier cannot work properly. |
| 1090 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1091 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1092 | } |
| 1093 | |
| 1094 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1095 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1096 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1097 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1098 | DCHECK(locations->CanCall()); |
| 1099 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1100 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1101 | instruction_->IsStaticFieldGet() || |
| 1102 | instruction_->IsArrayGet() || |
| 1103 | instruction_->IsInstanceOf() || |
| 1104 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1105 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1106 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1107 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1108 | // The read barrier instrumentation of object ArrayGet |
| 1109 | // instructions does not support the HIntermediateAddress |
| 1110 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1111 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1112 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1113 | |
| 1114 | __ Bind(GetEntryLabel()); |
| 1115 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1116 | SaveLiveRegisters(codegen, locations); |
| 1117 | |
| 1118 | // We may have to change the index's value, but as `index_` is a |
| 1119 | // constant member (like other "inputs" of this slow path), |
| 1120 | // introduce a copy of it, `index`. |
| 1121 | Location index = index_; |
| 1122 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1123 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1124 | if (instruction_->IsArrayGet()) { |
| 1125 | // Compute the actual memory offset and store it in `index`. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1126 | Register index_reg = RegisterFrom(index_, DataType::Type::kInt32); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1127 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 1128 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 1129 | // We are about to change the value of `index_reg` (see the |
| 1130 | // calls to vixl::MacroAssembler::Lsl and |
| 1131 | // vixl::MacroAssembler::Mov below), but it has |
| 1132 | // not been saved by the previous call to |
| 1133 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1134 | // callee-save register -- |
| 1135 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1136 | // callee-save registers, as it has been designed with the |
| 1137 | // assumption that callee-save registers are supposed to be |
| 1138 | // handled by the called function. So, as a callee-save |
| 1139 | // register, `index_reg` _would_ eventually be saved onto |
| 1140 | // the stack, but it would be too late: we would have |
| 1141 | // changed its value earlier. Therefore, we manually save |
| 1142 | // it here into another freely available register, |
| 1143 | // `free_reg`, chosen of course among the caller-save |
| 1144 | // registers (as a callee-save `free_reg` register would |
| 1145 | // exhibit the same problem). |
| 1146 | // |
| 1147 | // Note we could have requested a temporary register from |
| 1148 | // the register allocator instead; but we prefer not to, as |
| 1149 | // this is a slow path, and we know we can find a |
| 1150 | // caller-save register that is available. |
| 1151 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1152 | __ Mov(free_reg.W(), index_reg); |
| 1153 | index_reg = free_reg; |
| 1154 | index = LocationFrom(index_reg); |
| 1155 | } else { |
| 1156 | // The initial register stored in `index_` has already been |
| 1157 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1158 | // (as it is not a callee-save register), so we can freely |
| 1159 | // use it. |
| 1160 | } |
| 1161 | // Shifting the index value contained in `index_reg` by the scale |
| 1162 | // factor (2) cannot overflow in practice, as the runtime is |
| 1163 | // unable to allocate object arrays with a size larger than |
| 1164 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1165 | __ Lsl(index_reg, index_reg, DataType::SizeShift(type)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1166 | static_assert( |
| 1167 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1168 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1169 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1170 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1171 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1172 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1173 | // (as in the case of ArrayGet), as it is actually an offset |
| 1174 | // to an object field within an object. |
| 1175 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1176 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1177 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1178 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1179 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1180 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1181 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | // We're moving two or three locations to locations that could |
| 1186 | // overlap, so we need a parallel move resolver. |
| 1187 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1188 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1189 | parallel_move.AddMove(ref_, |
| 1190 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1191 | type, |
| 1192 | nullptr); |
| 1193 | parallel_move.AddMove(obj_, |
| 1194 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1195 | type, |
| 1196 | nullptr); |
| 1197 | if (index.IsValid()) { |
| 1198 | parallel_move.AddMove(index, |
| 1199 | LocationFrom(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1200 | DataType::Type::kInt32, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1201 | nullptr); |
| 1202 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1203 | } else { |
| 1204 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1205 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1206 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1207 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1208 | instruction_, |
| 1209 | instruction_->GetDexPc(), |
| 1210 | this); |
| 1211 | CheckEntrypointTypes< |
| 1212 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1213 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1214 | |
| 1215 | RestoreLiveRegisters(codegen, locations); |
| 1216 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1217 | __ B(GetExitLabel()); |
| 1218 | } |
| 1219 | |
| 1220 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1221 | |
| 1222 | private: |
| 1223 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1224 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1225 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1226 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1227 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1228 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1229 | } |
| 1230 | } |
| 1231 | // We shall never fail to find a free caller-save register, as |
| 1232 | // there are more than two core caller-save registers on ARM64 |
| 1233 | // (meaning it is possible to find one which is different from |
| 1234 | // `ref` and `obj`). |
| 1235 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1236 | LOG(FATAL) << "Could not find a free register"; |
| 1237 | UNREACHABLE(); |
| 1238 | } |
| 1239 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1240 | const Location out_; |
| 1241 | const Location ref_; |
| 1242 | const Location obj_; |
| 1243 | const uint32_t offset_; |
| 1244 | // An additional location containing an index to an array. |
| 1245 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1246 | // UnsafeGetObjectVolatile intrinsics. |
| 1247 | const Location index_; |
| 1248 | |
| 1249 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1250 | }; |
| 1251 | |
| 1252 | // Slow path generating a read barrier for a GC root. |
| 1253 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1254 | public: |
| 1255 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1256 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1257 | DCHECK(kEmitCompilerReadBarrier); |
| 1258 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1259 | |
| 1260 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1261 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1262 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1263 | DCHECK(locations->CanCall()); |
| 1264 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1265 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1266 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1267 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1268 | |
| 1269 | __ Bind(GetEntryLabel()); |
| 1270 | SaveLiveRegisters(codegen, locations); |
| 1271 | |
| 1272 | InvokeRuntimeCallingConvention calling_convention; |
| 1273 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1274 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1275 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1276 | // thus we need a 64-bit move here, and we cannot use |
| 1277 | // |
| 1278 | // arm64_codegen->MoveLocation( |
| 1279 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1280 | // root_, |
| 1281 | // type); |
| 1282 | // |
| 1283 | // 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] | 1284 | // reference type (`DataType::Type::kReference`). |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1285 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1286 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1287 | instruction_, |
| 1288 | instruction_->GetDexPc(), |
| 1289 | this); |
| 1290 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1291 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1292 | |
| 1293 | RestoreLiveRegisters(codegen, locations); |
| 1294 | __ B(GetExitLabel()); |
| 1295 | } |
| 1296 | |
| 1297 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1298 | |
| 1299 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1300 | const Location out_; |
| 1301 | const Location root_; |
| 1302 | |
| 1303 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1304 | }; |
| 1305 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1306 | #undef __ |
| 1307 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1308 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(DataType::Type type) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1309 | Location next_location; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1310 | if (type == DataType::Type::kVoid) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1311 | LOG(FATAL) << "Unreachable type " << type; |
| 1312 | } |
| 1313 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1314 | if (DataType::IsFloatingPointType(type) && |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1315 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
| 1316 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1317 | } else if (!DataType::IsFloatingPointType(type) && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1318 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1319 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1320 | } else { |
| 1321 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1322 | next_location = DataType::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1323 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1324 | } |
| 1325 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1326 | // Space on the stack is reserved for all arguments. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1327 | stack_index_ += DataType::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1328 | return next_location; |
| 1329 | } |
| 1330 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1331 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1332 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1333 | } |
| 1334 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1335 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1336 | const CompilerOptions& compiler_options, |
| 1337 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1338 | : CodeGenerator(graph, |
| 1339 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1340 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1341 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1342 | callee_saved_core_registers.GetList(), |
| 1343 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1344 | compiler_options, |
| 1345 | stats), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1346 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1347 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1348 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1349 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1350 | move_resolver_(graph->GetAllocator(), this), |
| 1351 | assembler_(graph->GetAllocator()), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1352 | uint32_literals_(std::less<uint32_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1353 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1354 | uint64_literals_(std::less<uint64_t>(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1355 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1356 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1357 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1358 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1359 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1360 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1361 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1362 | boot_image_intrinsic_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1363 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1364 | jit_string_patches_(StringReferenceValueComparator(), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1365 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1366 | jit_class_patches_(TypeReferenceValueComparator(), |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1367 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1368 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 1369 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1370 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1371 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1372 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1373 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1374 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1375 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1376 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1377 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1378 | jump_table->EmitTable(this); |
| 1379 | } |
| 1380 | } |
| 1381 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1382 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1383 | EmitJumpTables(); |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1384 | |
| 1385 | // Emit JIT baker read barrier slow paths. |
| 1386 | DCHECK(Runtime::Current()->UseJitCompilation() || jit_baker_read_barrier_slow_paths_.empty()); |
| 1387 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 1388 | uint32_t encoded_data = entry.first; |
| 1389 | vixl::aarch64::Label* slow_path_entry = &entry.second.label; |
| 1390 | __ Bind(slow_path_entry); |
| 1391 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name */ nullptr); |
| 1392 | } |
| 1393 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1394 | // Ensure we emit the literal pool. |
| 1395 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1396 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1397 | CodeGenerator::Finalize(allocator); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1398 | |
| 1399 | // Verify Baker read barrier linker patches. |
| 1400 | if (kIsDebugBuild) { |
| 1401 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 1402 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 1403 | DCHECK(info.label.IsBound()); |
| 1404 | uint32_t literal_offset = info.label.GetLocation(); |
| 1405 | DCHECK_ALIGNED(literal_offset, 4u); |
| 1406 | |
| 1407 | auto GetInsn = [&code](uint32_t offset) { |
| 1408 | DCHECK_ALIGNED(offset, 4u); |
| 1409 | return |
| 1410 | (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 1411 | (static_cast<uint32_t>(code[offset + 1]) << 8) + |
| 1412 | (static_cast<uint32_t>(code[offset + 2]) << 16)+ |
| 1413 | (static_cast<uint32_t>(code[offset + 3]) << 24); |
| 1414 | }; |
| 1415 | |
| 1416 | const uint32_t encoded_data = info.custom_data; |
| 1417 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 1418 | // Check that the next instruction matches the expected LDR. |
| 1419 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame^] | 1420 | case BakerReadBarrierKind::kField: |
| 1421 | case BakerReadBarrierKind::kAcquire: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1422 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1423 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1424 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1425 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame^] | 1426 | if (kind == BakerReadBarrierKind::kField) { |
| 1427 | // LDR (immediate) with correct base_reg. |
| 1428 | CHECK_EQ(next_insn & 0xffc003e0u, 0xb9400000u | (base_reg << 5)); |
| 1429 | } else { |
| 1430 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 1431 | // LDAR with correct base_reg. |
| 1432 | CHECK_EQ(next_insn & 0xffffffe0u, 0x88dffc00u | (base_reg << 5)); |
| 1433 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1434 | break; |
| 1435 | } |
| 1436 | case BakerReadBarrierKind::kArray: { |
| 1437 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1438 | uint32_t next_insn = GetInsn(literal_offset + 4u); |
| 1439 | // LDR (register) with the correct base_reg, size=10 (32-bit), option=011 (extend = LSL), |
| 1440 | // and S=1 (shift amount = 2 for 32-bit version), i.e. LDR Wt, [Xn, Xm, LSL #2]. |
| 1441 | CheckValidReg(next_insn & 0x1fu); // Check destination register. |
| 1442 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1443 | CHECK_EQ(next_insn & 0xffe0ffe0u, 0xb8607800u | (base_reg << 5)); |
| 1444 | CheckValidReg((next_insn >> 16) & 0x1f); // Check index register |
| 1445 | break; |
| 1446 | } |
| 1447 | case BakerReadBarrierKind::kGcRoot: { |
| 1448 | DCHECK_GE(literal_offset, 4u); |
| 1449 | uint32_t prev_insn = GetInsn(literal_offset - 4u); |
| 1450 | // LDR (immediate) with correct root_reg. |
| 1451 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1452 | CHECK_EQ(prev_insn & 0xffc0001fu, 0xb9400000u | root_reg); |
| 1453 | break; |
| 1454 | } |
| 1455 | default: |
| 1456 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 1457 | UNREACHABLE(); |
| 1458 | } |
| 1459 | } |
| 1460 | } |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1463 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1464 | // Note: There are 6 kinds of moves: |
| 1465 | // 1. constant -> GPR/FPR (non-cycle) |
| 1466 | // 2. constant -> stack (non-cycle) |
| 1467 | // 3. GPR/FPR -> GPR/FPR |
| 1468 | // 4. GPR/FPR -> stack |
| 1469 | // 5. stack -> GPR/FPR |
| 1470 | // 6. stack -> stack (non-cycle) |
| 1471 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1472 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1473 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1474 | // dependency. |
| 1475 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1476 | } |
| 1477 | |
| 1478 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1479 | vixl_temps_.Close(); |
| 1480 | } |
| 1481 | |
| 1482 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1483 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1484 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1485 | || kind == Location::kSIMDStackSlot); |
| 1486 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1487 | ? Location::kFpuRegister |
| 1488 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1489 | Location scratch = GetScratchLocation(kind); |
| 1490 | if (!scratch.Equals(Location::NoLocation())) { |
| 1491 | return scratch; |
| 1492 | } |
| 1493 | // Allocate from VIXL temp registers. |
| 1494 | if (kind == Location::kRegister) { |
| 1495 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1496 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1497 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1498 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1499 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1500 | : vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1501 | } |
| 1502 | AddScratchLocation(scratch); |
| 1503 | return scratch; |
| 1504 | } |
| 1505 | |
| 1506 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1507 | if (loc.IsRegister()) { |
| 1508 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1509 | } else { |
| 1510 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1511 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1512 | } |
| 1513 | RemoveScratchLocation(loc); |
| 1514 | } |
| 1515 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1516 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1517 | MoveOperands* move = moves_[index]; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1518 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1521 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1522 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1523 | __ Bind(&frame_entry_label_); |
| 1524 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1525 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1526 | UseScratchRegisterScope temps(masm); |
| 1527 | Register temp = temps.AcquireX(); |
| 1528 | __ Ldrh(temp, MemOperand(kArtMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1529 | __ Add(temp, temp, 1); |
| 1530 | __ Strh(temp, MemOperand(kArtMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 1531 | } |
| 1532 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1533 | bool do_overflow_check = |
| 1534 | FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm64) || !IsLeafMethod(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1535 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1536 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1537 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1538 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1539 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(InstructionSet::kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1540 | { |
| 1541 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1542 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1543 | kInstructionSize, |
| 1544 | CodeBufferCheckScope::kExactSize); |
| 1545 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1546 | RecordPcInfo(nullptr, 0); |
| 1547 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1548 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1549 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1550 | if (!HasEmptyFrame()) { |
| 1551 | int frame_size = GetFrameSize(); |
| 1552 | // Stack layout: |
| 1553 | // sp[frame_size - 8] : lr. |
| 1554 | // ... : other preserved core registers. |
| 1555 | // ... : other preserved fp registers. |
| 1556 | // ... : reserved frame space. |
| 1557 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1558 | |
| 1559 | // Save the current method if we need it. Note that we do not |
| 1560 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1561 | // in the SSA graph. |
| 1562 | if (RequiresCurrentMethod()) { |
| 1563 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1564 | } else { |
| 1565 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1566 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1567 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1568 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1569 | frame_size - GetCoreSpillSize()); |
| 1570 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1571 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1572 | |
| 1573 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1574 | // Initialize should_deoptimize flag to 0. |
| 1575 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1576 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1577 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1578 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 1579 | |
| 1580 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1584 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1585 | if (!HasEmptyFrame()) { |
| 1586 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1587 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1588 | frame_size - FrameEntrySpillSize()); |
| 1589 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1590 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1591 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1592 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1593 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1594 | __ Ret(); |
| 1595 | GetAssembler()->cfi().RestoreState(); |
| 1596 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1597 | } |
| 1598 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1599 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1600 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1601 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1602 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1603 | } |
| 1604 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1605 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1606 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1607 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1608 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1609 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1610 | } |
| 1611 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1612 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1613 | __ Bind(GetLabelOf(block)); |
| 1614 | } |
| 1615 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1616 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1617 | DCHECK(location.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1618 | __ Mov(RegisterFrom(location, DataType::Type::kInt32), value); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1619 | } |
| 1620 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1621 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1622 | if (location.IsRegister()) { |
| 1623 | locations->AddTemp(location); |
| 1624 | } else { |
| 1625 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1626 | } |
| 1627 | } |
| 1628 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1629 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1630 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1631 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1632 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1633 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1634 | if (value_can_be_null) { |
| 1635 | __ Cbz(value, &done); |
| 1636 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1637 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1638 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1639 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1640 | if (value_can_be_null) { |
| 1641 | __ Bind(&done); |
| 1642 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1643 | } |
| 1644 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1645 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1646 | // Blocked core registers: |
| 1647 | // lr : Runtime reserved. |
| 1648 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1649 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1650 | // ip1 : VIXL core temp. |
| 1651 | // ip0 : VIXL core temp. |
| 1652 | // |
| 1653 | // Blocked fp registers: |
| 1654 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1655 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1656 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1657 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1658 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1659 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1660 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1661 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1662 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1663 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1664 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1665 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1666 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1667 | // Stubs do not save callee-save floating point registers. If the graph |
| 1668 | // is debuggable, we need to deal with these registers differently. For |
| 1669 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1670 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1671 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1672 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1673 | } |
| 1674 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1675 | } |
| 1676 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1677 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1678 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1679 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1680 | return kArm64WordSize; |
| 1681 | } |
| 1682 | |
| 1683 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1684 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1685 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1686 | return kArm64WordSize; |
| 1687 | } |
| 1688 | |
| 1689 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1690 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1691 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1692 | return kArm64WordSize; |
| 1693 | } |
| 1694 | |
| 1695 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1696 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1697 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1698 | return kArm64WordSize; |
| 1699 | } |
| 1700 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1701 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1702 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1706 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1707 | } |
| 1708 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1709 | const Arm64InstructionSetFeatures& CodeGeneratorARM64::GetInstructionSetFeatures() const { |
| 1710 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArm64InstructionSetFeatures(); |
| 1711 | } |
| 1712 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1713 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1714 | if (constant->IsIntConstant()) { |
| 1715 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1716 | } else if (constant->IsLongConstant()) { |
| 1717 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1718 | } else if (constant->IsNullConstant()) { |
| 1719 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1720 | } else if (constant->IsFloatConstant()) { |
| 1721 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1722 | } else { |
| 1723 | DCHECK(constant->IsDoubleConstant()); |
| 1724 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1725 | } |
| 1726 | } |
| 1727 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1728 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1729 | static bool CoherentConstantAndType(Location constant, DataType::Type type) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1730 | DCHECK(constant.IsConstant()); |
| 1731 | HConstant* cst = constant.GetConstant(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1732 | return (cst->IsIntConstant() && type == DataType::Type::kInt32) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1733 | // 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] | 1734 | (cst->IsNullConstant() && type == DataType::Type::kInt32) || |
| 1735 | (cst->IsLongConstant() && type == DataType::Type::kInt64) || |
| 1736 | (cst->IsFloatConstant() && type == DataType::Type::kFloat32) || |
| 1737 | (cst->IsDoubleConstant() && type == DataType::Type::kFloat64); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1738 | } |
| 1739 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1740 | // Allocate a scratch register from the VIXL pool, querying first |
| 1741 | // the floating-point register pool, and then the core register |
| 1742 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1743 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1744 | // using a different allocation strategy. |
| 1745 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1746 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1747 | int size_in_bits) { |
| 1748 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1749 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1750 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1751 | } |
| 1752 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1753 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1754 | Location source, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1755 | DataType::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1756 | if (source.Equals(destination)) { |
| 1757 | return; |
| 1758 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1759 | |
| 1760 | // A valid move can always be inferred from the destination and source |
| 1761 | // locations. When moving from and to a register, the argument type can be |
| 1762 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1763 | // checks the coherency of the locations and the type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1764 | bool unspecified_type = (dst_type == DataType::Type::kVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1765 | |
| 1766 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1767 | if (unspecified_type) { |
| 1768 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1769 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1770 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1771 | || src_cst->IsFloatConstant() |
| 1772 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1773 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1774 | dst_type = destination.IsRegister() ? DataType::Type::kInt32 : DataType::Type::kFloat32; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1775 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1776 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1777 | // type is appropriate. Else the source is a register, and since the |
| 1778 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1779 | // move. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1780 | dst_type = destination.IsRegister() ? DataType::Type::kInt64 : DataType::Type::kFloat64; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1781 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1782 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1783 | DCHECK((destination.IsFpuRegister() && DataType::IsFloatingPointType(dst_type)) || |
| 1784 | (destination.IsRegister() && !DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1785 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1786 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1787 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1788 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1789 | } else if (source.IsSIMDStackSlot()) { |
| 1790 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1791 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1792 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1793 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1794 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1795 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1796 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1797 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1798 | DCHECK(destination.IsFpuRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1799 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1800 | ? DataType::Type::kInt64 |
| 1801 | : DataType::Type::kInt32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1802 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1803 | } |
| 1804 | } else { |
| 1805 | DCHECK(source.IsFpuRegister()); |
| 1806 | if (destination.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1807 | DataType::Type source_type = DataType::Is64BitType(dst_type) |
| 1808 | ? DataType::Type::kFloat64 |
| 1809 | : DataType::Type::kFloat32; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1810 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1811 | } else { |
| 1812 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1813 | if (GetGraph()->HasSIMD()) { |
| 1814 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1815 | } else { |
| 1816 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1817 | } |
| 1818 | } |
| 1819 | } |
| 1820 | } else if (destination.IsSIMDStackSlot()) { |
| 1821 | if (source.IsFpuRegister()) { |
| 1822 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1823 | } else { |
| 1824 | DCHECK(source.IsSIMDStackSlot()); |
| 1825 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1826 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1827 | Register temp = temps.AcquireX(); |
| 1828 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1829 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1830 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1831 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1832 | } else { |
| 1833 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1834 | __ Ldr(temp, StackOperandFrom(source)); |
| 1835 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1836 | } |
| 1837 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1838 | } else { // The destination is not a register. It must be a stack slot. |
| 1839 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1840 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1841 | if (unspecified_type) { |
| 1842 | if (source.IsRegister()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1843 | dst_type = destination.IsStackSlot() ? DataType::Type::kInt32 : DataType::Type::kInt64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1844 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1845 | dst_type = |
| 1846 | destination.IsStackSlot() ? DataType::Type::kFloat32 : DataType::Type::kFloat64; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1847 | } |
| 1848 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1849 | DCHECK((destination.IsDoubleStackSlot() == DataType::Is64BitType(dst_type)) && |
| 1850 | (source.IsFpuRegister() == DataType::IsFloatingPointType(dst_type))); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1851 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1852 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1853 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1854 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1855 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1856 | HConstant* src_cst = source.GetConstant(); |
| 1857 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1858 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1859 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1860 | ? Register(xzr) |
| 1861 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1862 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1863 | if (src_cst->IsIntConstant()) { |
| 1864 | temp = temps.AcquireW(); |
| 1865 | } else if (src_cst->IsLongConstant()) { |
| 1866 | temp = temps.AcquireX(); |
| 1867 | } else if (src_cst->IsFloatConstant()) { |
| 1868 | temp = temps.AcquireS(); |
| 1869 | } else { |
| 1870 | DCHECK(src_cst->IsDoubleConstant()); |
| 1871 | temp = temps.AcquireD(); |
| 1872 | } |
| 1873 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1874 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1875 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1876 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1877 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1878 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1879 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1880 | // Use any scratch register (a core or a floating-point one) |
| 1881 | // from VIXL scratch register pools as a temporary. |
| 1882 | // |
| 1883 | // We used to only use the FP scratch register pool, but in some |
| 1884 | // rare cases the only register from this pool (D31) would |
| 1885 | // already be used (e.g. within a ParallelMove instruction, when |
| 1886 | // a move is blocked by a another move requiring a scratch FP |
| 1887 | // register, which would reserve D31). To prevent this issue, we |
| 1888 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1889 | // |
| 1890 | // 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] | 1891 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1892 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1893 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1894 | // allocates core scratch registers first. |
| 1895 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1896 | GetVIXLAssembler(), |
| 1897 | &temps, |
| 1898 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1899 | __ Ldr(temp, StackOperandFrom(source)); |
| 1900 | __ Str(temp, StackOperandFrom(destination)); |
| 1901 | } |
| 1902 | } |
| 1903 | } |
| 1904 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1905 | void CodeGeneratorARM64::Load(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1906 | CPURegister dst, |
| 1907 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1908 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1909 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1910 | case DataType::Type::kUint8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1911 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1912 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1913 | case DataType::Type::kInt8: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1914 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1915 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1916 | case DataType::Type::kUint16: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1917 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1918 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1919 | case DataType::Type::kInt16: |
| 1920 | __ Ldrsh(Register(dst), src); |
| 1921 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1922 | case DataType::Type::kInt32: |
| 1923 | case DataType::Type::kReference: |
| 1924 | case DataType::Type::kInt64: |
| 1925 | case DataType::Type::kFloat32: |
| 1926 | case DataType::Type::kFloat64: |
| 1927 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1928 | __ Ldr(dst, src); |
| 1929 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1930 | case DataType::Type::kUint32: |
| 1931 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1932 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1933 | LOG(FATAL) << "Unreachable type " << type; |
| 1934 | } |
| 1935 | } |
| 1936 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1937 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1938 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1939 | const MemOperand& src, |
| 1940 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1941 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1942 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1943 | Register temp_base = temps.AcquireX(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1944 | DataType::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1945 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1946 | DCHECK(!src.IsPreIndex()); |
| 1947 | DCHECK(!src.IsPostIndex()); |
| 1948 | |
| 1949 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1950 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1951 | { |
| 1952 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1953 | MemOperand base = MemOperand(temp_base); |
| 1954 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1955 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1956 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1957 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1958 | { |
| 1959 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1960 | __ ldarb(Register(dst), base); |
| 1961 | if (needs_null_check) { |
| 1962 | MaybeRecordImplicitNullCheck(instruction); |
| 1963 | } |
| 1964 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1965 | if (type == DataType::Type::kInt8) { |
| 1966 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1967 | } |
| 1968 | break; |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1969 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1970 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1971 | { |
| 1972 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1973 | __ ldarh(Register(dst), base); |
| 1974 | if (needs_null_check) { |
| 1975 | MaybeRecordImplicitNullCheck(instruction); |
| 1976 | } |
| 1977 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1978 | if (type == DataType::Type::kInt16) { |
| 1979 | __ Sbfx(Register(dst), Register(dst), 0, DataType::Size(type) * kBitsPerByte); |
| 1980 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1981 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1982 | case DataType::Type::kInt32: |
| 1983 | case DataType::Type::kReference: |
| 1984 | case DataType::Type::kInt64: |
| 1985 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1986 | { |
| 1987 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1988 | __ ldar(Register(dst), base); |
| 1989 | if (needs_null_check) { |
| 1990 | MaybeRecordImplicitNullCheck(instruction); |
| 1991 | } |
| 1992 | } |
| 1993 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1994 | case DataType::Type::kFloat32: |
| 1995 | case DataType::Type::kFloat64: { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1996 | DCHECK(dst.IsFPRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1997 | DCHECK_EQ(dst.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1998 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1999 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2000 | { |
| 2001 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2002 | __ ldar(temp, base); |
| 2003 | if (needs_null_check) { |
| 2004 | MaybeRecordImplicitNullCheck(instruction); |
| 2005 | } |
| 2006 | } |
| 2007 | __ Fmov(FPRegister(dst), temp); |
| 2008 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2009 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2010 | case DataType::Type::kUint32: |
| 2011 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2012 | case DataType::Type::kVoid: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2013 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2014 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2015 | } |
| 2016 | } |
| 2017 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2018 | void CodeGeneratorARM64::Store(DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2019 | CPURegister src, |
| 2020 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2021 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2022 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2023 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2024 | case DataType::Type::kInt8: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2025 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2026 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2027 | case DataType::Type::kUint16: |
| 2028 | case DataType::Type::kInt16: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2029 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2030 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2031 | case DataType::Type::kInt32: |
| 2032 | case DataType::Type::kReference: |
| 2033 | case DataType::Type::kInt64: |
| 2034 | case DataType::Type::kFloat32: |
| 2035 | case DataType::Type::kFloat64: |
| 2036 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2037 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2038 | break; |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2039 | case DataType::Type::kUint32: |
| 2040 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2041 | case DataType::Type::kVoid: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2042 | LOG(FATAL) << "Unreachable type " << type; |
| 2043 | } |
| 2044 | } |
| 2045 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2046 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2047 | DataType::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2048 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2049 | const MemOperand& dst, |
| 2050 | bool needs_null_check) { |
| 2051 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2052 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2053 | Register temp_base = temps.AcquireX(); |
| 2054 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2055 | DCHECK(!dst.IsPreIndex()); |
| 2056 | DCHECK(!dst.IsPostIndex()); |
| 2057 | |
| 2058 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2059 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2060 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2061 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2062 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2063 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2064 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2065 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2066 | case DataType::Type::kInt8: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2067 | { |
| 2068 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2069 | __ stlrb(Register(src), base); |
| 2070 | if (needs_null_check) { |
| 2071 | MaybeRecordImplicitNullCheck(instruction); |
| 2072 | } |
| 2073 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2074 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2075 | case DataType::Type::kUint16: |
| 2076 | case DataType::Type::kInt16: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2077 | { |
| 2078 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2079 | __ stlrh(Register(src), base); |
| 2080 | if (needs_null_check) { |
| 2081 | MaybeRecordImplicitNullCheck(instruction); |
| 2082 | } |
| 2083 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2084 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2085 | case DataType::Type::kInt32: |
| 2086 | case DataType::Type::kReference: |
| 2087 | case DataType::Type::kInt64: |
| 2088 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2089 | { |
| 2090 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2091 | __ stlr(Register(src), base); |
| 2092 | if (needs_null_check) { |
| 2093 | MaybeRecordImplicitNullCheck(instruction); |
| 2094 | } |
| 2095 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2096 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2097 | case DataType::Type::kFloat32: |
| 2098 | case DataType::Type::kFloat64: { |
| 2099 | DCHECK_EQ(src.Is64Bits(), DataType::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2100 | Register temp_src; |
| 2101 | if (src.IsZero()) { |
| 2102 | // The zero register is used to avoid synthesizing zero constants. |
| 2103 | temp_src = Register(src); |
| 2104 | } else { |
| 2105 | DCHECK(src.IsFPRegister()); |
| 2106 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2107 | __ Fmov(temp_src, FPRegister(src)); |
| 2108 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2109 | { |
| 2110 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2111 | __ stlr(temp_src, base); |
| 2112 | if (needs_null_check) { |
| 2113 | MaybeRecordImplicitNullCheck(instruction); |
| 2114 | } |
| 2115 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2116 | break; |
| 2117 | } |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2118 | case DataType::Type::kUint32: |
| 2119 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2120 | case DataType::Type::kVoid: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2121 | LOG(FATAL) << "Unreachable type " << type; |
| 2122 | } |
| 2123 | } |
| 2124 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2125 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2126 | HInstruction* instruction, |
| 2127 | uint32_t dex_pc, |
| 2128 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2129 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2130 | |
| 2131 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 2132 | { |
| 2133 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 2134 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2135 | __ blr(lr); |
| 2136 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2137 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2138 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2139 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2142 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2143 | HInstruction* instruction, |
| 2144 | SlowPathCode* slow_path) { |
| 2145 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2146 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2147 | __ Blr(lr); |
| 2148 | } |
| 2149 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2150 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2151 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2152 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2153 | Register temp = temps.AcquireW(); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2154 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 2155 | const size_t status_byte_offset = |
| 2156 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 2157 | constexpr uint32_t shifted_initialized_value = |
| 2158 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2159 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2160 | // 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] | 2161 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2162 | __ Add(temp, class_reg, status_byte_offset); |
Igor Murashkin | 86083f7 | 2017-10-27 10:59:04 -0700 | [diff] [blame] | 2163 | __ Ldarb(temp, HeapOperand(temp)); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 2164 | __ Cmp(temp, shifted_initialized_value); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 2165 | __ B(lo, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2166 | __ Bind(slow_path->GetExitLabel()); |
| 2167 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2168 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 2169 | void InstructionCodeGeneratorARM64::GenerateBitstringTypeCheckCompare( |
| 2170 | HTypeCheckInstruction* check, vixl::aarch64::Register temp) { |
| 2171 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 2172 | uint32_t mask = check->GetBitstringMask(); |
| 2173 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 2174 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 2175 | |
| 2176 | if (mask_bits == 16u) { |
| 2177 | // Load only the bitstring part of the status word. |
| 2178 | __ Ldrh(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 2179 | } else { |
| 2180 | // /* uint32_t */ temp = temp->status_ |
| 2181 | __ Ldr(temp, HeapOperand(temp, mirror::Class::StatusOffset())); |
| 2182 | // Extract the bitstring bits. |
| 2183 | __ Ubfx(temp, temp, 0, mask_bits); |
| 2184 | } |
| 2185 | // Compare the bitstring bits to `path_to_root`. |
| 2186 | __ Cmp(temp, path_to_root); |
| 2187 | } |
| 2188 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2189 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2190 | BarrierType type = BarrierAll; |
| 2191 | |
| 2192 | switch (kind) { |
| 2193 | case MemBarrierKind::kAnyAny: |
| 2194 | case MemBarrierKind::kAnyStore: { |
| 2195 | type = BarrierAll; |
| 2196 | break; |
| 2197 | } |
| 2198 | case MemBarrierKind::kLoadAny: { |
| 2199 | type = BarrierReads; |
| 2200 | break; |
| 2201 | } |
| 2202 | case MemBarrierKind::kStoreStore: { |
| 2203 | type = BarrierWrites; |
| 2204 | break; |
| 2205 | } |
| 2206 | default: |
| 2207 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2208 | } |
| 2209 | __ Dmb(InnerShareable, type); |
| 2210 | } |
| 2211 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2212 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2213 | HBasicBlock* successor) { |
| 2214 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2215 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2216 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2217 | slow_path = |
| 2218 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARM64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2219 | instruction->SetSlowPath(slow_path); |
| 2220 | codegen_->AddSlowPath(slow_path); |
| 2221 | if (successor != nullptr) { |
| 2222 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2223 | } |
| 2224 | } else { |
| 2225 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2226 | } |
| 2227 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2228 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2229 | Register temp = temps.AcquireW(); |
| 2230 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2231 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2232 | if (successor == nullptr) { |
| 2233 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2234 | __ Bind(slow_path->GetReturnLabel()); |
| 2235 | } else { |
| 2236 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 2237 | __ B(slow_path->GetEntryLabel()); |
| 2238 | // slow_path will return to GetLabelOf(successor). |
| 2239 | } |
| 2240 | } |
| 2241 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2242 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2243 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2244 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2245 | assembler_(codegen->GetAssembler()), |
| 2246 | codegen_(codegen) {} |
| 2247 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2248 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2249 | DCHECK_EQ(instr->InputCount(), 2U); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2250 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2251 | DataType::Type type = instr->GetResultType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2252 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2253 | case DataType::Type::kInt32: |
| 2254 | case DataType::Type::kInt64: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2255 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2256 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2257 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2258 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2259 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2260 | case DataType::Type::kFloat32: |
| 2261 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2262 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2263 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2264 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2265 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2266 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2267 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2268 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2269 | } |
| 2270 | } |
| 2271 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2272 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2273 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2274 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2275 | |
| 2276 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2277 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2278 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2279 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2280 | object_field_get_with_read_barrier |
| 2281 | ? LocationSummary::kCallOnSlowPath |
| 2282 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2283 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2284 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame^] | 2285 | // We need a temporary register for the read barrier load in |
| 2286 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2287 | // only if the field is volatile or the offset is too big. |
| 2288 | if (field_info.IsVolatile() || |
| 2289 | field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2290 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2291 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2292 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2293 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2294 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2295 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2296 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2297 | // The output overlaps for an object field get when read barriers |
| 2298 | // are enabled: we do not want the load to overwrite the object's |
| 2299 | // location, as we need it to emit the read barrier. |
| 2300 | locations->SetOut( |
| 2301 | Location::RequiresRegister(), |
| 2302 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2303 | } |
| 2304 | } |
| 2305 | |
| 2306 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2307 | const FieldInfo& field_info) { |
| 2308 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2309 | LocationSummary* locations = instruction->GetLocations(); |
| 2310 | Location base_loc = locations->InAt(0); |
| 2311 | Location out = locations->Out(); |
| 2312 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2313 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 2314 | DataType::Type load_type = instruction->GetType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2315 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2316 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2317 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2318 | load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2319 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2320 | // /* HeapReference<Object> */ out = *(base + offset) |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2321 | Register base = RegisterFrom(base_loc, DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2322 | Location maybe_temp = |
| 2323 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2324 | // Note that potential implicit null checks are handled in this |
| 2325 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2326 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2327 | instruction, |
| 2328 | out, |
| 2329 | base, |
| 2330 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2331 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2332 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2333 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2334 | } else { |
| 2335 | // General case. |
| 2336 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2337 | // Note that a potential implicit null check is handled in this |
| 2338 | // CodeGeneratorARM64::LoadAcquire call. |
| 2339 | // NB: LoadAcquire will record the pc info if needed. |
| 2340 | codegen_->LoadAcquire( |
| 2341 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2342 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2343 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2344 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2345 | codegen_->Load(load_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2346 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2347 | } |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 2348 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2349 | // If read barriers are enabled, emit read barriers other than |
| 2350 | // Baker's using a slow path (and also unpoison the loaded |
| 2351 | // reference, if heap poisoning is enabled). |
| 2352 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2353 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2354 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2358 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2359 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2360 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2361 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2362 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2363 | } else if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2364 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2365 | } else { |
| 2366 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2371 | const FieldInfo& field_info, |
| 2372 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2373 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2374 | |
| 2375 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2376 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2377 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2378 | Offset offset = field_info.GetFieldOffset(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2379 | DataType::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2380 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2381 | { |
| 2382 | // We use a block to end the scratch scope before the write barrier, thus |
| 2383 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2384 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2385 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2386 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2387 | DCHECK(value.IsW()); |
| 2388 | Register temp = temps.AcquireW(); |
| 2389 | __ Mov(temp, value.W()); |
| 2390 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2391 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2392 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2393 | |
| 2394 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2395 | codegen_->StoreRelease( |
| 2396 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2397 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2398 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2399 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2400 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2401 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2402 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2406 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2407 | } |
| 2408 | } |
| 2409 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2410 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2411 | DataType::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2412 | |
| 2413 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2414 | case DataType::Type::kInt32: |
| 2415 | case DataType::Type::kInt64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2416 | Register dst = OutputRegister(instr); |
| 2417 | Register lhs = InputRegisterAt(instr, 0); |
| 2418 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2419 | if (instr->IsAdd()) { |
| 2420 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2421 | } else if (instr->IsAnd()) { |
| 2422 | __ And(dst, lhs, rhs); |
| 2423 | } else if (instr->IsOr()) { |
| 2424 | __ Orr(dst, lhs, rhs); |
| 2425 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2426 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2427 | } else if (instr->IsRor()) { |
| 2428 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2429 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2430 | __ Ror(dst, lhs, shift); |
| 2431 | } else { |
| 2432 | // Ensure shift distance is in the same size register as the result. If |
| 2433 | // we are rotating a long and the shift comes in a w register originally, |
| 2434 | // we don't need to sxtw for use as an x since the shift distances are |
| 2435 | // all & reg_bits - 1. |
| 2436 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2437 | } |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2438 | } else if (instr->IsMin() || instr->IsMax()) { |
| 2439 | __ Cmp(lhs, rhs); |
| 2440 | __ Csel(dst, lhs, rhs, instr->IsMin() ? lt : gt); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2441 | } else { |
| 2442 | DCHECK(instr->IsXor()); |
| 2443 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2444 | } |
| 2445 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2446 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2447 | case DataType::Type::kFloat32: |
| 2448 | case DataType::Type::kFloat64: { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2449 | FPRegister dst = OutputFPRegister(instr); |
| 2450 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2451 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2452 | if (instr->IsAdd()) { |
| 2453 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2454 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2455 | __ Fsub(dst, lhs, rhs); |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 2456 | } else if (instr->IsMin()) { |
| 2457 | __ Fmin(dst, lhs, rhs); |
| 2458 | } else if (instr->IsMax()) { |
| 2459 | __ Fmax(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2460 | } else { |
| 2461 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2462 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2463 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2464 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2465 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2466 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2467 | } |
| 2468 | } |
| 2469 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2470 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2471 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2472 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2473 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2474 | DataType::Type type = instr->GetResultType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2475 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2476 | case DataType::Type::kInt32: |
| 2477 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2478 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2479 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2480 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2481 | break; |
| 2482 | } |
| 2483 | default: |
| 2484 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2485 | } |
| 2486 | } |
| 2487 | |
| 2488 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2489 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2490 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2491 | DataType::Type type = instr->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2492 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2493 | case DataType::Type::kInt32: |
| 2494 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2495 | Register dst = OutputRegister(instr); |
| 2496 | Register lhs = InputRegisterAt(instr, 0); |
| 2497 | Operand rhs = InputOperandAt(instr, 1); |
| 2498 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2499 | uint32_t shift_value = rhs.GetImmediate() & |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2500 | (type == DataType::Type::kInt32 ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2501 | if (instr->IsShl()) { |
| 2502 | __ Lsl(dst, lhs, shift_value); |
| 2503 | } else if (instr->IsShr()) { |
| 2504 | __ Asr(dst, lhs, shift_value); |
| 2505 | } else { |
| 2506 | __ Lsr(dst, lhs, shift_value); |
| 2507 | } |
| 2508 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2509 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2510 | |
| 2511 | if (instr->IsShl()) { |
| 2512 | __ Lsl(dst, lhs, rhs_reg); |
| 2513 | } else if (instr->IsShr()) { |
| 2514 | __ Asr(dst, lhs, rhs_reg); |
| 2515 | } else { |
| 2516 | __ Lsr(dst, lhs, rhs_reg); |
| 2517 | } |
| 2518 | } |
| 2519 | break; |
| 2520 | } |
| 2521 | default: |
| 2522 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2523 | } |
| 2524 | } |
| 2525 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2526 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2527 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2531 | HandleBinaryOp(instruction); |
| 2532 | } |
| 2533 | |
| 2534 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2535 | HandleBinaryOp(instruction); |
| 2536 | } |
| 2537 | |
| 2538 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2539 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2540 | } |
| 2541 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2542 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2543 | DCHECK(DataType::IsIntegralType(instr->GetType())) << instr->GetType(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2544 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instr); |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2545 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2546 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2547 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2548 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2549 | } |
| 2550 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2551 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2552 | Register dst = OutputRegister(instr); |
| 2553 | Register lhs = InputRegisterAt(instr, 0); |
| 2554 | Register rhs = InputRegisterAt(instr, 1); |
| 2555 | |
| 2556 | switch (instr->GetOpKind()) { |
| 2557 | case HInstruction::kAnd: |
| 2558 | __ Bic(dst, lhs, rhs); |
| 2559 | break; |
| 2560 | case HInstruction::kOr: |
| 2561 | __ Orn(dst, lhs, rhs); |
| 2562 | break; |
| 2563 | case HInstruction::kXor: |
| 2564 | __ Eon(dst, lhs, rhs); |
| 2565 | break; |
| 2566 | default: |
| 2567 | LOG(FATAL) << "Unreachable"; |
| 2568 | } |
| 2569 | } |
| 2570 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2571 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2572 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2573 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 2574 | instruction->GetType() == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2575 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2576 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2577 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2578 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2579 | } else { |
| 2580 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2581 | } |
| 2582 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2583 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2584 | } |
| 2585 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2586 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2587 | HDataProcWithShifterOp* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2588 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2589 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2590 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2591 | Register out = OutputRegister(instruction); |
| 2592 | Register left; |
| 2593 | if (kind != HInstruction::kNeg) { |
| 2594 | left = InputRegisterAt(instruction, 0); |
| 2595 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2596 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2597 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2598 | // conversion) can have a different type from the current instruction's type, |
| 2599 | // so we manually indicate the type. |
| 2600 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2601 | Operand right_operand(0); |
| 2602 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2603 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2604 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2605 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2606 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2607 | right_operand = Operand(right_reg, |
| 2608 | helpers::ShiftFromOpKind(op_kind), |
| 2609 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | // Logical binary operations do not support extension operations in the |
| 2613 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2614 | // the extension as a separate instruction. |
| 2615 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2616 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2617 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2618 | kind != HInstruction::kNeg)); |
| 2619 | switch (kind) { |
| 2620 | case HInstruction::kAdd: |
| 2621 | __ Add(out, left, right_operand); |
| 2622 | break; |
| 2623 | case HInstruction::kAnd: |
| 2624 | __ And(out, left, right_operand); |
| 2625 | break; |
| 2626 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2627 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2628 | __ Neg(out, right_operand); |
| 2629 | break; |
| 2630 | case HInstruction::kOr: |
| 2631 | __ Orr(out, left, right_operand); |
| 2632 | break; |
| 2633 | case HInstruction::kSub: |
| 2634 | __ Sub(out, left, right_operand); |
| 2635 | break; |
| 2636 | case HInstruction::kXor: |
| 2637 | __ Eor(out, left, right_operand); |
| 2638 | break; |
| 2639 | default: |
| 2640 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2641 | UNREACHABLE(); |
| 2642 | } |
| 2643 | } |
| 2644 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2645 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2646 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2647 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2648 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2649 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2650 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2651 | } |
| 2652 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2653 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2654 | __ Add(OutputRegister(instruction), |
| 2655 | InputRegisterAt(instruction, 0), |
| 2656 | Operand(InputOperandAt(instruction, 1))); |
| 2657 | } |
| 2658 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2659 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2660 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2661 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2662 | |
| 2663 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2664 | |
| 2665 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2666 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2667 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2668 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2669 | // loop. |
| 2670 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2671 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2672 | : Location::RequiresRegister()); |
| 2673 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2674 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2675 | } |
| 2676 | |
| 2677 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2678 | HIntermediateAddressIndex* instruction) { |
| 2679 | Register index_reg = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2680 | uint32_t shift = Int64FromLocation(instruction->GetLocations()->InAt(2)); |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2681 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2682 | |
| 2683 | if (shift == 0) { |
| 2684 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2685 | } else { |
| 2686 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2687 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2688 | } |
| 2689 | } |
| 2690 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2691 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2692 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2693 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2694 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2695 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2696 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2697 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2698 | // Don't allocate register for Mneg instruction. |
| 2699 | } else { |
| 2700 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2701 | Location::RequiresRegister()); |
| 2702 | } |
| 2703 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2704 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2705 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2706 | } |
| 2707 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2708 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2709 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2710 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2711 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2712 | |
| 2713 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2714 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2715 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2716 | if (instr->GetType() == DataType::Type::kInt64 && |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2717 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2718 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2719 | vixl::aarch64::Instruction* prev = |
| 2720 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2721 | if (prev->IsLoadOrStore()) { |
| 2722 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2723 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2724 | __ nop(); |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2729 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2730 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2731 | } else { |
| 2732 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2733 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2734 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2735 | __ Mneg(res, mul_left, mul_right); |
| 2736 | } else { |
| 2737 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2738 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2739 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2740 | } |
| 2741 | } |
| 2742 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2743 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2744 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2745 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2746 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2747 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 2748 | object_array_get_with_read_barrier |
| 2749 | ? LocationSummary::kCallOnSlowPath |
| 2750 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2751 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2752 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2753 | if (instruction->GetIndex()->IsConstant()) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2754 | // Array loads with constant index are treated as field loads. |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2755 | // We need a temporary register for the read barrier load in |
| 2756 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier() |
| 2757 | // only if the offset is too big. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2758 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2759 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2760 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2761 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2762 | locations->AddTemp(FixedTempLocation()); |
| 2763 | } |
| 2764 | } else { |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2765 | // We need a non-scratch temporary for the array data pointer in |
| 2766 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(). |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2767 | locations->AddTemp(Location::RequiresRegister()); |
| 2768 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2769 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2770 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2771 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2772 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2773 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2774 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2775 | // The output overlaps in the case of an object array get with |
| 2776 | // read barriers enabled: we do not want the move to overwrite the |
| 2777 | // array's location, as we need it to emit the read barrier. |
| 2778 | locations->SetOut( |
| 2779 | Location::RequiresRegister(), |
| 2780 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2781 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2782 | } |
| 2783 | |
| 2784 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2785 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2786 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2787 | LocationSummary* locations = instruction->GetLocations(); |
| 2788 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2789 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2790 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2791 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2792 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2793 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2794 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2795 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2796 | // The read barrier instrumentation of object ArrayGet instructions |
| 2797 | // does not support the HIntermediateAddress instruction. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2798 | DCHECK(!((type == DataType::Type::kReference) && |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2799 | instruction->GetArray()->IsIntermediateAddress() && |
| 2800 | kEmitCompilerReadBarrier)); |
| 2801 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2802 | if (type == DataType::Type::kReference && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2803 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2804 | // Note that a potential implicit null check is handled in the |
| 2805 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2806 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2807 | if (index.IsConstant()) { |
| 2808 | // 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] | 2809 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2810 | Location maybe_temp = |
| 2811 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2812 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2813 | out, |
| 2814 | obj.W(), |
| 2815 | offset, |
| 2816 | maybe_temp, |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2817 | /* needs_null_check */ false, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2818 | /* use_load_acquire */ false); |
| 2819 | } else { |
| 2820 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
| 2821 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 2822 | out, obj.W(), offset, index, temp, /* needs_null_check */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2823 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2824 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2825 | // General case. |
| 2826 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2827 | Register length; |
| 2828 | if (maybe_compressed_char_at) { |
| 2829 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2830 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2831 | { |
| 2832 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2833 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2834 | |
| 2835 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2836 | DCHECK_LT(count_offset, offset); |
| 2837 | int64_t adjusted_offset = |
| 2838 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2839 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2840 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2841 | } else { |
| 2842 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2843 | } |
| 2844 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2845 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2846 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2847 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2848 | if (maybe_compressed_char_at) { |
| 2849 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2850 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2851 | "Expecting 0=compressed, 1=uncompressed"); |
| 2852 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2853 | __ Ldrb(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2854 | HeapOperand(obj, offset + Int64FromLocation(index))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2855 | __ B(&done); |
| 2856 | __ Bind(&uncompressed_load); |
| 2857 | __ Ldrh(Register(OutputCPURegister(instruction)), |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2858 | HeapOperand(obj, offset + (Int64FromLocation(index) << 1))); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2859 | __ Bind(&done); |
| 2860 | } else { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2861 | offset += Int64FromLocation(index) << DataType::SizeShift(type); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2862 | source = HeapOperand(obj, offset); |
| 2863 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2864 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2865 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2866 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2867 | // We do not need to compute the intermediate address from the array: the |
| 2868 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2869 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2870 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2871 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2872 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2873 | } |
| 2874 | temp = obj; |
| 2875 | } else { |
| 2876 | __ Add(temp, obj, offset); |
| 2877 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2878 | if (maybe_compressed_char_at) { |
| 2879 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2880 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2881 | "Expecting 0=compressed, 1=uncompressed"); |
| 2882 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2883 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2884 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2885 | __ B(&done); |
| 2886 | __ Bind(&uncompressed_load); |
| 2887 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2888 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2889 | __ Bind(&done); |
| 2890 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2891 | source = HeapOperand(temp, XRegisterFrom(index), LSL, DataType::SizeShift(type)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2892 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2893 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2894 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2895 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2896 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2897 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2898 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2899 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2900 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2901 | if (type == DataType::Type::kReference) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2902 | static_assert( |
| 2903 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2904 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2905 | Location obj_loc = locations->InAt(0); |
| 2906 | if (index.IsConstant()) { |
| 2907 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2908 | } else { |
| 2909 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2910 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2911 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2912 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2913 | } |
| 2914 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2915 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2916 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2917 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2918 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2922 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2923 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2924 | { |
| 2925 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2926 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2927 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2928 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2929 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2930 | // Mask out compression flag from String's array length. |
| 2931 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2932 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2933 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2934 | } |
| 2935 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2936 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2937 | DataType::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2938 | |
| 2939 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2940 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2941 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2942 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2943 | LocationSummary::kCallOnSlowPath : |
| 2944 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2945 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2946 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2947 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2948 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2949 | } else if (DataType::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2950 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2951 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2952 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2957 | DataType::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2958 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2959 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2960 | bool needs_write_barrier = |
| 2961 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2962 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2963 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2964 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2965 | CPURegister source = value; |
| 2966 | Location index = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2967 | size_t offset = mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2968 | MemOperand destination = HeapOperand(array); |
| 2969 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2970 | |
| 2971 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2972 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2973 | if (index.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 2974 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2975 | destination = HeapOperand(array, offset); |
| 2976 | } else { |
| 2977 | UseScratchRegisterScope temps(masm); |
| 2978 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2979 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2980 | // We do not need to compute the intermediate address from the array: the |
| 2981 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2982 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2983 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2984 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2985 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2986 | } |
| 2987 | temp = array; |
| 2988 | } else { |
| 2989 | __ Add(temp, array, offset); |
| 2990 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2991 | destination = HeapOperand(temp, |
| 2992 | XRegisterFrom(index), |
| 2993 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2994 | DataType::SizeShift(value_type)); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2995 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2996 | { |
| 2997 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2998 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2999 | codegen_->Store(value_type, value, destination); |
| 3000 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3001 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3002 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3003 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3004 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3005 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3006 | { |
| 3007 | // We use a block to end the scratch scope before the write barrier, thus |
| 3008 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 3009 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3010 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3011 | if (index.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3012 | offset += Int64FromLocation(index) << DataType::SizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3013 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3014 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 3015 | destination = HeapOperand(temp, |
| 3016 | XRegisterFrom(index), |
| 3017 | LSL, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3018 | DataType::SizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3019 | } |
| 3020 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3021 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3022 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3023 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3024 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3025 | if (may_need_runtime_call_for_type_check) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3026 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARM64(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3027 | codegen_->AddSlowPath(slow_path); |
| 3028 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3029 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3030 | __ Cbnz(Register(value), &non_zero); |
| 3031 | if (!index.IsConstant()) { |
| 3032 | __ Add(temp, array, offset); |
| 3033 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3034 | { |
| 3035 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 3036 | // emitted. |
| 3037 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3038 | __ Str(wzr, destination); |
| 3039 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3040 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3041 | __ B(&done); |
| 3042 | __ Bind(&non_zero); |
| 3043 | } |
| 3044 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3045 | // Note that when Baker read barriers are enabled, the type |
| 3046 | // checks are performed without read barriers. This is fine, |
| 3047 | // even in the case where a class object is in the from-space |
| 3048 | // after the flip, as a comparison involving such a type would |
| 3049 | // not produce a false positive; it may of course produce a |
| 3050 | // false negative, in which case we would take the ArraySet |
| 3051 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3052 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3053 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 3054 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3055 | { |
| 3056 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3057 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3058 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 3059 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3060 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3061 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3062 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3063 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 3064 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 3065 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3066 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 3067 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 3068 | // nor `temp2`, as we are comparing two poisoned references. |
| 3069 | __ Cmp(temp, temp2); |
| 3070 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3071 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3072 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3073 | vixl::aarch64::Label do_put; |
| 3074 | __ B(eq, &do_put); |
| 3075 | // If heap poisoning is enabled, the `temp` reference has |
| 3076 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3077 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3078 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3079 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 3080 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 3081 | // If heap poisoning is enabled, no need to unpoison |
| 3082 | // `temp`, as we are comparing against null below. |
| 3083 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 3084 | __ Bind(&do_put); |
| 3085 | } else { |
| 3086 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3087 | } |
| 3088 | } |
| 3089 | |
| 3090 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3091 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3092 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3093 | __ Mov(temp2, value.W()); |
| 3094 | GetAssembler()->PoisonHeapReference(temp2); |
| 3095 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | if (!index.IsConstant()) { |
| 3099 | __ Add(temp, array, offset); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 3100 | } else { |
| 3101 | // We no longer need the `temp` here so release it as the store below may |
| 3102 | // need a scratch register (if the constant index makes the offset too large) |
| 3103 | // and the poisoned `source` could be using the other scratch register. |
| 3104 | temps.Release(temp); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3105 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3106 | { |
| 3107 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3108 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3109 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3110 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3111 | if (!may_need_runtime_call_for_type_check) { |
| 3112 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3113 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3114 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3115 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3116 | |
| 3117 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 3118 | |
| 3119 | if (done.IsLinked()) { |
| 3120 | __ Bind(&done); |
| 3121 | } |
| 3122 | |
| 3123 | if (slow_path != nullptr) { |
| 3124 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3125 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3126 | } |
| 3127 | } |
| 3128 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3129 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3130 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3131 | InvokeRuntimeCallingConvention calling_convention; |
| 3132 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3133 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 3134 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3135 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 3136 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3137 | } |
| 3138 | |
| 3139 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3140 | BoundsCheckSlowPathARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3141 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3142 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3143 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 3144 | __ B(slow_path->GetEntryLabel(), hs); |
| 3145 | } |
| 3146 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3147 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3148 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3149 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3150 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3151 | if (check->HasUses()) { |
| 3152 | locations->SetOut(Location::SameAsFirstInput()); |
| 3153 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 3154 | // Rely on the type initialization to save everything we need. |
| 3155 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3159 | // We assume the class is not null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 3160 | SlowPathCodeARM64* slow_path = |
| 3161 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(check->GetLoadClass(), check); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3162 | codegen_->AddSlowPath(slow_path); |
| 3163 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3164 | } |
| 3165 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3166 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3167 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3168 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3169 | } |
| 3170 | |
| 3171 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 3172 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 3173 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3174 | if (rhs_loc.IsConstant()) { |
| 3175 | // 0.0 is the only immediate that can be encoded directly in |
| 3176 | // an FCMP instruction. |
| 3177 | // |
| 3178 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3179 | // specify that in a floating-point comparison, positive zero |
| 3180 | // and negative zero are considered equal, so we can use the |
| 3181 | // literal 0.0 for both cases here. |
| 3182 | // |
| 3183 | // Note however that some methods (Float.equal, Float.compare, |
| 3184 | // Float.compareTo, Double.equal, Double.compare, |
| 3185 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3186 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3187 | // -0.0. So if we ever translate calls to these methods into a |
| 3188 | // HCompare instruction, we must handle the -0.0 case with |
| 3189 | // care here. |
| 3190 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3191 | __ Fcmp(lhs_reg, 0.0); |
| 3192 | } else { |
| 3193 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3194 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3195 | } |
| 3196 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3197 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3198 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3199 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3200 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3201 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3202 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3203 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3204 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3205 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3206 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3207 | case DataType::Type::kInt32: |
| 3208 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3209 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3210 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3211 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3212 | break; |
| 3213 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3214 | case DataType::Type::kFloat32: |
| 3215 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3216 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3217 | locations->SetInAt(1, |
| 3218 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3219 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3220 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3221 | locations->SetOut(Location::RequiresRegister()); |
| 3222 | break; |
| 3223 | } |
| 3224 | default: |
| 3225 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3226 | } |
| 3227 | } |
| 3228 | |
| 3229 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3230 | DataType::Type in_type = compare->InputAt(0)->GetType(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3231 | |
| 3232 | // 0 if: left == right |
| 3233 | // 1 if: left > right |
| 3234 | // -1 if: left < right |
| 3235 | switch (in_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3236 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3237 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3238 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3239 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3240 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3241 | case DataType::Type::kInt32: |
| 3242 | case DataType::Type::kInt64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3243 | Register result = OutputRegister(compare); |
| 3244 | Register left = InputRegisterAt(compare, 0); |
| 3245 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3246 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3247 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3248 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3249 | break; |
| 3250 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3251 | case DataType::Type::kFloat32: |
| 3252 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3253 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3254 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3255 | __ Cset(result, ne); |
| 3256 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3257 | break; |
| 3258 | } |
| 3259 | default: |
| 3260 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3261 | } |
| 3262 | } |
| 3263 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3264 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3265 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3266 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3267 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3268 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3269 | locations->SetInAt(1, |
| 3270 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3271 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3272 | : Location::RequiresFpuRegister()); |
| 3273 | } else { |
| 3274 | // Integer cases. |
| 3275 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3276 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3277 | } |
| 3278 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3279 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3280 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3281 | } |
| 3282 | } |
| 3283 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3284 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3285 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3286 | return; |
| 3287 | } |
| 3288 | |
| 3289 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3290 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3291 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3292 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3293 | if (DataType::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3294 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3295 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3296 | } else { |
| 3297 | // Integer cases. |
| 3298 | Register lhs = InputRegisterAt(instruction, 0); |
| 3299 | Operand rhs = InputOperandAt(instruction, 1); |
| 3300 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3301 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3302 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3303 | } |
| 3304 | |
| 3305 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3306 | M(Equal) \ |
| 3307 | M(NotEqual) \ |
| 3308 | M(LessThan) \ |
| 3309 | M(LessThanOrEqual) \ |
| 3310 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3311 | M(GreaterThanOrEqual) \ |
| 3312 | M(Below) \ |
| 3313 | M(BelowOrEqual) \ |
| 3314 | M(Above) \ |
| 3315 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3316 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3317 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3318 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3319 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3320 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3321 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3322 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3323 | void InstructionCodeGeneratorARM64::GenerateIntDivForPower2Denom(HDiv* instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3324 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3325 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3326 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 3327 | |
| 3328 | Register out = OutputRegister(instruction); |
| 3329 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 3330 | |
| 3331 | if (abs_imm == 2) { |
| 3332 | int bits = DataType::Size(instruction->GetResultType()) * kBitsPerByte; |
| 3333 | __ Add(out, dividend, Operand(dividend, LSR, bits - 1)); |
| 3334 | } else { |
| 3335 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3336 | Register temp = temps.AcquireSameSizeAs(out); |
| 3337 | __ Add(temp, dividend, abs_imm - 1); |
| 3338 | __ Cmp(dividend, 0); |
| 3339 | __ Csel(out, temp, dividend, lt); |
| 3340 | } |
| 3341 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3342 | int ctz_imm = CTZ(abs_imm); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3343 | if (imm > 0) { |
| 3344 | __ Asr(out, out, ctz_imm); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3345 | } else { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3346 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3347 | } |
| 3348 | } |
| 3349 | |
| 3350 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3351 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3352 | |
| 3353 | LocationSummary* locations = instruction->GetLocations(); |
| 3354 | Location second = locations->InAt(1); |
| 3355 | DCHECK(second.IsConstant()); |
| 3356 | |
| 3357 | Register out = OutputRegister(instruction); |
| 3358 | Register dividend = InputRegisterAt(instruction, 0); |
| 3359 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3360 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3361 | DataType::Type type = instruction->GetResultType(); |
| 3362 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3363 | |
| 3364 | int64_t magic; |
| 3365 | int shift; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3366 | CalculateMagicAndShiftForDivRem( |
| 3367 | imm, type == DataType::Type::kInt64 /* is_long */, &magic, &shift); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3368 | |
| 3369 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3370 | Register temp = temps.AcquireSameSizeAs(out); |
| 3371 | |
| 3372 | // temp = get_high(dividend * magic) |
| 3373 | __ Mov(temp, magic); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3374 | if (type == DataType::Type::kInt64) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3375 | __ Smulh(temp, dividend, temp); |
| 3376 | } else { |
| 3377 | __ Smull(temp.X(), dividend, temp); |
| 3378 | __ Lsr(temp.X(), temp.X(), 32); |
| 3379 | } |
| 3380 | |
| 3381 | if (imm > 0 && magic < 0) { |
| 3382 | __ Add(temp, temp, dividend); |
| 3383 | } else if (imm < 0 && magic > 0) { |
| 3384 | __ Sub(temp, temp, dividend); |
| 3385 | } |
| 3386 | |
| 3387 | if (shift != 0) { |
| 3388 | __ Asr(temp, temp, shift); |
| 3389 | } |
| 3390 | |
| 3391 | if (instruction->IsDiv()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3392 | __ Sub(out, temp, Operand(temp, ASR, type == DataType::Type::kInt64 ? 63 : 31)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3393 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3394 | __ Sub(temp, temp, Operand(temp, ASR, type == DataType::Type::kInt64 ? 63 : 31)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3395 | // TODO: Strength reduction for msub. |
| 3396 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3397 | __ Mov(temp_imm, imm); |
| 3398 | __ Msub(out, temp, temp_imm, dividend); |
| 3399 | } |
| 3400 | } |
| 3401 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3402 | void InstructionCodeGeneratorARM64::GenerateIntDivForConstDenom(HDiv *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3403 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3404 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3405 | if (imm == 0) { |
| 3406 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3407 | return; |
| 3408 | } |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3409 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3410 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3411 | GenerateIntDivForPower2Denom(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3412 | } else { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3413 | // Cases imm == -1 or imm == 1 are handled by InstructionSimplifier. |
| 3414 | DCHECK(imm < -2 || imm > 2) << imm; |
| 3415 | GenerateDivRemWithAnyConstant(instruction); |
| 3416 | } |
| 3417 | } |
| 3418 | |
| 3419 | void InstructionCodeGeneratorARM64::GenerateIntDiv(HDiv *instruction) { |
| 3420 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 3421 | << instruction->GetResultType(); |
| 3422 | |
| 3423 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 3424 | GenerateIntDivForConstDenom(instruction); |
| 3425 | } else { |
| 3426 | Register out = OutputRegister(instruction); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3427 | Register dividend = InputRegisterAt(instruction, 0); |
| 3428 | Register divisor = InputRegisterAt(instruction, 1); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3429 | __ Sdiv(out, dividend, divisor); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3430 | } |
| 3431 | } |
| 3432 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3433 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3434 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3435 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3436 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3437 | case DataType::Type::kInt32: |
| 3438 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3439 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3440 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3441 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3442 | break; |
| 3443 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3444 | case DataType::Type::kFloat32: |
| 3445 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3446 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3447 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3448 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3449 | break; |
| 3450 | |
| 3451 | default: |
| 3452 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3453 | } |
| 3454 | } |
| 3455 | |
| 3456 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3457 | DataType::Type type = div->GetResultType(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3458 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3459 | case DataType::Type::kInt32: |
| 3460 | case DataType::Type::kInt64: |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 3461 | GenerateIntDiv(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3462 | break; |
| 3463 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3464 | case DataType::Type::kFloat32: |
| 3465 | case DataType::Type::kFloat64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3466 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3467 | break; |
| 3468 | |
| 3469 | default: |
| 3470 | LOG(FATAL) << "Unexpected div type " << type; |
| 3471 | } |
| 3472 | } |
| 3473 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3474 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3475 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3476 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3480 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3481 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3482 | codegen_->AddSlowPath(slow_path); |
| 3483 | Location value = instruction->GetLocations()->InAt(0); |
| 3484 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3485 | DataType::Type type = instruction->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3486 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3487 | if (!DataType::IsIntegralType(type)) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3488 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3489 | return; |
| 3490 | } |
| 3491 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3492 | if (value.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 3493 | int64_t divisor = Int64FromLocation(value); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3494 | if (divisor == 0) { |
| 3495 | __ B(slow_path->GetEntryLabel()); |
| 3496 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3497 | // A division by a non-null constant is valid. We don't need to perform |
| 3498 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3499 | } |
| 3500 | } else { |
| 3501 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3502 | } |
| 3503 | } |
| 3504 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3505 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3506 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3507 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3508 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3509 | } |
| 3510 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3511 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3512 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3513 | // Will be generated at use site. |
| 3514 | } |
| 3515 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3516 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3517 | exit->SetLocations(nullptr); |
| 3518 | } |
| 3519 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3520 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3521 | } |
| 3522 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3523 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3524 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3525 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3526 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3527 | } |
| 3528 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3529 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3530 | // Will be generated at use site. |
| 3531 | } |
| 3532 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3533 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 3534 | if (successor->IsExitBlock()) { |
| 3535 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 3536 | return; // no code needed |
| 3537 | } |
| 3538 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3539 | HBasicBlock* block = got->GetBlock(); |
| 3540 | HInstruction* previous = got->GetPrevious(); |
| 3541 | HLoopInformation* info = block->GetLoopInformation(); |
| 3542 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3543 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 3544 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 3545 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3546 | Register temp1 = temps.AcquireX(); |
| 3547 | Register temp2 = temps.AcquireX(); |
| 3548 | __ Ldr(temp1, MemOperand(sp, 0)); |
| 3549 | __ Ldrh(temp2, MemOperand(temp1, ArtMethod::HotnessCountOffset().Int32Value())); |
| 3550 | __ Add(temp2, temp2, 1); |
| 3551 | __ Strh(temp2, MemOperand(temp1, ArtMethod::HotnessCountOffset().Int32Value())); |
| 3552 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3553 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3554 | return; |
| 3555 | } |
| 3556 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3557 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 3558 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3559 | } |
| 3560 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3561 | __ B(codegen_->GetLabelOf(successor)); |
| 3562 | } |
| 3563 | } |
| 3564 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3565 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3566 | got->SetLocations(nullptr); |
| 3567 | } |
| 3568 | |
| 3569 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3570 | HandleGoto(got, got->GetSuccessor()); |
| 3571 | } |
| 3572 | |
| 3573 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3574 | try_boundary->SetLocations(nullptr); |
| 3575 | } |
| 3576 | |
| 3577 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3578 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3579 | if (!successor->IsExitBlock()) { |
| 3580 | HandleGoto(try_boundary, successor); |
| 3581 | } |
| 3582 | } |
| 3583 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3584 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3585 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3586 | vixl::aarch64::Label* true_target, |
| 3587 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3588 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3589 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3590 | if (true_target == nullptr && false_target == nullptr) { |
| 3591 | // Nothing to do. The code always falls through. |
| 3592 | return; |
| 3593 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3594 | // Constant condition, statically compared against "true" (integer value 1). |
| 3595 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3596 | if (true_target != nullptr) { |
| 3597 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3598 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3599 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3600 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3601 | if (false_target != nullptr) { |
| 3602 | __ B(false_target); |
| 3603 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3604 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3605 | return; |
| 3606 | } |
| 3607 | |
| 3608 | // The following code generates these patterns: |
| 3609 | // (1) true_target == nullptr && false_target != nullptr |
| 3610 | // - opposite condition true => branch to false_target |
| 3611 | // (2) true_target != nullptr && false_target == nullptr |
| 3612 | // - condition true => branch to true_target |
| 3613 | // (3) true_target != nullptr && false_target != nullptr |
| 3614 | // - condition true => branch to true_target |
| 3615 | // - branch to false_target |
| 3616 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3617 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3618 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3619 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3620 | if (true_target == nullptr) { |
| 3621 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3622 | } else { |
| 3623 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3624 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3625 | } else { |
| 3626 | // The condition instruction has not been materialized, use its inputs as |
| 3627 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3628 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3629 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3630 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 3631 | if (DataType::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3632 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3633 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3634 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3635 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3636 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3637 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3638 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3639 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3640 | // Integer cases. |
| 3641 | Register lhs = InputRegisterAt(condition, 0); |
| 3642 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3643 | |
| 3644 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3645 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3646 | if (true_target == nullptr) { |
| 3647 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3648 | non_fallthrough_target = false_target; |
| 3649 | } else { |
| 3650 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3651 | non_fallthrough_target = true_target; |
| 3652 | } |
| 3653 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3654 | 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] | 3655 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3656 | switch (arm64_cond) { |
| 3657 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3658 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3659 | break; |
| 3660 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3661 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3662 | break; |
| 3663 | case lt: |
| 3664 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3665 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3666 | break; |
| 3667 | case ge: |
| 3668 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3669 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3670 | break; |
| 3671 | default: |
| 3672 | // Without the `static_cast` the compiler throws an error for |
| 3673 | // `-Werror=sign-promo`. |
| 3674 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3675 | } |
| 3676 | } else { |
| 3677 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3678 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3679 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3680 | } |
| 3681 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3682 | |
| 3683 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3684 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3685 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3686 | __ B(false_target); |
| 3687 | } |
| 3688 | } |
| 3689 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3690 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3691 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3692 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3693 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3694 | } |
| 3695 | } |
| 3696 | |
| 3697 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3698 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3699 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3700 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3701 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3702 | true_target = nullptr; |
| 3703 | } |
| 3704 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3705 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3706 | false_target = nullptr; |
| 3707 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3708 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3712 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3713 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3714 | InvokeRuntimeCallingConvention calling_convention; |
| 3715 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3716 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3717 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3718 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3719 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3720 | } |
| 3721 | } |
| 3722 | |
| 3723 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3724 | SlowPathCodeARM64* slow_path = |
| 3725 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3726 | GenerateTestAndBranch(deoptimize, |
| 3727 | /* condition_input_index */ 0, |
| 3728 | slow_path->GetEntryLabel(), |
| 3729 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3730 | } |
| 3731 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3732 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3733 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3734 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3735 | locations->SetOut(Location::RequiresRegister()); |
| 3736 | } |
| 3737 | |
| 3738 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3739 | __ Ldr(OutputRegister(flag), |
| 3740 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3741 | } |
| 3742 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3743 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3744 | return condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3745 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3746 | } |
| 3747 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3748 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3749 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3750 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3751 | : ARM64Condition(cond); |
| 3752 | } |
| 3753 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3754 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3755 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3756 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3757 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3758 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3759 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3760 | } else { |
| 3761 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3762 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3763 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3764 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3765 | // Ask VIXL whether we should synthesize constants in registers. |
| 3766 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3767 | Operand true_op = is_true_value_constant ? |
| 3768 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3769 | Operand false_op = is_false_value_constant ? |
| 3770 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3771 | bool true_value_in_register = false; |
| 3772 | bool false_value_in_register = false; |
| 3773 | MacroAssembler::GetCselSynthesisInformation( |
| 3774 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3775 | true_value_in_register |= !is_true_value_constant; |
| 3776 | false_value_in_register |= !is_false_value_constant; |
| 3777 | |
| 3778 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3779 | : Location::ConstantLocation(cst_true_value)); |
| 3780 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3781 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3782 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3783 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3784 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3785 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3786 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3787 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3791 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3792 | Condition csel_cond; |
| 3793 | |
| 3794 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3795 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3796 | // Use the condition flags set by the previous instruction. |
| 3797 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3798 | } else { |
| 3799 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3800 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3801 | } |
| 3802 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3803 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3804 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3805 | } else { |
| 3806 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3807 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3810 | if (DataType::IsFloatingPointType(select->GetType())) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3811 | __ Fcsel(OutputFPRegister(select), |
| 3812 | InputFPRegisterAt(select, 1), |
| 3813 | InputFPRegisterAt(select, 0), |
| 3814 | csel_cond); |
| 3815 | } else { |
| 3816 | __ Csel(OutputRegister(select), |
| 3817 | InputOperandAt(select, 1), |
| 3818 | InputOperandAt(select, 0), |
| 3819 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3820 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3821 | } |
| 3822 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3823 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3824 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3825 | } |
| 3826 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3827 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3828 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3829 | } |
| 3830 | |
| 3831 | void CodeGeneratorARM64::GenerateNop() { |
| 3832 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3833 | } |
| 3834 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3835 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3836 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3837 | } |
| 3838 | |
| 3839 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3840 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3844 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3848 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3849 | } |
| 3850 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3851 | // Temp is used for read barrier. |
| 3852 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3853 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3854 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3855 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3856 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3857 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3858 | return 1; |
| 3859 | } |
| 3860 | return 0; |
| 3861 | } |
| 3862 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3863 | // 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] | 3864 | // interface pointer, one for loading the current interface. |
| 3865 | // The other checks have one temp for loading the object's class. |
| 3866 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3867 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3868 | return 3; |
| 3869 | } |
| 3870 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3871 | } |
| 3872 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3873 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3874 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3875 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3876 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3877 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3878 | case TypeCheckKind::kExactCheck: |
| 3879 | case TypeCheckKind::kAbstractClassCheck: |
| 3880 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3881 | case TypeCheckKind::kArrayObjectCheck: { |
| 3882 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 3883 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 3884 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3885 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3886 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3887 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3888 | case TypeCheckKind::kUnresolvedCheck: |
| 3889 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3890 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3891 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3892 | case TypeCheckKind::kBitstringCheck: |
| 3893 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3894 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3895 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3896 | LocationSummary* locations = |
| 3897 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3898 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3899 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3900 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3901 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3902 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 3903 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 3904 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 3905 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 3906 | } else { |
| 3907 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3908 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3909 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3910 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3911 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3912 | // Add temps if necessary for read barriers. |
| 3913 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3917 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3918 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3919 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3920 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 3921 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 3922 | ? Register() |
| 3923 | : InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3924 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3925 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3926 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3927 | DCHECK_LE(num_temps, 1u); |
| 3928 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3929 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3930 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3931 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3932 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3933 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3934 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3935 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3936 | |
| 3937 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3938 | // Avoid null check if we know `obj` is not null. |
| 3939 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3940 | __ Cbz(obj, &zero); |
| 3941 | } |
| 3942 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3943 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3944 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3945 | ReadBarrierOption read_barrier_option = |
| 3946 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3947 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3948 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3949 | out_loc, |
| 3950 | obj_loc, |
| 3951 | class_offset, |
| 3952 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3953 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3954 | __ Cmp(out, cls); |
| 3955 | __ Cset(out, eq); |
| 3956 | if (zero.IsLinked()) { |
| 3957 | __ B(&done); |
| 3958 | } |
| 3959 | break; |
| 3960 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3961 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3962 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3963 | ReadBarrierOption read_barrier_option = |
| 3964 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3965 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3966 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3967 | out_loc, |
| 3968 | obj_loc, |
| 3969 | class_offset, |
| 3970 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3971 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3972 | // If the class is abstract, we eagerly fetch the super class of the |
| 3973 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3974 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3975 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3976 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3977 | GenerateReferenceLoadOneRegister(instruction, |
| 3978 | out_loc, |
| 3979 | super_offset, |
| 3980 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3981 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3982 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3983 | __ Cbz(out, &done); |
| 3984 | __ Cmp(out, cls); |
| 3985 | __ B(ne, &loop); |
| 3986 | __ Mov(out, 1); |
| 3987 | if (zero.IsLinked()) { |
| 3988 | __ B(&done); |
| 3989 | } |
| 3990 | break; |
| 3991 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3992 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3993 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 3994 | ReadBarrierOption read_barrier_option = |
| 3995 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3996 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3997 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3998 | out_loc, |
| 3999 | obj_loc, |
| 4000 | class_offset, |
| 4001 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4002 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4003 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4004 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4005 | __ Bind(&loop); |
| 4006 | __ Cmp(out, cls); |
| 4007 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4008 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4009 | GenerateReferenceLoadOneRegister(instruction, |
| 4010 | out_loc, |
| 4011 | super_offset, |
| 4012 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4013 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4014 | __ Cbnz(out, &loop); |
| 4015 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4016 | __ B(&done); |
| 4017 | __ Bind(&success); |
| 4018 | __ Mov(out, 1); |
| 4019 | if (zero.IsLinked()) { |
| 4020 | __ B(&done); |
| 4021 | } |
| 4022 | break; |
| 4023 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4024 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4025 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4026 | ReadBarrierOption read_barrier_option = |
| 4027 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4028 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4029 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4030 | out_loc, |
| 4031 | obj_loc, |
| 4032 | class_offset, |
| 4033 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4034 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4035 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4036 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4037 | __ Cmp(out, cls); |
| 4038 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4039 | // 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] | 4040 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4041 | GenerateReferenceLoadOneRegister(instruction, |
| 4042 | out_loc, |
| 4043 | component_offset, |
| 4044 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4045 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4046 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4047 | __ Cbz(out, &done); |
| 4048 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4049 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4050 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4051 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4052 | __ Mov(out, 1); |
| 4053 | __ B(&done); |
| 4054 | break; |
| 4055 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4056 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4057 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4058 | // No read barrier since the slow path will retry upon failure. |
| 4059 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4060 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4061 | out_loc, |
| 4062 | obj_loc, |
| 4063 | class_offset, |
| 4064 | maybe_temp_loc, |
| 4065 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4066 | __ Cmp(out, cls); |
| 4067 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4068 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4069 | instruction, /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4070 | codegen_->AddSlowPath(slow_path); |
| 4071 | __ B(ne, slow_path->GetEntryLabel()); |
| 4072 | __ Mov(out, 1); |
| 4073 | if (zero.IsLinked()) { |
| 4074 | __ B(&done); |
| 4075 | } |
| 4076 | break; |
| 4077 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4078 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4079 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4080 | case TypeCheckKind::kInterfaceCheck: { |
| 4081 | // Note that we indeed only call on slow path, but we always go |
| 4082 | // into the slow path for the unresolved and interface check |
| 4083 | // cases. |
| 4084 | // |
| 4085 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4086 | // entry point without resorting to a type checking slow path |
| 4087 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4088 | // require to assign fixed registers for the inputs of this |
| 4089 | // HInstanceOf instruction (following the runtime calling |
| 4090 | // convention), which might be cluttered by the potential first |
| 4091 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4092 | // |
| 4093 | // TODO: Introduce a new runtime entry point taking the object |
| 4094 | // to test (instead of its class) as argument, and let it deal |
| 4095 | // with the read barrier issues. This will let us refactor this |
| 4096 | // case of the `switch` code as it was previously (with a direct |
| 4097 | // call to the runtime not using a type checking slow path). |
| 4098 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4099 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4100 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4101 | instruction, /* is_fatal */ false); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4102 | codegen_->AddSlowPath(slow_path); |
| 4103 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4104 | if (zero.IsLinked()) { |
| 4105 | __ B(&done); |
| 4106 | } |
| 4107 | break; |
| 4108 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4109 | |
| 4110 | case TypeCheckKind::kBitstringCheck: { |
| 4111 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4112 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4113 | out_loc, |
| 4114 | obj_loc, |
| 4115 | class_offset, |
| 4116 | maybe_temp_loc, |
| 4117 | kWithoutReadBarrier); |
| 4118 | |
| 4119 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 4120 | __ Cset(out, eq); |
| 4121 | if (zero.IsLinked()) { |
| 4122 | __ B(&done); |
| 4123 | } |
| 4124 | break; |
| 4125 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4126 | } |
| 4127 | |
| 4128 | if (zero.IsLinked()) { |
| 4129 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4130 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4131 | } |
| 4132 | |
| 4133 | if (done.IsLinked()) { |
| 4134 | __ Bind(&done); |
| 4135 | } |
| 4136 | |
| 4137 | if (slow_path != nullptr) { |
| 4138 | __ Bind(slow_path->GetExitLabel()); |
| 4139 | } |
| 4140 | } |
| 4141 | |
| 4142 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4143 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4144 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4145 | LocationSummary* locations = |
| 4146 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4147 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4148 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 4149 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 4150 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 4151 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 4152 | } else { |
| 4153 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4154 | } |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4155 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4156 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4157 | } |
| 4158 | |
| 4159 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4160 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4161 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4162 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4163 | Register obj = InputRegisterAt(instruction, 0); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4164 | Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 4165 | ? Register() |
| 4166 | : InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4167 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4168 | DCHECK_GE(num_temps, 1u); |
| 4169 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4170 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4171 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4172 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4173 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4174 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4175 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4176 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4177 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4178 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4179 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4180 | const uint32_t object_array_data_offset = |
| 4181 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4182 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 4183 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4184 | SlowPathCodeARM64* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4185 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARM64( |
| 4186 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4187 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4188 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4189 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4190 | // Avoid null check if we know obj is not null. |
| 4191 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4192 | __ Cbz(obj, &done); |
| 4193 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4194 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4195 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4196 | case TypeCheckKind::kExactCheck: |
| 4197 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4198 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4199 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4200 | temp_loc, |
| 4201 | obj_loc, |
| 4202 | class_offset, |
| 4203 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4204 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4205 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4206 | __ Cmp(temp, cls); |
| 4207 | // Jump to slow path for throwing the exception or doing a |
| 4208 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4209 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4210 | break; |
| 4211 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4212 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4213 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4214 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4215 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4216 | temp_loc, |
| 4217 | obj_loc, |
| 4218 | class_offset, |
| 4219 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4220 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4221 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4222 | // If the class is abstract, we eagerly fetch the super class of the |
| 4223 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4224 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4225 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4226 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4227 | GenerateReferenceLoadOneRegister(instruction, |
| 4228 | temp_loc, |
| 4229 | super_offset, |
| 4230 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4231 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4232 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4233 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4234 | // exception. |
| 4235 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4236 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4237 | __ Cmp(temp, cls); |
| 4238 | __ B(ne, &loop); |
| 4239 | break; |
| 4240 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4241 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4242 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4243 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4244 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4245 | temp_loc, |
| 4246 | obj_loc, |
| 4247 | class_offset, |
| 4248 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4249 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4250 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4251 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4252 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4253 | __ Bind(&loop); |
| 4254 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4255 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4256 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4257 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4258 | GenerateReferenceLoadOneRegister(instruction, |
| 4259 | temp_loc, |
| 4260 | super_offset, |
| 4261 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4262 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4263 | |
| 4264 | // If the class reference currently in `temp` is not null, jump |
| 4265 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4266 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4267 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4268 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4269 | break; |
| 4270 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4271 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4272 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4273 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4274 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4275 | temp_loc, |
| 4276 | obj_loc, |
| 4277 | class_offset, |
| 4278 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4279 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4280 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4281 | // Do an exact check. |
| 4282 | __ Cmp(temp, cls); |
| 4283 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4284 | |
| 4285 | // 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] | 4286 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4287 | GenerateReferenceLoadOneRegister(instruction, |
| 4288 | temp_loc, |
| 4289 | component_offset, |
| 4290 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4291 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4292 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4293 | // If the component type is null, jump to the slow path to throw the exception. |
| 4294 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4295 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4296 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4297 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4298 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4299 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4300 | break; |
| 4301 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4302 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4303 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4304 | // 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] | 4305 | // |
| 4306 | // We cannot directly call the CheckCast runtime entry point |
| 4307 | // without resorting to a type checking slow path here (i.e. by |
| 4308 | // calling InvokeRuntime directly), as it would require to |
| 4309 | // assign fixed registers for the inputs of this HInstanceOf |
| 4310 | // instruction (following the runtime calling convention), which |
| 4311 | // might be cluttered by the potential first read barrier |
| 4312 | // emission at the beginning of this method. |
| 4313 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4314 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4315 | case TypeCheckKind::kInterfaceCheck: { |
| 4316 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4317 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4318 | temp_loc, |
| 4319 | obj_loc, |
| 4320 | class_offset, |
| 4321 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4322 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4323 | |
| 4324 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4325 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4326 | temp_loc, |
| 4327 | temp_loc, |
| 4328 | iftable_offset, |
| 4329 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4330 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4331 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4332 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4333 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4334 | vixl::aarch64::Label start_loop; |
| 4335 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4336 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4337 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4338 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4339 | // Go to next interface. |
| 4340 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4341 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4342 | // Compare the classes and continue the loop if they do not match. |
| 4343 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4344 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4345 | break; |
| 4346 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 4347 | |
| 4348 | case TypeCheckKind::kBitstringCheck: { |
| 4349 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4350 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4351 | temp_loc, |
| 4352 | obj_loc, |
| 4353 | class_offset, |
| 4354 | maybe_temp2_loc, |
| 4355 | kWithoutReadBarrier); |
| 4356 | |
| 4357 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 4358 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 4359 | break; |
| 4360 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4361 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4362 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4363 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4364 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4365 | } |
| 4366 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4367 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4368 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4369 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4370 | } |
| 4371 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4372 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4373 | // Will be generated at use site. |
| 4374 | } |
| 4375 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4376 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4377 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4378 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4379 | } |
| 4380 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4381 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4382 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4383 | } |
| 4384 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4385 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4386 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4387 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4388 | // the method_idx. |
| 4389 | HandleInvoke(invoke); |
| 4390 | } |
| 4391 | |
| 4392 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4393 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4394 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4395 | } |
| 4396 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4397 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4398 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4399 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4400 | } |
| 4401 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4402 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4403 | HandleInvoke(invoke); |
| 4404 | } |
| 4405 | |
| 4406 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4407 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4408 | LocationSummary* locations = invoke->GetLocations(); |
| 4409 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4410 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4411 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4412 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4413 | |
| 4414 | // The register ip1 is required to be used for the hidden argument in |
| 4415 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4416 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4417 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4418 | scratch_scope.Exclude(ip1); |
| 4419 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4420 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4421 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4422 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4423 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4424 | { |
| 4425 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4426 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4427 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4428 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4429 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4430 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4431 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4432 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4433 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4434 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4435 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4436 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4437 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4438 | // emit a read barrier for the previous class reference load. |
| 4439 | // However this is not required in practice, as this is an |
| 4440 | // intermediate/temporary reference and because the current |
| 4441 | // concurrent copying collector keeps the from-space memory |
| 4442 | // intact/accessible until the end of the marking phase (the |
| 4443 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4444 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4445 | __ Ldr(temp, |
| 4446 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4447 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4448 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4449 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4450 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4451 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4452 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4453 | |
| 4454 | { |
| 4455 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4456 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4457 | |
| 4458 | // lr(); |
| 4459 | __ blr(lr); |
| 4460 | DCHECK(!codegen_->IsLeafMethod()); |
| 4461 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4462 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4463 | |
| 4464 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4468 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4469 | if (intrinsic.TryDispatch(invoke)) { |
| 4470 | return; |
| 4471 | } |
| 4472 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4473 | HandleInvoke(invoke); |
| 4474 | } |
| 4475 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4476 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4477 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4478 | // art::PrepareForRegisterAllocation. |
| 4479 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4480 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4481 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetAllocator(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4482 | if (intrinsic.TryDispatch(invoke)) { |
| 4483 | return; |
| 4484 | } |
| 4485 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4486 | HandleInvoke(invoke); |
| 4487 | } |
| 4488 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4489 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4490 | if (invoke->GetLocations()->Intrinsified()) { |
| 4491 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4492 | intrinsic.Dispatch(invoke); |
| 4493 | return true; |
| 4494 | } |
| 4495 | return false; |
| 4496 | } |
| 4497 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4498 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4499 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4500 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4501 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4502 | return desired_dispatch_info; |
| 4503 | } |
| 4504 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4505 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4506 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4507 | // 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] | 4508 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4509 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4510 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4511 | uint32_t offset = |
| 4512 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4513 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4514 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4515 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4516 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4517 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4518 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4519 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4520 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4521 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4522 | // Add ADRP with its PC-relative method patch. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4523 | vixl::aarch64::Label* adrp_label = NewBootImageMethodPatch(invoke->GetTargetMethod()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4524 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4525 | // Add ADD with its PC-relative method patch. |
| 4526 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4527 | NewBootImageMethodPatch(invoke->GetTargetMethod(), adrp_label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4528 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4529 | break; |
| 4530 | } |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4531 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 4532 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4533 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4534 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_offset); |
| 4535 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4536 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
| 4537 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
| 4538 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 4539 | EmitLdrOffsetPlaceholder(ldr_label, WRegisterFrom(temp), XRegisterFrom(temp)); |
| 4540 | break; |
| 4541 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4542 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4543 | // Add ADRP with its PC-relative .bss entry patch. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4544 | MethodReference target_method(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4545 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(target_method); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4546 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4547 | // Add LDR with its PC-relative .bss entry patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4548 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4549 | NewMethodBssEntryPatch(target_method, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4550 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4551 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4552 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4553 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 4554 | // Load method address from literal pool. |
| 4555 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
| 4556 | break; |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4557 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4558 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4559 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4560 | } |
| 4561 | } |
| 4562 | |
| 4563 | switch (invoke->GetCodePtrLocation()) { |
| 4564 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4565 | { |
| 4566 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4567 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4568 | kInstructionSize, |
| 4569 | CodeBufferCheckScope::kExactSize); |
| 4570 | __ bl(&frame_entry_label_); |
| 4571 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4572 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4573 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4574 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4575 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4576 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4577 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4578 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4579 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4580 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4581 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4582 | kInstructionSize, |
| 4583 | CodeBufferCheckScope::kExactSize); |
| 4584 | // lr() |
| 4585 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4586 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4587 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4588 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4589 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4590 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4591 | DCHECK(!IsLeafMethod()); |
| 4592 | } |
| 4593 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4594 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4595 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4596 | // Use the calling convention instead of the location of the receiver, as |
| 4597 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4598 | // slow path, the arguments have been moved to the right place, so here we are |
| 4599 | // guaranteed that the receiver is the first register of the calling convention. |
| 4600 | InvokeDexCallingConvention calling_convention; |
| 4601 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4602 | Register temp = XRegisterFrom(temp_in); |
| 4603 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4604 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4605 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4606 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4607 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4608 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4609 | |
| 4610 | { |
| 4611 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4612 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4613 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4614 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4615 | MaybeRecordImplicitNullCheck(invoke); |
| 4616 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4617 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4618 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4619 | // intermediate/temporary reference and because the current |
| 4620 | // concurrent copying collector keeps the from-space memory |
| 4621 | // intact/accessible until the end of the marking phase (the |
| 4622 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4623 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4624 | // temp = temp->GetMethodAt(method_offset); |
| 4625 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4626 | // lr = temp->GetEntryPoint(); |
| 4627 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4628 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4629 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4630 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4631 | // lr(); |
| 4632 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4633 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4634 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4635 | } |
| 4636 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4637 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4638 | HandleInvoke(invoke); |
| 4639 | } |
| 4640 | |
| 4641 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4642 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4643 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4644 | } |
| 4645 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4646 | void LocationsBuilderARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4647 | HandleInvoke(invoke); |
| 4648 | } |
| 4649 | |
| 4650 | void InstructionCodeGeneratorARM64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 4651 | codegen_->GenerateInvokeCustomCall(invoke); |
| 4652 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
| 4653 | } |
| 4654 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4655 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageIntrinsicPatch( |
| 4656 | uint32_t intrinsic_data, |
| 4657 | vixl::aarch64::Label* adrp_label) { |
| 4658 | return NewPcRelativePatch( |
| 4659 | /* dex_file */ nullptr, intrinsic_data, adrp_label, &boot_image_intrinsic_patches_); |
| 4660 | } |
| 4661 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4662 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageRelRoPatch( |
| 4663 | uint32_t boot_image_offset, |
| 4664 | vixl::aarch64::Label* adrp_label) { |
| 4665 | return NewPcRelativePatch( |
| 4666 | /* dex_file */ nullptr, boot_image_offset, adrp_label, &boot_image_method_patches_); |
| 4667 | } |
| 4668 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4669 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageMethodPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4670 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4671 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4672 | return NewPcRelativePatch( |
| 4673 | 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] | 4674 | } |
| 4675 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4676 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4677 | MethodReference target_method, |
| 4678 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4679 | return NewPcRelativePatch( |
| 4680 | 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] | 4681 | } |
| 4682 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4683 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageTypePatch( |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4684 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4685 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4686 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4687 | 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] | 4688 | } |
| 4689 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4690 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4691 | const DexFile& dex_file, |
| 4692 | dex::TypeIndex type_index, |
| 4693 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4694 | 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] | 4695 | } |
| 4696 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4697 | vixl::aarch64::Label* CodeGeneratorARM64::NewBootImageStringPatch( |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4698 | const DexFile& dex_file, |
| 4699 | dex::StringIndex string_index, |
| 4700 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4701 | return NewPcRelativePatch( |
| 4702 | &dex_file, string_index.index_, adrp_label, &boot_image_string_patches_); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4703 | } |
| 4704 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4705 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4706 | const DexFile& dex_file, |
| 4707 | dex::StringIndex string_index, |
| 4708 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4709 | 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] | 4710 | } |
| 4711 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 4712 | void CodeGeneratorARM64::EmitBakerReadBarrierCbnz(uint32_t custom_data) { |
| 4713 | ExactAssemblyScope guard(GetVIXLAssembler(), 1 * vixl::aarch64::kInstructionSize); |
| 4714 | if (Runtime::Current()->UseJitCompilation()) { |
| 4715 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 4716 | vixl::aarch64::Label* slow_path_entry = &it->second.label; |
| 4717 | __ cbnz(mr, slow_path_entry); |
| 4718 | } else { |
| 4719 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4720 | vixl::aarch64::Label* cbnz_label = &baker_read_barrier_patches_.back().label; |
| 4721 | __ bind(cbnz_label); |
| 4722 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 4723 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4724 | } |
| 4725 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4726 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4727 | const DexFile* dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4728 | uint32_t offset_or_index, |
| 4729 | vixl::aarch64::Label* adrp_label, |
| 4730 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4731 | // Add a patch entry and return the label. |
| 4732 | patches->emplace_back(dex_file, offset_or_index); |
| 4733 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4734 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4735 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4736 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4737 | return label; |
| 4738 | } |
| 4739 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4740 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4741 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4742 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4743 | } |
| 4744 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4745 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4746 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4747 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4748 | return jit_string_patches_.GetOrCreate( |
| 4749 | StringReference(&dex_file, string_index), |
| 4750 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4751 | } |
| 4752 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4753 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4754 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4755 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4756 | return jit_class_patches_.GetOrCreate( |
| 4757 | TypeReference(&dex_file, type_index), |
| 4758 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4759 | } |
| 4760 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4761 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4762 | vixl::aarch64::Register reg) { |
| 4763 | DCHECK(reg.IsX()); |
| 4764 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4765 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4766 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4767 | } |
| 4768 | |
| 4769 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4770 | vixl::aarch64::Register out, |
| 4771 | vixl::aarch64::Register base) { |
| 4772 | DCHECK(out.IsX()); |
| 4773 | DCHECK(base.IsX()); |
| 4774 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4775 | __ Bind(fixup_label); |
| 4776 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4777 | } |
| 4778 | |
| 4779 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4780 | vixl::aarch64::Register out, |
| 4781 | vixl::aarch64::Register base) { |
| 4782 | DCHECK(base.IsX()); |
| 4783 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4784 | __ Bind(fixup_label); |
| 4785 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4786 | } |
| 4787 | |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4788 | void CodeGeneratorARM64::LoadBootImageAddress(vixl::aarch64::Register reg, |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4789 | uint32_t boot_image_reference) { |
| 4790 | if (GetCompilerOptions().IsBootImage()) { |
| 4791 | // Add ADRP with its PC-relative type patch. |
| 4792 | vixl::aarch64::Label* adrp_label = NewBootImageIntrinsicPatch(boot_image_reference); |
| 4793 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4794 | // Add ADD with its PC-relative type patch. |
| 4795 | vixl::aarch64::Label* add_label = NewBootImageIntrinsicPatch(boot_image_reference, adrp_label); |
| 4796 | EmitAddPlaceholder(add_label, reg.X(), reg.X()); |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4797 | } else if (Runtime::Current()->IsAotCompiler()) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4798 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4799 | vixl::aarch64::Label* adrp_label = NewBootImageRelRoPatch(boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4800 | EmitAdrpPlaceholder(adrp_label, reg.X()); |
| 4801 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4802 | vixl::aarch64::Label* ldr_label = NewBootImageRelRoPatch(boot_image_reference, adrp_label); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4803 | EmitLdrOffsetPlaceholder(ldr_label, reg.W(), reg.X()); |
| 4804 | } else { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4805 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4806 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 4807 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4808 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 4809 | __ Ldr(reg.W(), DeduplicateBootImageAddressLiteral(reinterpret_cast<uintptr_t>(address))); |
| 4810 | } |
| 4811 | } |
| 4812 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4813 | void CodeGeneratorARM64::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 4814 | uint32_t boot_image_offset) { |
| 4815 | DCHECK(invoke->IsStatic()); |
| 4816 | InvokeRuntimeCallingConvention calling_convention; |
| 4817 | Register argument = calling_convention.GetRegisterAt(0); |
| 4818 | if (GetCompilerOptions().IsBootImage()) { |
| 4819 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 4820 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 4821 | MethodReference target_method = invoke->GetTargetMethod(); |
| 4822 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 4823 | // Add ADRP with its PC-relative type patch. |
| 4824 | vixl::aarch64::Label* adrp_label = NewBootImageTypePatch(*target_method.dex_file, type_idx); |
| 4825 | EmitAdrpPlaceholder(adrp_label, argument.X()); |
| 4826 | // Add ADD with its PC-relative type patch. |
| 4827 | vixl::aarch64::Label* add_label = |
| 4828 | NewBootImageTypePatch(*target_method.dex_file, type_idx, adrp_label); |
| 4829 | EmitAddPlaceholder(add_label, argument.X(), argument.X()); |
| 4830 | } else { |
| 4831 | LoadBootImageAddress(argument, boot_image_offset); |
| 4832 | } |
| 4833 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 4834 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4835 | } |
| 4836 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4837 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4838 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4839 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4840 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4841 | for (const PcRelativePatchInfo& info : infos) { |
| 4842 | linker_patches->push_back(Factory(info.label.GetLocation(), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4843 | info.target_dex_file, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4844 | info.pc_insn_label->GetLocation(), |
| 4845 | info.offset_or_index)); |
| 4846 | } |
| 4847 | } |
| 4848 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4849 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 4850 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 4851 | const DexFile* target_dex_file, |
| 4852 | uint32_t pc_insn_offset, |
| 4853 | uint32_t boot_image_offset) { |
| 4854 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 4855 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4856 | } |
| 4857 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4858 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4859 | DCHECK(linker_patches->empty()); |
| 4860 | size_t size = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4861 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4862 | method_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4863 | boot_image_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4864 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4865 | boot_image_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4866 | string_bss_entry_patches_.size() + |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4867 | boot_image_intrinsic_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4868 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4869 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4870 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4871 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4872 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4873 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4874 | boot_image_type_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4875 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4876 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4877 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 4878 | boot_image_intrinsic_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4879 | } else { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4880 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4881 | boot_image_method_patches_, linker_patches); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4882 | DCHECK(boot_image_type_patches_.empty()); |
| 4883 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4884 | DCHECK(boot_image_intrinsic_patches_.empty()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4885 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4886 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4887 | method_bss_entry_patches_, linker_patches); |
| 4888 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4889 | type_bss_entry_patches_, linker_patches); |
| 4890 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4891 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4892 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4893 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 4894 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4895 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4896 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4897 | } |
| 4898 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 4899 | bool CodeGeneratorARM64::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
| 4900 | return patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
| 4901 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 4902 | } |
| 4903 | |
| 4904 | void CodeGeneratorARM64::EmitThunkCode(const linker::LinkerPatch& patch, |
| 4905 | /*out*/ ArenaVector<uint8_t>* code, |
| 4906 | /*out*/ std::string* debug_name) { |
| 4907 | Arm64Assembler assembler(GetGraph()->GetAllocator()); |
| 4908 | switch (patch.GetType()) { |
| 4909 | case linker::LinkerPatch::Type::kCallRelative: { |
| 4910 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 4911 | // to the generic JNI and interpreter trampolines. |
| 4912 | Offset offset(ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4913 | kArm64PointerSize).Int32Value()); |
| 4914 | assembler.JumpTo(ManagedRegister(arm64::X0), offset, ManagedRegister(arm64::IP0)); |
| 4915 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 4916 | *debug_name = "MethodCallThunk"; |
| 4917 | } |
| 4918 | break; |
| 4919 | } |
| 4920 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| 4921 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 4922 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 4923 | break; |
| 4924 | } |
| 4925 | default: |
| 4926 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 4927 | UNREACHABLE(); |
| 4928 | } |
| 4929 | |
| 4930 | // Ensure we emit the literal pool if any. |
| 4931 | assembler.FinalizeCode(); |
| 4932 | code->resize(assembler.CodeSize()); |
| 4933 | MemoryRegion code_region(code->data(), code->size()); |
| 4934 | assembler.FinalizeInstructions(code_region); |
| 4935 | } |
| 4936 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4937 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4938 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4939 | value, |
| 4940 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4941 | } |
| 4942 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4943 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4944 | return uint64_literals_.GetOrCreate( |
| 4945 | value, |
| 4946 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4947 | } |
| 4948 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4949 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4950 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4951 | // art::PrepareForRegisterAllocation. |
| 4952 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4953 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4954 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4955 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4956 | return; |
| 4957 | } |
| 4958 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4959 | { |
| 4960 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4961 | // are no pools emitted. |
| 4962 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4963 | LocationSummary* locations = invoke->GetLocations(); |
| 4964 | codegen_->GenerateStaticOrDirectCall( |
| 4965 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| 4966 | } |
| 4967 | |
| 4968 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4969 | } |
| 4970 | |
| 4971 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4972 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4973 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4974 | return; |
| 4975 | } |
| 4976 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4977 | { |
| 4978 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4979 | // are no pools emitted. |
| 4980 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4981 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 4982 | DCHECK(!codegen_->IsLeafMethod()); |
| 4983 | } |
| 4984 | |
| 4985 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4986 | } |
| 4987 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4988 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4989 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4990 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4991 | case HLoadClass::LoadKind::kInvalid: |
| 4992 | LOG(FATAL) << "UNREACHABLE"; |
| 4993 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4994 | case HLoadClass::LoadKind::kReferrersClass: |
| 4995 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4996 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4997 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4998 | case HLoadClass::LoadKind::kBssEntry: |
| 4999 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5000 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5001 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5002 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5003 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5004 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5005 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5006 | break; |
| 5007 | } |
| 5008 | return desired_class_load_kind; |
| 5009 | } |
| 5010 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5011 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5012 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5013 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5014 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5015 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5016 | cls, |
| 5017 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5018 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5019 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5020 | return; |
| 5021 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5022 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5023 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5024 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5025 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5026 | ? LocationSummary::kCallOnSlowPath |
| 5027 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5028 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5029 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5030 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5031 | } |
| 5032 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5033 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5034 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5035 | } |
| 5036 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5037 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 5038 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5039 | // 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] | 5040 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5041 | } else { |
| 5042 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5043 | } |
| 5044 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5045 | } |
| 5046 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5047 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5048 | // move. |
| 5049 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5050 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5051 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5052 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5053 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5054 | return; |
| 5055 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5056 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5057 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5058 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5059 | Register out = OutputRegister(cls); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5060 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5061 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5062 | ? kWithoutReadBarrier |
| 5063 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5064 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5065 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5066 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5067 | DCHECK(!cls->CanCallRuntime()); |
| 5068 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5069 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5070 | Register current_method = InputRegisterAt(cls, 0); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5071 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5072 | out_loc, |
| 5073 | current_method, |
| 5074 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 5075 | /* fixup_label */ nullptr, |
| 5076 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5077 | break; |
| 5078 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5079 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5080 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5081 | // Add ADRP with its PC-relative type patch. |
| 5082 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5083 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5084 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5085 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5086 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5087 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5088 | codegen_->NewBootImageTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5089 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5090 | break; |
| 5091 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5092 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5093 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5094 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(cls); |
| 5095 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5096 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5097 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5098 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5099 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5100 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5101 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5102 | break; |
| 5103 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5104 | case HLoadClass::LoadKind::kBssEntry: { |
| 5105 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 5106 | const DexFile& dex_file = cls->GetDexFile(); |
| 5107 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5108 | vixl::aarch64::Register temp = XRegisterFrom(out_loc); |
| 5109 | vixl::aarch64::Label* adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 5110 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5111 | // Add LDR with its PC-relative Class .bss entry patch. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5112 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5113 | codegen_->NewBssEntryTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5114 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5115 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5116 | out_loc, |
| 5117 | temp, |
| 5118 | /* offset placeholder */ 0u, |
| 5119 | ldr_label, |
| 5120 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5121 | generate_null_check = true; |
| 5122 | break; |
| 5123 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5124 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 5125 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 5126 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 5127 | DCHECK_NE(address, 0u); |
| 5128 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5129 | break; |
| 5130 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5131 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5132 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5133 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5134 | cls->GetClass())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5135 | codegen_->GenerateGcRootFieldLoad(cls, |
| 5136 | out_loc, |
| 5137 | out.X(), |
| 5138 | /* offset */ 0, |
| 5139 | /* fixup_label */ nullptr, |
| 5140 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5141 | break; |
| 5142 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5143 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5144 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5145 | LOG(FATAL) << "UNREACHABLE"; |
| 5146 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5147 | } |
| 5148 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5149 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5150 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5151 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 5152 | SlowPathCodeARM64* slow_path = |
| 5153 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARM64(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5154 | codegen_->AddSlowPath(slow_path); |
| 5155 | if (generate_null_check) { |
| 5156 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5157 | } |
| 5158 | if (cls->MustGenerateClinitCheck()) { |
| 5159 | GenerateClassInitializationCheck(slow_path, out); |
| 5160 | } else { |
| 5161 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5162 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5163 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5164 | } |
| 5165 | } |
| 5166 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 5167 | void LocationsBuilderARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5168 | InvokeRuntimeCallingConvention calling_convention; |
| 5169 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5170 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 5171 | } |
| 5172 | |
| 5173 | void InstructionCodeGeneratorARM64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5174 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 5175 | } |
| 5176 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 5177 | void LocationsBuilderARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5178 | InvokeRuntimeCallingConvention calling_convention; |
| 5179 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 5180 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 5181 | } |
| 5182 | |
| 5183 | void InstructionCodeGeneratorARM64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5184 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 5185 | } |
| 5186 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5187 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5188 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5189 | } |
| 5190 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5191 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5192 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5193 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5194 | locations->SetOut(Location::RequiresRegister()); |
| 5195 | } |
| 5196 | |
| 5197 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5198 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5199 | } |
| 5200 | |
| 5201 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5202 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5203 | } |
| 5204 | |
| 5205 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5206 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5207 | } |
| 5208 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5209 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5210 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5211 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5212 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5213 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5214 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5215 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5216 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5217 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5218 | case HLoadString::LoadKind::kJitTableAddress: |
| 5219 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5220 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5221 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5222 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5223 | } |
| 5224 | return desired_string_load_kind; |
| 5225 | } |
| 5226 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5227 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5228 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5229 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5230 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5231 | InvokeRuntimeCallingConvention calling_convention; |
| 5232 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5233 | } else { |
| 5234 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5235 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5236 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5237 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 5238 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5239 | } else { |
| 5240 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5241 | } |
| 5242 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5243 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5244 | } |
| 5245 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5246 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5247 | // move. |
| 5248 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5249 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5250 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5251 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5252 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5253 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5254 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5255 | // Add ADRP with its PC-relative String patch. |
| 5256 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5257 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5258 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5259 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5260 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5261 | vixl::aarch64::Label* add_label = |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5262 | codegen_->NewBootImageStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5263 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5264 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5265 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5266 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5267 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5268 | // Add ADRP with its PC-relative .data.bimg.rel.ro patch. |
| 5269 | uint32_t boot_image_offset = codegen_->GetBootImageOffset(load); |
| 5270 | vixl::aarch64::Label* adrp_label = codegen_->NewBootImageRelRoPatch(boot_image_offset); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5271 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5272 | // Add LDR with its PC-relative .data.bimg.rel.ro patch. |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5273 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5274 | codegen_->NewBootImageRelRoPatch(boot_image_offset, adrp_label); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5275 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 5276 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5277 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5278 | case HLoadString::LoadKind::kBssEntry: { |
| 5279 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5280 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5281 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5282 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5283 | Register temp = XRegisterFrom(out_loc); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5284 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5285 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5286 | // Add LDR with its PC-relative String .bss entry patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5287 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5288 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5289 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5290 | codegen_->GenerateGcRootFieldLoad(load, |
| 5291 | out_loc, |
| 5292 | temp, |
| 5293 | /* offset placeholder */ 0u, |
| 5294 | ldr_label, |
| 5295 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5296 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 5297 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARM64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5298 | codegen_->AddSlowPath(slow_path); |
| 5299 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5300 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5301 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5302 | return; |
| 5303 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5304 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 5305 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 5306 | DCHECK_NE(address, 0u); |
| 5307 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5308 | return; |
| 5309 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5310 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5311 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5312 | load->GetStringIndex(), |
| 5313 | load->GetString())); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 5314 | codegen_->GenerateGcRootFieldLoad(load, |
| 5315 | out_loc, |
| 5316 | out.X(), |
| 5317 | /* offset */ 0, |
| 5318 | /* fixup_label */ nullptr, |
| 5319 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5320 | return; |
| 5321 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5322 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5323 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5324 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5325 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5326 | // 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] | 5327 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5328 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5329 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5330 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5331 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5332 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5333 | } |
| 5334 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5335 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5336 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(constant); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5337 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5338 | } |
| 5339 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5340 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5341 | // Will be generated at use site. |
| 5342 | } |
| 5343 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5344 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5345 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5346 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5347 | InvokeRuntimeCallingConvention calling_convention; |
| 5348 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5349 | } |
| 5350 | |
| 5351 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5352 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5353 | instruction, |
| 5354 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5355 | if (instruction->IsEnter()) { |
| 5356 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5357 | } else { |
| 5358 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5359 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5360 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5361 | } |
| 5362 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5363 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5364 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5365 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5366 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5367 | case DataType::Type::kInt32: |
| 5368 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5369 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5370 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5371 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5372 | break; |
| 5373 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5374 | case DataType::Type::kFloat32: |
| 5375 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5376 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5377 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5378 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5379 | break; |
| 5380 | |
| 5381 | default: |
| 5382 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5383 | } |
| 5384 | } |
| 5385 | |
| 5386 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5387 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5388 | case DataType::Type::kInt32: |
| 5389 | case DataType::Type::kInt64: |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5390 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5391 | break; |
| 5392 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5393 | case DataType::Type::kFloat32: |
| 5394 | case DataType::Type::kFloat64: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5395 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5396 | break; |
| 5397 | |
| 5398 | default: |
| 5399 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5400 | } |
| 5401 | } |
| 5402 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5403 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5404 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5405 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5406 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5407 | case DataType::Type::kInt32: |
| 5408 | case DataType::Type::kInt64: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5409 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5410 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5411 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5412 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5413 | case DataType::Type::kFloat32: |
| 5414 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5415 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5416 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5417 | break; |
| 5418 | |
| 5419 | default: |
| 5420 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5421 | } |
| 5422 | } |
| 5423 | |
| 5424 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5425 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5426 | case DataType::Type::kInt32: |
| 5427 | case DataType::Type::kInt64: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5428 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5429 | break; |
| 5430 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5431 | case DataType::Type::kFloat32: |
| 5432 | case DataType::Type::kFloat64: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5433 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5434 | break; |
| 5435 | |
| 5436 | default: |
| 5437 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5438 | } |
| 5439 | } |
| 5440 | |
| 5441 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5442 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5443 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5444 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5445 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5446 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5447 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5448 | } |
| 5449 | |
| 5450 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5451 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5452 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5453 | QuickEntrypointEnum entrypoint = |
| 5454 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5455 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5456 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5457 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5458 | } |
| 5459 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5460 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5461 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5462 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5463 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5464 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5465 | locations->SetOut(calling_convention.GetReturnLocation(DataType::Type::kReference)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5466 | } |
| 5467 | |
| 5468 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5469 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5470 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5471 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5472 | } |
| 5473 | |
| 5474 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5475 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5476 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5477 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5478 | } |
| 5479 | |
| 5480 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5481 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5482 | case DataType::Type::kInt32: |
| 5483 | case DataType::Type::kInt64: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5484 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5485 | break; |
| 5486 | |
| 5487 | default: |
| 5488 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5489 | } |
| 5490 | } |
| 5491 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5492 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5493 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5494 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5495 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5496 | } |
| 5497 | |
| 5498 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5499 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5500 | } |
| 5501 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5502 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5503 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5504 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5505 | } |
| 5506 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5507 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5508 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5509 | return; |
| 5510 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5511 | { |
| 5512 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5513 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5514 | Location obj = instruction->GetLocations()->InAt(0); |
| 5515 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5516 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5517 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5518 | } |
| 5519 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5520 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5521 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5522 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5523 | |
| 5524 | LocationSummary* locations = instruction->GetLocations(); |
| 5525 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5526 | |
| 5527 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5528 | } |
| 5529 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5530 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5531 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5532 | } |
| 5533 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5534 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5535 | HandleBinaryOp(instruction); |
| 5536 | } |
| 5537 | |
| 5538 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5539 | HandleBinaryOp(instruction); |
| 5540 | } |
| 5541 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5542 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5543 | LOG(FATAL) << "Unreachable"; |
| 5544 | } |
| 5545 | |
| 5546 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5547 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5548 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5549 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5550 | // The back edge will generate the suspend check. |
| 5551 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5552 | } |
| 5553 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5554 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5555 | } |
| 5556 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5557 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5558 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5559 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5560 | if (location.IsStackSlot()) { |
| 5561 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5562 | } else if (location.IsDoubleStackSlot()) { |
| 5563 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5564 | } |
| 5565 | locations->SetOut(location); |
| 5566 | } |
| 5567 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5568 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5569 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5570 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5571 | } |
| 5572 | |
| 5573 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5574 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5575 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5576 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5577 | } |
| 5578 | |
| 5579 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5580 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5581 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5582 | } |
| 5583 | |
| 5584 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5585 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5586 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5587 | locations->SetInAt(i, Location::Any()); |
| 5588 | } |
| 5589 | locations->SetOut(Location::Any()); |
| 5590 | } |
| 5591 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5592 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5593 | LOG(FATAL) << "Unreachable"; |
| 5594 | } |
| 5595 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5596 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5597 | DataType::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5598 | LocationSummary::CallKind call_kind = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5599 | DataType::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5600 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5601 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5602 | |
| 5603 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5604 | case DataType::Type::kInt32: |
| 5605 | case DataType::Type::kInt64: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5606 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5607 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5608 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5609 | break; |
| 5610 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5611 | case DataType::Type::kFloat32: |
| 5612 | case DataType::Type::kFloat64: { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5613 | InvokeRuntimeCallingConvention calling_convention; |
| 5614 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5615 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5616 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5617 | |
| 5618 | break; |
| 5619 | } |
| 5620 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5621 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5622 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5623 | } |
| 5624 | } |
| 5625 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5626 | void InstructionCodeGeneratorARM64::GenerateIntRemForPower2Denom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5627 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5628 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
| 5629 | DCHECK(IsPowerOfTwo(abs_imm)) << abs_imm; |
| 5630 | |
| 5631 | Register out = OutputRegister(instruction); |
| 5632 | Register dividend = InputRegisterAt(instruction, 0); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5633 | |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5634 | if (abs_imm == 2) { |
| 5635 | __ Cmp(dividend, 0); |
| 5636 | __ And(out, dividend, 1); |
| 5637 | __ Csneg(out, out, out, ge); |
| 5638 | } else { |
| 5639 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5640 | Register temp = temps.AcquireSameSizeAs(out); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5641 | |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 5642 | __ Negs(temp, dividend); |
| 5643 | __ And(out, dividend, abs_imm - 1); |
| 5644 | __ And(temp, temp, abs_imm - 1); |
| 5645 | __ Csneg(out, out, temp, mi); |
| 5646 | } |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5647 | } |
| 5648 | |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5649 | void InstructionCodeGeneratorARM64::GenerateIntRemForConstDenom(HRem *instruction) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 5650 | int64_t imm = Int64FromLocation(instruction->GetLocations()->InAt(1)); |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5651 | |
| 5652 | if (imm == 0) { |
| 5653 | // Do not generate anything. |
| 5654 | // DivZeroCheck would prevent any code to be executed. |
| 5655 | return; |
| 5656 | } |
| 5657 | |
Evgeny Astigeevich | f58dc65 | 2018-06-25 17:54:07 +0100 | [diff] [blame] | 5658 | if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 5659 | // Cases imm == -1 or imm == 1 are handled in constant folding by |
| 5660 | // InstructionWithAbsorbingInputSimplifier. |
| 5661 | // If the cases have survided till code generation they are handled in |
| 5662 | // GenerateIntRemForPower2Denom becauses -1 and 1 are the power of 2 (2^0). |
| 5663 | // The correct code is generated for them, just more instructions. |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5664 | GenerateIntRemForPower2Denom(instruction); |
| 5665 | } else { |
| 5666 | DCHECK(imm < -2 || imm > 2) << imm; |
| 5667 | GenerateDivRemWithAnyConstant(instruction); |
| 5668 | } |
| 5669 | } |
| 5670 | |
| 5671 | void InstructionCodeGeneratorARM64::GenerateIntRem(HRem* instruction) { |
| 5672 | DCHECK(DataType::IsIntOrLongType(instruction->GetResultType())) |
| 5673 | << instruction->GetResultType(); |
| 5674 | |
| 5675 | if (instruction->GetLocations()->InAt(1).IsConstant()) { |
| 5676 | GenerateIntRemForConstDenom(instruction); |
| 5677 | } else { |
| 5678 | Register out = OutputRegister(instruction); |
| 5679 | Register dividend = InputRegisterAt(instruction, 0); |
| 5680 | Register divisor = InputRegisterAt(instruction, 1); |
| 5681 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5682 | Register temp = temps.AcquireSameSizeAs(out); |
| 5683 | __ Sdiv(temp, dividend, divisor); |
| 5684 | __ Msub(out, temp, divisor, dividend); |
| 5685 | } |
| 5686 | } |
| 5687 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5688 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5689 | DataType::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5690 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5691 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5692 | case DataType::Type::kInt32: |
| 5693 | case DataType::Type::kInt64: { |
Evgeny Astigeevich | 878f17d | 2018-06-01 16:53:58 +0100 | [diff] [blame] | 5694 | GenerateIntRem(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5695 | break; |
| 5696 | } |
| 5697 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5698 | case DataType::Type::kFloat32: |
| 5699 | case DataType::Type::kFloat64: { |
| 5700 | QuickEntrypointEnum entrypoint = |
| 5701 | (type == DataType::Type::kFloat32) ? kQuickFmodf : kQuickFmod; |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5702 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5703 | if (type == DataType::Type::kFloat32) { |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5704 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5705 | } else { |
| 5706 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5707 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5708 | break; |
| 5709 | } |
| 5710 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5711 | default: |
| 5712 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5713 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5714 | } |
| 5715 | } |
| 5716 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5717 | void LocationsBuilderARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5718 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5719 | } |
| 5720 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5721 | void InstructionCodeGeneratorARM64::VisitMin(HMin* min) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5722 | HandleBinaryOp(min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5723 | } |
| 5724 | |
| 5725 | void LocationsBuilderARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5726 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5727 | } |
| 5728 | |
| 5729 | void InstructionCodeGeneratorARM64::VisitMax(HMax* max) { |
Petre-Ionut Tudor | 2227fe4 | 2018-04-20 17:12:05 +0100 | [diff] [blame] | 5730 | HandleBinaryOp(max); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5731 | } |
| 5732 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5733 | void LocationsBuilderARM64::VisitAbs(HAbs* abs) { |
| 5734 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 5735 | switch (abs->GetResultType()) { |
| 5736 | case DataType::Type::kInt32: |
| 5737 | case DataType::Type::kInt64: |
| 5738 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5739 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5740 | break; |
| 5741 | case DataType::Type::kFloat32: |
| 5742 | case DataType::Type::kFloat64: |
| 5743 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5744 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5745 | break; |
| 5746 | default: |
| 5747 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5748 | } |
| 5749 | } |
| 5750 | |
| 5751 | void InstructionCodeGeneratorARM64::VisitAbs(HAbs* abs) { |
| 5752 | switch (abs->GetResultType()) { |
| 5753 | case DataType::Type::kInt32: |
| 5754 | case DataType::Type::kInt64: { |
| 5755 | Register in_reg = InputRegisterAt(abs, 0); |
| 5756 | Register out_reg = OutputRegister(abs); |
| 5757 | __ Cmp(in_reg, Operand(0)); |
| 5758 | __ Cneg(out_reg, in_reg, lt); |
| 5759 | break; |
| 5760 | } |
| 5761 | case DataType::Type::kFloat32: |
| 5762 | case DataType::Type::kFloat64: { |
| 5763 | FPRegister in_reg = InputFPRegisterAt(abs, 0); |
| 5764 | FPRegister out_reg = OutputFPRegister(abs); |
| 5765 | __ Fabs(out_reg, in_reg); |
| 5766 | break; |
| 5767 | } |
| 5768 | default: |
| 5769 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 5770 | } |
| 5771 | } |
| 5772 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5773 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5774 | constructor_fence->SetLocations(nullptr); |
| 5775 | } |
| 5776 | |
| 5777 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5778 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5779 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5780 | } |
| 5781 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5782 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5783 | memory_barrier->SetLocations(nullptr); |
| 5784 | } |
| 5785 | |
| 5786 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5787 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5788 | } |
| 5789 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5790 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5791 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5792 | DataType::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5793 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5794 | } |
| 5795 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5796 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5797 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5801 | instruction->SetLocations(nullptr); |
| 5802 | } |
| 5803 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5804 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5805 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5806 | } |
| 5807 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5808 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5809 | HandleBinaryOp(ror); |
| 5810 | } |
| 5811 | |
| 5812 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5813 | HandleBinaryOp(ror); |
| 5814 | } |
| 5815 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5816 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5817 | HandleShift(shl); |
| 5818 | } |
| 5819 | |
| 5820 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5821 | HandleShift(shl); |
| 5822 | } |
| 5823 | |
| 5824 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5825 | HandleShift(shr); |
| 5826 | } |
| 5827 | |
| 5828 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5829 | HandleShift(shr); |
| 5830 | } |
| 5831 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5832 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5833 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5834 | } |
| 5835 | |
| 5836 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5837 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5838 | } |
| 5839 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5840 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5841 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5842 | } |
| 5843 | |
| 5844 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5845 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5846 | } |
| 5847 | |
| 5848 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5849 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5850 | } |
| 5851 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5852 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5853 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5854 | } |
| 5855 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5856 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5857 | HUnresolvedInstanceFieldGet* instruction) { |
| 5858 | FieldAccessCallingConventionARM64 calling_convention; |
| 5859 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5860 | instruction, instruction->GetFieldType(), calling_convention); |
| 5861 | } |
| 5862 | |
| 5863 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5864 | HUnresolvedInstanceFieldGet* instruction) { |
| 5865 | FieldAccessCallingConventionARM64 calling_convention; |
| 5866 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5867 | instruction->GetFieldType(), |
| 5868 | instruction->GetFieldIndex(), |
| 5869 | instruction->GetDexPc(), |
| 5870 | calling_convention); |
| 5871 | } |
| 5872 | |
| 5873 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5874 | HUnresolvedInstanceFieldSet* instruction) { |
| 5875 | FieldAccessCallingConventionARM64 calling_convention; |
| 5876 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5877 | instruction, instruction->GetFieldType(), calling_convention); |
| 5878 | } |
| 5879 | |
| 5880 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5881 | HUnresolvedInstanceFieldSet* instruction) { |
| 5882 | FieldAccessCallingConventionARM64 calling_convention; |
| 5883 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5884 | instruction->GetFieldType(), |
| 5885 | instruction->GetFieldIndex(), |
| 5886 | instruction->GetDexPc(), |
| 5887 | calling_convention); |
| 5888 | } |
| 5889 | |
| 5890 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5891 | HUnresolvedStaticFieldGet* instruction) { |
| 5892 | FieldAccessCallingConventionARM64 calling_convention; |
| 5893 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5894 | instruction, instruction->GetFieldType(), calling_convention); |
| 5895 | } |
| 5896 | |
| 5897 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5898 | HUnresolvedStaticFieldGet* instruction) { |
| 5899 | FieldAccessCallingConventionARM64 calling_convention; |
| 5900 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5901 | instruction->GetFieldType(), |
| 5902 | instruction->GetFieldIndex(), |
| 5903 | instruction->GetDexPc(), |
| 5904 | calling_convention); |
| 5905 | } |
| 5906 | |
| 5907 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5908 | HUnresolvedStaticFieldSet* instruction) { |
| 5909 | FieldAccessCallingConventionARM64 calling_convention; |
| 5910 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5911 | instruction, instruction->GetFieldType(), calling_convention); |
| 5912 | } |
| 5913 | |
| 5914 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5915 | HUnresolvedStaticFieldSet* instruction) { |
| 5916 | FieldAccessCallingConventionARM64 calling_convention; |
| 5917 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5918 | instruction->GetFieldType(), |
| 5919 | instruction->GetFieldIndex(), |
| 5920 | instruction->GetDexPc(), |
| 5921 | calling_convention); |
| 5922 | } |
| 5923 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5924 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5925 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5926 | instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5927 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5928 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5929 | // registers in full width (since the runtime only saves/restores lower part). |
| 5930 | locations->SetCustomSlowPathCallerSaves( |
| 5931 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5932 | } |
| 5933 | |
| 5934 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5935 | HBasicBlock* block = instruction->GetBlock(); |
| 5936 | if (block->GetLoopInformation() != nullptr) { |
| 5937 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5938 | // The back edge will generate the suspend check. |
| 5939 | return; |
| 5940 | } |
| 5941 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5942 | // The goto will generate the suspend check. |
| 5943 | return; |
| 5944 | } |
| 5945 | GenerateSuspendCheck(instruction, nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5946 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5947 | } |
| 5948 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5949 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5950 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5951 | instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5952 | InvokeRuntimeCallingConvention calling_convention; |
| 5953 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5954 | } |
| 5955 | |
| 5956 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5957 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5958 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5959 | } |
| 5960 | |
| 5961 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5962 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5963 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5964 | DataType::Type input_type = conversion->GetInputType(); |
| 5965 | DataType::Type result_type = conversion->GetResultType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5966 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5967 | << input_type << " -> " << result_type; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5968 | if ((input_type == DataType::Type::kReference) || (input_type == DataType::Type::kVoid) || |
| 5969 | (result_type == DataType::Type::kReference) || (result_type == DataType::Type::kVoid)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5970 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5971 | } |
| 5972 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5973 | if (DataType::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5974 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5975 | } else { |
| 5976 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5977 | } |
| 5978 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5979 | if (DataType::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5980 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5981 | } else { |
| 5982 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5983 | } |
| 5984 | } |
| 5985 | |
| 5986 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5987 | DataType::Type result_type = conversion->GetResultType(); |
| 5988 | DataType::Type input_type = conversion->GetInputType(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5989 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5990 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 5991 | << input_type << " -> " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5992 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5993 | if (DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type)) { |
| 5994 | int result_size = DataType::Size(result_type); |
| 5995 | int input_size = DataType::Size(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5996 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5997 | Register output = OutputRegister(conversion); |
| 5998 | Register source = InputRegisterAt(conversion, 0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5999 | if (result_type == DataType::Type::kInt32 && input_type == DataType::Type::kInt64) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 6000 | // 'int' values are used directly as W registers, discarding the top |
| 6001 | // bits, so we don't need to sign-extend and can just perform a move. |
| 6002 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 6003 | // top 32 bits of the target register. We theoretically could leave those |
| 6004 | // bits unchanged, but we would have to make sure that no code uses a |
| 6005 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 6006 | // zero. |
| 6007 | __ Mov(output.W(), source.W()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6008 | } else if (DataType::IsUnsignedType(result_type) || |
| 6009 | (DataType::IsUnsignedType(input_type) && input_size < result_size)) { |
| 6010 | __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, result_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6011 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 6012 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6013 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6014 | } else if (DataType::IsFloatingPointType(result_type) && DataType::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6015 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6016 | } else if (DataType::IsIntegralType(result_type) && DataType::IsFloatingPointType(input_type)) { |
| 6017 | CHECK(result_type == DataType::Type::kInt32 || result_type == DataType::Type::kInt64); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6018 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6019 | } else if (DataType::IsFloatingPointType(result_type) && |
| 6020 | DataType::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6021 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 6022 | } else { |
| 6023 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 6024 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6025 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6026 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6027 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 6028 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 6029 | HandleShift(ushr); |
| 6030 | } |
| 6031 | |
| 6032 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 6033 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6034 | } |
| 6035 | |
| 6036 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 6037 | HandleBinaryOp(instruction); |
| 6038 | } |
| 6039 | |
| 6040 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 6041 | HandleBinaryOp(instruction); |
| 6042 | } |
| 6043 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6044 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6045 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6046 | LOG(FATAL) << "Unreachable"; |
| 6047 | } |
| 6048 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6049 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6050 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6051 | LOG(FATAL) << "Unreachable"; |
| 6052 | } |
| 6053 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6054 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6055 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6056 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6057 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6058 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6059 | } |
| 6060 | |
| 6061 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6062 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6063 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6064 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 6065 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6066 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6067 | // 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] | 6068 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6069 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 6070 | // make sure we don't emit it if the target may run out of range. |
| 6071 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 6072 | // ranges and emit the tables only as required. |
| 6073 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6074 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6075 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6076 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 6077 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 6078 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6079 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6080 | Register temp = temps.AcquireW(); |
| 6081 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 6082 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6083 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6084 | // Jump to successors[0] if value == lower_bound. |
| 6085 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 6086 | int32_t last_index = 0; |
| 6087 | for (; num_entries - last_index > 2; last_index += 2) { |
| 6088 | __ Subs(temp, temp, Operand(2)); |
| 6089 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 6090 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 6091 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 6092 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 6093 | } |
| 6094 | if (num_entries - last_index == 2) { |
| 6095 | // The last missing case_value. |
| 6096 | __ Cmp(temp, Operand(1)); |
| 6097 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6098 | } |
| 6099 | |
| 6100 | // And the default for any other value. |
| 6101 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6102 | __ B(codegen_->GetLabelOf(default_block)); |
| 6103 | } |
| 6104 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 6105 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 6106 | |
| 6107 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 6108 | |
| 6109 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 6110 | // registers, we are free to block one. |
| 6111 | Register temp_w = temps.AcquireW(); |
| 6112 | Register index; |
| 6113 | // Remove the bias. |
| 6114 | if (lower_bound != 0) { |
| 6115 | index = temp_w; |
| 6116 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 6117 | } else { |
| 6118 | index = value_reg; |
| 6119 | } |
| 6120 | |
| 6121 | // Jump to default block if index is out of the range. |
| 6122 | __ Cmp(index, Operand(num_entries)); |
| 6123 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 6124 | |
| 6125 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 6126 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 6127 | // register pressure. |
| 6128 | Register table_base = temps.AcquireX(); |
| 6129 | // Load jump offset from the table. |
| 6130 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 6131 | Register jump_offset = temp_w; |
| 6132 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 6133 | |
| 6134 | // Jump to target block by branching to table_base(pc related) + offset. |
| 6135 | Register target_address = table_base; |
| 6136 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 6137 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6138 | } |
| 6139 | } |
| 6140 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6141 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 6142 | HInstruction* instruction, |
| 6143 | Location out, |
| 6144 | uint32_t offset, |
| 6145 | Location maybe_temp, |
| 6146 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6147 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6148 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6149 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6150 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6151 | if (kUseBakerReadBarrier) { |
| 6152 | // Load with fast path based Baker's read barrier. |
| 6153 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6154 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6155 | out, |
| 6156 | out_reg, |
| 6157 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6158 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6159 | /* needs_null_check */ false, |
| 6160 | /* use_load_acquire */ false); |
| 6161 | } else { |
| 6162 | // Load with slow path based read barrier. |
| 6163 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 6164 | // in the following move operation, as we will need it for the |
| 6165 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6166 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6167 | __ Mov(temp_reg, out_reg); |
| 6168 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6169 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6170 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 6171 | } |
| 6172 | } else { |
| 6173 | // Plain load with no read barrier. |
| 6174 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6175 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 6176 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6177 | } |
| 6178 | } |
| 6179 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6180 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 6181 | HInstruction* instruction, |
| 6182 | Location out, |
| 6183 | Location obj, |
| 6184 | uint32_t offset, |
| 6185 | Location maybe_temp, |
| 6186 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6187 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6188 | Register out_reg = RegisterFrom(out, type); |
| 6189 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6190 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6191 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6192 | if (kUseBakerReadBarrier) { |
| 6193 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6194 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6195 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6196 | out, |
| 6197 | obj_reg, |
| 6198 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6199 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6200 | /* needs_null_check */ false, |
| 6201 | /* use_load_acquire */ false); |
| 6202 | } else { |
| 6203 | // Load with slow path based read barrier. |
| 6204 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6205 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6206 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6207 | } |
| 6208 | } else { |
| 6209 | // Plain load with no read barrier. |
| 6210 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6211 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 6212 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 6213 | } |
| 6214 | } |
| 6215 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6216 | void CodeGeneratorARM64::GenerateGcRootFieldLoad( |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6217 | HInstruction* instruction, |
| 6218 | Location root, |
| 6219 | Register obj, |
| 6220 | uint32_t offset, |
| 6221 | vixl::aarch64::Label* fixup_label, |
| 6222 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6223 | DCHECK(fixup_label == nullptr || offset == 0u); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6224 | Register root_reg = RegisterFrom(root, DataType::Type::kReference); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6225 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6226 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6227 | if (kUseBakerReadBarrier) { |
| 6228 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6229 | // Baker's read barrier are used. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6230 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6231 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6232 | // the Marking Register) to decide whether we need to enter |
| 6233 | // the slow path to mark the GC root. |
| 6234 | // |
| 6235 | // We use shared thunks for the slow path; shared within the method |
| 6236 | // for JIT, across methods for AOT. That thunk checks the reference |
| 6237 | // and jumps to the entrypoint if needed. |
| 6238 | // |
| 6239 | // lr = &return_address; |
| 6240 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6241 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6242 | // goto gc_root_thunk<root_reg>(lr) |
| 6243 | // } |
| 6244 | // return_address: |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6245 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6246 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6247 | DCHECK(temps.IsAvailable(ip0)); |
| 6248 | DCHECK(temps.IsAvailable(ip1)); |
| 6249 | temps.Exclude(ip0, ip1); |
| 6250 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6251 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6252 | ExactAssemblyScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6253 | vixl::aarch64::Label return_address; |
| 6254 | __ adr(lr, &return_address); |
| 6255 | if (fixup_label != nullptr) { |
| 6256 | __ bind(fixup_label); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6257 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6258 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6259 | "GC root LDR must be 2 instruction (8B) before the return address label."); |
| 6260 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6261 | EmitBakerReadBarrierCbnz(custom_data); |
| 6262 | __ bind(&return_address); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6263 | } else { |
| 6264 | // GC root loaded through a slow path for read barriers other |
| 6265 | // than Baker's. |
| 6266 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6267 | if (fixup_label == nullptr) { |
| 6268 | __ Add(root_reg.X(), obj.X(), offset); |
| 6269 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6270 | EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6271 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6272 | // /* mirror::Object* */ root = root->Read() |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6273 | GenerateReadBarrierForRootSlow(instruction, root, root); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6274 | } |
| 6275 | } else { |
| 6276 | // Plain GC root load with no read barrier. |
| 6277 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6278 | if (fixup_label == nullptr) { |
| 6279 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6280 | } else { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6281 | EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6282 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6283 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6284 | // do not have to unpoison `root_reg` here. |
| 6285 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6286 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6287 | } |
| 6288 | |
| 6289 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6290 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6291 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6292 | uint32_t offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6293 | Location maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6294 | bool needs_null_check, |
| 6295 | bool use_load_acquire) { |
| 6296 | DCHECK(kEmitCompilerReadBarrier); |
| 6297 | DCHECK(kUseBakerReadBarrier); |
| 6298 | |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame^] | 6299 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6300 | // Marking Register) to decide whether we need to enter the slow |
| 6301 | // path to mark the reference. Then, in the slow path, check the |
| 6302 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6303 | // decide whether to mark `ref` or not. |
| 6304 | // |
| 6305 | // We use shared thunks for the slow path; shared within the method |
| 6306 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6307 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6308 | // it creates a fake dependency and returns to the LDR instruction. |
| 6309 | // |
| 6310 | // lr = &gray_return_address; |
| 6311 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6312 | // goto field_thunk<holder_reg, base_reg, use_load_acquire>(lr) |
| 6313 | // } |
| 6314 | // not_gray_return_address: |
| 6315 | // // Original reference load. If the offset is too large to fit |
| 6316 | // // into LDR, we use an adjusted base register here. |
| 6317 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 6318 | // gray_return_address: |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6319 | |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame^] | 6320 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6321 | Register base = obj; |
| 6322 | if (use_load_acquire) { |
| 6323 | DCHECK(maybe_temp.IsRegister()); |
| 6324 | base = WRegisterFrom(maybe_temp); |
| 6325 | __ Add(base, obj, offset); |
| 6326 | offset = 0u; |
| 6327 | } else if (offset >= kReferenceLoadMinFarOffset) { |
| 6328 | DCHECK(maybe_temp.IsRegister()); |
| 6329 | base = WRegisterFrom(maybe_temp); |
| 6330 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6331 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6332 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6333 | } |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame^] | 6334 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6335 | DCHECK(temps.IsAvailable(ip0)); |
| 6336 | DCHECK(temps.IsAvailable(ip1)); |
| 6337 | temps.Exclude(ip0, ip1); |
| 6338 | uint32_t custom_data = use_load_acquire |
| 6339 | ? EncodeBakerReadBarrierAcquireData(base.GetCode(), obj.GetCode()) |
| 6340 | : EncodeBakerReadBarrierFieldData(base.GetCode(), obj.GetCode()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6341 | |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame^] | 6342 | { |
| 6343 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6344 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6345 | vixl::aarch64::Label return_address; |
| 6346 | __ adr(lr, &return_address); |
| 6347 | EmitBakerReadBarrierCbnz(custom_data); |
| 6348 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6349 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6350 | " 2 instructions (8B) for heap poisoning."); |
| 6351 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 6352 | if (use_load_acquire) { |
| 6353 | DCHECK_EQ(offset, 0u); |
| 6354 | __ ldar(ref_reg, MemOperand(base.X())); |
| 6355 | } else { |
| 6356 | __ ldr(ref_reg, MemOperand(base.X(), offset)); |
| 6357 | } |
| 6358 | if (needs_null_check) { |
| 6359 | MaybeRecordImplicitNullCheck(instruction); |
| 6360 | } |
| 6361 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6362 | // macro instructions disallowed in ExactAssemblyScope. |
| 6363 | if (kPoisonHeapReferences) { |
| 6364 | __ neg(ref_reg, Operand(ref_reg)); |
| 6365 | } |
| 6366 | __ bind(&return_address); |
| 6367 | } |
| 6368 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6369 | } |
| 6370 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6371 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6372 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6373 | uint32_t data_offset, |
| 6374 | Location index, |
| 6375 | Register temp, |
| 6376 | bool needs_null_check) { |
| 6377 | DCHECK(kEmitCompilerReadBarrier); |
| 6378 | DCHECK(kUseBakerReadBarrier); |
| 6379 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6380 | static_assert( |
| 6381 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6382 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6383 | size_t scale_factor = DataType::SizeShift(DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6384 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6385 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6386 | // Marking Register) to decide whether we need to enter the slow |
| 6387 | // path to mark the reference. Then, in the slow path, check the |
| 6388 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6389 | // decide whether to mark `ref` or not. |
| 6390 | // |
| 6391 | // We use shared thunks for the slow path; shared within the method |
| 6392 | // for JIT, across methods for AOT. That thunk checks the holder |
| 6393 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 6394 | // it creates a fake dependency and returns to the LDR instruction. |
| 6395 | // |
| 6396 | // lr = &gray_return_address; |
| 6397 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6398 | // goto array_thunk<base_reg>(lr) |
| 6399 | // } |
| 6400 | // not_gray_return_address: |
| 6401 | // // Original reference load. If the offset is too large to fit |
| 6402 | // // into LDR, we use an adjusted base register here. |
| 6403 | // HeapReference<mirror::Object> reference = data[index]; |
| 6404 | // gray_return_address: |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6405 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6406 | DCHECK(index.IsValid()); |
| 6407 | Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 6408 | Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6409 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6410 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6411 | DCHECK(temps.IsAvailable(ip0)); |
| 6412 | DCHECK(temps.IsAvailable(ip1)); |
| 6413 | temps.Exclude(ip0, ip1); |
| 6414 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(temp.GetCode()); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6415 | |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6416 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
| 6417 | { |
| 6418 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 6419 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6420 | vixl::aarch64::Label return_address; |
| 6421 | __ adr(lr, &return_address); |
| 6422 | EmitBakerReadBarrierCbnz(custom_data); |
| 6423 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6424 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6425 | " 2 instructions (8B) for heap poisoning."); |
| 6426 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6427 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6428 | // Unpoison the reference explicitly if needed. MaybeUnpoisonHeapReference() uses |
| 6429 | // macro instructions disallowed in ExactAssemblyScope. |
| 6430 | if (kPoisonHeapReferences) { |
| 6431 | __ neg(ref_reg, Operand(ref_reg)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6432 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6433 | __ bind(&return_address); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6434 | } |
Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6435 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6436 | } |
| 6437 | |
| 6438 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6439 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6440 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6441 | uint32_t offset, |
| 6442 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6443 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6444 | Register temp, |
| 6445 | bool needs_null_check, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6446 | bool use_load_acquire) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6447 | DCHECK(kEmitCompilerReadBarrier); |
| 6448 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6449 | // If we are emitting an array load, we should not be using a |
| 6450 | // Load Acquire instruction. In other words: |
| 6451 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6452 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6453 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6454 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6455 | // Marking Register) to decide whether we need to enter the slow |
| 6456 | // path to mark the reference. Then, in the slow path, check the |
| 6457 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6458 | // decide whether to mark `ref` or not. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6459 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6460 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6461 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6462 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6463 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6464 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 6465 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6466 | // if (is_gray) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6467 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6468 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6469 | // } |
| 6470 | // } else { |
| 6471 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6472 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6473 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6474 | // Slow path marking the object `ref` when the GC is marking. The |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6475 | // entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6476 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6477 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierSlowPathARM64( |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6478 | instruction, |
| 6479 | ref, |
| 6480 | obj, |
| 6481 | offset, |
| 6482 | index, |
| 6483 | scale_factor, |
| 6484 | needs_null_check, |
| 6485 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6486 | temp); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6487 | AddSlowPath(slow_path); |
| 6488 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6489 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6490 | // Fast path: the GC is not marking: just load the reference. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6491 | GenerateRawReferenceLoad( |
| 6492 | instruction, ref, obj, offset, index, scale_factor, needs_null_check, use_load_acquire); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6493 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6494 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6495 | } |
| 6496 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6497 | void CodeGeneratorARM64::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 6498 | Location ref, |
| 6499 | Register obj, |
| 6500 | Location field_offset, |
| 6501 | Register temp, |
| 6502 | bool needs_null_check, |
| 6503 | bool use_load_acquire) { |
| 6504 | DCHECK(kEmitCompilerReadBarrier); |
| 6505 | DCHECK(kUseBakerReadBarrier); |
| 6506 | // If we are emitting an array load, we should not be using a |
| 6507 | // Load Acquire instruction. In other words: |
| 6508 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6509 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
| 6510 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6511 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6512 | // Marking Register) to decide whether we need to enter the slow |
| 6513 | // path to update the reference field within `obj`. Then, in the |
| 6514 | // slow path, check the gray bit in the lock word of the reference's |
| 6515 | // holder (`obj`) to decide whether to mark `ref` and update the |
| 6516 | // field or not. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6517 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6518 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6519 | // // Slow path. |
| 6520 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6521 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6522 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
| 6523 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6524 | // if (is_gray) { |
| 6525 | // old_ref = ref; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6526 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6527 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6528 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 6529 | // } |
| 6530 | // } |
| 6531 | |
| 6532 | // Slow path updating the object reference at address `obj + field_offset` |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6533 | // when the GC is marking. The entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6534 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6535 | new (GetScopedAllocator()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6536 | instruction, |
| 6537 | ref, |
| 6538 | obj, |
| 6539 | /* offset */ 0u, |
| 6540 | /* index */ field_offset, |
| 6541 | /* scale_factor */ 0u /* "times 1" */, |
| 6542 | needs_null_check, |
| 6543 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6544 | temp); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6545 | AddSlowPath(slow_path); |
| 6546 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6547 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6548 | // Fast path: the GC is not marking: nothing to do (the field is |
| 6549 | // up-to-date, and we don't need to load the reference). |
| 6550 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6551 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6552 | } |
| 6553 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6554 | void CodeGeneratorARM64::GenerateRawReferenceLoad(HInstruction* instruction, |
| 6555 | Location ref, |
| 6556 | Register obj, |
| 6557 | uint32_t offset, |
| 6558 | Location index, |
| 6559 | size_t scale_factor, |
| 6560 | bool needs_null_check, |
| 6561 | bool use_load_acquire) { |
| 6562 | DCHECK(obj.IsW()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6563 | DataType::Type type = DataType::Type::kReference; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6564 | Register ref_reg = RegisterFrom(ref, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6565 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6566 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 6567 | // that no pools are emitted between the load (macro) instruction |
| 6568 | // and MaybeRecordImplicitNullCheck. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6569 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6570 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6571 | // Load types involving an "index": ArrayGet, |
| 6572 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6573 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6574 | if (use_load_acquire) { |
| 6575 | // UnsafeGetObjectVolatile intrinsic case. |
| 6576 | // Register `index` is not an index in an object array, but an |
| 6577 | // offset to an object reference field within object `obj`. |
| 6578 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 6579 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 6580 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 6581 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6582 | DCHECK_EQ(offset, 0u); |
| 6583 | DCHECK_EQ(scale_factor, 0u); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6584 | DCHECK_EQ(needs_null_check, false); |
| 6585 | // /* HeapReference<mirror::Object> */ ref = *(obj + index) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6586 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 6587 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6588 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6589 | // ArrayGet and UnsafeGetObject and UnsafeCASObject intrinsics cases. |
| 6590 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6591 | if (index.IsConstant()) { |
Evgeny Astigeevich | f9e9054 | 2018-06-25 13:43:53 +0100 | [diff] [blame] | 6592 | uint32_t computed_offset = offset + (Int64FromLocation(index) << scale_factor); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6593 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6594 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6595 | if (needs_null_check) { |
| 6596 | MaybeRecordImplicitNullCheck(instruction); |
| 6597 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6598 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6599 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6600 | Register temp = temps.AcquireW(); |
| 6601 | __ Add(temp, obj, offset); |
| 6602 | { |
| 6603 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6604 | Load(type, ref_reg, HeapOperand(temp, XRegisterFrom(index), LSL, scale_factor)); |
| 6605 | if (needs_null_check) { |
| 6606 | MaybeRecordImplicitNullCheck(instruction); |
| 6607 | } |
| 6608 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6609 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6610 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6611 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6612 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6613 | MemOperand field = HeapOperand(obj, offset); |
| 6614 | if (use_load_acquire) { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6615 | // Implicit null checks are handled by CodeGeneratorARM64::LoadAcquire. |
| 6616 | LoadAcquire(instruction, ref_reg, field, needs_null_check); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6617 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6618 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6619 | Load(type, ref_reg, field); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6620 | if (needs_null_check) { |
| 6621 | MaybeRecordImplicitNullCheck(instruction); |
| 6622 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6623 | } |
| 6624 | } |
| 6625 | |
| 6626 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6627 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6628 | } |
| 6629 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6630 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6631 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6632 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6633 | // The following condition is a run-time one; it is executed after the |
| 6634 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6635 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6636 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6637 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6638 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6639 | } |
| 6640 | } |
| 6641 | } |
| 6642 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6643 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6644 | Location out, |
| 6645 | Location ref, |
| 6646 | Location obj, |
| 6647 | uint32_t offset, |
| 6648 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6649 | DCHECK(kEmitCompilerReadBarrier); |
| 6650 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6651 | // Insert a slow path based read barrier *after* the reference load. |
| 6652 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6653 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6654 | // reference will be carried out by the runtime within the slow |
| 6655 | // path. |
| 6656 | // |
| 6657 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6658 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6659 | // not used by the artReadBarrierSlow entry point. |
| 6660 | // |
| 6661 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6662 | SlowPathCodeARM64* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6663 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6664 | AddSlowPath(slow_path); |
| 6665 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6666 | __ B(slow_path->GetEntryLabel()); |
| 6667 | __ Bind(slow_path->GetExitLabel()); |
| 6668 | } |
| 6669 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6670 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6671 | Location out, |
| 6672 | Location ref, |
| 6673 | Location obj, |
| 6674 | uint32_t offset, |
| 6675 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6676 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6677 | // Baker's read barriers shall be handled by the fast path |
| 6678 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6679 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6680 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6681 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6682 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6683 | } else if (kPoisonHeapReferences) { |
| 6684 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6685 | } |
| 6686 | } |
| 6687 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6688 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6689 | Location out, |
| 6690 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6691 | DCHECK(kEmitCompilerReadBarrier); |
| 6692 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6693 | // Insert a slow path based read barrier *after* the GC root load. |
| 6694 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6695 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6696 | // not need to do anything special for this here. |
| 6697 | SlowPathCodeARM64* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6698 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6699 | AddSlowPath(slow_path); |
| 6700 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6701 | __ B(slow_path->GetEntryLabel()); |
| 6702 | __ Bind(slow_path->GetExitLabel()); |
| 6703 | } |
| 6704 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6705 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6706 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6707 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6708 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6709 | locations->SetOut(Location::RequiresRegister()); |
| 6710 | } |
| 6711 | |
| 6712 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6713 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6714 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6715 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6716 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6717 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6718 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6719 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6720 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6721 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6722 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6723 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6724 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6725 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6726 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6727 | } |
| 6728 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6729 | static void PatchJitRootUse(uint8_t* code, |
| 6730 | const uint8_t* roots_data, |
| 6731 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6732 | uint64_t index_in_table) { |
| 6733 | uint32_t literal_offset = literal->GetOffset(); |
| 6734 | uintptr_t address = |
| 6735 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6736 | uint8_t* data = code + literal_offset; |
| 6737 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6738 | } |
| 6739 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6740 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6741 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6742 | const StringReference& string_reference = entry.first; |
| 6743 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6744 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6745 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6746 | } |
| 6747 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6748 | const TypeReference& type_reference = entry.first; |
| 6749 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6750 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6751 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6752 | } |
| 6753 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6754 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6755 | #undef __ |
| 6756 | #undef QUICK_ENTRY_POINT |
| 6757 | |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6758 | #define __ assembler.GetVIXLAssembler()-> |
| 6759 | |
| 6760 | static void EmitGrayCheckAndFastPath(arm64::Arm64Assembler& assembler, |
| 6761 | vixl::aarch64::Register base_reg, |
| 6762 | vixl::aarch64::MemOperand& lock_word, |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6763 | vixl::aarch64::Label* slow_path, |
| 6764 | vixl::aarch64::Label* throw_npe = nullptr) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6765 | // Load the lock word containing the rb_state. |
| 6766 | __ Ldr(ip0.W(), lock_word); |
| 6767 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 6768 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 6769 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 6770 | __ Tbnz(ip0.W(), LockWord::kReadBarrierStateShift, slow_path); |
| 6771 | static_assert( |
| 6772 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET, |
| 6773 | "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] | 6774 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 6775 | if (throw_npe != nullptr) { |
| 6776 | __ Bind(throw_npe); |
| 6777 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6778 | // Adjust the return address back to the LDR (1 instruction; 2 for heap poisoning). |
| 6779 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6780 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6781 | " 2 instructions (8B) for heap poisoning."); |
| 6782 | __ Add(lr, lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6783 | // Introduce a dependency on the lock_word including rb_state, |
| 6784 | // to prevent load-load reordering, and without using |
| 6785 | // a memory barrier (which would be more expensive). |
| 6786 | __ Add(base_reg, base_reg, Operand(ip0, LSR, 32)); |
| 6787 | __ Br(lr); // And return back to the function. |
| 6788 | // Note: The fake dependency is unnecessary for the slow path. |
| 6789 | } |
| 6790 | |
| 6791 | // Load the read barrier introspection entrypoint in register `entrypoint`. |
| 6792 | static void LoadReadBarrierMarkIntrospectionEntrypoint(arm64::Arm64Assembler& assembler, |
| 6793 | vixl::aarch64::Register entrypoint) { |
| 6794 | // entrypoint = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6795 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6796 | const int32_t entry_point_offset = |
| 6797 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6798 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| 6799 | } |
| 6800 | |
| 6801 | void CodeGeneratorARM64::CompileBakerReadBarrierThunk(Arm64Assembler& assembler, |
| 6802 | uint32_t encoded_data, |
| 6803 | /*out*/ std::string* debug_name) { |
| 6804 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 6805 | switch (kind) { |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame^] | 6806 | case BakerReadBarrierKind::kField: |
| 6807 | case BakerReadBarrierKind::kAcquire: { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6808 | auto base_reg = |
| 6809 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6810 | CheckValidReg(base_reg.GetCode()); |
| 6811 | auto holder_reg = |
| 6812 | Register::GetXRegFromCode(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6813 | CheckValidReg(holder_reg.GetCode()); |
| 6814 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6815 | temps.Exclude(ip0, ip1); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6816 | // If base_reg differs from holder_reg, the offset was too large and we must have emitted |
| 6817 | // an explicit null check before the load. Otherwise, for implicit null checks, we need to |
| 6818 | // null-check the holder as we do not necessarily do that check before going to the thunk. |
| 6819 | vixl::aarch64::Label throw_npe_label; |
| 6820 | vixl::aarch64::Label* throw_npe = nullptr; |
| 6821 | if (GetCompilerOptions().GetImplicitNullChecks() && holder_reg.Is(base_reg)) { |
| 6822 | throw_npe = &throw_npe_label; |
| 6823 | __ Cbz(holder_reg.W(), throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6824 | } |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6825 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 6826 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 6827 | // to load the reference and call the entrypoint that performs further checks on the |
| 6828 | // reference and marks it if needed. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6829 | vixl::aarch64::Label slow_path; |
| 6830 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 6831 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, throw_npe); |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6832 | __ Bind(&slow_path); |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame^] | 6833 | if (kind == BakerReadBarrierKind::kField) { |
| 6834 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET); |
| 6835 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (immediate) unsigned offset. |
| 6836 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6837 | __ Ubfx(ip0.W(), ip0.W(), 10, 12); // Extract the offset. |
| 6838 | __ Ldr(ip0.W(), MemOperand(base_reg, ip0, LSL, 2)); // Load the reference. |
| 6839 | } else { |
| 6840 | DCHECK(kind == BakerReadBarrierKind::kAcquire); |
| 6841 | DCHECK(!base_reg.Is(holder_reg)); |
| 6842 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6843 | __ Ldar(ip0.W(), MemOperand(base_reg)); |
| 6844 | } |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6845 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 6846 | __ Br(ip1); // Jump to the entrypoint. |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6847 | break; |
| 6848 | } |
| 6849 | case BakerReadBarrierKind::kArray: { |
| 6850 | auto base_reg = |
| 6851 | Register::GetXRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6852 | CheckValidReg(base_reg.GetCode()); |
| 6853 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6854 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6855 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6856 | temps.Exclude(ip0, ip1); |
| 6857 | vixl::aarch64::Label slow_path; |
| 6858 | int32_t data_offset = |
| 6859 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 6860 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 6861 | DCHECK_LT(lock_word.GetOffset(), 0); |
| 6862 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path); |
| 6863 | __ Bind(&slow_path); |
| 6864 | MemOperand ldr_address(lr, BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| 6865 | __ Ldr(ip0.W(), ldr_address); // Load the LDR (register) unsigned offset. |
| 6866 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6867 | __ Ubfx(ip0, ip0, 16, 6); // Extract the index register, plus 32 (bit 21 is set). |
| 6868 | __ Bfi(ip1, ip0, 3, 6); // Insert ip0 to the entrypoint address to create |
| 6869 | // a switch case target based on the index register. |
| 6870 | __ Mov(ip0, base_reg); // Move the base register to ip0. |
| 6871 | __ Br(ip1); // Jump to the entrypoint's array switch case. |
| 6872 | break; |
| 6873 | } |
| 6874 | case BakerReadBarrierKind::kGcRoot: { |
| 6875 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 6876 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 6877 | // otherwise return the reference (or the extracted forwarding address). |
| 6878 | // There is no gray bit check for GC roots. |
| 6879 | auto root_reg = |
| 6880 | Register::GetWRegFromCode(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 6881 | CheckValidReg(root_reg.GetCode()); |
| 6882 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6883 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6884 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 6885 | temps.Exclude(ip0, ip1); |
| 6886 | vixl::aarch64::Label return_label, not_marked, forwarding_address; |
| 6887 | __ Cbz(root_reg, &return_label); |
| 6888 | MemOperand lock_word(root_reg.X(), mirror::Object::MonitorOffset().Int32Value()); |
| 6889 | __ Ldr(ip0.W(), lock_word); |
| 6890 | __ Tbz(ip0.W(), LockWord::kMarkBitStateShift, ¬_marked); |
| 6891 | __ Bind(&return_label); |
| 6892 | __ Br(lr); |
| 6893 | __ Bind(¬_marked); |
| 6894 | __ Tst(ip0.W(), Operand(ip0.W(), LSL, 1)); |
| 6895 | __ B(&forwarding_address, mi); |
| 6896 | LoadReadBarrierMarkIntrospectionEntrypoint(assembler, ip1); |
| 6897 | // Adjust the art_quick_read_barrier_mark_introspection address in IP1 to |
| 6898 | // art_quick_read_barrier_mark_introspection_gc_roots. |
| 6899 | __ Add(ip1, ip1, Operand(BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRYPOINT_OFFSET)); |
| 6900 | __ Mov(ip0.W(), root_reg); |
| 6901 | __ Br(ip1); |
| 6902 | __ Bind(&forwarding_address); |
| 6903 | __ Lsl(root_reg, ip0.W(), LockWord::kForwardingAddressShift); |
| 6904 | __ Br(lr); |
| 6905 | break; |
| 6906 | } |
| 6907 | default: |
| 6908 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 6909 | UNREACHABLE(); |
| 6910 | } |
| 6911 | |
Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 6912 | // For JIT, the slow path is considered part of the compiled method, |
| 6913 | // so JIT should pass null as `debug_name`. Tests may not have a runtime. |
| 6914 | DCHECK(Runtime::Current() == nullptr || |
| 6915 | !Runtime::Current()->UseJitCompilation() || |
| 6916 | debug_name == nullptr); |
| 6917 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6918 | std::ostringstream oss; |
| 6919 | oss << "BakerReadBarrierThunk"; |
| 6920 | switch (kind) { |
| 6921 | case BakerReadBarrierKind::kField: |
| 6922 | oss << "Field_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 6923 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 6924 | break; |
Vladimir Marko | 0ecac68 | 2018-08-07 10:40:38 +0100 | [diff] [blame^] | 6925 | case BakerReadBarrierKind::kAcquire: |
| 6926 | oss << "Acquire_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 6927 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 6928 | break; |
Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 6929 | case BakerReadBarrierKind::kArray: |
| 6930 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6931 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6932 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6933 | break; |
| 6934 | case BakerReadBarrierKind::kGcRoot: |
| 6935 | oss << "GcRoot_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 6936 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 6937 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 6938 | break; |
| 6939 | } |
| 6940 | *debug_name = oss.str(); |
| 6941 | } |
| 6942 | } |
| 6943 | |
| 6944 | #undef __ |
| 6945 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6946 | } // namespace arm64 |
| 6947 | } // namespace art |