Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm64.h" |
| 18 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 19 | #include "arch/arm64/asm_support_arm64.h" |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 20 | #include "arch/arm64/instruction_set_features_arm64.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 21 | #include "art_method.h" |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 22 | #include "base/bit_utils.h" |
| 23 | #include "base/bit_utils_iterator.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 24 | #include "class_table.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 25 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 26 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 27 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 28 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 29 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 30 | #include "heap_poisoning.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 31 | #include "intrinsics.h" |
| 32 | #include "intrinsics_arm64.h" |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 33 | #include "linker/arm64/relative_patcher_arm64.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 34 | #include "linker/linker_patch.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 35 | #include "lock_word.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 36 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 37 | #include "mirror/class-inl.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 38 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 39 | #include "thread.h" |
| 40 | #include "utils/arm64/assembler_arm64.h" |
| 41 | #include "utils/assembler.h" |
| 42 | #include "utils/stack_checks.h" |
| 43 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 44 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 45 | using vixl::ExactAssemblyScope; |
| 46 | using vixl::CodeBufferCheckScope; |
| 47 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 48 | |
| 49 | #ifdef __ |
| 50 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 51 | #endif |
| 52 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 53 | namespace art { |
| 54 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 55 | template<class MirrorType> |
| 56 | class GcRoot; |
| 57 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 58 | namespace arm64 { |
| 59 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 60 | using helpers::ARM64EncodableConstantOrRegister; |
| 61 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 62 | using helpers::CPURegisterFrom; |
| 63 | using helpers::DRegisterFrom; |
| 64 | using helpers::FPRegisterFrom; |
| 65 | using helpers::HeapOperand; |
| 66 | using helpers::HeapOperandFrom; |
| 67 | using helpers::InputCPURegisterAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 68 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 70 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 71 | using helpers::InputRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 72 | using helpers::Int64ConstantFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 73 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 74 | using helpers::LocationFrom; |
| 75 | using helpers::OperandFromMemOperand; |
| 76 | using helpers::OutputCPURegister; |
| 77 | using helpers::OutputFPRegister; |
| 78 | using helpers::OutputRegister; |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 79 | using helpers::QRegisterFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 80 | using helpers::RegisterFrom; |
| 81 | using helpers::StackOperandFrom; |
| 82 | using helpers::VIXLRegCodeFromART; |
| 83 | using helpers::WRegisterFrom; |
| 84 | using helpers::XRegisterFrom; |
| 85 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 86 | // The compare/jump sequence will generate about (1.5 * num_entries + 3) instructions. While jump |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 87 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 88 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 89 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 90 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 91 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 92 | // offset < 16KiB. For offsets >= 16KiB, the load shall be emitted as two or more instructions. |
| 93 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 94 | // the offset explicitly. |
| 95 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 96 | |
| 97 | // Flags controlling the use of link-time generated thunks for Baker read barriers. |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 98 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 99 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 100 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 101 | |
| 102 | // Some instructions have special requirements for a temporary, for example |
| 103 | // LoadClass/kBssEntry and LoadString/kBssEntry for Baker read barrier require |
| 104 | // temp that's not an R0 (to avoid an extra move) and Baker read barrier field |
| 105 | // loads with large offsets need a fixed register to limit the number of link-time |
| 106 | // thunks we generate. For these and similar cases, we want to reserve a specific |
| 107 | // register that's neither callee-save nor an argument register. We choose x15. |
| 108 | inline Location FixedTempLocation() { |
| 109 | return Location::RegisterLocation(x15.GetCode()); |
| 110 | } |
| 111 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 112 | inline Condition ARM64Condition(IfCondition cond) { |
| 113 | switch (cond) { |
| 114 | case kCondEQ: return eq; |
| 115 | case kCondNE: return ne; |
| 116 | case kCondLT: return lt; |
| 117 | case kCondLE: return le; |
| 118 | case kCondGT: return gt; |
| 119 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 120 | case kCondB: return lo; |
| 121 | case kCondBE: return ls; |
| 122 | case kCondA: return hi; |
| 123 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 124 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 125 | LOG(FATAL) << "Unreachable"; |
| 126 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 127 | } |
| 128 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 129 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 130 | // The ARM64 condition codes can express all the necessary branches, see the |
| 131 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 132 | // There is no dex instruction or HIR that would need the missing conditions |
| 133 | // "equal or unordered" or "not equal". |
| 134 | switch (cond) { |
| 135 | case kCondEQ: return eq; |
| 136 | case kCondNE: return ne /* unordered */; |
| 137 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 138 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 139 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 140 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 141 | default: |
| 142 | LOG(FATAL) << "UNREACHABLE"; |
| 143 | UNREACHABLE(); |
| 144 | } |
| 145 | } |
| 146 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 147 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 148 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 149 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 150 | // but we use the exact registers for clarity. |
| 151 | if (return_type == Primitive::kPrimFloat) { |
| 152 | return LocationFrom(s0); |
| 153 | } else if (return_type == Primitive::kPrimDouble) { |
| 154 | return LocationFrom(d0); |
| 155 | } else if (return_type == Primitive::kPrimLong) { |
| 156 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 157 | } else if (return_type == Primitive::kPrimVoid) { |
| 158 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 159 | } else { |
| 160 | return LocationFrom(w0); |
| 161 | } |
| 162 | } |
| 163 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 164 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 165 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 166 | } |
| 167 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 168 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 169 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 170 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 171 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 172 | // Calculate memory accessing operand for save/restore live registers. |
| 173 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 174 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 175 | int64_t spill_offset, |
| 176 | bool is_save) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 177 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 178 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 179 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 180 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 181 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 182 | codegen->GetNumberOfFloatingPointRegisters())); |
| 183 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 184 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 185 | unsigned v_reg_size = codegen->GetGraph()->HasSIMD() ? kQRegSize : kDRegSize; |
| 186 | CPURegList fp_list = CPURegList(CPURegister::kVRegister, v_reg_size, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 187 | |
| 188 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 189 | UseScratchRegisterScope temps(masm); |
| 190 | |
| 191 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 192 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 193 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 194 | int64_t reg_size = kXRegSizeInBytes; |
| 195 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 196 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 197 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 198 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 199 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 200 | // to compute the base address(float point registers spill base address). |
| 201 | Register new_base = temps.AcquireSameSizeAs(base); |
| 202 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 203 | base = new_base; |
| 204 | spill_offset = -core_spill_size; |
| 205 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 206 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 207 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 208 | } |
| 209 | |
| 210 | if (is_save) { |
| 211 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 212 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 213 | } else { |
| 214 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 215 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 220 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 221 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 222 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 223 | // If the register holds an object, update the stack mask. |
| 224 | if (locations->RegisterContainsObject(i)) { |
| 225 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 226 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 227 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 228 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 229 | saved_core_stack_offsets_[i] = stack_offset; |
| 230 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 231 | } |
| 232 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 233 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 234 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 235 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 236 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 237 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 238 | stack_offset += kDRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 239 | } |
| 240 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 241 | SaveRestoreLiveRegistersHelper(codegen, |
| 242 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 243 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 244 | } |
| 245 | |
| 246 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 247 | SaveRestoreLiveRegistersHelper(codegen, |
| 248 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 249 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 250 | } |
| 251 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 252 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 253 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 254 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 255 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 256 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 257 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 258 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 259 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 260 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 261 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 262 | // Live registers will be restored in the catch block if caught. |
| 263 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 264 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 265 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 266 | // move resolver. |
| 267 | InvokeRuntimeCallingConvention calling_convention; |
| 268 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 269 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 270 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 271 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 272 | ? kQuickThrowStringBounds |
| 273 | : kQuickThrowArrayBounds; |
| 274 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 275 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 276 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 277 | } |
| 278 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 279 | bool IsFatal() const OVERRIDE { return true; } |
| 280 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 281 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 282 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 283 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 284 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 285 | }; |
| 286 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 287 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 288 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 289 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 290 | |
| 291 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 292 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 293 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 294 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 295 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 298 | bool IsFatal() const OVERRIDE { return true; } |
| 299 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 300 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 301 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 302 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 303 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 304 | }; |
| 305 | |
| 306 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 307 | public: |
| 308 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 309 | HInstruction* at, |
| 310 | uint32_t dex_pc, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 311 | bool do_clinit, |
| 312 | vixl::aarch64::Register bss_entry_temp = vixl::aarch64::Register(), |
| 313 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr) |
| 314 | : SlowPathCodeARM64(at), |
| 315 | cls_(cls), |
| 316 | dex_pc_(dex_pc), |
| 317 | do_clinit_(do_clinit), |
| 318 | bss_entry_temp_(bss_entry_temp), |
| 319 | bss_entry_adrp_label_(bss_entry_adrp_label) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 320 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 321 | } |
| 322 | |
| 323 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 324 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 325 | Location out = locations->Out(); |
| 326 | constexpr bool call_saves_everything_except_r0_ip0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 327 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 328 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 329 | InvokeRuntimeCallingConvention calling_convention; |
| 330 | // For HLoadClass/kBssEntry/kSaveEverything, the page address of the entry is in a temp |
| 331 | // register, make sure it's not clobbered by the call or by saving/restoring registers. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 332 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 333 | bool is_load_class_bss_entry = |
| 334 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 335 | if (is_load_class_bss_entry) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 336 | DCHECK(bss_entry_temp_.IsValid()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 337 | DCHECK(!bss_entry_temp_.Is(calling_convention.GetRegisterAt(0))); |
| 338 | DCHECK( |
| 339 | !UseScratchRegisterScope(arm64_codegen->GetVIXLAssembler()).IsAvailable(bss_entry_temp_)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 342 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 343 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 344 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 345 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 346 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 347 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 348 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 349 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 350 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 351 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 352 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 353 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 354 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 355 | |
| 356 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 357 | if (out.IsValid()) { |
| 358 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 359 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 360 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 361 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 362 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 363 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 364 | if (is_load_class_bss_entry) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 365 | DCHECK(out.IsValid()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 366 | const DexFile& dex_file = cls_->GetDexFile(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 367 | if (call_saves_everything_except_r0_ip0) { |
| 368 | // The class entry page address was preserved in bss_entry_temp_ thanks to kSaveEverything. |
| 369 | } else { |
| 370 | // For non-Baker read barrier, we need to re-calculate the address of the class entry page. |
| 371 | bss_entry_adrp_label_ = arm64_codegen->NewBssEntryTypePatch(dex_file, type_index); |
| 372 | arm64_codegen->EmitAdrpPlaceholder(bss_entry_adrp_label_, bss_entry_temp_); |
| 373 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 374 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 375 | arm64_codegen->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label_); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 376 | { |
| 377 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 378 | __ Bind(strp_label); |
| 379 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 380 | MemOperand(bss_entry_temp_, /* offset placeholder */ 0)); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 381 | } |
| 382 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 383 | __ B(GetExitLabel()); |
| 384 | } |
| 385 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 386 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 387 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 388 | private: |
| 389 | // The class this slow path will load. |
| 390 | HLoadClass* const cls_; |
| 391 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 392 | // The dex PC of `at_`. |
| 393 | const uint32_t dex_pc_; |
| 394 | |
| 395 | // Whether to initialize the class. |
| 396 | const bool do_clinit_; |
| 397 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 398 | // For HLoadClass/kBssEntry, the temp register and the label of the ADRP where it was loaded. |
| 399 | vixl::aarch64::Register bss_entry_temp_; |
| 400 | vixl::aarch64::Label* bss_entry_adrp_label_; |
| 401 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 402 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 403 | }; |
| 404 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 405 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 406 | public: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 407 | LoadStringSlowPathARM64(HLoadString* instruction, Register temp, vixl::aarch64::Label* adrp_label) |
| 408 | : SlowPathCodeARM64(instruction), |
| 409 | temp_(temp), |
| 410 | adrp_label_(adrp_label) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 411 | |
| 412 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 413 | LocationSummary* locations = instruction_->GetLocations(); |
| 414 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 415 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 416 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 417 | InvokeRuntimeCallingConvention calling_convention; |
| 418 | // Make sure `temp_` is not clobbered by the call or by saving/restoring registers. |
| 419 | DCHECK(temp_.IsValid()); |
| 420 | DCHECK(!temp_.Is(calling_convention.GetRegisterAt(0))); |
| 421 | DCHECK(!UseScratchRegisterScope(arm64_codegen->GetVIXLAssembler()).IsAvailable(temp_)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 422 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 423 | __ Bind(GetEntryLabel()); |
| 424 | SaveLiveRegisters(codegen, locations); |
| 425 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 426 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 427 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 428 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 429 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 430 | Primitive::Type type = instruction_->GetType(); |
| 431 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 432 | |
| 433 | RestoreLiveRegisters(codegen, locations); |
| 434 | |
| 435 | // Store the resolved String to the BSS entry. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 436 | const DexFile& dex_file = instruction_->AsLoadString()->GetDexFile(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 437 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 438 | // The string entry page address was preserved in temp_ thanks to kSaveEverything. |
| 439 | } else { |
| 440 | // For non-Baker read barrier, we need to re-calculate the address of the string entry page. |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 441 | adrp_label_ = arm64_codegen->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 442 | arm64_codegen->EmitAdrpPlaceholder(adrp_label_, temp_); |
| 443 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 444 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 445 | arm64_codegen->NewStringBssEntryPatch(dex_file, string_index, adrp_label_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 446 | { |
| 447 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 448 | __ Bind(strp_label); |
| 449 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 450 | MemOperand(temp_, /* offset placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | __ B(GetExitLabel()); |
| 454 | } |
| 455 | |
| 456 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 457 | |
| 458 | private: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 459 | const Register temp_; |
| 460 | vixl::aarch64::Label* adrp_label_; |
| 461 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 462 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 463 | }; |
| 464 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 465 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 466 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 467 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 468 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 469 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 470 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 471 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 472 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 473 | // Live registers will be restored in the catch block if caught. |
| 474 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 475 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 476 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 477 | instruction_, |
| 478 | instruction_->GetDexPc(), |
| 479 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 480 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 481 | } |
| 482 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 483 | bool IsFatal() const OVERRIDE { return true; } |
| 484 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 485 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 486 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 487 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 488 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 489 | }; |
| 490 | |
| 491 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 492 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 493 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 494 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 495 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 496 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 497 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 498 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 499 | __ Bind(GetEntryLabel()); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 500 | SaveLiveRegisters(codegen, locations); // Only saves live 128-bit regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 501 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 502 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 503 | RestoreLiveRegisters(codegen, locations); // Only restores live 128-bit regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 504 | if (successor_ == nullptr) { |
| 505 | __ B(GetReturnLabel()); |
| 506 | } else { |
| 507 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 508 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 509 | } |
| 510 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 511 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 512 | DCHECK(successor_ == nullptr); |
| 513 | return &return_label_; |
| 514 | } |
| 515 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 516 | HBasicBlock* GetSuccessor() const { |
| 517 | return successor_; |
| 518 | } |
| 519 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 520 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 521 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 522 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 523 | // If not null, the block to branch to after the suspend check. |
| 524 | HBasicBlock* const successor_; |
| 525 | |
| 526 | // 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] | 527 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 528 | |
| 529 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 530 | }; |
| 531 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 532 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 533 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 534 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 535 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 536 | |
| 537 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 538 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 539 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 540 | DCHECK(instruction_->IsCheckCast() |
| 541 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 542 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 543 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 544 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 545 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 546 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 547 | if (!is_fatal_) { |
| 548 | SaveLiveRegisters(codegen, locations); |
| 549 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 550 | |
| 551 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 552 | // move resolver. |
| 553 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 554 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 555 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 556 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 557 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 558 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 559 | Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 560 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 561 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 562 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 563 | Primitive::Type ret_type = instruction_->GetType(); |
| 564 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 565 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 566 | } else { |
| 567 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 568 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 569 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 572 | if (!is_fatal_) { |
| 573 | RestoreLiveRegisters(codegen, locations); |
| 574 | __ B(GetExitLabel()); |
| 575 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 578 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 579 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 580 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 581 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 582 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 583 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 584 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 585 | }; |
| 586 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 587 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 588 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 589 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 590 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 591 | |
| 592 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 593 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 594 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 595 | LocationSummary* locations = instruction_->GetLocations(); |
| 596 | SaveLiveRegisters(codegen, locations); |
| 597 | InvokeRuntimeCallingConvention calling_convention; |
| 598 | __ Mov(calling_convention.GetRegisterAt(0), |
| 599 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 600 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 601 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 604 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 605 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 606 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 607 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 608 | }; |
| 609 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 610 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 611 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 612 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 613 | |
| 614 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 615 | LocationSummary* locations = instruction_->GetLocations(); |
| 616 | __ Bind(GetEntryLabel()); |
| 617 | SaveLiveRegisters(codegen, locations); |
| 618 | |
| 619 | InvokeRuntimeCallingConvention calling_convention; |
| 620 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 621 | parallel_move.AddMove( |
| 622 | locations->InAt(0), |
| 623 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 624 | Primitive::kPrimNot, |
| 625 | nullptr); |
| 626 | parallel_move.AddMove( |
| 627 | locations->InAt(1), |
| 628 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 629 | Primitive::kPrimInt, |
| 630 | nullptr); |
| 631 | parallel_move.AddMove( |
| 632 | locations->InAt(2), |
| 633 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 634 | Primitive::kPrimNot, |
| 635 | nullptr); |
| 636 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 637 | |
| 638 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 639 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 640 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 641 | RestoreLiveRegisters(codegen, locations); |
| 642 | __ B(GetExitLabel()); |
| 643 | } |
| 644 | |
| 645 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 646 | |
| 647 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 648 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 649 | }; |
| 650 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 651 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 652 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 653 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 654 | |
| 655 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 656 | // 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] | 657 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 658 | num_entries * sizeof(int32_t), |
| 659 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 660 | |
| 661 | __ Bind(&table_start_); |
| 662 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 663 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 664 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 665 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 666 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 667 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 668 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 669 | Literal<int32_t> literal(jump_offset); |
| 670 | __ place(&literal); |
| 671 | } |
| 672 | } |
| 673 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 674 | // Abstract base class for read barrier slow paths marking a reference |
| 675 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 676 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 677 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 678 | // barrier marking runtime entry point to be invoked or an empty |
| 679 | // location; in the latter case, the read barrier marking runtime |
| 680 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 681 | class ReadBarrierMarkSlowPathBaseARM64 : public SlowPathCodeARM64 { |
| 682 | protected: |
| 683 | ReadBarrierMarkSlowPathBaseARM64(HInstruction* instruction, Location ref, Location entrypoint) |
| 684 | : SlowPathCodeARM64(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 685 | DCHECK(kEmitCompilerReadBarrier); |
| 686 | } |
| 687 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 688 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM64"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 689 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 690 | // Generate assembly code calling the read barrier marking runtime |
| 691 | // entry point (ReadBarrierMarkRegX). |
| 692 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 693 | // No need to save live registers; it's taken care of by the |
| 694 | // entrypoint. Also, there is no need to update the stack mask, |
| 695 | // as this runtime call will not trigger a garbage collection. |
| 696 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 697 | DCHECK_NE(ref_.reg(), LR); |
| 698 | DCHECK_NE(ref_.reg(), WSP); |
| 699 | DCHECK_NE(ref_.reg(), WZR); |
| 700 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 701 | // as a temporary, it cannot be the entry point's input/output. |
| 702 | DCHECK_NE(ref_.reg(), IP0); |
| 703 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 704 | // "Compact" slow path, saving two moves. |
| 705 | // |
| 706 | // Instead of using the standard runtime calling convention (input |
| 707 | // and output in W0): |
| 708 | // |
| 709 | // W0 <- ref |
| 710 | // W0 <- ReadBarrierMark(W0) |
| 711 | // ref <- W0 |
| 712 | // |
| 713 | // we just use rX (the register containing `ref`) as input and output |
| 714 | // of a dedicated entrypoint: |
| 715 | // |
| 716 | // rX <- ReadBarrierMarkRegX(rX) |
| 717 | // |
| 718 | if (entrypoint_.IsValid()) { |
| 719 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 720 | __ Blr(XRegisterFrom(entrypoint_)); |
| 721 | } else { |
| 722 | // Entrypoint is not already loaded, load from the thread. |
| 723 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 724 | Thread::ReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 725 | // This runtime call does not require a stack map. |
| 726 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | // The location (register) of the marked object reference. |
| 731 | const Location ref_; |
| 732 | |
| 733 | // The location of the entrypoint if it is already loaded. |
| 734 | const Location entrypoint_; |
| 735 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 736 | private: |
| 737 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM64); |
| 738 | }; |
| 739 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 740 | // Slow path marking an object reference `ref` during a read |
| 741 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 742 | // reference does not get updated by this slow path after marking. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 743 | // |
| 744 | // This means that after the execution of this slow path, `ref` will |
| 745 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 746 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 747 | // probably still be a from-space reference (unless it gets updated by |
| 748 | // another thread, or if another thread installed another object |
| 749 | // reference (different from `ref`) in `obj.field`). |
| 750 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 751 | // Argument `entrypoint` must be a register location holding the read |
| 752 | // barrier marking runtime entry point to be invoked or an empty |
| 753 | // location; in the latter case, the read barrier marking runtime |
| 754 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 755 | class ReadBarrierMarkSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 756 | public: |
| 757 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 758 | Location ref, |
| 759 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 760 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 761 | DCHECK(kEmitCompilerReadBarrier); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 765 | |
| 766 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 767 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 768 | DCHECK(locations->CanCall()); |
| 769 | DCHECK(ref_.IsRegister()) << ref_; |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 770 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 771 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 772 | << "Unexpected instruction in read barrier marking slow path: " |
| 773 | << instruction_->DebugName(); |
| 774 | |
| 775 | __ Bind(GetEntryLabel()); |
| 776 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 777 | __ B(GetExitLabel()); |
| 778 | } |
| 779 | |
| 780 | private: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 781 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 782 | }; |
| 783 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 784 | // Slow path loading `obj`'s lock word, loading a reference from |
| 785 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 786 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 787 | // read barrier). The field `obj.field` in the object `obj` holding |
| 788 | // this reference does not get updated by this slow path after marking |
| 789 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 790 | // below for that). |
| 791 | // |
| 792 | // This means that after the execution of this slow path, `ref` will |
| 793 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 794 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 795 | // probably still be a from-space reference (unless it gets updated by |
| 796 | // another thread, or if another thread installed another object |
| 797 | // reference (different from `ref`) in `obj.field`). |
| 798 | // |
| 799 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 800 | // barrier marking runtime entry point to be invoked or an empty |
| 801 | // location; in the latter case, the read barrier marking runtime |
| 802 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 803 | class LoadReferenceWithBakerReadBarrierSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
| 804 | public: |
| 805 | LoadReferenceWithBakerReadBarrierSlowPathARM64(HInstruction* instruction, |
| 806 | Location ref, |
| 807 | Register obj, |
| 808 | uint32_t offset, |
| 809 | Location index, |
| 810 | size_t scale_factor, |
| 811 | bool needs_null_check, |
| 812 | bool use_load_acquire, |
| 813 | Register temp, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 814 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 815 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
| 816 | obj_(obj), |
| 817 | offset_(offset), |
| 818 | index_(index), |
| 819 | scale_factor_(scale_factor), |
| 820 | needs_null_check_(needs_null_check), |
| 821 | use_load_acquire_(use_load_acquire), |
| 822 | temp_(temp) { |
| 823 | DCHECK(kEmitCompilerReadBarrier); |
| 824 | DCHECK(kUseBakerReadBarrier); |
| 825 | } |
| 826 | |
| 827 | const char* GetDescription() const OVERRIDE { |
| 828 | return "LoadReferenceWithBakerReadBarrierSlowPathARM64"; |
| 829 | } |
| 830 | |
| 831 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 832 | LocationSummary* locations = instruction_->GetLocations(); |
| 833 | DCHECK(locations->CanCall()); |
| 834 | DCHECK(ref_.IsRegister()) << ref_; |
| 835 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 836 | DCHECK(obj_.IsW()); |
| 837 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 838 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 839 | instruction_->IsStaticFieldGet() || |
| 840 | instruction_->IsArrayGet() || |
| 841 | instruction_->IsArraySet() || |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 842 | instruction_->IsInstanceOf() || |
| 843 | instruction_->IsCheckCast() || |
| 844 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 845 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 846 | << "Unexpected instruction in read barrier marking slow path: " |
| 847 | << instruction_->DebugName(); |
| 848 | // The read barrier instrumentation of object ArrayGet |
| 849 | // instructions does not support the HIntermediateAddress |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 850 | // instruction. |
| 851 | DCHECK(!(instruction_->IsArrayGet() && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 852 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 853 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 854 | // Temporary register `temp_`, used to store the lock word, must |
| 855 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 856 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 857 | // need the lock word to still be in `temp_` after the reference |
| 858 | // load. |
| 859 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 860 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
| 861 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 862 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 863 | |
| 864 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 865 | // inserted after the original load. However, in fast path based |
| 866 | // Baker's read barriers, we need to perform the load of |
| 867 | // mirror::Object::monitor_ *before* the original reference load. |
| 868 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 869 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 870 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 871 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 872 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 873 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 874 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 875 | // if (is_gray) { |
| 876 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 877 | // } |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 878 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 879 | // Note: the original implementation in ReadBarrier::Barrier is |
| 880 | // slightly more complex as it performs additional checks that we do |
| 881 | // not do here for performance reasons. |
| 882 | |
| 883 | // /* int32_t */ monitor = obj->monitor_ |
| 884 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 885 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 886 | if (needs_null_check_) { |
| 887 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 888 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 889 | // /* LockWord */ lock_word = LockWord(monitor) |
| 890 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 891 | "art::LockWord and int32_t have different sizes."); |
| 892 | |
| 893 | // Introduce a dependency on the lock_word including rb_state, |
| 894 | // to prevent load-load reordering, and without using |
| 895 | // a memory barrier (which would be more expensive). |
| 896 | // `obj` is unchanged by this operation, but its value now depends |
| 897 | // on `temp`. |
| 898 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 899 | |
| 900 | // The actual reference load. |
| 901 | // A possible implicit null check has already been handled above. |
| 902 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 903 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 904 | ref_, |
| 905 | obj_, |
| 906 | offset_, |
| 907 | index_, |
| 908 | scale_factor_, |
| 909 | /* needs_null_check */ false, |
| 910 | use_load_acquire_); |
| 911 | |
| 912 | // Mark the object `ref` when `obj` is gray. |
| 913 | // |
| 914 | // if (rb_state == ReadBarrier::GrayState()) |
| 915 | // ref = ReadBarrier::Mark(ref); |
| 916 | // |
| 917 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 918 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 919 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 920 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 921 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 922 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 923 | __ B(GetExitLabel()); |
| 924 | } |
| 925 | |
| 926 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 927 | // The register containing the object holding the marked object reference field. |
| 928 | Register obj_; |
| 929 | // The offset, index and scale factor to access the reference in `obj_`. |
| 930 | uint32_t offset_; |
| 931 | Location index_; |
| 932 | size_t scale_factor_; |
| 933 | // Is a null check required? |
| 934 | bool needs_null_check_; |
| 935 | // Should this reference load use Load-Acquire semantics? |
| 936 | bool use_load_acquire_; |
| 937 | // A temporary register used to hold the lock word of `obj_`. |
| 938 | Register temp_; |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 939 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 940 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM64); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 941 | }; |
| 942 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 943 | // Slow path loading `obj`'s lock word, loading a reference from |
| 944 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 945 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 946 | // read barrier). If needed, this slow path also atomically updates |
| 947 | // the field `obj.field` in the object `obj` holding this reference |
| 948 | // after marking (contrary to |
| 949 | // LoadReferenceWithBakerReadBarrierSlowPathARM64 above, which never |
| 950 | // tries to update `obj.field`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 951 | // |
| 952 | // This means that after the execution of this slow path, both `ref` |
| 953 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 954 | // hold the same to-space reference (unless another thread installed |
| 955 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 956 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 957 | // Argument `entrypoint` must be a register location holding the read |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 958 | // barrier marking runtime entry point to be invoked or an empty |
| 959 | // location; in the latter case, the read barrier marking runtime |
| 960 | // entry point will be loaded by the slow path code itself. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 961 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 962 | : public ReadBarrierMarkSlowPathBaseARM64 { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 963 | public: |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 964 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 965 | HInstruction* instruction, |
| 966 | Location ref, |
| 967 | Register obj, |
| 968 | uint32_t offset, |
| 969 | Location index, |
| 970 | size_t scale_factor, |
| 971 | bool needs_null_check, |
| 972 | bool use_load_acquire, |
| 973 | Register temp, |
| 974 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 975 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 976 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 977 | offset_(offset), |
| 978 | index_(index), |
| 979 | scale_factor_(scale_factor), |
| 980 | needs_null_check_(needs_null_check), |
| 981 | use_load_acquire_(use_load_acquire), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 982 | temp_(temp) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 983 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 984 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 988 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64"; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 992 | LocationSummary* locations = instruction_->GetLocations(); |
| 993 | Register ref_reg = WRegisterFrom(ref_); |
| 994 | DCHECK(locations->CanCall()); |
| 995 | DCHECK(ref_.IsRegister()) << ref_; |
| 996 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 997 | DCHECK(obj_.IsW()); |
| 998 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
| 999 | |
| 1000 | // 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] | 1001 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 1002 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 1003 | << instruction_->DebugName(); |
| 1004 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1005 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1006 | DCHECK_EQ(offset_, 0u); |
| 1007 | DCHECK_EQ(scale_factor_, 0u); |
| 1008 | DCHECK_EQ(use_load_acquire_, false); |
| 1009 | // The location of the offset of the marked reference field within `obj_`. |
| 1010 | Location field_offset = index_; |
| 1011 | DCHECK(field_offset.IsRegister()) << field_offset; |
| 1012 | |
| 1013 | // Temporary register `temp_`, used to store the lock word, must |
| 1014 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 1015 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 1016 | // need the lock word to still be in `temp_` after the reference |
| 1017 | // load. |
| 1018 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1019 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1020 | |
| 1021 | __ Bind(GetEntryLabel()); |
| 1022 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 1023 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM64's: |
| 1024 | // |
| 1025 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 1026 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 1027 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 1028 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 1029 | // if (is_gray) { |
| 1030 | // old_ref = ref; |
| 1031 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 1032 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1033 | // } |
| 1034 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1035 | // /* int32_t */ monitor = obj->monitor_ |
| 1036 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1037 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 1038 | if (needs_null_check_) { |
| 1039 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1040 | } |
| 1041 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1042 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1043 | "art::LockWord and int32_t have different sizes."); |
| 1044 | |
| 1045 | // Introduce a dependency on the lock_word including rb_state, |
| 1046 | // to prevent load-load reordering, and without using |
| 1047 | // a memory barrier (which would be more expensive). |
| 1048 | // `obj` is unchanged by this operation, but its value now depends |
| 1049 | // on `temp`. |
| 1050 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 1051 | |
| 1052 | // The actual reference load. |
| 1053 | // A possible implicit null check has already been handled above. |
| 1054 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1055 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 1056 | ref_, |
| 1057 | obj_, |
| 1058 | offset_, |
| 1059 | index_, |
| 1060 | scale_factor_, |
| 1061 | /* needs_null_check */ false, |
| 1062 | use_load_acquire_); |
| 1063 | |
| 1064 | // Mark the object `ref` when `obj` is gray. |
| 1065 | // |
| 1066 | // if (rb_state == ReadBarrier::GrayState()) |
| 1067 | // ref = ReadBarrier::Mark(ref); |
| 1068 | // |
| 1069 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 1070 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1071 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1072 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 1073 | |
| 1074 | // Save the old value of the reference before marking it. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1075 | // Note that we cannot use IP to save the old reference, as IP is |
| 1076 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1077 | // need the old reference after the call to that entry point. |
| 1078 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1079 | __ Mov(temp_.W(), ref_reg); |
| 1080 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1081 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1082 | |
| 1083 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1084 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1085 | // |
| 1086 | // Note that this field could also hold a different object, if |
| 1087 | // another thread had concurrently changed it. In that case, the |
| 1088 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 1089 | // (CAS) operation below would abort the CAS, leaving the field |
| 1090 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1091 | __ Cmp(temp_.W(), ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1092 | __ B(eq, GetExitLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1093 | |
| 1094 | // Update the the holder's field atomically. This may fail if |
| 1095 | // mutator updates before us, but it's OK. This is achieved |
| 1096 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1097 | // memory synchronization ordering, where the expected value is |
| 1098 | // the old reference and the desired value is the new reference. |
| 1099 | |
| 1100 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 1101 | UseScratchRegisterScope temps(masm); |
| 1102 | |
| 1103 | // Convenience aliases. |
| 1104 | Register base = obj_.W(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1105 | Register offset = XRegisterFrom(field_offset); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1106 | Register expected = temp_.W(); |
| 1107 | Register value = ref_reg; |
| 1108 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1109 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 1110 | |
| 1111 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1112 | |
| 1113 | if (kPoisonHeapReferences) { |
| 1114 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1115 | if (value.Is(expected)) { |
| 1116 | // Do not poison `value`, as it is the same register as |
| 1117 | // `expected`, which has just been poisoned. |
| 1118 | } else { |
| 1119 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | // do { |
| 1124 | // tmp_value = [tmp_ptr] - expected; |
| 1125 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1126 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1127 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1128 | __ Bind(&loop_head); |
| 1129 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 1130 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1131 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1132 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 1133 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1134 | __ B(&exit_loop); |
| 1135 | __ Bind(&comparison_failed); |
| 1136 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1137 | __ Bind(&exit_loop); |
| 1138 | |
| 1139 | if (kPoisonHeapReferences) { |
| 1140 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1141 | if (value.Is(expected)) { |
| 1142 | // Do not unpoison `value`, as it is the same register as |
| 1143 | // `expected`, which has just been unpoisoned. |
| 1144 | } else { |
| 1145 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1146 | } |
| 1147 | } |
| 1148 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1149 | __ B(GetExitLabel()); |
| 1150 | } |
| 1151 | |
| 1152 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1153 | // The register containing the object holding the marked object reference field. |
| 1154 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1155 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1156 | uint32_t offset_; |
| 1157 | Location index_; |
| 1158 | size_t scale_factor_; |
| 1159 | // Is a null check required? |
| 1160 | bool needs_null_check_; |
| 1161 | // Should this reference load use Load-Acquire semantics? |
| 1162 | bool use_load_acquire_; |
| 1163 | // A temporary register used to hold the lock word of `obj_`; and |
| 1164 | // also to hold the original reference value, when the reference is |
| 1165 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1166 | const Register temp_; |
| 1167 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1168 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1169 | }; |
| 1170 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1171 | // Slow path generating a read barrier for a heap reference. |
| 1172 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 1173 | public: |
| 1174 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 1175 | Location out, |
| 1176 | Location ref, |
| 1177 | Location obj, |
| 1178 | uint32_t offset, |
| 1179 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1180 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1181 | out_(out), |
| 1182 | ref_(ref), |
| 1183 | obj_(obj), |
| 1184 | offset_(offset), |
| 1185 | index_(index) { |
| 1186 | DCHECK(kEmitCompilerReadBarrier); |
| 1187 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1188 | // has been overwritten by (or after) the heap object reference load |
| 1189 | // to be instrumented, e.g.: |
| 1190 | // |
| 1191 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1192 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1193 | // |
| 1194 | // In that case, we have lost the information about the original |
| 1195 | // object, and the emitted read barrier cannot work properly. |
| 1196 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1197 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1198 | } |
| 1199 | |
| 1200 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1201 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1202 | LocationSummary* locations = instruction_->GetLocations(); |
| 1203 | Primitive::Type type = Primitive::kPrimNot; |
| 1204 | DCHECK(locations->CanCall()); |
| 1205 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1206 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1207 | instruction_->IsStaticFieldGet() || |
| 1208 | instruction_->IsArrayGet() || |
| 1209 | instruction_->IsInstanceOf() || |
| 1210 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1211 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1212 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1213 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1214 | // The read barrier instrumentation of object ArrayGet |
| 1215 | // instructions does not support the HIntermediateAddress |
| 1216 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1217 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1218 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1219 | |
| 1220 | __ Bind(GetEntryLabel()); |
| 1221 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1222 | SaveLiveRegisters(codegen, locations); |
| 1223 | |
| 1224 | // We may have to change the index's value, but as `index_` is a |
| 1225 | // constant member (like other "inputs" of this slow path), |
| 1226 | // introduce a copy of it, `index`. |
| 1227 | Location index = index_; |
| 1228 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1229 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1230 | if (instruction_->IsArrayGet()) { |
| 1231 | // Compute the actual memory offset and store it in `index`. |
| 1232 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 1233 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 1234 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 1235 | // We are about to change the value of `index_reg` (see the |
| 1236 | // calls to vixl::MacroAssembler::Lsl and |
| 1237 | // vixl::MacroAssembler::Mov below), but it has |
| 1238 | // not been saved by the previous call to |
| 1239 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1240 | // callee-save register -- |
| 1241 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1242 | // callee-save registers, as it has been designed with the |
| 1243 | // assumption that callee-save registers are supposed to be |
| 1244 | // handled by the called function. So, as a callee-save |
| 1245 | // register, `index_reg` _would_ eventually be saved onto |
| 1246 | // the stack, but it would be too late: we would have |
| 1247 | // changed its value earlier. Therefore, we manually save |
| 1248 | // it here into another freely available register, |
| 1249 | // `free_reg`, chosen of course among the caller-save |
| 1250 | // registers (as a callee-save `free_reg` register would |
| 1251 | // exhibit the same problem). |
| 1252 | // |
| 1253 | // Note we could have requested a temporary register from |
| 1254 | // the register allocator instead; but we prefer not to, as |
| 1255 | // this is a slow path, and we know we can find a |
| 1256 | // caller-save register that is available. |
| 1257 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1258 | __ Mov(free_reg.W(), index_reg); |
| 1259 | index_reg = free_reg; |
| 1260 | index = LocationFrom(index_reg); |
| 1261 | } else { |
| 1262 | // The initial register stored in `index_` has already been |
| 1263 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1264 | // (as it is not a callee-save register), so we can freely |
| 1265 | // use it. |
| 1266 | } |
| 1267 | // Shifting the index value contained in `index_reg` by the scale |
| 1268 | // factor (2) cannot overflow in practice, as the runtime is |
| 1269 | // unable to allocate object arrays with a size larger than |
| 1270 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1271 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 1272 | static_assert( |
| 1273 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1274 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1275 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1276 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1277 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1278 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1279 | // (as in the case of ArrayGet), as it is actually an offset |
| 1280 | // to an object field within an object. |
| 1281 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1282 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1283 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1284 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1285 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1286 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1287 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | // We're moving two or three locations to locations that could |
| 1292 | // overlap, so we need a parallel move resolver. |
| 1293 | InvokeRuntimeCallingConvention calling_convention; |
| 1294 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1295 | parallel_move.AddMove(ref_, |
| 1296 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1297 | type, |
| 1298 | nullptr); |
| 1299 | parallel_move.AddMove(obj_, |
| 1300 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1301 | type, |
| 1302 | nullptr); |
| 1303 | if (index.IsValid()) { |
| 1304 | parallel_move.AddMove(index, |
| 1305 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 1306 | Primitive::kPrimInt, |
| 1307 | nullptr); |
| 1308 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1309 | } else { |
| 1310 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1311 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1312 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1313 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1314 | instruction_, |
| 1315 | instruction_->GetDexPc(), |
| 1316 | this); |
| 1317 | CheckEntrypointTypes< |
| 1318 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1319 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1320 | |
| 1321 | RestoreLiveRegisters(codegen, locations); |
| 1322 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1323 | __ B(GetExitLabel()); |
| 1324 | } |
| 1325 | |
| 1326 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1327 | |
| 1328 | private: |
| 1329 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1330 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1331 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1332 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1333 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1334 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1335 | } |
| 1336 | } |
| 1337 | // We shall never fail to find a free caller-save register, as |
| 1338 | // there are more than two core caller-save registers on ARM64 |
| 1339 | // (meaning it is possible to find one which is different from |
| 1340 | // `ref` and `obj`). |
| 1341 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1342 | LOG(FATAL) << "Could not find a free register"; |
| 1343 | UNREACHABLE(); |
| 1344 | } |
| 1345 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1346 | const Location out_; |
| 1347 | const Location ref_; |
| 1348 | const Location obj_; |
| 1349 | const uint32_t offset_; |
| 1350 | // An additional location containing an index to an array. |
| 1351 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1352 | // UnsafeGetObjectVolatile intrinsics. |
| 1353 | const Location index_; |
| 1354 | |
| 1355 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1356 | }; |
| 1357 | |
| 1358 | // Slow path generating a read barrier for a GC root. |
| 1359 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1360 | public: |
| 1361 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1362 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1363 | DCHECK(kEmitCompilerReadBarrier); |
| 1364 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1365 | |
| 1366 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1367 | LocationSummary* locations = instruction_->GetLocations(); |
| 1368 | Primitive::Type type = Primitive::kPrimNot; |
| 1369 | DCHECK(locations->CanCall()); |
| 1370 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1371 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1372 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1373 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1374 | |
| 1375 | __ Bind(GetEntryLabel()); |
| 1376 | SaveLiveRegisters(codegen, locations); |
| 1377 | |
| 1378 | InvokeRuntimeCallingConvention calling_convention; |
| 1379 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1380 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1381 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1382 | // thus we need a 64-bit move here, and we cannot use |
| 1383 | // |
| 1384 | // arm64_codegen->MoveLocation( |
| 1385 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1386 | // root_, |
| 1387 | // type); |
| 1388 | // |
| 1389 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 1390 | // reference type (`Primitive::kPrimNot`). |
| 1391 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1392 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1393 | instruction_, |
| 1394 | instruction_->GetDexPc(), |
| 1395 | this); |
| 1396 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1397 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1398 | |
| 1399 | RestoreLiveRegisters(codegen, locations); |
| 1400 | __ B(GetExitLabel()); |
| 1401 | } |
| 1402 | |
| 1403 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1404 | |
| 1405 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1406 | const Location out_; |
| 1407 | const Location root_; |
| 1408 | |
| 1409 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1410 | }; |
| 1411 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1412 | #undef __ |
| 1413 | |
| 1414 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
| 1415 | Location next_location; |
| 1416 | if (type == Primitive::kPrimVoid) { |
| 1417 | LOG(FATAL) << "Unreachable type " << type; |
| 1418 | } |
| 1419 | |
| 1420 | if (Primitive::IsFloatingPointType(type) && |
| 1421 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1422 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1423 | } else if (!Primitive::IsFloatingPointType(type) && |
| 1424 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 1425 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1426 | } else { |
| 1427 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1428 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1429 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1430 | } |
| 1431 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1432 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1433 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1434 | return next_location; |
| 1435 | } |
| 1436 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1437 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1438 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1439 | } |
| 1440 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1441 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1442 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1443 | const CompilerOptions& compiler_options, |
| 1444 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1445 | : CodeGenerator(graph, |
| 1446 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1447 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1448 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1449 | callee_saved_core_registers.GetList(), |
| 1450 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1451 | compiler_options, |
| 1452 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1453 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1454 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1455 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1456 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1457 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1458 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1459 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1460 | uint32_literals_(std::less<uint32_t>(), |
| 1461 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1462 | uint64_literals_(std::less<uint64_t>(), |
| 1463 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1464 | pc_relative_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1465 | method_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1466 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1467 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1468 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1469 | string_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1470 | baker_read_barrier_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1471 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1472 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1473 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1474 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1475 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1476 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1477 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1478 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1479 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1480 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1481 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1482 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1483 | jump_table->EmitTable(this); |
| 1484 | } |
| 1485 | } |
| 1486 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1487 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1488 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1489 | // Ensure we emit the literal pool. |
| 1490 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1491 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1492 | CodeGenerator::Finalize(allocator); |
| 1493 | } |
| 1494 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1495 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1496 | // Note: There are 6 kinds of moves: |
| 1497 | // 1. constant -> GPR/FPR (non-cycle) |
| 1498 | // 2. constant -> stack (non-cycle) |
| 1499 | // 3. GPR/FPR -> GPR/FPR |
| 1500 | // 4. GPR/FPR -> stack |
| 1501 | // 5. stack -> GPR/FPR |
| 1502 | // 6. stack -> stack (non-cycle) |
| 1503 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1504 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1505 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1506 | // dependency. |
| 1507 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1508 | } |
| 1509 | |
| 1510 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1511 | vixl_temps_.Close(); |
| 1512 | } |
| 1513 | |
| 1514 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1515 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1516 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1517 | || kind == Location::kSIMDStackSlot); |
| 1518 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1519 | ? Location::kFpuRegister |
| 1520 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1521 | Location scratch = GetScratchLocation(kind); |
| 1522 | if (!scratch.Equals(Location::NoLocation())) { |
| 1523 | return scratch; |
| 1524 | } |
| 1525 | // Allocate from VIXL temp registers. |
| 1526 | if (kind == Location::kRegister) { |
| 1527 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1528 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1529 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1530 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1531 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1532 | : vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1533 | } |
| 1534 | AddScratchLocation(scratch); |
| 1535 | return scratch; |
| 1536 | } |
| 1537 | |
| 1538 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1539 | if (loc.IsRegister()) { |
| 1540 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1541 | } else { |
| 1542 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1543 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1544 | } |
| 1545 | RemoveScratchLocation(loc); |
| 1546 | } |
| 1547 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1548 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1549 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1550 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1553 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1554 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1555 | __ Bind(&frame_entry_label_); |
| 1556 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1557 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1558 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1559 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1560 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1561 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1562 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1563 | { |
| 1564 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1565 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1566 | kInstructionSize, |
| 1567 | CodeBufferCheckScope::kExactSize); |
| 1568 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1569 | RecordPcInfo(nullptr, 0); |
| 1570 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1571 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1572 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1573 | if (!HasEmptyFrame()) { |
| 1574 | int frame_size = GetFrameSize(); |
| 1575 | // Stack layout: |
| 1576 | // sp[frame_size - 8] : lr. |
| 1577 | // ... : other preserved core registers. |
| 1578 | // ... : other preserved fp registers. |
| 1579 | // ... : reserved frame space. |
| 1580 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1581 | |
| 1582 | // Save the current method if we need it. Note that we do not |
| 1583 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1584 | // in the SSA graph. |
| 1585 | if (RequiresCurrentMethod()) { |
| 1586 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1587 | } else { |
| 1588 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1589 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1590 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1591 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1592 | frame_size - GetCoreSpillSize()); |
| 1593 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1594 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1595 | |
| 1596 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1597 | // Initialize should_deoptimize flag to 0. |
| 1598 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1599 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1600 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1601 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 1602 | |
| 1603 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1607 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1608 | if (!HasEmptyFrame()) { |
| 1609 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1610 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1611 | frame_size - FrameEntrySpillSize()); |
| 1612 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1613 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1614 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1615 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1616 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1617 | __ Ret(); |
| 1618 | GetAssembler()->cfi().RestoreState(); |
| 1619 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1620 | } |
| 1621 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1622 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1623 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1624 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1625 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1626 | } |
| 1627 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1628 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1629 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1630 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1631 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1632 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1633 | } |
| 1634 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1635 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1636 | __ Bind(GetLabelOf(block)); |
| 1637 | } |
| 1638 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1639 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1640 | DCHECK(location.IsRegister()); |
| 1641 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1642 | } |
| 1643 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1644 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1645 | if (location.IsRegister()) { |
| 1646 | locations->AddTemp(location); |
| 1647 | } else { |
| 1648 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1649 | } |
| 1650 | } |
| 1651 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1652 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1653 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1654 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1655 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1656 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1657 | if (value_can_be_null) { |
| 1658 | __ Cbz(value, &done); |
| 1659 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1660 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1661 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1662 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1663 | if (value_can_be_null) { |
| 1664 | __ Bind(&done); |
| 1665 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1666 | } |
| 1667 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1668 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1669 | // Blocked core registers: |
| 1670 | // lr : Runtime reserved. |
| 1671 | // tr : Runtime reserved. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 1672 | // mr : Runtime reserved. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1673 | // ip1 : VIXL core temp. |
| 1674 | // ip0 : VIXL core temp. |
| 1675 | // |
| 1676 | // Blocked fp registers: |
| 1677 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1678 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1679 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1680 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1681 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1682 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1683 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1684 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1685 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1686 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1687 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1688 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1689 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1690 | // Stubs do not save callee-save floating point registers. If the graph |
| 1691 | // is debuggable, we need to deal with these registers differently. For |
| 1692 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1693 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1694 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1695 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1696 | } |
| 1697 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1698 | } |
| 1699 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1700 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1701 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1702 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1703 | return kArm64WordSize; |
| 1704 | } |
| 1705 | |
| 1706 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1707 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1708 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1709 | return kArm64WordSize; |
| 1710 | } |
| 1711 | |
| 1712 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1713 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1714 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1715 | return kArm64WordSize; |
| 1716 | } |
| 1717 | |
| 1718 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1719 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1720 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1721 | return kArm64WordSize; |
| 1722 | } |
| 1723 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1724 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1725 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1729 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1730 | } |
| 1731 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1732 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1733 | if (constant->IsIntConstant()) { |
| 1734 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1735 | } else if (constant->IsLongConstant()) { |
| 1736 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1737 | } else if (constant->IsNullConstant()) { |
| 1738 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1739 | } else if (constant->IsFloatConstant()) { |
| 1740 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1741 | } else { |
| 1742 | DCHECK(constant->IsDoubleConstant()); |
| 1743 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1744 | } |
| 1745 | } |
| 1746 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1747 | |
| 1748 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1749 | DCHECK(constant.IsConstant()); |
| 1750 | HConstant* cst = constant.GetConstant(); |
| 1751 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1752 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1753 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1754 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1755 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1756 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1757 | } |
| 1758 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1759 | // Allocate a scratch register from the VIXL pool, querying first |
| 1760 | // the floating-point register pool, and then the core register |
| 1761 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1762 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1763 | // using a different allocation strategy. |
| 1764 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1765 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1766 | int size_in_bits) { |
| 1767 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1768 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1769 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1770 | } |
| 1771 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1772 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1773 | Location source, |
| 1774 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1775 | if (source.Equals(destination)) { |
| 1776 | return; |
| 1777 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1778 | |
| 1779 | // A valid move can always be inferred from the destination and source |
| 1780 | // locations. When moving from and to a register, the argument type can be |
| 1781 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1782 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1783 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1784 | |
| 1785 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1786 | if (unspecified_type) { |
| 1787 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1788 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1789 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1790 | || src_cst->IsFloatConstant() |
| 1791 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1792 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1793 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1794 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1795 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1796 | // type is appropriate. Else the source is a register, and since the |
| 1797 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1798 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1799 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1800 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1801 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1802 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1803 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1804 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1805 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1806 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1807 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1808 | } else if (source.IsSIMDStackSlot()) { |
| 1809 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1810 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1811 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1812 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1813 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1814 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1815 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1816 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1817 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1818 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1819 | ? Primitive::kPrimLong |
| 1820 | : Primitive::kPrimInt; |
| 1821 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1822 | } |
| 1823 | } else { |
| 1824 | DCHECK(source.IsFpuRegister()); |
| 1825 | if (destination.IsRegister()) { |
| 1826 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1827 | ? Primitive::kPrimDouble |
| 1828 | : Primitive::kPrimFloat; |
| 1829 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1830 | } else { |
| 1831 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1832 | if (GetGraph()->HasSIMD()) { |
| 1833 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1834 | } else { |
| 1835 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1836 | } |
| 1837 | } |
| 1838 | } |
| 1839 | } else if (destination.IsSIMDStackSlot()) { |
| 1840 | if (source.IsFpuRegister()) { |
| 1841 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1842 | } else { |
| 1843 | DCHECK(source.IsSIMDStackSlot()); |
| 1844 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1845 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1846 | Register temp = temps.AcquireX(); |
| 1847 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1848 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1849 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1850 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1851 | } else { |
| 1852 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1853 | __ Ldr(temp, StackOperandFrom(source)); |
| 1854 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1855 | } |
| 1856 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1857 | } else { // The destination is not a register. It must be a stack slot. |
| 1858 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1859 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1860 | if (unspecified_type) { |
| 1861 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1862 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1863 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1864 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1865 | } |
| 1866 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1867 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1868 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1869 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1870 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1871 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1872 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1873 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1874 | HConstant* src_cst = source.GetConstant(); |
| 1875 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1876 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1877 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1878 | ? Register(xzr) |
| 1879 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1880 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1881 | if (src_cst->IsIntConstant()) { |
| 1882 | temp = temps.AcquireW(); |
| 1883 | } else if (src_cst->IsLongConstant()) { |
| 1884 | temp = temps.AcquireX(); |
| 1885 | } else if (src_cst->IsFloatConstant()) { |
| 1886 | temp = temps.AcquireS(); |
| 1887 | } else { |
| 1888 | DCHECK(src_cst->IsDoubleConstant()); |
| 1889 | temp = temps.AcquireD(); |
| 1890 | } |
| 1891 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1892 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1893 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1894 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1895 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1896 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1897 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1898 | // Use any scratch register (a core or a floating-point one) |
| 1899 | // from VIXL scratch register pools as a temporary. |
| 1900 | // |
| 1901 | // We used to only use the FP scratch register pool, but in some |
| 1902 | // rare cases the only register from this pool (D31) would |
| 1903 | // already be used (e.g. within a ParallelMove instruction, when |
| 1904 | // a move is blocked by a another move requiring a scratch FP |
| 1905 | // register, which would reserve D31). To prevent this issue, we |
| 1906 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1907 | // |
| 1908 | // Also, we start by asking for a FP scratch register first, as the |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1909 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1910 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1911 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1912 | // allocates core scratch registers first. |
| 1913 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1914 | GetVIXLAssembler(), |
| 1915 | &temps, |
| 1916 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1917 | __ Ldr(temp, StackOperandFrom(source)); |
| 1918 | __ Str(temp, StackOperandFrom(destination)); |
| 1919 | } |
| 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1924 | CPURegister dst, |
| 1925 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1926 | switch (type) { |
| 1927 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1928 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1929 | break; |
| 1930 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1931 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1932 | break; |
| 1933 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1934 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1935 | break; |
| 1936 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1937 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1938 | break; |
| 1939 | case Primitive::kPrimInt: |
| 1940 | case Primitive::kPrimNot: |
| 1941 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1942 | case Primitive::kPrimFloat: |
| 1943 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1944 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1945 | __ Ldr(dst, src); |
| 1946 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1947 | case Primitive::kPrimVoid: |
| 1948 | LOG(FATAL) << "Unreachable type " << type; |
| 1949 | } |
| 1950 | } |
| 1951 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1952 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1953 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1954 | const MemOperand& src, |
| 1955 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1956 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1957 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1958 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1959 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1960 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1961 | DCHECK(!src.IsPreIndex()); |
| 1962 | DCHECK(!src.IsPostIndex()); |
| 1963 | |
| 1964 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1965 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1966 | { |
| 1967 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1968 | MemOperand base = MemOperand(temp_base); |
| 1969 | switch (type) { |
| 1970 | case Primitive::kPrimBoolean: |
| 1971 | { |
| 1972 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1973 | __ ldarb(Register(dst), base); |
| 1974 | if (needs_null_check) { |
| 1975 | MaybeRecordImplicitNullCheck(instruction); |
| 1976 | } |
| 1977 | } |
| 1978 | break; |
| 1979 | case Primitive::kPrimByte: |
| 1980 | { |
| 1981 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1982 | __ ldarb(Register(dst), base); |
| 1983 | if (needs_null_check) { |
| 1984 | MaybeRecordImplicitNullCheck(instruction); |
| 1985 | } |
| 1986 | } |
| 1987 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1988 | break; |
| 1989 | case Primitive::kPrimChar: |
| 1990 | { |
| 1991 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1992 | __ ldarh(Register(dst), base); |
| 1993 | if (needs_null_check) { |
| 1994 | MaybeRecordImplicitNullCheck(instruction); |
| 1995 | } |
| 1996 | } |
| 1997 | break; |
| 1998 | case Primitive::kPrimShort: |
| 1999 | { |
| 2000 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2001 | __ ldarh(Register(dst), base); |
| 2002 | if (needs_null_check) { |
| 2003 | MaybeRecordImplicitNullCheck(instruction); |
| 2004 | } |
| 2005 | } |
| 2006 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 2007 | break; |
| 2008 | case Primitive::kPrimInt: |
| 2009 | case Primitive::kPrimNot: |
| 2010 | case Primitive::kPrimLong: |
| 2011 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
| 2012 | { |
| 2013 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2014 | __ ldar(Register(dst), base); |
| 2015 | if (needs_null_check) { |
| 2016 | MaybeRecordImplicitNullCheck(instruction); |
| 2017 | } |
| 2018 | } |
| 2019 | break; |
| 2020 | case Primitive::kPrimFloat: |
| 2021 | case Primitive::kPrimDouble: { |
| 2022 | DCHECK(dst.IsFPRegister()); |
| 2023 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2024 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2025 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2026 | { |
| 2027 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2028 | __ ldar(temp, base); |
| 2029 | if (needs_null_check) { |
| 2030 | MaybeRecordImplicitNullCheck(instruction); |
| 2031 | } |
| 2032 | } |
| 2033 | __ Fmov(FPRegister(dst), temp); |
| 2034 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2035 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2036 | case Primitive::kPrimVoid: |
| 2037 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2038 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2039 | } |
| 2040 | } |
| 2041 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2042 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2043 | CPURegister src, |
| 2044 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2045 | switch (type) { |
| 2046 | case Primitive::kPrimBoolean: |
| 2047 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2048 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2049 | break; |
| 2050 | case Primitive::kPrimChar: |
| 2051 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2052 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2053 | break; |
| 2054 | case Primitive::kPrimInt: |
| 2055 | case Primitive::kPrimNot: |
| 2056 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2057 | case Primitive::kPrimFloat: |
| 2058 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2059 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2060 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2061 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2062 | case Primitive::kPrimVoid: |
| 2063 | LOG(FATAL) << "Unreachable type " << type; |
| 2064 | } |
| 2065 | } |
| 2066 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2067 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
| 2068 | Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2069 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2070 | const MemOperand& dst, |
| 2071 | bool needs_null_check) { |
| 2072 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2073 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2074 | Register temp_base = temps.AcquireX(); |
| 2075 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2076 | DCHECK(!dst.IsPreIndex()); |
| 2077 | DCHECK(!dst.IsPostIndex()); |
| 2078 | |
| 2079 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2080 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2081 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2082 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2083 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2084 | switch (type) { |
| 2085 | case Primitive::kPrimBoolean: |
| 2086 | case Primitive::kPrimByte: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2087 | { |
| 2088 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2089 | __ stlrb(Register(src), base); |
| 2090 | if (needs_null_check) { |
| 2091 | MaybeRecordImplicitNullCheck(instruction); |
| 2092 | } |
| 2093 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2094 | break; |
| 2095 | case Primitive::kPrimChar: |
| 2096 | case Primitive::kPrimShort: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2097 | { |
| 2098 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2099 | __ stlrh(Register(src), base); |
| 2100 | if (needs_null_check) { |
| 2101 | MaybeRecordImplicitNullCheck(instruction); |
| 2102 | } |
| 2103 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2104 | break; |
| 2105 | case Primitive::kPrimInt: |
| 2106 | case Primitive::kPrimNot: |
| 2107 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2108 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2109 | { |
| 2110 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2111 | __ stlr(Register(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 | case Primitive::kPrimFloat: |
| 2118 | case Primitive::kPrimDouble: { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2119 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2120 | Register temp_src; |
| 2121 | if (src.IsZero()) { |
| 2122 | // The zero register is used to avoid synthesizing zero constants. |
| 2123 | temp_src = Register(src); |
| 2124 | } else { |
| 2125 | DCHECK(src.IsFPRegister()); |
| 2126 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2127 | __ Fmov(temp_src, FPRegister(src)); |
| 2128 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2129 | { |
| 2130 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2131 | __ stlr(temp_src, base); |
| 2132 | if (needs_null_check) { |
| 2133 | MaybeRecordImplicitNullCheck(instruction); |
| 2134 | } |
| 2135 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2136 | break; |
| 2137 | } |
| 2138 | case Primitive::kPrimVoid: |
| 2139 | LOG(FATAL) << "Unreachable type " << type; |
| 2140 | } |
| 2141 | } |
| 2142 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2143 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2144 | HInstruction* instruction, |
| 2145 | uint32_t dex_pc, |
| 2146 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2147 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2148 | |
| 2149 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 2150 | { |
| 2151 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 2152 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2153 | __ blr(lr); |
| 2154 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2155 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2156 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2157 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2160 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2161 | HInstruction* instruction, |
| 2162 | SlowPathCode* slow_path) { |
| 2163 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2164 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2165 | __ Blr(lr); |
| 2166 | } |
| 2167 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2168 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2169 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2170 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2171 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2172 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 2173 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2174 | // 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] | 2175 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 2176 | __ Add(temp, class_reg, status_offset); |
| 2177 | __ Ldar(temp, HeapOperand(temp)); |
| 2178 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 2179 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2180 | __ Bind(slow_path->GetExitLabel()); |
| 2181 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2182 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2183 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2184 | BarrierType type = BarrierAll; |
| 2185 | |
| 2186 | switch (kind) { |
| 2187 | case MemBarrierKind::kAnyAny: |
| 2188 | case MemBarrierKind::kAnyStore: { |
| 2189 | type = BarrierAll; |
| 2190 | break; |
| 2191 | } |
| 2192 | case MemBarrierKind::kLoadAny: { |
| 2193 | type = BarrierReads; |
| 2194 | break; |
| 2195 | } |
| 2196 | case MemBarrierKind::kStoreStore: { |
| 2197 | type = BarrierWrites; |
| 2198 | break; |
| 2199 | } |
| 2200 | default: |
| 2201 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2202 | } |
| 2203 | __ Dmb(InnerShareable, type); |
| 2204 | } |
| 2205 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2206 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2207 | HBasicBlock* successor) { |
| 2208 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2209 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2210 | if (slow_path == nullptr) { |
| 2211 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 2212 | instruction->SetSlowPath(slow_path); |
| 2213 | codegen_->AddSlowPath(slow_path); |
| 2214 | if (successor != nullptr) { |
| 2215 | DCHECK(successor->IsLoopHeader()); |
| 2216 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 2217 | } |
| 2218 | } else { |
| 2219 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2220 | } |
| 2221 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2222 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2223 | Register temp = temps.AcquireW(); |
| 2224 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2225 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2226 | if (successor == nullptr) { |
| 2227 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2228 | __ Bind(slow_path->GetReturnLabel()); |
| 2229 | } else { |
| 2230 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 2231 | __ B(slow_path->GetEntryLabel()); |
| 2232 | // slow_path will return to GetLabelOf(successor). |
| 2233 | } |
| 2234 | } |
| 2235 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2236 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2237 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2238 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2239 | assembler_(codegen->GetAssembler()), |
| 2240 | codegen_(codegen) {} |
| 2241 | |
| 2242 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2243 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2244 | |
| 2245 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 2246 | |
| 2247 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2248 | // Using a base helps identify when we hit such breakpoints. |
| 2249 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2250 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 2251 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 2252 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 2253 | }; |
| 2254 | |
| 2255 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2256 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2257 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 2258 | } \ |
| 2259 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 2260 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 2261 | locations->SetOut(Location::Any()); \ |
| 2262 | } |
| 2263 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 2264 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 2265 | |
| 2266 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2267 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2268 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2269 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2270 | DCHECK_EQ(instr->InputCount(), 2U); |
| 2271 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2272 | Primitive::Type type = instr->GetResultType(); |
| 2273 | switch (type) { |
| 2274 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2275 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2276 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2277 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2278 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2279 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2280 | |
| 2281 | case Primitive::kPrimFloat: |
| 2282 | case Primitive::kPrimDouble: |
| 2283 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2284 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2285 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2286 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2287 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2288 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2289 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2290 | } |
| 2291 | } |
| 2292 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2293 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2294 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2295 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2296 | |
| 2297 | bool object_field_get_with_read_barrier = |
| 2298 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2299 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2300 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2301 | object_field_get_with_read_barrier ? |
| 2302 | LocationSummary::kCallOnSlowPath : |
| 2303 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2304 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2305 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2306 | // We need a temporary register for the read barrier marking slow |
| 2307 | // path in CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2308 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2309 | !Runtime::Current()->UseJitCompilation() && |
| 2310 | !field_info.IsVolatile()) { |
| 2311 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2312 | // non-volatile loads we need a temporary only if the offset is too big. |
| 2313 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2314 | locations->AddTemp(FixedTempLocation()); |
| 2315 | } |
| 2316 | } else { |
| 2317 | locations->AddTemp(Location::RequiresRegister()); |
| 2318 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2319 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2320 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2321 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2322 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2323 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2324 | // The output overlaps for an object field get when read barriers |
| 2325 | // are enabled: we do not want the load to overwrite the object's |
| 2326 | // location, as we need it to emit the read barrier. |
| 2327 | locations->SetOut( |
| 2328 | Location::RequiresRegister(), |
| 2329 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2330 | } |
| 2331 | } |
| 2332 | |
| 2333 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2334 | const FieldInfo& field_info) { |
| 2335 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2336 | LocationSummary* locations = instruction->GetLocations(); |
| 2337 | Location base_loc = locations->InAt(0); |
| 2338 | Location out = locations->Out(); |
| 2339 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2340 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2341 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2342 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2343 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2344 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2345 | // /* HeapReference<Object> */ out = *(base + offset) |
| 2346 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2347 | Location maybe_temp = |
| 2348 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2349 | // Note that potential implicit null checks are handled in this |
| 2350 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2351 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2352 | instruction, |
| 2353 | out, |
| 2354 | base, |
| 2355 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2356 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2357 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2358 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2359 | } else { |
| 2360 | // General case. |
| 2361 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2362 | // Note that a potential implicit null check is handled in this |
| 2363 | // CodeGeneratorARM64::LoadAcquire call. |
| 2364 | // NB: LoadAcquire will record the pc info if needed. |
| 2365 | codegen_->LoadAcquire( |
| 2366 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2367 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2368 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2369 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2370 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2371 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2372 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2373 | if (field_type == Primitive::kPrimNot) { |
| 2374 | // If read barriers are enabled, emit read barriers other than |
| 2375 | // Baker's using a slow path (and also unpoison the loaded |
| 2376 | // reference, if heap poisoning is enabled). |
| 2377 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2378 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2379 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2383 | LocationSummary* locations = |
| 2384 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2385 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2386 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2387 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 2388 | } else if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2389 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2390 | } else { |
| 2391 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2392 | } |
| 2393 | } |
| 2394 | |
| 2395 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2396 | const FieldInfo& field_info, |
| 2397 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2398 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2399 | |
| 2400 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2401 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2402 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2403 | Offset offset = field_info.GetFieldOffset(); |
| 2404 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2405 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2406 | { |
| 2407 | // We use a block to end the scratch scope before the write barrier, thus |
| 2408 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2409 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2410 | |
| 2411 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 2412 | DCHECK(value.IsW()); |
| 2413 | Register temp = temps.AcquireW(); |
| 2414 | __ Mov(temp, value.W()); |
| 2415 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2416 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2417 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2418 | |
| 2419 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2420 | codegen_->StoreRelease( |
| 2421 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2422 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2423 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2424 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2425 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2426 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2427 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2428 | } |
| 2429 | |
| 2430 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2431 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2432 | } |
| 2433 | } |
| 2434 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2435 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2436 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2437 | |
| 2438 | switch (type) { |
| 2439 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2440 | case Primitive::kPrimLong: { |
| 2441 | Register dst = OutputRegister(instr); |
| 2442 | Register lhs = InputRegisterAt(instr, 0); |
| 2443 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2444 | if (instr->IsAdd()) { |
| 2445 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2446 | } else if (instr->IsAnd()) { |
| 2447 | __ And(dst, lhs, rhs); |
| 2448 | } else if (instr->IsOr()) { |
| 2449 | __ Orr(dst, lhs, rhs); |
| 2450 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2451 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2452 | } else if (instr->IsRor()) { |
| 2453 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2454 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2455 | __ Ror(dst, lhs, shift); |
| 2456 | } else { |
| 2457 | // Ensure shift distance is in the same size register as the result. If |
| 2458 | // we are rotating a long and the shift comes in a w register originally, |
| 2459 | // we don't need to sxtw for use as an x since the shift distances are |
| 2460 | // all & reg_bits - 1. |
| 2461 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2462 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2463 | } else { |
| 2464 | DCHECK(instr->IsXor()); |
| 2465 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2466 | } |
| 2467 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2468 | } |
| 2469 | case Primitive::kPrimFloat: |
| 2470 | case Primitive::kPrimDouble: { |
| 2471 | FPRegister dst = OutputFPRegister(instr); |
| 2472 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2473 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2474 | if (instr->IsAdd()) { |
| 2475 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2476 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2477 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2478 | } else { |
| 2479 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2480 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2481 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2482 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2483 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2484 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2485 | } |
| 2486 | } |
| 2487 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2488 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2489 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2490 | |
| 2491 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2492 | Primitive::Type type = instr->GetResultType(); |
| 2493 | switch (type) { |
| 2494 | case Primitive::kPrimInt: |
| 2495 | case Primitive::kPrimLong: { |
| 2496 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2497 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2498 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2499 | break; |
| 2500 | } |
| 2501 | default: |
| 2502 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2503 | } |
| 2504 | } |
| 2505 | |
| 2506 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2507 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2508 | |
| 2509 | Primitive::Type type = instr->GetType(); |
| 2510 | switch (type) { |
| 2511 | case Primitive::kPrimInt: |
| 2512 | case Primitive::kPrimLong: { |
| 2513 | Register dst = OutputRegister(instr); |
| 2514 | Register lhs = InputRegisterAt(instr, 0); |
| 2515 | Operand rhs = InputOperandAt(instr, 1); |
| 2516 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2517 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2518 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2519 | if (instr->IsShl()) { |
| 2520 | __ Lsl(dst, lhs, shift_value); |
| 2521 | } else if (instr->IsShr()) { |
| 2522 | __ Asr(dst, lhs, shift_value); |
| 2523 | } else { |
| 2524 | __ Lsr(dst, lhs, shift_value); |
| 2525 | } |
| 2526 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2527 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2528 | |
| 2529 | if (instr->IsShl()) { |
| 2530 | __ Lsl(dst, lhs, rhs_reg); |
| 2531 | } else if (instr->IsShr()) { |
| 2532 | __ Asr(dst, lhs, rhs_reg); |
| 2533 | } else { |
| 2534 | __ Lsr(dst, lhs, rhs_reg); |
| 2535 | } |
| 2536 | } |
| 2537 | break; |
| 2538 | } |
| 2539 | default: |
| 2540 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2541 | } |
| 2542 | } |
| 2543 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2544 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2545 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2546 | } |
| 2547 | |
| 2548 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2549 | HandleBinaryOp(instruction); |
| 2550 | } |
| 2551 | |
| 2552 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2553 | HandleBinaryOp(instruction); |
| 2554 | } |
| 2555 | |
| 2556 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2557 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2558 | } |
| 2559 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2560 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2561 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 2562 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2563 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2564 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2565 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2566 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2567 | } |
| 2568 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2569 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2570 | Register dst = OutputRegister(instr); |
| 2571 | Register lhs = InputRegisterAt(instr, 0); |
| 2572 | Register rhs = InputRegisterAt(instr, 1); |
| 2573 | |
| 2574 | switch (instr->GetOpKind()) { |
| 2575 | case HInstruction::kAnd: |
| 2576 | __ Bic(dst, lhs, rhs); |
| 2577 | break; |
| 2578 | case HInstruction::kOr: |
| 2579 | __ Orn(dst, lhs, rhs); |
| 2580 | break; |
| 2581 | case HInstruction::kXor: |
| 2582 | __ Eon(dst, lhs, rhs); |
| 2583 | break; |
| 2584 | default: |
| 2585 | LOG(FATAL) << "Unreachable"; |
| 2586 | } |
| 2587 | } |
| 2588 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2589 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2590 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2591 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 2592 | instruction->GetType() == Primitive::kPrimLong); |
| 2593 | LocationSummary* locations = |
| 2594 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2595 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2596 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2597 | } else { |
| 2598 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2599 | } |
| 2600 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2601 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2602 | } |
| 2603 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2604 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2605 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2606 | Primitive::Type type = instruction->GetType(); |
| 2607 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 2608 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2609 | Register out = OutputRegister(instruction); |
| 2610 | Register left; |
| 2611 | if (kind != HInstruction::kNeg) { |
| 2612 | left = InputRegisterAt(instruction, 0); |
| 2613 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2614 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2615 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2616 | // conversion) can have a different type from the current instruction's type, |
| 2617 | // so we manually indicate the type. |
| 2618 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2619 | Operand right_operand(0); |
| 2620 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2621 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2622 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2623 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2624 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2625 | right_operand = Operand(right_reg, |
| 2626 | helpers::ShiftFromOpKind(op_kind), |
| 2627 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2628 | } |
| 2629 | |
| 2630 | // Logical binary operations do not support extension operations in the |
| 2631 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2632 | // the extension as a separate instruction. |
| 2633 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2634 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2635 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2636 | kind != HInstruction::kNeg)); |
| 2637 | switch (kind) { |
| 2638 | case HInstruction::kAdd: |
| 2639 | __ Add(out, left, right_operand); |
| 2640 | break; |
| 2641 | case HInstruction::kAnd: |
| 2642 | __ And(out, left, right_operand); |
| 2643 | break; |
| 2644 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2645 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2646 | __ Neg(out, right_operand); |
| 2647 | break; |
| 2648 | case HInstruction::kOr: |
| 2649 | __ Orr(out, left, right_operand); |
| 2650 | break; |
| 2651 | case HInstruction::kSub: |
| 2652 | __ Sub(out, left, right_operand); |
| 2653 | break; |
| 2654 | case HInstruction::kXor: |
| 2655 | __ Eor(out, left, right_operand); |
| 2656 | break; |
| 2657 | default: |
| 2658 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2659 | UNREACHABLE(); |
| 2660 | } |
| 2661 | } |
| 2662 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2663 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2664 | LocationSummary* locations = |
| 2665 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2666 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2667 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2668 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2669 | } |
| 2670 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2671 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2672 | __ Add(OutputRegister(instruction), |
| 2673 | InputRegisterAt(instruction, 0), |
| 2674 | Operand(InputOperandAt(instruction, 1))); |
| 2675 | } |
| 2676 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2677 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2678 | LocationSummary* locations = |
| 2679 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2680 | |
| 2681 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2682 | |
| 2683 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2684 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2685 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2686 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2687 | // loop. |
| 2688 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2689 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2690 | : Location::RequiresRegister()); |
| 2691 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2692 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2693 | } |
| 2694 | |
| 2695 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2696 | HIntermediateAddressIndex* instruction) { |
| 2697 | Register index_reg = InputRegisterAt(instruction, 0); |
| 2698 | uint32_t shift = Int64ConstantFrom(instruction->GetLocations()->InAt(2)); |
| 2699 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2700 | |
| 2701 | if (shift == 0) { |
| 2702 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2703 | } else { |
| 2704 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2705 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2706 | } |
| 2707 | } |
| 2708 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2709 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2710 | LocationSummary* locations = |
| 2711 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2712 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2713 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2714 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2715 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2716 | // Don't allocate register for Mneg instruction. |
| 2717 | } else { |
| 2718 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2719 | Location::RequiresRegister()); |
| 2720 | } |
| 2721 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2722 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2723 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2724 | } |
| 2725 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2726 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2727 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2728 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2729 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2730 | |
| 2731 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2732 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2733 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2734 | if (instr->GetType() == Primitive::kPrimLong && |
| 2735 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2736 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2737 | vixl::aarch64::Instruction* prev = |
| 2738 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2739 | if (prev->IsLoadOrStore()) { |
| 2740 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2741 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2742 | __ nop(); |
| 2743 | } |
| 2744 | } |
| 2745 | |
| 2746 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2747 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2748 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2749 | } else { |
| 2750 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2751 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2752 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2753 | __ Mneg(res, mul_left, mul_right); |
| 2754 | } else { |
| 2755 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2756 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2757 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2758 | } |
| 2759 | } |
| 2760 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2761 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2762 | bool object_array_get_with_read_barrier = |
| 2763 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2764 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2765 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2766 | object_array_get_with_read_barrier ? |
| 2767 | LocationSummary::kCallOnSlowPath : |
| 2768 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2769 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2770 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 2771 | // We need a temporary register for the read barrier marking slow |
| 2772 | // path in CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2773 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2774 | !Runtime::Current()->UseJitCompilation() && |
| 2775 | instruction->GetIndex()->IsConstant()) { |
| 2776 | // Array loads with constant index are treated as field loads. |
| 2777 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2778 | // constant index loads we need a temporary only if the offset is too big. |
| 2779 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2780 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| 2781 | offset += index << Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 2782 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2783 | locations->AddTemp(FixedTempLocation()); |
| 2784 | } |
| 2785 | } else { |
| 2786 | locations->AddTemp(Location::RequiresRegister()); |
| 2787 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2788 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2789 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2790 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2791 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2792 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2793 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2794 | // The output overlaps in the case of an object array get with |
| 2795 | // read barriers enabled: we do not want the move to overwrite the |
| 2796 | // array's location, as we need it to emit the read barrier. |
| 2797 | locations->SetOut( |
| 2798 | Location::RequiresRegister(), |
| 2799 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2800 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2804 | Primitive::Type type = instruction->GetType(); |
| 2805 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2806 | LocationSummary* locations = instruction->GetLocations(); |
| 2807 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2808 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2809 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2810 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2811 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2812 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2813 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2814 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2815 | // The read barrier instrumentation of object ArrayGet instructions |
| 2816 | // does not support the HIntermediateAddress instruction. |
| 2817 | DCHECK(!((type == Primitive::kPrimNot) && |
| 2818 | instruction->GetArray()->IsIntermediateAddress() && |
| 2819 | kEmitCompilerReadBarrier)); |
| 2820 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2821 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2822 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2823 | // Note that a potential implicit null check is handled in the |
| 2824 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2825 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2826 | if (index.IsConstant()) { |
| 2827 | // Array load with a constant index can be treated as a field load. |
| 2828 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2829 | Location maybe_temp = |
| 2830 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2831 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2832 | out, |
| 2833 | obj.W(), |
| 2834 | offset, |
| 2835 | maybe_temp, |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2836 | /* needs_null_check */ false, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2837 | /* use_load_acquire */ false); |
| 2838 | } else { |
| 2839 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
| 2840 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2841 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2842 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2843 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2844 | // General case. |
| 2845 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2846 | Register length; |
| 2847 | if (maybe_compressed_char_at) { |
| 2848 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2849 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2850 | { |
| 2851 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2852 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2853 | |
| 2854 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2855 | DCHECK_LT(count_offset, offset); |
| 2856 | int64_t adjusted_offset = |
| 2857 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2858 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2859 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2860 | } else { |
| 2861 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2862 | } |
| 2863 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2864 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2865 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2866 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2867 | if (maybe_compressed_char_at) { |
| 2868 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2869 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2870 | "Expecting 0=compressed, 1=uncompressed"); |
| 2871 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2872 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2873 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2874 | __ B(&done); |
| 2875 | __ Bind(&uncompressed_load); |
| 2876 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2877 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2878 | __ Bind(&done); |
| 2879 | } else { |
| 2880 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2881 | source = HeapOperand(obj, offset); |
| 2882 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2883 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2884 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2885 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2886 | // We do not need to compute the intermediate address from the array: the |
| 2887 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2888 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2889 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2890 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2891 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2892 | } |
| 2893 | temp = obj; |
| 2894 | } else { |
| 2895 | __ Add(temp, obj, offset); |
| 2896 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2897 | if (maybe_compressed_char_at) { |
| 2898 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2899 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2900 | "Expecting 0=compressed, 1=uncompressed"); |
| 2901 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2902 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2903 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2904 | __ B(&done); |
| 2905 | __ Bind(&uncompressed_load); |
| 2906 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2907 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2908 | __ Bind(&done); |
| 2909 | } else { |
| 2910 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2911 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2912 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2913 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2914 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2915 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2916 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2917 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2918 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2919 | |
| 2920 | if (type == Primitive::kPrimNot) { |
| 2921 | static_assert( |
| 2922 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2923 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2924 | Location obj_loc = locations->InAt(0); |
| 2925 | if (index.IsConstant()) { |
| 2926 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2927 | } else { |
| 2928 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2929 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2930 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2931 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2932 | } |
| 2933 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2934 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2935 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2936 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2937 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2941 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2942 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2943 | { |
| 2944 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2945 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2946 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2947 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2948 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2949 | // Mask out compression flag from String's array length. |
| 2950 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2951 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2952 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2953 | } |
| 2954 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2955 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2956 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2957 | |
| 2958 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2959 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2960 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2961 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2962 | LocationSummary::kCallOnSlowPath : |
| 2963 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2964 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2965 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2966 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2967 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 2968 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2969 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2970 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2971 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2972 | } |
| 2973 | } |
| 2974 | |
| 2975 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2976 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2977 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2978 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2979 | bool needs_write_barrier = |
| 2980 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2981 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2982 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2983 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2984 | CPURegister source = value; |
| 2985 | Location index = locations->InAt(1); |
| 2986 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2987 | MemOperand destination = HeapOperand(array); |
| 2988 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2989 | |
| 2990 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2991 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2992 | if (index.IsConstant()) { |
| 2993 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2994 | destination = HeapOperand(array, offset); |
| 2995 | } else { |
| 2996 | UseScratchRegisterScope temps(masm); |
| 2997 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2998 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2999 | // We do not need to compute the intermediate address from the array: the |
| 3000 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3001 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 3002 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3003 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 3004 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 3005 | } |
| 3006 | temp = array; |
| 3007 | } else { |
| 3008 | __ Add(temp, array, offset); |
| 3009 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3010 | destination = HeapOperand(temp, |
| 3011 | XRegisterFrom(index), |
| 3012 | LSL, |
| 3013 | Primitive::ComponentSizeShift(value_type)); |
| 3014 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3015 | { |
| 3016 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3017 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3018 | codegen_->Store(value_type, value, destination); |
| 3019 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3020 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3021 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3022 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3023 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3024 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3025 | { |
| 3026 | // We use a block to end the scratch scope before the write barrier, thus |
| 3027 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 3028 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3029 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3030 | if (index.IsConstant()) { |
| 3031 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3032 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3033 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 3034 | destination = HeapOperand(temp, |
| 3035 | XRegisterFrom(index), |
| 3036 | LSL, |
| 3037 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3038 | } |
| 3039 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3040 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3041 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3042 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3043 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3044 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3045 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 3046 | codegen_->AddSlowPath(slow_path); |
| 3047 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3048 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3049 | __ Cbnz(Register(value), &non_zero); |
| 3050 | if (!index.IsConstant()) { |
| 3051 | __ Add(temp, array, offset); |
| 3052 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3053 | { |
| 3054 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 3055 | // emitted. |
| 3056 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3057 | __ Str(wzr, destination); |
| 3058 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3059 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3060 | __ B(&done); |
| 3061 | __ Bind(&non_zero); |
| 3062 | } |
| 3063 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3064 | // Note that when Baker read barriers are enabled, the type |
| 3065 | // checks are performed without read barriers. This is fine, |
| 3066 | // even in the case where a class object is in the from-space |
| 3067 | // after the flip, as a comparison involving such a type would |
| 3068 | // not produce a false positive; it may of course produce a |
| 3069 | // false negative, in which case we would take the ArraySet |
| 3070 | // slow path. |
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 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 3073 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3074 | { |
| 3075 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3076 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3077 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 3078 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3079 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3080 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3081 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3082 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 3083 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 3084 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3085 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 3086 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 3087 | // nor `temp2`, as we are comparing two poisoned references. |
| 3088 | __ Cmp(temp, temp2); |
| 3089 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3090 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3091 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3092 | vixl::aarch64::Label do_put; |
| 3093 | __ B(eq, &do_put); |
| 3094 | // If heap poisoning is enabled, the `temp` reference has |
| 3095 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3096 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3097 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3098 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 3099 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 3100 | // If heap poisoning is enabled, no need to unpoison |
| 3101 | // `temp`, as we are comparing against null below. |
| 3102 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 3103 | __ Bind(&do_put); |
| 3104 | } else { |
| 3105 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3106 | } |
| 3107 | } |
| 3108 | |
| 3109 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3110 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3111 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3112 | __ Mov(temp2, value.W()); |
| 3113 | GetAssembler()->PoisonHeapReference(temp2); |
| 3114 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | if (!index.IsConstant()) { |
| 3118 | __ Add(temp, array, offset); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 3119 | } else { |
| 3120 | // We no longer need the `temp` here so release it as the store below may |
| 3121 | // need a scratch register (if the constant index makes the offset too large) |
| 3122 | // and the poisoned `source` could be using the other scratch register. |
| 3123 | temps.Release(temp); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3124 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3125 | { |
| 3126 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3127 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3128 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3129 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3130 | if (!may_need_runtime_call_for_type_check) { |
| 3131 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3132 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3133 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3134 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3135 | |
| 3136 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 3137 | |
| 3138 | if (done.IsLinked()) { |
| 3139 | __ Bind(&done); |
| 3140 | } |
| 3141 | |
| 3142 | if (slow_path != nullptr) { |
| 3143 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3144 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3145 | } |
| 3146 | } |
| 3147 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3148 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3149 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3150 | InvokeRuntimeCallingConvention calling_convention; |
| 3151 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3152 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 3153 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3154 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 3155 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3159 | BoundsCheckSlowPathARM64* slow_path = |
| 3160 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3161 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3162 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 3163 | __ B(slow_path->GetEntryLabel(), hs); |
| 3164 | } |
| 3165 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3166 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3167 | LocationSummary* locations = |
| 3168 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3169 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3170 | if (check->HasUses()) { |
| 3171 | locations->SetOut(Location::SameAsFirstInput()); |
| 3172 | } |
| 3173 | } |
| 3174 | |
| 3175 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3176 | // We assume the class is not null. |
| 3177 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 3178 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 3179 | codegen_->AddSlowPath(slow_path); |
| 3180 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3181 | } |
| 3182 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3183 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3184 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3185 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3186 | } |
| 3187 | |
| 3188 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 3189 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 3190 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3191 | if (rhs_loc.IsConstant()) { |
| 3192 | // 0.0 is the only immediate that can be encoded directly in |
| 3193 | // an FCMP instruction. |
| 3194 | // |
| 3195 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3196 | // specify that in a floating-point comparison, positive zero |
| 3197 | // and negative zero are considered equal, so we can use the |
| 3198 | // literal 0.0 for both cases here. |
| 3199 | // |
| 3200 | // Note however that some methods (Float.equal, Float.compare, |
| 3201 | // Float.compareTo, Double.equal, Double.compare, |
| 3202 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3203 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3204 | // -0.0. So if we ever translate calls to these methods into a |
| 3205 | // HCompare instruction, we must handle the -0.0 case with |
| 3206 | // care here. |
| 3207 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3208 | __ Fcmp(lhs_reg, 0.0); |
| 3209 | } else { |
| 3210 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3211 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3212 | } |
| 3213 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3214 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3215 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3216 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 3217 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3218 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3219 | case Primitive::kPrimBoolean: |
| 3220 | case Primitive::kPrimByte: |
| 3221 | case Primitive::kPrimShort: |
| 3222 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3223 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3224 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3225 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3226 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3227 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3228 | break; |
| 3229 | } |
| 3230 | case Primitive::kPrimFloat: |
| 3231 | case Primitive::kPrimDouble: { |
| 3232 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3233 | locations->SetInAt(1, |
| 3234 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3235 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3236 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3237 | locations->SetOut(Location::RequiresRegister()); |
| 3238 | break; |
| 3239 | } |
| 3240 | default: |
| 3241 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3242 | } |
| 3243 | } |
| 3244 | |
| 3245 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 3246 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 3247 | |
| 3248 | // 0 if: left == right |
| 3249 | // 1 if: left > right |
| 3250 | // -1 if: left < right |
| 3251 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3252 | case Primitive::kPrimBoolean: |
| 3253 | case Primitive::kPrimByte: |
| 3254 | case Primitive::kPrimShort: |
| 3255 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3256 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3257 | case Primitive::kPrimLong: { |
| 3258 | Register result = OutputRegister(compare); |
| 3259 | Register left = InputRegisterAt(compare, 0); |
| 3260 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3261 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3262 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3263 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3264 | break; |
| 3265 | } |
| 3266 | case Primitive::kPrimFloat: |
| 3267 | case Primitive::kPrimDouble: { |
| 3268 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3269 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3270 | __ Cset(result, ne); |
| 3271 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3272 | break; |
| 3273 | } |
| 3274 | default: |
| 3275 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3276 | } |
| 3277 | } |
| 3278 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3279 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3280 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3281 | |
| 3282 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 3283 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3284 | locations->SetInAt(1, |
| 3285 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3286 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3287 | : Location::RequiresFpuRegister()); |
| 3288 | } else { |
| 3289 | // Integer cases. |
| 3290 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3291 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3292 | } |
| 3293 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3294 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3295 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3296 | } |
| 3297 | } |
| 3298 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3299 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3300 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3301 | return; |
| 3302 | } |
| 3303 | |
| 3304 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3305 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3306 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3307 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3308 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3309 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3310 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3311 | } else { |
| 3312 | // Integer cases. |
| 3313 | Register lhs = InputRegisterAt(instruction, 0); |
| 3314 | Operand rhs = InputOperandAt(instruction, 1); |
| 3315 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3316 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3317 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3321 | M(Equal) \ |
| 3322 | M(NotEqual) \ |
| 3323 | M(LessThan) \ |
| 3324 | M(LessThanOrEqual) \ |
| 3325 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3326 | M(GreaterThanOrEqual) \ |
| 3327 | M(Below) \ |
| 3328 | M(BelowOrEqual) \ |
| 3329 | M(Above) \ |
| 3330 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3331 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3332 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3333 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3334 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3335 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3336 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3337 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3338 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3339 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3340 | |
| 3341 | LocationSummary* locations = instruction->GetLocations(); |
| 3342 | Location second = locations->InAt(1); |
| 3343 | DCHECK(second.IsConstant()); |
| 3344 | |
| 3345 | Register out = OutputRegister(instruction); |
| 3346 | Register dividend = InputRegisterAt(instruction, 0); |
| 3347 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3348 | DCHECK(imm == 1 || imm == -1); |
| 3349 | |
| 3350 | if (instruction->IsRem()) { |
| 3351 | __ Mov(out, 0); |
| 3352 | } else { |
| 3353 | if (imm == 1) { |
| 3354 | __ Mov(out, dividend); |
| 3355 | } else { |
| 3356 | __ Neg(out, dividend); |
| 3357 | } |
| 3358 | } |
| 3359 | } |
| 3360 | |
| 3361 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3362 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3363 | |
| 3364 | LocationSummary* locations = instruction->GetLocations(); |
| 3365 | Location second = locations->InAt(1); |
| 3366 | DCHECK(second.IsConstant()); |
| 3367 | |
| 3368 | Register out = OutputRegister(instruction); |
| 3369 | Register dividend = InputRegisterAt(instruction, 0); |
| 3370 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3371 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3372 | int ctz_imm = CTZ(abs_imm); |
| 3373 | |
| 3374 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3375 | Register temp = temps.AcquireSameSizeAs(out); |
| 3376 | |
| 3377 | if (instruction->IsDiv()) { |
| 3378 | __ Add(temp, dividend, abs_imm - 1); |
| 3379 | __ Cmp(dividend, 0); |
| 3380 | __ Csel(out, temp, dividend, lt); |
| 3381 | if (imm > 0) { |
| 3382 | __ Asr(out, out, ctz_imm); |
| 3383 | } else { |
| 3384 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 3385 | } |
| 3386 | } else { |
| 3387 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 3388 | __ Asr(temp, dividend, bits - 1); |
| 3389 | __ Lsr(temp, temp, bits - ctz_imm); |
| 3390 | __ Add(out, dividend, temp); |
| 3391 | __ And(out, out, abs_imm - 1); |
| 3392 | __ Sub(out, out, temp); |
| 3393 | } |
| 3394 | } |
| 3395 | |
| 3396 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3397 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3398 | |
| 3399 | LocationSummary* locations = instruction->GetLocations(); |
| 3400 | Location second = locations->InAt(1); |
| 3401 | DCHECK(second.IsConstant()); |
| 3402 | |
| 3403 | Register out = OutputRegister(instruction); |
| 3404 | Register dividend = InputRegisterAt(instruction, 0); |
| 3405 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3406 | |
| 3407 | Primitive::Type type = instruction->GetResultType(); |
| 3408 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 3409 | |
| 3410 | int64_t magic; |
| 3411 | int shift; |
| 3412 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 3413 | |
| 3414 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3415 | Register temp = temps.AcquireSameSizeAs(out); |
| 3416 | |
| 3417 | // temp = get_high(dividend * magic) |
| 3418 | __ Mov(temp, magic); |
| 3419 | if (type == Primitive::kPrimLong) { |
| 3420 | __ Smulh(temp, dividend, temp); |
| 3421 | } else { |
| 3422 | __ Smull(temp.X(), dividend, temp); |
| 3423 | __ Lsr(temp.X(), temp.X(), 32); |
| 3424 | } |
| 3425 | |
| 3426 | if (imm > 0 && magic < 0) { |
| 3427 | __ Add(temp, temp, dividend); |
| 3428 | } else if (imm < 0 && magic > 0) { |
| 3429 | __ Sub(temp, temp, dividend); |
| 3430 | } |
| 3431 | |
| 3432 | if (shift != 0) { |
| 3433 | __ Asr(temp, temp, shift); |
| 3434 | } |
| 3435 | |
| 3436 | if (instruction->IsDiv()) { |
| 3437 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3438 | } else { |
| 3439 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3440 | // TODO: Strength reduction for msub. |
| 3441 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3442 | __ Mov(temp_imm, imm); |
| 3443 | __ Msub(out, temp, temp_imm, dividend); |
| 3444 | } |
| 3445 | } |
| 3446 | |
| 3447 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3448 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3449 | Primitive::Type type = instruction->GetResultType(); |
Calin Juravle | c70d1d9 | 2017-03-27 18:10:04 -0700 | [diff] [blame] | 3450 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3451 | |
| 3452 | LocationSummary* locations = instruction->GetLocations(); |
| 3453 | Register out = OutputRegister(instruction); |
| 3454 | Location second = locations->InAt(1); |
| 3455 | |
| 3456 | if (second.IsConstant()) { |
| 3457 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3458 | |
| 3459 | if (imm == 0) { |
| 3460 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3461 | } else if (imm == 1 || imm == -1) { |
| 3462 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3463 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3464 | DivRemByPowerOfTwo(instruction); |
| 3465 | } else { |
| 3466 | DCHECK(imm <= -2 || imm >= 2); |
| 3467 | GenerateDivRemWithAnyConstant(instruction); |
| 3468 | } |
| 3469 | } else { |
| 3470 | Register dividend = InputRegisterAt(instruction, 0); |
| 3471 | Register divisor = InputRegisterAt(instruction, 1); |
| 3472 | if (instruction->IsDiv()) { |
| 3473 | __ Sdiv(out, dividend, divisor); |
| 3474 | } else { |
| 3475 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3476 | Register temp = temps.AcquireSameSizeAs(out); |
| 3477 | __ Sdiv(temp, dividend, divisor); |
| 3478 | __ Msub(out, temp, divisor, dividend); |
| 3479 | } |
| 3480 | } |
| 3481 | } |
| 3482 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3483 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3484 | LocationSummary* locations = |
| 3485 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3486 | switch (div->GetResultType()) { |
| 3487 | case Primitive::kPrimInt: |
| 3488 | case Primitive::kPrimLong: |
| 3489 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3490 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3491 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3492 | break; |
| 3493 | |
| 3494 | case Primitive::kPrimFloat: |
| 3495 | case Primitive::kPrimDouble: |
| 3496 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3497 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3498 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3499 | break; |
| 3500 | |
| 3501 | default: |
| 3502 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3503 | } |
| 3504 | } |
| 3505 | |
| 3506 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 3507 | Primitive::Type type = div->GetResultType(); |
| 3508 | switch (type) { |
| 3509 | case Primitive::kPrimInt: |
| 3510 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3511 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3512 | break; |
| 3513 | |
| 3514 | case Primitive::kPrimFloat: |
| 3515 | case Primitive::kPrimDouble: |
| 3516 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3517 | break; |
| 3518 | |
| 3519 | default: |
| 3520 | LOG(FATAL) << "Unexpected div type " << type; |
| 3521 | } |
| 3522 | } |
| 3523 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3524 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3525 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3526 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3527 | } |
| 3528 | |
| 3529 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3530 | SlowPathCodeARM64* slow_path = |
| 3531 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 3532 | codegen_->AddSlowPath(slow_path); |
| 3533 | Location value = instruction->GetLocations()->InAt(0); |
| 3534 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3535 | Primitive::Type type = instruction->GetType(); |
| 3536 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3537 | if (!Primitive::IsIntegralType(type)) { |
| 3538 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3539 | return; |
| 3540 | } |
| 3541 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3542 | if (value.IsConstant()) { |
| 3543 | int64_t divisor = Int64ConstantFrom(value); |
| 3544 | if (divisor == 0) { |
| 3545 | __ B(slow_path->GetEntryLabel()); |
| 3546 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3547 | // A division by a non-null constant is valid. We don't need to perform |
| 3548 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3549 | } |
| 3550 | } else { |
| 3551 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3552 | } |
| 3553 | } |
| 3554 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3555 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3556 | LocationSummary* locations = |
| 3557 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3558 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3559 | } |
| 3560 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3561 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3562 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3563 | // Will be generated at use site. |
| 3564 | } |
| 3565 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3566 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3567 | exit->SetLocations(nullptr); |
| 3568 | } |
| 3569 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3570 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3571 | } |
| 3572 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3573 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3574 | LocationSummary* locations = |
| 3575 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3576 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3577 | } |
| 3578 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3579 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3580 | // Will be generated at use site. |
| 3581 | } |
| 3582 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3583 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3584 | DCHECK(!successor->IsExitBlock()); |
| 3585 | HBasicBlock* block = got->GetBlock(); |
| 3586 | HInstruction* previous = got->GetPrevious(); |
| 3587 | HLoopInformation* info = block->GetLoopInformation(); |
| 3588 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3589 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3590 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3591 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3592 | return; |
| 3593 | } |
| 3594 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3595 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 3596 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3597 | } |
| 3598 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3599 | __ B(codegen_->GetLabelOf(successor)); |
| 3600 | } |
| 3601 | } |
| 3602 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3603 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3604 | got->SetLocations(nullptr); |
| 3605 | } |
| 3606 | |
| 3607 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3608 | HandleGoto(got, got->GetSuccessor()); |
| 3609 | } |
| 3610 | |
| 3611 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3612 | try_boundary->SetLocations(nullptr); |
| 3613 | } |
| 3614 | |
| 3615 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3616 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3617 | if (!successor->IsExitBlock()) { |
| 3618 | HandleGoto(try_boundary, successor); |
| 3619 | } |
| 3620 | } |
| 3621 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3622 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3623 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3624 | vixl::aarch64::Label* true_target, |
| 3625 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3626 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3627 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3628 | if (true_target == nullptr && false_target == nullptr) { |
| 3629 | // Nothing to do. The code always falls through. |
| 3630 | return; |
| 3631 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3632 | // Constant condition, statically compared against "true" (integer value 1). |
| 3633 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3634 | if (true_target != nullptr) { |
| 3635 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3636 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3637 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3638 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3639 | if (false_target != nullptr) { |
| 3640 | __ B(false_target); |
| 3641 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3642 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3643 | return; |
| 3644 | } |
| 3645 | |
| 3646 | // The following code generates these patterns: |
| 3647 | // (1) true_target == nullptr && false_target != nullptr |
| 3648 | // - opposite condition true => branch to false_target |
| 3649 | // (2) true_target != nullptr && false_target == nullptr |
| 3650 | // - condition true => branch to true_target |
| 3651 | // (3) true_target != nullptr && false_target != nullptr |
| 3652 | // - condition true => branch to true_target |
| 3653 | // - branch to false_target |
| 3654 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3655 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3656 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3657 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3658 | if (true_target == nullptr) { |
| 3659 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3660 | } else { |
| 3661 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3662 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3663 | } else { |
| 3664 | // The condition instruction has not been materialized, use its inputs as |
| 3665 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3666 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3667 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3668 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3669 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3670 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3671 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3672 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3673 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3674 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3675 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3676 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3677 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3678 | // Integer cases. |
| 3679 | Register lhs = InputRegisterAt(condition, 0); |
| 3680 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3681 | |
| 3682 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3683 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3684 | if (true_target == nullptr) { |
| 3685 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3686 | non_fallthrough_target = false_target; |
| 3687 | } else { |
| 3688 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3689 | non_fallthrough_target = true_target; |
| 3690 | } |
| 3691 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3692 | 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] | 3693 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3694 | switch (arm64_cond) { |
| 3695 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3696 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3697 | break; |
| 3698 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3699 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3700 | break; |
| 3701 | case lt: |
| 3702 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3703 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3704 | break; |
| 3705 | case ge: |
| 3706 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3707 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3708 | break; |
| 3709 | default: |
| 3710 | // Without the `static_cast` the compiler throws an error for |
| 3711 | // `-Werror=sign-promo`. |
| 3712 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3713 | } |
| 3714 | } else { |
| 3715 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3716 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3717 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3718 | } |
| 3719 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3720 | |
| 3721 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3722 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3723 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3724 | __ B(false_target); |
| 3725 | } |
| 3726 | } |
| 3727 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3728 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 3729 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3730 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3731 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3732 | } |
| 3733 | } |
| 3734 | |
| 3735 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3736 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3737 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3738 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3739 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3740 | true_target = nullptr; |
| 3741 | } |
| 3742 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3743 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3744 | false_target = nullptr; |
| 3745 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3746 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3750 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3751 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3752 | InvokeRuntimeCallingConvention calling_convention; |
| 3753 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3754 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3755 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3756 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3757 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3758 | } |
| 3759 | } |
| 3760 | |
| 3761 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3762 | SlowPathCodeARM64* slow_path = |
| 3763 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3764 | GenerateTestAndBranch(deoptimize, |
| 3765 | /* condition_input_index */ 0, |
| 3766 | slow_path->GetEntryLabel(), |
| 3767 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3768 | } |
| 3769 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3770 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3771 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3772 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3773 | locations->SetOut(Location::RequiresRegister()); |
| 3774 | } |
| 3775 | |
| 3776 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3777 | __ Ldr(OutputRegister(flag), |
| 3778 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3779 | } |
| 3780 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3781 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3782 | return condition->IsCondition() && |
| 3783 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 3784 | } |
| 3785 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3786 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3787 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3788 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3789 | : ARM64Condition(cond); |
| 3790 | } |
| 3791 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3792 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3793 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3794 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3795 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3796 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3797 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3798 | } else { |
| 3799 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3800 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3801 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3802 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3803 | // Ask VIXL whether we should synthesize constants in registers. |
| 3804 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3805 | Operand true_op = is_true_value_constant ? |
| 3806 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3807 | Operand false_op = is_false_value_constant ? |
| 3808 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3809 | bool true_value_in_register = false; |
| 3810 | bool false_value_in_register = false; |
| 3811 | MacroAssembler::GetCselSynthesisInformation( |
| 3812 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3813 | true_value_in_register |= !is_true_value_constant; |
| 3814 | false_value_in_register |= !is_false_value_constant; |
| 3815 | |
| 3816 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3817 | : Location::ConstantLocation(cst_true_value)); |
| 3818 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3819 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3820 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3821 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3822 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3823 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3824 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3825 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3829 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3830 | Condition csel_cond; |
| 3831 | |
| 3832 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3833 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3834 | // Use the condition flags set by the previous instruction. |
| 3835 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3836 | } else { |
| 3837 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3838 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3839 | } |
| 3840 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3841 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3842 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3843 | } else { |
| 3844 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3845 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3846 | } |
| 3847 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3848 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3849 | __ Fcsel(OutputFPRegister(select), |
| 3850 | InputFPRegisterAt(select, 1), |
| 3851 | InputFPRegisterAt(select, 0), |
| 3852 | csel_cond); |
| 3853 | } else { |
| 3854 | __ Csel(OutputRegister(select), |
| 3855 | InputOperandAt(select, 1), |
| 3856 | InputOperandAt(select, 0), |
| 3857 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3858 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3859 | } |
| 3860 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3861 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3862 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3863 | } |
| 3864 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3865 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3866 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | void CodeGeneratorARM64::GenerateNop() { |
| 3870 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3871 | } |
| 3872 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3873 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3874 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3875 | } |
| 3876 | |
| 3877 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3878 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3882 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3883 | } |
| 3884 | |
| 3885 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3886 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3887 | } |
| 3888 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3889 | // Temp is used for read barrier. |
| 3890 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3891 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3892 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3893 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3894 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3895 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3896 | return 1; |
| 3897 | } |
| 3898 | return 0; |
| 3899 | } |
| 3900 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3901 | // 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] | 3902 | // interface pointer, one for loading the current interface. |
| 3903 | // The other checks have one temp for loading the object's class. |
| 3904 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3905 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3906 | return 3; |
| 3907 | } |
| 3908 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3909 | } |
| 3910 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3911 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3912 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3913 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3914 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3915 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3916 | case TypeCheckKind::kExactCheck: |
| 3917 | case TypeCheckKind::kAbstractClassCheck: |
| 3918 | case TypeCheckKind::kClassHierarchyCheck: |
| 3919 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3920 | call_kind = |
| 3921 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3922 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3923 | break; |
| 3924 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3925 | case TypeCheckKind::kUnresolvedCheck: |
| 3926 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3927 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3928 | break; |
| 3929 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3930 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3931 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3932 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3933 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3934 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3935 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3936 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3937 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3938 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3939 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3940 | // Add temps if necessary for read barriers. |
| 3941 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3942 | } |
| 3943 | |
| 3944 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3945 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3946 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3947 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3948 | Register obj = InputRegisterAt(instruction, 0); |
| 3949 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3950 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3951 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3952 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3953 | DCHECK_LE(num_temps, 1u); |
| 3954 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3955 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3956 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3957 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3958 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3959 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3960 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3961 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3962 | |
| 3963 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3964 | // Avoid null check if we know `obj` is not null. |
| 3965 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3966 | __ Cbz(obj, &zero); |
| 3967 | } |
| 3968 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3969 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3970 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3971 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3972 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3973 | out_loc, |
| 3974 | obj_loc, |
| 3975 | class_offset, |
| 3976 | maybe_temp_loc, |
| 3977 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3978 | __ Cmp(out, cls); |
| 3979 | __ Cset(out, eq); |
| 3980 | if (zero.IsLinked()) { |
| 3981 | __ B(&done); |
| 3982 | } |
| 3983 | break; |
| 3984 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3985 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3986 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3987 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3988 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3989 | out_loc, |
| 3990 | obj_loc, |
| 3991 | class_offset, |
| 3992 | maybe_temp_loc, |
| 3993 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3994 | // If the class is abstract, we eagerly fetch the super class of the |
| 3995 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3996 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3997 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3998 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3999 | GenerateReferenceLoadOneRegister(instruction, |
| 4000 | out_loc, |
| 4001 | super_offset, |
| 4002 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4003 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4004 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4005 | __ Cbz(out, &done); |
| 4006 | __ Cmp(out, cls); |
| 4007 | __ B(ne, &loop); |
| 4008 | __ Mov(out, 1); |
| 4009 | if (zero.IsLinked()) { |
| 4010 | __ B(&done); |
| 4011 | } |
| 4012 | break; |
| 4013 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4014 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4015 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4016 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4017 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4018 | out_loc, |
| 4019 | obj_loc, |
| 4020 | class_offset, |
| 4021 | maybe_temp_loc, |
| 4022 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4023 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4024 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4025 | __ Bind(&loop); |
| 4026 | __ Cmp(out, cls); |
| 4027 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4028 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4029 | GenerateReferenceLoadOneRegister(instruction, |
| 4030 | out_loc, |
| 4031 | super_offset, |
| 4032 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4033 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4034 | __ Cbnz(out, &loop); |
| 4035 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4036 | __ B(&done); |
| 4037 | __ Bind(&success); |
| 4038 | __ Mov(out, 1); |
| 4039 | if (zero.IsLinked()) { |
| 4040 | __ B(&done); |
| 4041 | } |
| 4042 | break; |
| 4043 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4044 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4045 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4046 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4047 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4048 | out_loc, |
| 4049 | obj_loc, |
| 4050 | class_offset, |
| 4051 | maybe_temp_loc, |
| 4052 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4053 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4054 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4055 | __ Cmp(out, cls); |
| 4056 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4057 | // 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] | 4058 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4059 | GenerateReferenceLoadOneRegister(instruction, |
| 4060 | out_loc, |
| 4061 | component_offset, |
| 4062 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4063 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4064 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4065 | __ Cbz(out, &done); |
| 4066 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4067 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4068 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4069 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4070 | __ Mov(out, 1); |
| 4071 | __ B(&done); |
| 4072 | break; |
| 4073 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4074 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4075 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4076 | // No read barrier since the slow path will retry upon failure. |
| 4077 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4078 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4079 | out_loc, |
| 4080 | obj_loc, |
| 4081 | class_offset, |
| 4082 | maybe_temp_loc, |
| 4083 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4084 | __ Cmp(out, cls); |
| 4085 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4086 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4087 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4088 | codegen_->AddSlowPath(slow_path); |
| 4089 | __ B(ne, slow_path->GetEntryLabel()); |
| 4090 | __ Mov(out, 1); |
| 4091 | if (zero.IsLinked()) { |
| 4092 | __ B(&done); |
| 4093 | } |
| 4094 | break; |
| 4095 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4096 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4097 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4098 | case TypeCheckKind::kInterfaceCheck: { |
| 4099 | // Note that we indeed only call on slow path, but we always go |
| 4100 | // into the slow path for the unresolved and interface check |
| 4101 | // cases. |
| 4102 | // |
| 4103 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4104 | // entry point without resorting to a type checking slow path |
| 4105 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4106 | // require to assign fixed registers for the inputs of this |
| 4107 | // HInstanceOf instruction (following the runtime calling |
| 4108 | // convention), which might be cluttered by the potential first |
| 4109 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4110 | // |
| 4111 | // TODO: Introduce a new runtime entry point taking the object |
| 4112 | // to test (instead of its class) as argument, and let it deal |
| 4113 | // with the read barrier issues. This will let us refactor this |
| 4114 | // case of the `switch` code as it was previously (with a direct |
| 4115 | // call to the runtime not using a type checking slow path). |
| 4116 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4117 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4118 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4119 | /* is_fatal */ false); |
| 4120 | codegen_->AddSlowPath(slow_path); |
| 4121 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4122 | if (zero.IsLinked()) { |
| 4123 | __ B(&done); |
| 4124 | } |
| 4125 | break; |
| 4126 | } |
| 4127 | } |
| 4128 | |
| 4129 | if (zero.IsLinked()) { |
| 4130 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4131 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4132 | } |
| 4133 | |
| 4134 | if (done.IsLinked()) { |
| 4135 | __ Bind(&done); |
| 4136 | } |
| 4137 | |
| 4138 | if (slow_path != nullptr) { |
| 4139 | __ Bind(slow_path->GetExitLabel()); |
| 4140 | } |
| 4141 | } |
| 4142 | |
| 4143 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 4144 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4145 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 4146 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4147 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 4148 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4149 | case TypeCheckKind::kExactCheck: |
| 4150 | case TypeCheckKind::kAbstractClassCheck: |
| 4151 | case TypeCheckKind::kClassHierarchyCheck: |
| 4152 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4153 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 4154 | LocationSummary::kCallOnSlowPath : |
| 4155 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4156 | break; |
| 4157 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4158 | case TypeCheckKind::kUnresolvedCheck: |
| 4159 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4160 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4161 | break; |
| 4162 | } |
| 4163 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4164 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4165 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4166 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4167 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4168 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4169 | } |
| 4170 | |
| 4171 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4172 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4173 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4174 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4175 | Register obj = InputRegisterAt(instruction, 0); |
| 4176 | Register cls = InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4177 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4178 | DCHECK_GE(num_temps, 1u); |
| 4179 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4180 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4181 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4182 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4183 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4184 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4185 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4186 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4187 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4188 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4189 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4190 | const uint32_t object_array_data_offset = |
| 4191 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4192 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4193 | bool is_type_check_slow_path_fatal = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4194 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 4195 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 4196 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4197 | if (!kEmitCompilerReadBarrier) { |
| 4198 | is_type_check_slow_path_fatal = |
| 4199 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 4200 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 4201 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 4202 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 4203 | !instruction->CanThrowIntoCatchBlock(); |
| 4204 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4205 | SlowPathCodeARM64* type_check_slow_path = |
| 4206 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4207 | is_type_check_slow_path_fatal); |
| 4208 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4209 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4210 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4211 | // Avoid null check if we know obj is not null. |
| 4212 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4213 | __ Cbz(obj, &done); |
| 4214 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4215 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4216 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4217 | case TypeCheckKind::kExactCheck: |
| 4218 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4219 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4220 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4221 | temp_loc, |
| 4222 | obj_loc, |
| 4223 | class_offset, |
| 4224 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4225 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4226 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4227 | __ Cmp(temp, cls); |
| 4228 | // Jump to slow path for throwing the exception or doing a |
| 4229 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4230 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4231 | break; |
| 4232 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4233 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4234 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4235 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4236 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4237 | temp_loc, |
| 4238 | obj_loc, |
| 4239 | class_offset, |
| 4240 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4241 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4242 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4243 | // If the class is abstract, we eagerly fetch the super class of the |
| 4244 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4245 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4246 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4247 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4248 | GenerateReferenceLoadOneRegister(instruction, |
| 4249 | temp_loc, |
| 4250 | super_offset, |
| 4251 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4252 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4253 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4254 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4255 | // exception. |
| 4256 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4257 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4258 | __ Cmp(temp, cls); |
| 4259 | __ B(ne, &loop); |
| 4260 | break; |
| 4261 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4262 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4263 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4264 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4265 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4266 | temp_loc, |
| 4267 | obj_loc, |
| 4268 | class_offset, |
| 4269 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4270 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4271 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4272 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4273 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4274 | __ Bind(&loop); |
| 4275 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4276 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4277 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4278 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4279 | GenerateReferenceLoadOneRegister(instruction, |
| 4280 | temp_loc, |
| 4281 | super_offset, |
| 4282 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4283 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4284 | |
| 4285 | // If the class reference currently in `temp` is not null, jump |
| 4286 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4287 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4288 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4289 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4290 | break; |
| 4291 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4292 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4293 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4294 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4295 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4296 | temp_loc, |
| 4297 | obj_loc, |
| 4298 | class_offset, |
| 4299 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4300 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4301 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4302 | // Do an exact check. |
| 4303 | __ Cmp(temp, cls); |
| 4304 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4305 | |
| 4306 | // 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] | 4307 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4308 | GenerateReferenceLoadOneRegister(instruction, |
| 4309 | temp_loc, |
| 4310 | component_offset, |
| 4311 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4312 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4313 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4314 | // If the component type is null, jump to the slow path to throw the exception. |
| 4315 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4316 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4317 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4318 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4319 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4320 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4321 | break; |
| 4322 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4323 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4324 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4325 | // 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] | 4326 | // |
| 4327 | // We cannot directly call the CheckCast runtime entry point |
| 4328 | // without resorting to a type checking slow path here (i.e. by |
| 4329 | // calling InvokeRuntime directly), as it would require to |
| 4330 | // assign fixed registers for the inputs of this HInstanceOf |
| 4331 | // instruction (following the runtime calling convention), which |
| 4332 | // might be cluttered by the potential first read barrier |
| 4333 | // emission at the beginning of this method. |
| 4334 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4335 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4336 | case TypeCheckKind::kInterfaceCheck: { |
| 4337 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4338 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4339 | temp_loc, |
| 4340 | obj_loc, |
| 4341 | class_offset, |
| 4342 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4343 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4344 | |
| 4345 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4346 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4347 | temp_loc, |
| 4348 | temp_loc, |
| 4349 | iftable_offset, |
| 4350 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4351 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4352 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4353 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4354 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4355 | vixl::aarch64::Label start_loop; |
| 4356 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4357 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4358 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4359 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4360 | // Go to next interface. |
| 4361 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4362 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4363 | // Compare the classes and continue the loop if they do not match. |
| 4364 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4365 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4366 | break; |
| 4367 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4368 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4369 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4370 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4371 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4372 | } |
| 4373 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4374 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 4375 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4376 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4377 | } |
| 4378 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4379 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4380 | // Will be generated at use site. |
| 4381 | } |
| 4382 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4383 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 4384 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4385 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4386 | } |
| 4387 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4388 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4389 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4390 | } |
| 4391 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4392 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4393 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4394 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4395 | // the method_idx. |
| 4396 | HandleInvoke(invoke); |
| 4397 | } |
| 4398 | |
| 4399 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4400 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4401 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4402 | } |
| 4403 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4404 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4405 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4406 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4407 | } |
| 4408 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4409 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4410 | HandleInvoke(invoke); |
| 4411 | } |
| 4412 | |
| 4413 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4414 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4415 | LocationSummary* locations = invoke->GetLocations(); |
| 4416 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4417 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4418 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4419 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4420 | |
| 4421 | // The register ip1 is required to be used for the hidden argument in |
| 4422 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4423 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4424 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4425 | scratch_scope.Exclude(ip1); |
| 4426 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4427 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4428 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4429 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4430 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4431 | { |
| 4432 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4433 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4434 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4435 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4436 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4437 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4438 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4439 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4440 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4441 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4442 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4443 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4444 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4445 | // emit a read barrier for the previous class reference load. |
| 4446 | // However this is not required in practice, as this is an |
| 4447 | // intermediate/temporary reference and because the current |
| 4448 | // concurrent copying collector keeps the from-space memory |
| 4449 | // intact/accessible until the end of the marking phase (the |
| 4450 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4451 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4452 | __ Ldr(temp, |
| 4453 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4454 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4455 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4456 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4457 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4458 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4459 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4460 | |
| 4461 | { |
| 4462 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4463 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4464 | |
| 4465 | // lr(); |
| 4466 | __ blr(lr); |
| 4467 | DCHECK(!codegen_->IsLeafMethod()); |
| 4468 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4469 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4470 | |
| 4471 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4475 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4476 | if (intrinsic.TryDispatch(invoke)) { |
| 4477 | return; |
| 4478 | } |
| 4479 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4480 | HandleInvoke(invoke); |
| 4481 | } |
| 4482 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4483 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4484 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4485 | // art::PrepareForRegisterAllocation. |
| 4486 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4487 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4488 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4489 | if (intrinsic.TryDispatch(invoke)) { |
| 4490 | return; |
| 4491 | } |
| 4492 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4493 | HandleInvoke(invoke); |
| 4494 | } |
| 4495 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4496 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4497 | if (invoke->GetLocations()->Intrinsified()) { |
| 4498 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4499 | intrinsic.Dispatch(invoke); |
| 4500 | return true; |
| 4501 | } |
| 4502 | return false; |
| 4503 | } |
| 4504 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4505 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4506 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4507 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4508 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4509 | return desired_dispatch_info; |
| 4510 | } |
| 4511 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4512 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4513 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4514 | // 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] | 4515 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4516 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4517 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4518 | uint32_t offset = |
| 4519 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4520 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4521 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4522 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4523 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4524 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4525 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4526 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4527 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4528 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4529 | // Add ADRP with its PC-relative method patch. |
| 4530 | vixl::aarch64::Label* adrp_label = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 4531 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4532 | // Add ADD with its PC-relative method patch. |
| 4533 | vixl::aarch64::Label* add_label = |
| 4534 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), adrp_label); |
| 4535 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4536 | break; |
| 4537 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4538 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4539 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4540 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4541 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4542 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4543 | // Add ADRP with its PC-relative DexCache access 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 | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4547 | // Add LDR with its PC-relative DexCache access 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 | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4553 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4554 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4555 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4556 | } |
| 4557 | } |
| 4558 | |
| 4559 | switch (invoke->GetCodePtrLocation()) { |
| 4560 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4561 | { |
| 4562 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4563 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4564 | kInstructionSize, |
| 4565 | CodeBufferCheckScope::kExactSize); |
| 4566 | __ bl(&frame_entry_label_); |
| 4567 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4568 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4569 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4570 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4571 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4572 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4573 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4574 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4575 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4576 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4577 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4578 | kInstructionSize, |
| 4579 | CodeBufferCheckScope::kExactSize); |
| 4580 | // lr() |
| 4581 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4582 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4583 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4584 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4585 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4586 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4587 | DCHECK(!IsLeafMethod()); |
| 4588 | } |
| 4589 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4590 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4591 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4592 | // Use the calling convention instead of the location of the receiver, as |
| 4593 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4594 | // slow path, the arguments have been moved to the right place, so here we are |
| 4595 | // guaranteed that the receiver is the first register of the calling convention. |
| 4596 | InvokeDexCallingConvention calling_convention; |
| 4597 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4598 | Register temp = XRegisterFrom(temp_in); |
| 4599 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4600 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4601 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4602 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4603 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4604 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4605 | |
| 4606 | { |
| 4607 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4608 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4609 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4610 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4611 | MaybeRecordImplicitNullCheck(invoke); |
| 4612 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4613 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4614 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4615 | // intermediate/temporary reference and because the current |
| 4616 | // concurrent copying collector keeps the from-space memory |
| 4617 | // intact/accessible until the end of the marking phase (the |
| 4618 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4619 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4620 | // temp = temp->GetMethodAt(method_offset); |
| 4621 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4622 | // lr = temp->GetEntryPoint(); |
| 4623 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4624 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4625 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4626 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4627 | // lr(); |
| 4628 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4629 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4630 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4631 | } |
| 4632 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4633 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4634 | HandleInvoke(invoke); |
| 4635 | } |
| 4636 | |
| 4637 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4638 | codegen_->GenerateInvokePolymorphicCall(invoke); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4639 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4640 | } |
| 4641 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4642 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeMethodPatch( |
| 4643 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4644 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4645 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4646 | target_method.index, |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4647 | adrp_label, |
| 4648 | &pc_relative_method_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4649 | } |
| 4650 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4651 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4652 | MethodReference target_method, |
| 4653 | vixl::aarch64::Label* adrp_label) { |
| 4654 | return NewPcRelativePatch(*target_method.dex_file, |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 4655 | target_method.index, |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4656 | adrp_label, |
| 4657 | &method_bss_entry_patches_); |
| 4658 | } |
| 4659 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4660 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 4661 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4662 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4663 | vixl::aarch64::Label* adrp_label) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4664 | return NewPcRelativePatch(dex_file, type_index.index_, adrp_label, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4665 | } |
| 4666 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4667 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4668 | const DexFile& dex_file, |
| 4669 | dex::TypeIndex type_index, |
| 4670 | vixl::aarch64::Label* adrp_label) { |
| 4671 | return NewPcRelativePatch(dex_file, type_index.index_, adrp_label, &type_bss_entry_patches_); |
| 4672 | } |
| 4673 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4674 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 4675 | const DexFile& dex_file, |
| 4676 | dex::StringIndex string_index, |
| 4677 | vixl::aarch64::Label* adrp_label) { |
| 4678 | return |
| 4679 | NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &pc_relative_string_patches_); |
| 4680 | } |
| 4681 | |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4682 | vixl::aarch64::Label* CodeGeneratorARM64::NewStringBssEntryPatch( |
| 4683 | const DexFile& dex_file, |
| 4684 | dex::StringIndex string_index, |
| 4685 | vixl::aarch64::Label* adrp_label) { |
| 4686 | return NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &string_bss_entry_patches_); |
| 4687 | } |
| 4688 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4689 | vixl::aarch64::Label* CodeGeneratorARM64::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 4690 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4691 | return &baker_read_barrier_patches_.back().label; |
| 4692 | } |
| 4693 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4694 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 4695 | const DexFile& dex_file, |
| 4696 | uint32_t offset_or_index, |
| 4697 | vixl::aarch64::Label* adrp_label, |
| 4698 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4699 | // Add a patch entry and return the label. |
| 4700 | patches->emplace_back(dex_file, offset_or_index); |
| 4701 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4702 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4703 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4704 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4705 | return label; |
| 4706 | } |
| 4707 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4708 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4709 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4710 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4711 | } |
| 4712 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4713 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4714 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
| 4715 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 4716 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4717 | return jit_string_patches_.GetOrCreate( |
| 4718 | StringReference(&dex_file, string_index), |
| 4719 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4720 | } |
| 4721 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4722 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4723 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
| 4724 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 4725 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4726 | return jit_class_patches_.GetOrCreate( |
| 4727 | TypeReference(&dex_file, type_index), |
| 4728 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4729 | } |
| 4730 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4731 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4732 | vixl::aarch64::Register reg) { |
| 4733 | DCHECK(reg.IsX()); |
| 4734 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4735 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4736 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4737 | } |
| 4738 | |
| 4739 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4740 | vixl::aarch64::Register out, |
| 4741 | vixl::aarch64::Register base) { |
| 4742 | DCHECK(out.IsX()); |
| 4743 | DCHECK(base.IsX()); |
| 4744 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4745 | __ Bind(fixup_label); |
| 4746 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4747 | } |
| 4748 | |
| 4749 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4750 | vixl::aarch64::Register out, |
| 4751 | vixl::aarch64::Register base) { |
| 4752 | DCHECK(base.IsX()); |
| 4753 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4754 | __ Bind(fixup_label); |
| 4755 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4756 | } |
| 4757 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4758 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4759 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4760 | const ArenaDeque<PcRelativePatchInfo>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4761 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4762 | for (const PcRelativePatchInfo& info : infos) { |
| 4763 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 4764 | &info.target_dex_file, |
| 4765 | info.pc_insn_label->GetLocation(), |
| 4766 | info.offset_or_index)); |
| 4767 | } |
| 4768 | } |
| 4769 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4770 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4771 | DCHECK(linker_patches->empty()); |
| 4772 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4773 | pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4774 | method_bss_entry_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4775 | pc_relative_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4776 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4777 | pc_relative_string_patches_.size() + |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4778 | string_bss_entry_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4779 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4780 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4781 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4782 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 4783 | pc_relative_method_patches_, linker_patches); |
| 4784 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 4785 | pc_relative_type_patches_, linker_patches); |
| 4786 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| 4787 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4788 | } else { |
| 4789 | DCHECK(pc_relative_method_patches_.empty()); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4790 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeClassTablePatch>( |
| 4791 | pc_relative_type_patches_, linker_patches); |
| 4792 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringInternTablePatch>( |
| 4793 | pc_relative_string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4794 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4795 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 4796 | method_bss_entry_patches_, linker_patches); |
| 4797 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 4798 | type_bss_entry_patches_, linker_patches); |
| 4799 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 4800 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4801 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 4802 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 4803 | info.label.GetLocation(), info.custom_data)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4804 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4805 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4806 | } |
| 4807 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4808 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4809 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4810 | value, |
| 4811 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4812 | } |
| 4813 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4814 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4815 | return uint64_literals_.GetOrCreate( |
| 4816 | value, |
| 4817 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4818 | } |
| 4819 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4820 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4821 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4822 | // art::PrepareForRegisterAllocation. |
| 4823 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4824 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4825 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4826 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4827 | return; |
| 4828 | } |
| 4829 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4830 | { |
| 4831 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4832 | // are no pools emitted. |
| 4833 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4834 | LocationSummary* locations = invoke->GetLocations(); |
| 4835 | codegen_->GenerateStaticOrDirectCall( |
| 4836 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| 4837 | } |
| 4838 | |
| 4839 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4840 | } |
| 4841 | |
| 4842 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4843 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4844 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4845 | return; |
| 4846 | } |
| 4847 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4848 | { |
| 4849 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4850 | // are no pools emitted. |
| 4851 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
| 4852 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| 4853 | DCHECK(!codegen_->IsLeafMethod()); |
| 4854 | } |
| 4855 | |
| 4856 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4857 | } |
| 4858 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4859 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4860 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4861 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4862 | case HLoadClass::LoadKind::kInvalid: |
| 4863 | LOG(FATAL) << "UNREACHABLE"; |
| 4864 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4865 | case HLoadClass::LoadKind::kReferrersClass: |
| 4866 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4867 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4868 | case HLoadClass::LoadKind::kBootImageClassTable: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4869 | case HLoadClass::LoadKind::kBssEntry: |
| 4870 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4871 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4872 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4873 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4874 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4875 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4876 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4877 | break; |
| 4878 | } |
| 4879 | return desired_class_load_kind; |
| 4880 | } |
| 4881 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4882 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4883 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4884 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4885 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4886 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4887 | cls, |
| 4888 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4889 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4890 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4891 | return; |
| 4892 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4893 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4894 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4895 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4896 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4897 | ? LocationSummary::kCallOnSlowPath |
| 4898 | : LocationSummary::kNoCall; |
| 4899 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4900 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4901 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4902 | } |
| 4903 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4904 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4905 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4906 | } |
| 4907 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4908 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 4909 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4910 | // Rely on the type resolution or initialization and marking to save everything we need. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4911 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4912 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4913 | InvokeRuntimeCallingConvention calling_convention; |
| 4914 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4915 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 4916 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 4917 | Primitive::kPrimNot).GetCode()); |
| 4918 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4919 | } else { |
| 4920 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4921 | } |
| 4922 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4923 | } |
| 4924 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4925 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4926 | // move. |
| 4927 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4928 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4929 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4930 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 4931 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4932 | return; |
| 4933 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4934 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4935 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4936 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4937 | Register out = OutputRegister(cls); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4938 | Register bss_entry_temp; |
| 4939 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4940 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4941 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4942 | ? kWithoutReadBarrier |
| 4943 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4944 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4945 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4946 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4947 | DCHECK(!cls->CanCallRuntime()); |
| 4948 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4949 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4950 | Register current_method = InputRegisterAt(cls, 0); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4951 | GenerateGcRootFieldLoad(cls, |
| 4952 | out_loc, |
| 4953 | current_method, |
| 4954 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4955 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4956 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4957 | break; |
| 4958 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4959 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4960 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4961 | // Add ADRP with its PC-relative type patch. |
| 4962 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4963 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4964 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4965 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4966 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4967 | vixl::aarch64::Label* add_label = |
| 4968 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4969 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4970 | break; |
| 4971 | } |
| 4972 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4973 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4974 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 4975 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 4976 | DCHECK_NE(address, 0u); |
| 4977 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4978 | break; |
| 4979 | } |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 4980 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 4981 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 4982 | // Add ADRP with its PC-relative type patch. |
| 4983 | const DexFile& dex_file = cls->GetDexFile(); |
| 4984 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
| 4985 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
| 4986 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| 4987 | // Add LDR with its PC-relative type patch. |
| 4988 | vixl::aarch64::Label* ldr_label = |
| 4989 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
| 4990 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 4991 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 4992 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 4993 | ComputeModifiedUtf8Hash(dex_file.StringByTypeIdx(type_index))); |
| 4994 | if (masked_hash != 0) { |
| 4995 | __ Sub(out.W(), out.W(), Operand(masked_hash)); |
| 4996 | } |
| 4997 | break; |
| 4998 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4999 | case HLoadClass::LoadKind::kBssEntry: { |
| 5000 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 5001 | const DexFile& dex_file = cls->GetDexFile(); |
| 5002 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5003 | bss_entry_temp = XRegisterFrom(cls->GetLocations()->GetTemp(0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5004 | bss_entry_adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 5005 | codegen_->EmitAdrpPlaceholder(bss_entry_adrp_label, bss_entry_temp); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5006 | // Add LDR with its PC-relative Class patch. |
| 5007 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5008 | codegen_->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5009 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 5010 | GenerateGcRootFieldLoad(cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5011 | out_loc, |
| 5012 | bss_entry_temp, |
| 5013 | /* offset placeholder */ 0u, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5014 | ldr_label, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5015 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5016 | generate_null_check = true; |
| 5017 | break; |
| 5018 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5019 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5020 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5021 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5022 | cls->GetClass())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5023 | GenerateGcRootFieldLoad(cls, |
| 5024 | out_loc, |
| 5025 | out.X(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5026 | /* offset */ 0, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5027 | /* fixup_label */ nullptr, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5028 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5029 | break; |
| 5030 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5031 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5032 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5033 | LOG(FATAL) << "UNREACHABLE"; |
| 5034 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5035 | } |
| 5036 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5037 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 5038 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5039 | DCHECK(cls->CanCallRuntime()); |
| 5040 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5041 | cls, cls, cls->GetDexPc(), do_clinit, bss_entry_temp, bss_entry_adrp_label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5042 | codegen_->AddSlowPath(slow_path); |
| 5043 | if (generate_null_check) { |
| 5044 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 5045 | } |
| 5046 | if (cls->MustGenerateClinitCheck()) { |
| 5047 | GenerateClassInitializationCheck(slow_path, out); |
| 5048 | } else { |
| 5049 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5050 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5051 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5052 | } |
| 5053 | } |
| 5054 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5055 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5056 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5057 | } |
| 5058 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5059 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5060 | LocationSummary* locations = |
| 5061 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5062 | locations->SetOut(Location::RequiresRegister()); |
| 5063 | } |
| 5064 | |
| 5065 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5066 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5067 | } |
| 5068 | |
| 5069 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 5070 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5071 | } |
| 5072 | |
| 5073 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5074 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5075 | } |
| 5076 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5077 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5078 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5079 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5080 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5081 | case HLoadString::LoadKind::kBootImageInternTable: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5082 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5083 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5084 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5085 | case HLoadString::LoadKind::kJitTableAddress: |
| 5086 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5087 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5088 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5089 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5090 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5091 | } |
| 5092 | return desired_string_load_kind; |
| 5093 | } |
| 5094 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5095 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5096 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5097 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5098 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5099 | InvokeRuntimeCallingConvention calling_convention; |
| 5100 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5101 | } else { |
| 5102 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5103 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5104 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5105 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5106 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5107 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5108 | InvokeRuntimeCallingConvention calling_convention; |
| 5109 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 5110 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 5111 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 5112 | Primitive::kPrimNot).GetCode()); |
| 5113 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5114 | } else { |
| 5115 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5116 | } |
| 5117 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5118 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5119 | } |
| 5120 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5121 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5122 | // move. |
| 5123 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5124 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5125 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5126 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5127 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5128 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5129 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5130 | // Add ADRP with its PC-relative String patch. |
| 5131 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5132 | const dex::StringIndex string_index = load->GetStringIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5133 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5134 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5135 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5136 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5137 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5138 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5139 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5140 | } |
| 5141 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5142 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5143 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5144 | DCHECK_NE(address, 0u); |
| 5145 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5146 | return; |
| 5147 | } |
| 5148 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 5149 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5150 | // Add ADRP with its PC-relative String patch. |
| 5151 | const DexFile& dex_file = load->GetDexFile(); |
| 5152 | const dex::StringIndex string_index = load->GetStringIndex(); |
| 5153 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
| 5154 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
| 5155 | // Add LDR with its PC-relative String patch. |
| 5156 | vixl::aarch64::Label* ldr_label = |
| 5157 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
| 5158 | codegen_->EmitLdrOffsetPlaceholder(ldr_label, out.W(), out.X()); |
| 5159 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5160 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5161 | case HLoadString::LoadKind::kBssEntry: { |
| 5162 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5163 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5164 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5165 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5166 | Register temp = XRegisterFrom(load->GetLocations()->GetTemp(0)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5167 | vixl::aarch64::Label* adrp_label = codegen_->NewStringBssEntryPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5168 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5169 | // Add LDR with its .bss entry String patch. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5170 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5171 | codegen_->NewStringBssEntryPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5172 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5173 | GenerateGcRootFieldLoad(load, |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5174 | out_loc, |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5175 | temp, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5176 | /* offset placeholder */ 0u, |
| 5177 | ldr_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5178 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5179 | SlowPathCodeARM64* slow_path = |
| 5180 | new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load, temp, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5181 | codegen_->AddSlowPath(slow_path); |
| 5182 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5183 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5184 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5185 | return; |
| 5186 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5187 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5188 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5189 | load->GetStringIndex(), |
| 5190 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5191 | GenerateGcRootFieldLoad(load, |
| 5192 | out_loc, |
| 5193 | out.X(), |
| 5194 | /* offset */ 0, |
| 5195 | /* fixup_label */ nullptr, |
| 5196 | kCompilerReadBarrierOption); |
| 5197 | return; |
| 5198 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5199 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5200 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5201 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5202 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5203 | // 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] | 5204 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5205 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5206 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5207 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5208 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5209 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5210 | } |
| 5211 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5212 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 5213 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5214 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5215 | } |
| 5216 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5217 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5218 | // Will be generated at use site. |
| 5219 | } |
| 5220 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5221 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5222 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5223 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5224 | InvokeRuntimeCallingConvention calling_convention; |
| 5225 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5226 | } |
| 5227 | |
| 5228 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5229 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5230 | instruction, |
| 5231 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5232 | if (instruction->IsEnter()) { |
| 5233 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5234 | } else { |
| 5235 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5236 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5237 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5238 | } |
| 5239 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5240 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5241 | LocationSummary* locations = |
| 5242 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 5243 | switch (mul->GetResultType()) { |
| 5244 | case Primitive::kPrimInt: |
| 5245 | case Primitive::kPrimLong: |
| 5246 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5247 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5248 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5249 | break; |
| 5250 | |
| 5251 | case Primitive::kPrimFloat: |
| 5252 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5253 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5254 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5255 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5256 | break; |
| 5257 | |
| 5258 | default: |
| 5259 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5260 | } |
| 5261 | } |
| 5262 | |
| 5263 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5264 | switch (mul->GetResultType()) { |
| 5265 | case Primitive::kPrimInt: |
| 5266 | case Primitive::kPrimLong: |
| 5267 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5268 | break; |
| 5269 | |
| 5270 | case Primitive::kPrimFloat: |
| 5271 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5272 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5273 | break; |
| 5274 | |
| 5275 | default: |
| 5276 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5277 | } |
| 5278 | } |
| 5279 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5280 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5281 | LocationSummary* locations = |
| 5282 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 5283 | switch (neg->GetResultType()) { |
| 5284 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5285 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5286 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5287 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5288 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5289 | |
| 5290 | case Primitive::kPrimFloat: |
| 5291 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5292 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5293 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5294 | break; |
| 5295 | |
| 5296 | default: |
| 5297 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5298 | } |
| 5299 | } |
| 5300 | |
| 5301 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5302 | switch (neg->GetResultType()) { |
| 5303 | case Primitive::kPrimInt: |
| 5304 | case Primitive::kPrimLong: |
| 5305 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5306 | break; |
| 5307 | |
| 5308 | case Primitive::kPrimFloat: |
| 5309 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5310 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5311 | break; |
| 5312 | |
| 5313 | default: |
| 5314 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5315 | } |
| 5316 | } |
| 5317 | |
| 5318 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 5319 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5320 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5321 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5322 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5323 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5324 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5328 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5329 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5330 | QuickEntrypointEnum entrypoint = |
| 5331 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5332 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5333 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5334 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5335 | } |
| 5336 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5337 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 5338 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5339 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5340 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5341 | if (instruction->IsStringAlloc()) { |
| 5342 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 5343 | } else { |
| 5344 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5345 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5346 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5347 | } |
| 5348 | |
| 5349 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5350 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5351 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5352 | if (instruction->IsStringAlloc()) { |
| 5353 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5354 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5355 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5356 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 5357 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5358 | |
| 5359 | { |
| 5360 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 5361 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 5362 | kInstructionSize, |
| 5363 | CodeBufferCheckScope::kExactSize); |
| 5364 | __ blr(lr); |
| 5365 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5366 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5367 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5368 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5369 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5370 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5371 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5372 | } |
| 5373 | |
| 5374 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 5375 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5376 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5377 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5378 | } |
| 5379 | |
| 5380 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5381 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5382 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5383 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5384 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5385 | break; |
| 5386 | |
| 5387 | default: |
| 5388 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5389 | } |
| 5390 | } |
| 5391 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5392 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 5393 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5394 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5395 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5396 | } |
| 5397 | |
| 5398 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5399 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5400 | } |
| 5401 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5402 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5403 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5404 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5405 | } |
| 5406 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5407 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5408 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5409 | return; |
| 5410 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5411 | { |
| 5412 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5413 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5414 | Location obj = instruction->GetLocations()->InAt(0); |
| 5415 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5416 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5417 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5418 | } |
| 5419 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5420 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5421 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5422 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5423 | |
| 5424 | LocationSummary* locations = instruction->GetLocations(); |
| 5425 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5426 | |
| 5427 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5428 | } |
| 5429 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5430 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5431 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5432 | } |
| 5433 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5434 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5435 | HandleBinaryOp(instruction); |
| 5436 | } |
| 5437 | |
| 5438 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5439 | HandleBinaryOp(instruction); |
| 5440 | } |
| 5441 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5442 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5443 | LOG(FATAL) << "Unreachable"; |
| 5444 | } |
| 5445 | |
| 5446 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 5447 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5448 | } |
| 5449 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5450 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 5451 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5452 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5453 | if (location.IsStackSlot()) { |
| 5454 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5455 | } else if (location.IsDoubleStackSlot()) { |
| 5456 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5457 | } |
| 5458 | locations->SetOut(location); |
| 5459 | } |
| 5460 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5461 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5462 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5463 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5464 | } |
| 5465 | |
| 5466 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5467 | LocationSummary* locations = |
| 5468 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5469 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5470 | } |
| 5471 | |
| 5472 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5473 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5474 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5475 | } |
| 5476 | |
| 5477 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 5478 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5479 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5480 | locations->SetInAt(i, Location::Any()); |
| 5481 | } |
| 5482 | locations->SetOut(Location::Any()); |
| 5483 | } |
| 5484 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5485 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5486 | LOG(FATAL) << "Unreachable"; |
| 5487 | } |
| 5488 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5489 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5490 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5491 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5492 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 5493 | : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5494 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 5495 | |
| 5496 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5497 | case Primitive::kPrimInt: |
| 5498 | case Primitive::kPrimLong: |
| 5499 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5500 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5501 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5502 | break; |
| 5503 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5504 | case Primitive::kPrimFloat: |
| 5505 | case Primitive::kPrimDouble: { |
| 5506 | InvokeRuntimeCallingConvention calling_convention; |
| 5507 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5508 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5509 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5510 | |
| 5511 | break; |
| 5512 | } |
| 5513 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5514 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5515 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5516 | } |
| 5517 | } |
| 5518 | |
| 5519 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 5520 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5521 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5522 | switch (type) { |
| 5523 | case Primitive::kPrimInt: |
| 5524 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5525 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5526 | break; |
| 5527 | } |
| 5528 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5529 | case Primitive::kPrimFloat: |
| 5530 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5531 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 5532 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5533 | if (type == Primitive::kPrimFloat) { |
| 5534 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5535 | } else { |
| 5536 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5537 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5538 | break; |
| 5539 | } |
| 5540 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5541 | default: |
| 5542 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5543 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5544 | } |
| 5545 | } |
| 5546 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5547 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5548 | constructor_fence->SetLocations(nullptr); |
| 5549 | } |
| 5550 | |
| 5551 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5552 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5553 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5554 | } |
| 5555 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5556 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5557 | memory_barrier->SetLocations(nullptr); |
| 5558 | } |
| 5559 | |
| 5560 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5561 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5562 | } |
| 5563 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5564 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 5565 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5566 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5567 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5568 | } |
| 5569 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5570 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5571 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5572 | } |
| 5573 | |
| 5574 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5575 | instruction->SetLocations(nullptr); |
| 5576 | } |
| 5577 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5578 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5579 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5580 | } |
| 5581 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5582 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5583 | HandleBinaryOp(ror); |
| 5584 | } |
| 5585 | |
| 5586 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5587 | HandleBinaryOp(ror); |
| 5588 | } |
| 5589 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5590 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5591 | HandleShift(shl); |
| 5592 | } |
| 5593 | |
| 5594 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5595 | HandleShift(shl); |
| 5596 | } |
| 5597 | |
| 5598 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5599 | HandleShift(shr); |
| 5600 | } |
| 5601 | |
| 5602 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5603 | HandleShift(shr); |
| 5604 | } |
| 5605 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5606 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5607 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5608 | } |
| 5609 | |
| 5610 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5611 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5612 | } |
| 5613 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5614 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5615 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5616 | } |
| 5617 | |
| 5618 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5619 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5620 | } |
| 5621 | |
| 5622 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5623 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5624 | } |
| 5625 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5626 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5627 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5628 | } |
| 5629 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5630 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5631 | HUnresolvedInstanceFieldGet* instruction) { |
| 5632 | FieldAccessCallingConventionARM64 calling_convention; |
| 5633 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5634 | instruction, instruction->GetFieldType(), calling_convention); |
| 5635 | } |
| 5636 | |
| 5637 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5638 | HUnresolvedInstanceFieldGet* instruction) { |
| 5639 | FieldAccessCallingConventionARM64 calling_convention; |
| 5640 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5641 | instruction->GetFieldType(), |
| 5642 | instruction->GetFieldIndex(), |
| 5643 | instruction->GetDexPc(), |
| 5644 | calling_convention); |
| 5645 | } |
| 5646 | |
| 5647 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5648 | HUnresolvedInstanceFieldSet* instruction) { |
| 5649 | FieldAccessCallingConventionARM64 calling_convention; |
| 5650 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5651 | instruction, instruction->GetFieldType(), calling_convention); |
| 5652 | } |
| 5653 | |
| 5654 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5655 | HUnresolvedInstanceFieldSet* instruction) { |
| 5656 | FieldAccessCallingConventionARM64 calling_convention; |
| 5657 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5658 | instruction->GetFieldType(), |
| 5659 | instruction->GetFieldIndex(), |
| 5660 | instruction->GetDexPc(), |
| 5661 | calling_convention); |
| 5662 | } |
| 5663 | |
| 5664 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5665 | HUnresolvedStaticFieldGet* instruction) { |
| 5666 | FieldAccessCallingConventionARM64 calling_convention; |
| 5667 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5668 | instruction, instruction->GetFieldType(), calling_convention); |
| 5669 | } |
| 5670 | |
| 5671 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5672 | HUnresolvedStaticFieldGet* instruction) { |
| 5673 | FieldAccessCallingConventionARM64 calling_convention; |
| 5674 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5675 | instruction->GetFieldType(), |
| 5676 | instruction->GetFieldIndex(), |
| 5677 | instruction->GetDexPc(), |
| 5678 | calling_convention); |
| 5679 | } |
| 5680 | |
| 5681 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5682 | HUnresolvedStaticFieldSet* instruction) { |
| 5683 | FieldAccessCallingConventionARM64 calling_convention; |
| 5684 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5685 | instruction, instruction->GetFieldType(), calling_convention); |
| 5686 | } |
| 5687 | |
| 5688 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5689 | HUnresolvedStaticFieldSet* instruction) { |
| 5690 | FieldAccessCallingConventionARM64 calling_convention; |
| 5691 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5692 | instruction->GetFieldType(), |
| 5693 | instruction->GetFieldIndex(), |
| 5694 | instruction->GetDexPc(), |
| 5695 | calling_convention); |
| 5696 | } |
| 5697 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5698 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5699 | LocationSummary* locations = |
| 5700 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5701 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5702 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5703 | // registers in full width (since the runtime only saves/restores lower part). |
| 5704 | locations->SetCustomSlowPathCallerSaves( |
| 5705 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5706 | } |
| 5707 | |
| 5708 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5709 | HBasicBlock* block = instruction->GetBlock(); |
| 5710 | if (block->GetLoopInformation() != nullptr) { |
| 5711 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5712 | // The back edge will generate the suspend check. |
| 5713 | return; |
| 5714 | } |
| 5715 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5716 | // The goto will generate the suspend check. |
| 5717 | return; |
| 5718 | } |
| 5719 | GenerateSuspendCheck(instruction, nullptr); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 5720 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5721 | } |
| 5722 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5723 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 5724 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5725 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5726 | InvokeRuntimeCallingConvention calling_convention; |
| 5727 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5728 | } |
| 5729 | |
| 5730 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5731 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5732 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5733 | } |
| 5734 | |
| 5735 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5736 | LocationSummary* locations = |
| 5737 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 5738 | Primitive::Type input_type = conversion->GetInputType(); |
| 5739 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 5740 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5741 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 5742 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 5743 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5744 | } |
| 5745 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5746 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5747 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5748 | } else { |
| 5749 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5750 | } |
| 5751 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5752 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5753 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5754 | } else { |
| 5755 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5756 | } |
| 5757 | } |
| 5758 | |
| 5759 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5760 | Primitive::Type result_type = conversion->GetResultType(); |
| 5761 | Primitive::Type input_type = conversion->GetInputType(); |
| 5762 | |
| 5763 | DCHECK_NE(input_type, result_type); |
| 5764 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5765 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5766 | int result_size = Primitive::ComponentSize(result_type); |
| 5767 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5768 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5769 | Register output = OutputRegister(conversion); |
| 5770 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5771 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5772 | // 'int' values are used directly as W registers, discarding the top |
| 5773 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5774 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5775 | // top 32 bits of the target register. We theoretically could leave those |
| 5776 | // bits unchanged, but we would have to make sure that no code uses a |
| 5777 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5778 | // zero. |
| 5779 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5780 | } else if (result_type == Primitive::kPrimChar || |
| 5781 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 5782 | __ Ubfx(output, |
| 5783 | output.IsX() ? source.X() : source.W(), |
| 5784 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5785 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5786 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5787 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5788 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5789 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5790 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5791 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 5792 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5793 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 5794 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5795 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5796 | } else { |
| 5797 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5798 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5799 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5800 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5801 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5802 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5803 | HandleShift(ushr); |
| 5804 | } |
| 5805 | |
| 5806 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5807 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5808 | } |
| 5809 | |
| 5810 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5811 | HandleBinaryOp(instruction); |
| 5812 | } |
| 5813 | |
| 5814 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5815 | HandleBinaryOp(instruction); |
| 5816 | } |
| 5817 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5818 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5819 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5820 | LOG(FATAL) << "Unreachable"; |
| 5821 | } |
| 5822 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5823 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5824 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5825 | LOG(FATAL) << "Unreachable"; |
| 5826 | } |
| 5827 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5828 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5829 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5830 | LocationSummary* locations = |
| 5831 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5832 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5833 | } |
| 5834 | |
| 5835 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5836 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5837 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5838 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5839 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5840 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5841 | // 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] | 5842 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5843 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5844 | // make sure we don't emit it if the target may run out of range. |
| 5845 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5846 | // ranges and emit the tables only as required. |
| 5847 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5848 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5849 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5850 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5851 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5852 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5853 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5854 | Register temp = temps.AcquireW(); |
| 5855 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5856 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5857 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5858 | // Jump to successors[0] if value == lower_bound. |
| 5859 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5860 | int32_t last_index = 0; |
| 5861 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5862 | __ Subs(temp, temp, Operand(2)); |
| 5863 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5864 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5865 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5866 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5867 | } |
| 5868 | if (num_entries - last_index == 2) { |
| 5869 | // The last missing case_value. |
| 5870 | __ Cmp(temp, Operand(1)); |
| 5871 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | // And the default for any other value. |
| 5875 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5876 | __ B(codegen_->GetLabelOf(default_block)); |
| 5877 | } |
| 5878 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5879 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5880 | |
| 5881 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5882 | |
| 5883 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5884 | // registers, we are free to block one. |
| 5885 | Register temp_w = temps.AcquireW(); |
| 5886 | Register index; |
| 5887 | // Remove the bias. |
| 5888 | if (lower_bound != 0) { |
| 5889 | index = temp_w; |
| 5890 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5891 | } else { |
| 5892 | index = value_reg; |
| 5893 | } |
| 5894 | |
| 5895 | // Jump to default block if index is out of the range. |
| 5896 | __ Cmp(index, Operand(num_entries)); |
| 5897 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5898 | |
| 5899 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5900 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5901 | // register pressure. |
| 5902 | Register table_base = temps.AcquireX(); |
| 5903 | // Load jump offset from the table. |
| 5904 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5905 | Register jump_offset = temp_w; |
| 5906 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5907 | |
| 5908 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5909 | Register target_address = table_base; |
| 5910 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5911 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5912 | } |
| 5913 | } |
| 5914 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5915 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 5916 | HInstruction* instruction, |
| 5917 | Location out, |
| 5918 | uint32_t offset, |
| 5919 | Location maybe_temp, |
| 5920 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5921 | Primitive::Type type = Primitive::kPrimNot; |
| 5922 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5923 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5924 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5925 | if (kUseBakerReadBarrier) { |
| 5926 | // Load with fast path based Baker's read barrier. |
| 5927 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5928 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5929 | out, |
| 5930 | out_reg, |
| 5931 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5932 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5933 | /* needs_null_check */ false, |
| 5934 | /* use_load_acquire */ false); |
| 5935 | } else { |
| 5936 | // Load with slow path based read barrier. |
| 5937 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5938 | // in the following move operation, as we will need it for the |
| 5939 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5940 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5941 | __ Mov(temp_reg, out_reg); |
| 5942 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5943 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5944 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5945 | } |
| 5946 | } else { |
| 5947 | // Plain load with no read barrier. |
| 5948 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5949 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5950 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5951 | } |
| 5952 | } |
| 5953 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5954 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 5955 | HInstruction* instruction, |
| 5956 | Location out, |
| 5957 | Location obj, |
| 5958 | uint32_t offset, |
| 5959 | Location maybe_temp, |
| 5960 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5961 | Primitive::Type type = Primitive::kPrimNot; |
| 5962 | Register out_reg = RegisterFrom(out, type); |
| 5963 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5964 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5965 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5966 | if (kUseBakerReadBarrier) { |
| 5967 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5968 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5969 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5970 | out, |
| 5971 | obj_reg, |
| 5972 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5973 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5974 | /* needs_null_check */ false, |
| 5975 | /* use_load_acquire */ false); |
| 5976 | } else { |
| 5977 | // Load with slow path based read barrier. |
| 5978 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5979 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5980 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5981 | } |
| 5982 | } else { |
| 5983 | // Plain load with no read barrier. |
| 5984 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5985 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5986 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5987 | } |
| 5988 | } |
| 5989 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5990 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad( |
| 5991 | HInstruction* instruction, |
| 5992 | Location root, |
| 5993 | Register obj, |
| 5994 | uint32_t offset, |
| 5995 | vixl::aarch64::Label* fixup_label, |
| 5996 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5997 | DCHECK(fixup_label == nullptr || offset == 0u); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5998 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5999 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6000 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6001 | if (kUseBakerReadBarrier) { |
| 6002 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6003 | // Baker's read barrier are used. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6004 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 6005 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6006 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6007 | // the Marking Register) to decide whether we need to enter |
| 6008 | // the slow path to mark the GC root. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6009 | // |
| 6010 | // We use link-time generated thunks for the slow path. That thunk |
| 6011 | // checks the reference and jumps to the entrypoint if needed. |
| 6012 | // |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6013 | // lr = &return_address; |
| 6014 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6015 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6016 | // goto gc_root_thunk<root_reg>(lr) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6017 | // } |
| 6018 | // return_address: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6019 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6020 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6021 | DCHECK(temps.IsAvailable(ip0)); |
| 6022 | DCHECK(temps.IsAvailable(ip1)); |
| 6023 | temps.Exclude(ip0, ip1); |
| 6024 | uint32_t custom_data = |
| 6025 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
| 6026 | vixl::aarch64::Label* cbnz_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6027 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6028 | EmissionCheckScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 6029 | vixl::aarch64::Label return_address; |
| 6030 | __ adr(lr, &return_address); |
| 6031 | if (fixup_label != nullptr) { |
| 6032 | __ Bind(fixup_label); |
| 6033 | } |
| 6034 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 6035 | "GC root LDR must be 2 instruction (8B) before the return address label."); |
| 6036 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 6037 | __ Bind(cbnz_label); |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6038 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6039 | __ Bind(&return_address); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6040 | } else { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6041 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 6042 | // the Marking Register) to decide whether we need to enter |
| 6043 | // the slow path to mark the GC root. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6044 | // |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6045 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6046 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6047 | // // Slow path. |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6048 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6049 | // root = entrypoint(root); // root = ReadBarrier::Mark(root); // Entry point call. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6050 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6051 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6052 | // Slow path marking the GC root `root`. The entrypoint will |
| 6053 | // be loaded by the slow path code. |
| 6054 | SlowPathCodeARM64* slow_path = |
| 6055 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, root); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6056 | codegen_->AddSlowPath(slow_path); |
| 6057 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6058 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6059 | if (fixup_label == nullptr) { |
| 6060 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6061 | } else { |
| 6062 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
| 6063 | } |
| 6064 | static_assert( |
| 6065 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6066 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6067 | "have different sizes."); |
| 6068 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6069 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6070 | "have different sizes."); |
| 6071 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6072 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6073 | __ Bind(slow_path->GetExitLabel()); |
| 6074 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6075 | } else { |
| 6076 | // GC root loaded through a slow path for read barriers other |
| 6077 | // than Baker's. |
| 6078 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6079 | if (fixup_label == nullptr) { |
| 6080 | __ Add(root_reg.X(), obj.X(), offset); |
| 6081 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6082 | codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6083 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6084 | // /* mirror::Object* */ root = root->Read() |
| 6085 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6086 | } |
| 6087 | } else { |
| 6088 | // Plain GC root load with no read barrier. |
| 6089 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6090 | if (fixup_label == nullptr) { |
| 6091 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6092 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6093 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6094 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6095 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6096 | // do not have to unpoison `root_reg` here. |
| 6097 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6098 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6099 | } |
| 6100 | |
| 6101 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6102 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6103 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6104 | uint32_t offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6105 | Location maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6106 | bool needs_null_check, |
| 6107 | bool use_load_acquire) { |
| 6108 | DCHECK(kEmitCompilerReadBarrier); |
| 6109 | DCHECK(kUseBakerReadBarrier); |
| 6110 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6111 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6112 | !use_load_acquire && |
| 6113 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6114 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6115 | // Marking Register) to decide whether we need to enter the slow |
| 6116 | // path to mark the reference. Then, in the slow path, check the |
| 6117 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6118 | // decide whether to mark `ref` or not. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6119 | // |
| 6120 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6121 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6122 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6123 | // |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6124 | // lr = &gray_return_address; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6125 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6126 | // goto field_thunk<holder_reg, base_reg>(lr) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6127 | // } |
| 6128 | // not_gray_return_address: |
| 6129 | // // Original reference load. If the offset is too large to fit |
| 6130 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6131 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6132 | // gray_return_address: |
| 6133 | |
| 6134 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6135 | Register base = obj; |
| 6136 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6137 | DCHECK(maybe_temp.IsRegister()); |
| 6138 | base = WRegisterFrom(maybe_temp); |
| 6139 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6140 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6141 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 6142 | } |
| 6143 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6144 | DCHECK(temps.IsAvailable(ip0)); |
| 6145 | DCHECK(temps.IsAvailable(ip1)); |
| 6146 | temps.Exclude(ip0, ip1); |
| 6147 | uint32_t custom_data = linker::Arm64RelativePatcher::EncodeBakerReadBarrierFieldData( |
| 6148 | base.GetCode(), |
| 6149 | obj.GetCode()); |
| 6150 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6151 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6152 | { |
| 6153 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6154 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6155 | vixl::aarch64::Label return_address; |
| 6156 | __ adr(lr, &return_address); |
| 6157 | __ Bind(cbnz_label); |
| 6158 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6159 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6160 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6161 | " 2 instructions (8B) for heap poisoning."); |
| 6162 | Register ref_reg = RegisterFrom(ref, Primitive::kPrimNot); |
| 6163 | __ ldr(ref_reg, MemOperand(base.X(), offset)); |
| 6164 | if (needs_null_check) { |
| 6165 | MaybeRecordImplicitNullCheck(instruction); |
| 6166 | } |
| 6167 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6168 | __ Bind(&return_address); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6169 | } |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6170 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6171 | return; |
| 6172 | } |
| 6173 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6174 | // /* HeapReference<Object> */ ref = *(obj + offset) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6175 | Register temp = WRegisterFrom(maybe_temp); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6176 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6177 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6178 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6179 | ref, |
| 6180 | obj, |
| 6181 | offset, |
| 6182 | no_index, |
| 6183 | no_scale_factor, |
| 6184 | temp, |
| 6185 | needs_null_check, |
| 6186 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6190 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6191 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6192 | uint32_t data_offset, |
| 6193 | Location index, |
| 6194 | Register temp, |
| 6195 | bool needs_null_check) { |
| 6196 | DCHECK(kEmitCompilerReadBarrier); |
| 6197 | DCHECK(kUseBakerReadBarrier); |
| 6198 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6199 | static_assert( |
| 6200 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6201 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6202 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 6203 | |
| 6204 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6205 | !Runtime::Current()->UseJitCompilation()) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6206 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6207 | // Marking Register) to decide whether we need to enter the slow |
| 6208 | // path to mark the reference. Then, in the slow path, check the |
| 6209 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6210 | // decide whether to mark `ref` or not. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6211 | // |
| 6212 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6213 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6214 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6215 | // |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6216 | // lr = &gray_return_address; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6217 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 6218 | // goto array_thunk<base_reg>(lr) |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6219 | // } |
| 6220 | // not_gray_return_address: |
| 6221 | // // Original reference load. If the offset is too large to fit |
| 6222 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6223 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6224 | // gray_return_address: |
| 6225 | |
| 6226 | DCHECK(index.IsValid()); |
| 6227 | Register index_reg = RegisterFrom(index, Primitive::kPrimInt); |
| 6228 | Register ref_reg = RegisterFrom(ref, Primitive::kPrimNot); |
| 6229 | |
| 6230 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6231 | DCHECK(temps.IsAvailable(ip0)); |
| 6232 | DCHECK(temps.IsAvailable(ip1)); |
| 6233 | temps.Exclude(ip0, ip1); |
| 6234 | uint32_t custom_data = |
| 6235 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierArrayData(temp.GetCode()); |
| 6236 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6237 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6238 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6239 | { |
| 6240 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6241 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6242 | vixl::aarch64::Label return_address; |
| 6243 | __ adr(lr, &return_address); |
| 6244 | __ Bind(cbnz_label); |
| 6245 | __ cbnz(mr, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6246 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6247 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6248 | " 2 instructions (8B) for heap poisoning."); |
| 6249 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6250 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6251 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6252 | __ Bind(&return_address); |
| 6253 | } |
| 6254 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__, /* temp_loc */ LocationFrom(ip1)); |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6255 | return; |
| 6256 | } |
| 6257 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6258 | // Array cells are never volatile variables, therefore array loads |
| 6259 | // never use Load-Acquire instructions on ARM64. |
| 6260 | const bool use_load_acquire = false; |
| 6261 | |
| 6262 | // /* HeapReference<Object> */ ref = |
| 6263 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6264 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6265 | ref, |
| 6266 | obj, |
| 6267 | data_offset, |
| 6268 | index, |
| 6269 | scale_factor, |
| 6270 | temp, |
| 6271 | needs_null_check, |
| 6272 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6273 | } |
| 6274 | |
| 6275 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6276 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6277 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6278 | uint32_t offset, |
| 6279 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6280 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6281 | Register temp, |
| 6282 | bool needs_null_check, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6283 | bool use_load_acquire) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6284 | DCHECK(kEmitCompilerReadBarrier); |
| 6285 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6286 | // If we are emitting an array load, we should not be using a |
| 6287 | // Load Acquire instruction. In other words: |
| 6288 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6289 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6290 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6291 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6292 | // Marking Register) to decide whether we need to enter the slow |
| 6293 | // path to mark the reference. Then, in the slow path, check the |
| 6294 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 6295 | // decide whether to mark `ref` or not. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6296 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6297 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6298 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6299 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6300 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6301 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 6302 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6303 | // if (is_gray) { |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6304 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6305 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6306 | // } |
| 6307 | // } else { |
| 6308 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6309 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6310 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6311 | // Slow path marking the object `ref` when the GC is marking. The |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6312 | // entrypoint will be loaded by the slow path code. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6313 | SlowPathCodeARM64* slow_path = |
| 6314 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM64( |
| 6315 | instruction, |
| 6316 | ref, |
| 6317 | obj, |
| 6318 | offset, |
| 6319 | index, |
| 6320 | scale_factor, |
| 6321 | needs_null_check, |
| 6322 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6323 | temp); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6324 | AddSlowPath(slow_path); |
| 6325 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6326 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6327 | // Fast path: the GC is not marking: just load the reference. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6328 | GenerateRawReferenceLoad( |
| 6329 | 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] | 6330 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6331 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6332 | } |
| 6333 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6334 | void CodeGeneratorARM64::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 6335 | Location ref, |
| 6336 | Register obj, |
| 6337 | Location field_offset, |
| 6338 | Register temp, |
| 6339 | bool needs_null_check, |
| 6340 | bool use_load_acquire) { |
| 6341 | DCHECK(kEmitCompilerReadBarrier); |
| 6342 | DCHECK(kUseBakerReadBarrier); |
| 6343 | // If we are emitting an array load, we should not be using a |
| 6344 | // Load Acquire instruction. In other words: |
| 6345 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6346 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
| 6347 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6348 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 6349 | // Marking Register) to decide whether we need to enter the slow |
| 6350 | // path to update the reference field within `obj`. Then, in the |
| 6351 | // slow path, check the gray bit in the lock word of the reference's |
| 6352 | // holder (`obj`) to decide whether to mark `ref` and update the |
| 6353 | // field or not. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6354 | // |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6355 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6356 | // // Slow path. |
| 6357 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6358 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6359 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
| 6360 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6361 | // if (is_gray) { |
| 6362 | // old_ref = ref; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6363 | // entrypoint = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6364 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6365 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 6366 | // } |
| 6367 | // } |
| 6368 | |
| 6369 | // Slow path updating the object reference at address `obj + field_offset` |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6370 | // 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] | 6371 | SlowPathCodeARM64* slow_path = |
| 6372 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 6373 | instruction, |
| 6374 | ref, |
| 6375 | obj, |
| 6376 | /* offset */ 0u, |
| 6377 | /* index */ field_offset, |
| 6378 | /* scale_factor */ 0u /* "times 1" */, |
| 6379 | needs_null_check, |
| 6380 | use_load_acquire, |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6381 | temp); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6382 | AddSlowPath(slow_path); |
| 6383 | |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6384 | __ Cbnz(mr, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6385 | // Fast path: the GC is not marking: nothing to do (the field is |
| 6386 | // up-to-date, and we don't need to load the reference). |
| 6387 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6388 | MaybeGenerateMarkingRegisterCheck(/* code */ __LINE__); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6389 | } |
| 6390 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6391 | void CodeGeneratorARM64::GenerateRawReferenceLoad(HInstruction* instruction, |
| 6392 | Location ref, |
| 6393 | Register obj, |
| 6394 | uint32_t offset, |
| 6395 | Location index, |
| 6396 | size_t scale_factor, |
| 6397 | bool needs_null_check, |
| 6398 | bool use_load_acquire) { |
| 6399 | DCHECK(obj.IsW()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6400 | Primitive::Type type = Primitive::kPrimNot; |
| 6401 | Register ref_reg = RegisterFrom(ref, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6402 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6403 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 6404 | // that no pools are emitted between the load (macro) instruction |
| 6405 | // and MaybeRecordImplicitNullCheck. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6406 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6407 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6408 | // Load types involving an "index": ArrayGet, |
| 6409 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6410 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6411 | if (use_load_acquire) { |
| 6412 | // UnsafeGetObjectVolatile intrinsic case. |
| 6413 | // Register `index` is not an index in an object array, but an |
| 6414 | // offset to an object reference field within object `obj`. |
| 6415 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 6416 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 6417 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 6418 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6419 | DCHECK_EQ(offset, 0u); |
| 6420 | DCHECK_EQ(scale_factor, 0u); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6421 | DCHECK_EQ(needs_null_check, false); |
| 6422 | // /* HeapReference<mirror::Object> */ ref = *(obj + index) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6423 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 6424 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6425 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6426 | // ArrayGet and UnsafeGetObject and UnsafeCASObject intrinsics cases. |
| 6427 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6428 | if (index.IsConstant()) { |
| 6429 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6430 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6431 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6432 | if (needs_null_check) { |
| 6433 | MaybeRecordImplicitNullCheck(instruction); |
| 6434 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6435 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6436 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6437 | Register temp = temps.AcquireW(); |
| 6438 | __ Add(temp, obj, offset); |
| 6439 | { |
| 6440 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6441 | Load(type, ref_reg, HeapOperand(temp, XRegisterFrom(index), LSL, scale_factor)); |
| 6442 | if (needs_null_check) { |
| 6443 | MaybeRecordImplicitNullCheck(instruction); |
| 6444 | } |
| 6445 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6446 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6447 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6448 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6449 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6450 | MemOperand field = HeapOperand(obj, offset); |
| 6451 | if (use_load_acquire) { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6452 | // Implicit null checks are handled by CodeGeneratorARM64::LoadAcquire. |
| 6453 | LoadAcquire(instruction, ref_reg, field, needs_null_check); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6454 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6455 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6456 | Load(type, ref_reg, field); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6457 | if (needs_null_check) { |
| 6458 | MaybeRecordImplicitNullCheck(instruction); |
| 6459 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6460 | } |
| 6461 | } |
| 6462 | |
| 6463 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6464 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6465 | } |
| 6466 | |
Roland Levillain | 2b03a1f | 2017-06-06 16:09:59 +0100 | [diff] [blame] | 6467 | void CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 6468 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 6469 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 6470 | // The following condition is a run-time one; it is executed after the |
| 6471 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 6472 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 6473 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6474 | Register temp = temp_loc.IsValid() ? WRegisterFrom(temp_loc) : temps.AcquireW(); |
| 6475 | GetAssembler()->GenerateMarkingRegisterCheck(temp, code); |
| 6476 | } |
| 6477 | } |
| 6478 | } |
| 6479 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6480 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6481 | Location out, |
| 6482 | Location ref, |
| 6483 | Location obj, |
| 6484 | uint32_t offset, |
| 6485 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6486 | DCHECK(kEmitCompilerReadBarrier); |
| 6487 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6488 | // Insert a slow path based read barrier *after* the reference load. |
| 6489 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6490 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6491 | // reference will be carried out by the runtime within the slow |
| 6492 | // path. |
| 6493 | // |
| 6494 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6495 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6496 | // not used by the artReadBarrierSlow entry point. |
| 6497 | // |
| 6498 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6499 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 6500 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6501 | AddSlowPath(slow_path); |
| 6502 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6503 | __ B(slow_path->GetEntryLabel()); |
| 6504 | __ Bind(slow_path->GetExitLabel()); |
| 6505 | } |
| 6506 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6507 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6508 | Location out, |
| 6509 | Location ref, |
| 6510 | Location obj, |
| 6511 | uint32_t offset, |
| 6512 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6513 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6514 | // Baker's read barriers shall be handled by the fast path |
| 6515 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6516 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6517 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6518 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6519 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6520 | } else if (kPoisonHeapReferences) { |
| 6521 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6522 | } |
| 6523 | } |
| 6524 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6525 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6526 | Location out, |
| 6527 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6528 | DCHECK(kEmitCompilerReadBarrier); |
| 6529 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6530 | // Insert a slow path based read barrier *after* the GC root load. |
| 6531 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6532 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6533 | // not need to do anything special for this here. |
| 6534 | SlowPathCodeARM64* slow_path = |
| 6535 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 6536 | AddSlowPath(slow_path); |
| 6537 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6538 | __ B(slow_path->GetEntryLabel()); |
| 6539 | __ Bind(slow_path->GetExitLabel()); |
| 6540 | } |
| 6541 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6542 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6543 | LocationSummary* locations = |
| 6544 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6545 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6546 | locations->SetOut(Location::RequiresRegister()); |
| 6547 | } |
| 6548 | |
| 6549 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6550 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6551 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6552 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6553 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6554 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6555 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6556 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6557 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6558 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6559 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6560 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6561 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6562 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6563 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6564 | } |
| 6565 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6566 | static void PatchJitRootUse(uint8_t* code, |
| 6567 | const uint8_t* roots_data, |
| 6568 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6569 | uint64_t index_in_table) { |
| 6570 | uint32_t literal_offset = literal->GetOffset(); |
| 6571 | uintptr_t address = |
| 6572 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6573 | uint8_t* data = code + literal_offset; |
| 6574 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6575 | } |
| 6576 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6577 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6578 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6579 | const StringReference& string_reference = entry.first; |
| 6580 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| 6581 | const auto it = jit_string_roots_.find(string_reference); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6582 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6583 | uint64_t index_in_table = it->second; |
| 6584 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6585 | } |
| 6586 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6587 | const TypeReference& type_reference = entry.first; |
| 6588 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| 6589 | const auto it = jit_class_roots_.find(type_reference); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6590 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6591 | uint64_t index_in_table = it->second; |
| 6592 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6593 | } |
| 6594 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6595 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6596 | #undef __ |
| 6597 | #undef QUICK_ENTRY_POINT |
| 6598 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6599 | } // namespace arm64 |
| 6600 | } // namespace art |