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" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 24 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 25 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 26 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 27 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 28 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 29 | #include "intrinsics.h" |
| 30 | #include "intrinsics_arm64.h" |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 31 | #include "linker/arm64/relative_patcher_arm64.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 32 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 33 | #include "mirror/class-inl.h" |
Andreas Gampe | d490129 | 2017-05-30 18:41:34 -0700 | [diff] [blame] | 34 | #include "lock_word.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 35 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 36 | #include "thread.h" |
| 37 | #include "utils/arm64/assembler_arm64.h" |
| 38 | #include "utils/assembler.h" |
| 39 | #include "utils/stack_checks.h" |
| 40 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 41 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 42 | using vixl::ExactAssemblyScope; |
| 43 | using vixl::CodeBufferCheckScope; |
| 44 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 45 | |
| 46 | #ifdef __ |
| 47 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 48 | #endif |
| 49 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 50 | namespace art { |
| 51 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 52 | template<class MirrorType> |
| 53 | class GcRoot; |
| 54 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 55 | namespace arm64 { |
| 56 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 57 | using helpers::ARM64EncodableConstantOrRegister; |
| 58 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 59 | using helpers::CPURegisterFrom; |
| 60 | using helpers::DRegisterFrom; |
| 61 | using helpers::FPRegisterFrom; |
| 62 | using helpers::HeapOperand; |
| 63 | using helpers::HeapOperandFrom; |
| 64 | using helpers::InputCPURegisterAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 65 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 66 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 67 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 68 | using helpers::InputRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 | using helpers::Int64ConstantFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 70 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 71 | using helpers::LocationFrom; |
| 72 | using helpers::OperandFromMemOperand; |
| 73 | using helpers::OutputCPURegister; |
| 74 | using helpers::OutputFPRegister; |
| 75 | using helpers::OutputRegister; |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 76 | using helpers::QRegisterFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 77 | using helpers::RegisterFrom; |
| 78 | using helpers::StackOperandFrom; |
| 79 | using helpers::VIXLRegCodeFromART; |
| 80 | using helpers::WRegisterFrom; |
| 81 | using helpers::XRegisterFrom; |
| 82 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 83 | // 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] | 84 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 85 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 86 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 87 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 88 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 89 | // offset < 16KiB. For offsets >= 16KiB, the load shall be emitted as two or more instructions. |
| 90 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 91 | // the offset explicitly. |
| 92 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 93 | |
| 94 | // 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] | 95 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 96 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 97 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 98 | |
| 99 | // Some instructions have special requirements for a temporary, for example |
| 100 | // LoadClass/kBssEntry and LoadString/kBssEntry for Baker read barrier require |
| 101 | // temp that's not an R0 (to avoid an extra move) and Baker read barrier field |
| 102 | // loads with large offsets need a fixed register to limit the number of link-time |
| 103 | // thunks we generate. For these and similar cases, we want to reserve a specific |
| 104 | // register that's neither callee-save nor an argument register. We choose x15. |
| 105 | inline Location FixedTempLocation() { |
| 106 | return Location::RegisterLocation(x15.GetCode()); |
| 107 | } |
| 108 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 109 | inline Condition ARM64Condition(IfCondition cond) { |
| 110 | switch (cond) { |
| 111 | case kCondEQ: return eq; |
| 112 | case kCondNE: return ne; |
| 113 | case kCondLT: return lt; |
| 114 | case kCondLE: return le; |
| 115 | case kCondGT: return gt; |
| 116 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 117 | case kCondB: return lo; |
| 118 | case kCondBE: return ls; |
| 119 | case kCondA: return hi; |
| 120 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 121 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 122 | LOG(FATAL) << "Unreachable"; |
| 123 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 126 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 127 | // The ARM64 condition codes can express all the necessary branches, see the |
| 128 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 129 | // There is no dex instruction or HIR that would need the missing conditions |
| 130 | // "equal or unordered" or "not equal". |
| 131 | switch (cond) { |
| 132 | case kCondEQ: return eq; |
| 133 | case kCondNE: return ne /* unordered */; |
| 134 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 135 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 136 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 137 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 138 | default: |
| 139 | LOG(FATAL) << "UNREACHABLE"; |
| 140 | UNREACHABLE(); |
| 141 | } |
| 142 | } |
| 143 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 144 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 145 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 146 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 147 | // but we use the exact registers for clarity. |
| 148 | if (return_type == Primitive::kPrimFloat) { |
| 149 | return LocationFrom(s0); |
| 150 | } else if (return_type == Primitive::kPrimDouble) { |
| 151 | return LocationFrom(d0); |
| 152 | } else if (return_type == Primitive::kPrimLong) { |
| 153 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 154 | } else if (return_type == Primitive::kPrimVoid) { |
| 155 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 156 | } else { |
| 157 | return LocationFrom(w0); |
| 158 | } |
| 159 | } |
| 160 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 161 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 162 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 165 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 166 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 167 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 168 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 169 | // Calculate memory accessing operand for save/restore live registers. |
| 170 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 171 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 172 | int64_t spill_offset, |
| 173 | bool is_save) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 174 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 175 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 176 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 177 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 178 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 179 | codegen->GetNumberOfFloatingPointRegisters())); |
| 180 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 181 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 182 | unsigned v_reg_size = codegen->GetGraph()->HasSIMD() ? kQRegSize : kDRegSize; |
| 183 | CPURegList fp_list = CPURegList(CPURegister::kVRegister, v_reg_size, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 184 | |
| 185 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 186 | UseScratchRegisterScope temps(masm); |
| 187 | |
| 188 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 189 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 190 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 191 | int64_t reg_size = kXRegSizeInBytes; |
| 192 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 193 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 194 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 195 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 196 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 197 | // to compute the base address(float point registers spill base address). |
| 198 | Register new_base = temps.AcquireSameSizeAs(base); |
| 199 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 200 | base = new_base; |
| 201 | spill_offset = -core_spill_size; |
| 202 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 203 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 204 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 205 | } |
| 206 | |
| 207 | if (is_save) { |
| 208 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 209 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 210 | } else { |
| 211 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 212 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 217 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 218 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 219 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 220 | // If the register holds an object, update the stack mask. |
| 221 | if (locations->RegisterContainsObject(i)) { |
| 222 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 223 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 224 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 225 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 226 | saved_core_stack_offsets_[i] = stack_offset; |
| 227 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 228 | } |
| 229 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 230 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 231 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 232 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 233 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 234 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 235 | stack_offset += kDRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 236 | } |
| 237 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 238 | SaveRestoreLiveRegistersHelper(codegen, |
| 239 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 240 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 241 | } |
| 242 | |
| 243 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 244 | SaveRestoreLiveRegistersHelper(codegen, |
| 245 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 246 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 247 | } |
| 248 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 249 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 250 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 251 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 252 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 253 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 254 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 255 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 256 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 257 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 258 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 259 | // Live registers will be restored in the catch block if caught. |
| 260 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 261 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 262 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 263 | // move resolver. |
| 264 | InvokeRuntimeCallingConvention calling_convention; |
| 265 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 266 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 267 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 268 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 269 | ? kQuickThrowStringBounds |
| 270 | : kQuickThrowArrayBounds; |
| 271 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 272 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 273 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 274 | } |
| 275 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 276 | bool IsFatal() const OVERRIDE { return true; } |
| 277 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 278 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 279 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 280 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 281 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 282 | }; |
| 283 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 284 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 285 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 286 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 287 | |
| 288 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 289 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 290 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 291 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 292 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 295 | bool IsFatal() const OVERRIDE { return true; } |
| 296 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 297 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 298 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 299 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 300 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 301 | }; |
| 302 | |
| 303 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 304 | public: |
| 305 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 306 | HInstruction* at, |
| 307 | uint32_t dex_pc, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 308 | bool do_clinit, |
| 309 | vixl::aarch64::Register bss_entry_temp = vixl::aarch64::Register(), |
| 310 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr) |
| 311 | : SlowPathCodeARM64(at), |
| 312 | cls_(cls), |
| 313 | dex_pc_(dex_pc), |
| 314 | do_clinit_(do_clinit), |
| 315 | bss_entry_temp_(bss_entry_temp), |
| 316 | bss_entry_adrp_label_(bss_entry_adrp_label) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 317 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 318 | } |
| 319 | |
| 320 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 321 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 322 | Location out = locations->Out(); |
| 323 | constexpr bool call_saves_everything_except_r0_ip0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 324 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 325 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 326 | InvokeRuntimeCallingConvention calling_convention; |
| 327 | // For HLoadClass/kBssEntry/kSaveEverything, the page address of the entry is in a temp |
| 328 | // 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] | 329 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 330 | bool is_load_class_bss_entry = |
| 331 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 332 | if (is_load_class_bss_entry) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 333 | DCHECK(bss_entry_temp_.IsValid()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 334 | DCHECK(!bss_entry_temp_.Is(calling_convention.GetRegisterAt(0))); |
| 335 | DCHECK( |
| 336 | !UseScratchRegisterScope(arm64_codegen->GetVIXLAssembler()).IsAvailable(bss_entry_temp_)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 339 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 340 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 341 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 342 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 343 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 344 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 345 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 346 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 347 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 348 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 349 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 350 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 351 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 352 | |
| 353 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 354 | if (out.IsValid()) { |
| 355 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 356 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 357 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 358 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 359 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 360 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 361 | if (is_load_class_bss_entry) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 362 | DCHECK(out.IsValid()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 363 | const DexFile& dex_file = cls_->GetDexFile(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 364 | if (call_saves_everything_except_r0_ip0) { |
| 365 | // The class entry page address was preserved in bss_entry_temp_ thanks to kSaveEverything. |
| 366 | } else { |
| 367 | // For non-Baker read barrier, we need to re-calculate the address of the class entry page. |
| 368 | bss_entry_adrp_label_ = arm64_codegen->NewBssEntryTypePatch(dex_file, type_index); |
| 369 | arm64_codegen->EmitAdrpPlaceholder(bss_entry_adrp_label_, bss_entry_temp_); |
| 370 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 371 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 372 | arm64_codegen->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label_); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 373 | { |
| 374 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 375 | __ Bind(strp_label); |
| 376 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 377 | MemOperand(bss_entry_temp_, /* offset placeholder */ 0)); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 378 | } |
| 379 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 380 | __ B(GetExitLabel()); |
| 381 | } |
| 382 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 383 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 384 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 385 | private: |
| 386 | // The class this slow path will load. |
| 387 | HLoadClass* const cls_; |
| 388 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 389 | // The dex PC of `at_`. |
| 390 | const uint32_t dex_pc_; |
| 391 | |
| 392 | // Whether to initialize the class. |
| 393 | const bool do_clinit_; |
| 394 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 395 | // For HLoadClass/kBssEntry, the temp register and the label of the ADRP where it was loaded. |
| 396 | vixl::aarch64::Register bss_entry_temp_; |
| 397 | vixl::aarch64::Label* bss_entry_adrp_label_; |
| 398 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 399 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 400 | }; |
| 401 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 402 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 403 | public: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 404 | LoadStringSlowPathARM64(HLoadString* instruction, Register temp, vixl::aarch64::Label* adrp_label) |
| 405 | : SlowPathCodeARM64(instruction), |
| 406 | temp_(temp), |
| 407 | adrp_label_(adrp_label) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 408 | |
| 409 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 410 | LocationSummary* locations = instruction_->GetLocations(); |
| 411 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 412 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 413 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 414 | InvokeRuntimeCallingConvention calling_convention; |
| 415 | // Make sure `temp_` is not clobbered by the call or by saving/restoring registers. |
| 416 | DCHECK(temp_.IsValid()); |
| 417 | DCHECK(!temp_.Is(calling_convention.GetRegisterAt(0))); |
| 418 | DCHECK(!UseScratchRegisterScope(arm64_codegen->GetVIXLAssembler()).IsAvailable(temp_)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 419 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 420 | __ Bind(GetEntryLabel()); |
| 421 | SaveLiveRegisters(codegen, locations); |
| 422 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 423 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 424 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 425 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 426 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 427 | Primitive::Type type = instruction_->GetType(); |
| 428 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 429 | |
| 430 | RestoreLiveRegisters(codegen, locations); |
| 431 | |
| 432 | // Store the resolved String to the BSS entry. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 433 | const DexFile& dex_file = instruction_->AsLoadString()->GetDexFile(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 434 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 435 | // The string entry page address was preserved in temp_ thanks to kSaveEverything. |
| 436 | } else { |
| 437 | // For non-Baker read barrier, we need to re-calculate the address of the string entry page. |
| 438 | adrp_label_ = arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index); |
| 439 | arm64_codegen->EmitAdrpPlaceholder(adrp_label_, temp_); |
| 440 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 441 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 442 | arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index, adrp_label_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 443 | { |
| 444 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 445 | __ Bind(strp_label); |
| 446 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 447 | MemOperand(temp_, /* offset placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | __ B(GetExitLabel()); |
| 451 | } |
| 452 | |
| 453 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 454 | |
| 455 | private: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 456 | const Register temp_; |
| 457 | vixl::aarch64::Label* adrp_label_; |
| 458 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 459 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 460 | }; |
| 461 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 462 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 463 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 464 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 465 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 466 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 467 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 468 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 469 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 470 | // Live registers will be restored in the catch block if caught. |
| 471 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 472 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 473 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 474 | instruction_, |
| 475 | instruction_->GetDexPc(), |
| 476 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 477 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 478 | } |
| 479 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 480 | bool IsFatal() const OVERRIDE { return true; } |
| 481 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 482 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 483 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 484 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 485 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 486 | }; |
| 487 | |
| 488 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 489 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 490 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 491 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 492 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 493 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 494 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 495 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 496 | __ Bind(GetEntryLabel()); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 497 | SaveLiveRegisters(codegen, locations); // Only saves live 128-bit regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 498 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 499 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 500 | RestoreLiveRegisters(codegen, locations); // Only restores live 128-bit regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 501 | if (successor_ == nullptr) { |
| 502 | __ B(GetReturnLabel()); |
| 503 | } else { |
| 504 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 505 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 506 | } |
| 507 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 508 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 509 | DCHECK(successor_ == nullptr); |
| 510 | return &return_label_; |
| 511 | } |
| 512 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 513 | HBasicBlock* GetSuccessor() const { |
| 514 | return successor_; |
| 515 | } |
| 516 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 517 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 518 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 519 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 520 | // If not null, the block to branch to after the suspend check. |
| 521 | HBasicBlock* const successor_; |
| 522 | |
| 523 | // 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] | 524 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 525 | |
| 526 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 527 | }; |
| 528 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 529 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 530 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 531 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 532 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 533 | |
| 534 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 535 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 536 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 537 | DCHECK(instruction_->IsCheckCast() |
| 538 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 539 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 540 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 541 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 542 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 543 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 544 | if (!is_fatal_) { |
| 545 | SaveLiveRegisters(codegen, locations); |
| 546 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 547 | |
| 548 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 549 | // move resolver. |
| 550 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 551 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 552 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 553 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 554 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 555 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 556 | Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 557 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 558 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 559 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 560 | Primitive::Type ret_type = instruction_->GetType(); |
| 561 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 562 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 563 | } else { |
| 564 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 565 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 566 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 569 | if (!is_fatal_) { |
| 570 | RestoreLiveRegisters(codegen, locations); |
| 571 | __ B(GetExitLabel()); |
| 572 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 575 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 576 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 577 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 578 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 579 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 580 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 581 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 582 | }; |
| 583 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 584 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 585 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 586 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 587 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 588 | |
| 589 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 590 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 591 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 592 | LocationSummary* locations = instruction_->GetLocations(); |
| 593 | SaveLiveRegisters(codegen, locations); |
| 594 | InvokeRuntimeCallingConvention calling_convention; |
| 595 | __ Mov(calling_convention.GetRegisterAt(0), |
| 596 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 597 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 598 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 601 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 602 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 603 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 604 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 605 | }; |
| 606 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 607 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 608 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 609 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 610 | |
| 611 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 612 | LocationSummary* locations = instruction_->GetLocations(); |
| 613 | __ Bind(GetEntryLabel()); |
| 614 | SaveLiveRegisters(codegen, locations); |
| 615 | |
| 616 | InvokeRuntimeCallingConvention calling_convention; |
| 617 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 618 | parallel_move.AddMove( |
| 619 | locations->InAt(0), |
| 620 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 621 | Primitive::kPrimNot, |
| 622 | nullptr); |
| 623 | parallel_move.AddMove( |
| 624 | locations->InAt(1), |
| 625 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 626 | Primitive::kPrimInt, |
| 627 | nullptr); |
| 628 | parallel_move.AddMove( |
| 629 | locations->InAt(2), |
| 630 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 631 | Primitive::kPrimNot, |
| 632 | nullptr); |
| 633 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 634 | |
| 635 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 636 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 637 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 638 | RestoreLiveRegisters(codegen, locations); |
| 639 | __ B(GetExitLabel()); |
| 640 | } |
| 641 | |
| 642 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 643 | |
| 644 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 645 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 646 | }; |
| 647 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 648 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 649 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 650 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 651 | |
| 652 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 653 | // 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] | 654 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 655 | num_entries * sizeof(int32_t), |
| 656 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 657 | |
| 658 | __ Bind(&table_start_); |
| 659 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 660 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 661 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 662 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 663 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 664 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 665 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 666 | Literal<int32_t> literal(jump_offset); |
| 667 | __ place(&literal); |
| 668 | } |
| 669 | } |
| 670 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 671 | // Abstract base class for read barrier slow paths marking a reference |
| 672 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 673 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 674 | // Argument `entrypoint` must be a register location holding the read |
| 675 | // barrier marking runtime entry point to be invoked. |
| 676 | class ReadBarrierMarkSlowPathBaseARM64 : public SlowPathCodeARM64 { |
| 677 | protected: |
| 678 | ReadBarrierMarkSlowPathBaseARM64(HInstruction* instruction, Location ref, Location entrypoint) |
| 679 | : SlowPathCodeARM64(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 680 | DCHECK(kEmitCompilerReadBarrier); |
| 681 | } |
| 682 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 683 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM64"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 684 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 685 | // Generate assembly code calling the read barrier marking runtime |
| 686 | // entry point (ReadBarrierMarkRegX). |
| 687 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 688 | // No need to save live registers; it's taken care of by the |
| 689 | // entrypoint. Also, there is no need to update the stack mask, |
| 690 | // as this runtime call will not trigger a garbage collection. |
| 691 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 692 | DCHECK_NE(ref_.reg(), LR); |
| 693 | DCHECK_NE(ref_.reg(), WSP); |
| 694 | DCHECK_NE(ref_.reg(), WZR); |
| 695 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 696 | // as a temporary, it cannot be the entry point's input/output. |
| 697 | DCHECK_NE(ref_.reg(), IP0); |
| 698 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 699 | // "Compact" slow path, saving two moves. |
| 700 | // |
| 701 | // Instead of using the standard runtime calling convention (input |
| 702 | // and output in W0): |
| 703 | // |
| 704 | // W0 <- ref |
| 705 | // W0 <- ReadBarrierMark(W0) |
| 706 | // ref <- W0 |
| 707 | // |
| 708 | // we just use rX (the register containing `ref`) as input and output |
| 709 | // of a dedicated entrypoint: |
| 710 | // |
| 711 | // rX <- ReadBarrierMarkRegX(rX) |
| 712 | // |
| 713 | if (entrypoint_.IsValid()) { |
| 714 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 715 | __ Blr(XRegisterFrom(entrypoint_)); |
| 716 | } else { |
| 717 | // Entrypoint is not already loaded, load from the thread. |
| 718 | int32_t entry_point_offset = |
| 719 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
| 720 | // This runtime call does not require a stack map. |
| 721 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | // The location (register) of the marked object reference. |
| 726 | const Location ref_; |
| 727 | |
| 728 | // The location of the entrypoint if it is already loaded. |
| 729 | const Location entrypoint_; |
| 730 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 731 | private: |
| 732 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM64); |
| 733 | }; |
| 734 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 735 | // Slow path marking an object reference `ref` during a read |
| 736 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 737 | // reference does not get updated by this slow path after marking. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 738 | // |
| 739 | // This means that after the execution of this slow path, `ref` will |
| 740 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 741 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 742 | // probably still be a from-space reference (unless it gets updated by |
| 743 | // another thread, or if another thread installed another object |
| 744 | // reference (different from `ref`) in `obj.field`). |
| 745 | // |
| 746 | // If `entrypoint` is a valid location it is assumed to already be |
| 747 | // holding the entrypoint. The case where the entrypoint is passed in |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 748 | // is when the decision to mark is based on whether the GC is marking. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 749 | class ReadBarrierMarkSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 750 | public: |
| 751 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 752 | Location ref, |
| 753 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 754 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 755 | DCHECK(kEmitCompilerReadBarrier); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 759 | |
| 760 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 761 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 762 | DCHECK(locations->CanCall()); |
| 763 | DCHECK(ref_.IsRegister()) << ref_; |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 764 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 765 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 766 | << "Unexpected instruction in read barrier marking slow path: " |
| 767 | << instruction_->DebugName(); |
| 768 | |
| 769 | __ Bind(GetEntryLabel()); |
| 770 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 771 | __ B(GetExitLabel()); |
| 772 | } |
| 773 | |
| 774 | private: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 775 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 776 | }; |
| 777 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 778 | // Slow path loading `obj`'s lock word, loading a reference from |
| 779 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 780 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 781 | // read barrier). The field `obj.field` in the object `obj` holding |
| 782 | // this reference does not get updated by this slow path after marking |
| 783 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 784 | // below for that). |
| 785 | // |
| 786 | // This means that after the execution of this slow path, `ref` will |
| 787 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 788 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 789 | // probably still be a from-space reference (unless it gets updated by |
| 790 | // another thread, or if another thread installed another object |
| 791 | // reference (different from `ref`) in `obj.field`). |
| 792 | // |
| 793 | // Argument `entrypoint` must be a register location holding the read |
| 794 | // barrier marking runtime entry point to be invoked. |
| 795 | class LoadReferenceWithBakerReadBarrierSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
| 796 | public: |
| 797 | LoadReferenceWithBakerReadBarrierSlowPathARM64(HInstruction* instruction, |
| 798 | Location ref, |
| 799 | Register obj, |
| 800 | uint32_t offset, |
| 801 | Location index, |
| 802 | size_t scale_factor, |
| 803 | bool needs_null_check, |
| 804 | bool use_load_acquire, |
| 805 | Register temp, |
| 806 | Location entrypoint) |
| 807 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
| 808 | obj_(obj), |
| 809 | offset_(offset), |
| 810 | index_(index), |
| 811 | scale_factor_(scale_factor), |
| 812 | needs_null_check_(needs_null_check), |
| 813 | use_load_acquire_(use_load_acquire), |
| 814 | temp_(temp) { |
| 815 | DCHECK(kEmitCompilerReadBarrier); |
| 816 | DCHECK(kUseBakerReadBarrier); |
| 817 | } |
| 818 | |
| 819 | const char* GetDescription() const OVERRIDE { |
| 820 | return "LoadReferenceWithBakerReadBarrierSlowPathARM64"; |
| 821 | } |
| 822 | |
| 823 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 824 | LocationSummary* locations = instruction_->GetLocations(); |
| 825 | DCHECK(locations->CanCall()); |
| 826 | DCHECK(ref_.IsRegister()) << ref_; |
| 827 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 828 | DCHECK(obj_.IsW()); |
| 829 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 830 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 831 | instruction_->IsStaticFieldGet() || |
| 832 | instruction_->IsArrayGet() || |
| 833 | instruction_->IsArraySet() || |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 834 | instruction_->IsInstanceOf() || |
| 835 | instruction_->IsCheckCast() || |
| 836 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 837 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 838 | << "Unexpected instruction in read barrier marking slow path: " |
| 839 | << instruction_->DebugName(); |
| 840 | // The read barrier instrumentation of object ArrayGet |
| 841 | // instructions does not support the HIntermediateAddress |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 842 | // instruction. |
| 843 | DCHECK(!(instruction_->IsArrayGet() && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 844 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 845 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 846 | // Temporary register `temp_`, used to store the lock word, must |
| 847 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 848 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 849 | // need the lock word to still be in `temp_` after the reference |
| 850 | // load. |
| 851 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 852 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
| 853 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 854 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 855 | |
| 856 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 857 | // inserted after the original load. However, in fast path based |
| 858 | // Baker's read barriers, we need to perform the load of |
| 859 | // mirror::Object::monitor_ *before* the original reference load. |
| 860 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 861 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 862 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 863 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 864 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 865 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 866 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 867 | // if (is_gray) { |
| 868 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 869 | // } |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 870 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 871 | // Note: the original implementation in ReadBarrier::Barrier is |
| 872 | // slightly more complex as it performs additional checks that we do |
| 873 | // not do here for performance reasons. |
| 874 | |
| 875 | // /* int32_t */ monitor = obj->monitor_ |
| 876 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 877 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 878 | if (needs_null_check_) { |
| 879 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 880 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 881 | // /* LockWord */ lock_word = LockWord(monitor) |
| 882 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 883 | "art::LockWord and int32_t have different sizes."); |
| 884 | |
| 885 | // Introduce a dependency on the lock_word including rb_state, |
| 886 | // to prevent load-load reordering, and without using |
| 887 | // a memory barrier (which would be more expensive). |
| 888 | // `obj` is unchanged by this operation, but its value now depends |
| 889 | // on `temp`. |
| 890 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 891 | |
| 892 | // The actual reference load. |
| 893 | // A possible implicit null check has already been handled above. |
| 894 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 895 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 896 | ref_, |
| 897 | obj_, |
| 898 | offset_, |
| 899 | index_, |
| 900 | scale_factor_, |
| 901 | /* needs_null_check */ false, |
| 902 | use_load_acquire_); |
| 903 | |
| 904 | // Mark the object `ref` when `obj` is gray. |
| 905 | // |
| 906 | // if (rb_state == ReadBarrier::GrayState()) |
| 907 | // ref = ReadBarrier::Mark(ref); |
| 908 | // |
| 909 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 910 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 911 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 912 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 913 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 914 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 915 | __ B(GetExitLabel()); |
| 916 | } |
| 917 | |
| 918 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 919 | // The register containing the object holding the marked object reference field. |
| 920 | Register obj_; |
| 921 | // The offset, index and scale factor to access the reference in `obj_`. |
| 922 | uint32_t offset_; |
| 923 | Location index_; |
| 924 | size_t scale_factor_; |
| 925 | // Is a null check required? |
| 926 | bool needs_null_check_; |
| 927 | // Should this reference load use Load-Acquire semantics? |
| 928 | bool use_load_acquire_; |
| 929 | // A temporary register used to hold the lock word of `obj_`. |
| 930 | Register temp_; |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 931 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 932 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM64); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 933 | }; |
| 934 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 935 | // Slow path loading `obj`'s lock word, loading a reference from |
| 936 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 937 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 938 | // read barrier). If needed, this slow path also atomically updates |
| 939 | // the field `obj.field` in the object `obj` holding this reference |
| 940 | // after marking (contrary to |
| 941 | // LoadReferenceWithBakerReadBarrierSlowPathARM64 above, which never |
| 942 | // tries to update `obj.field`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 943 | // |
| 944 | // This means that after the execution of this slow path, both `ref` |
| 945 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 946 | // hold the same to-space reference (unless another thread installed |
| 947 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 948 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 949 | // Argument `entrypoint` must be a register location holding the read |
| 950 | // barrier marking runtime entry point to be invoked. |
| 951 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 952 | : public ReadBarrierMarkSlowPathBaseARM64 { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 953 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 954 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64(HInstruction* instruction, |
| 955 | Location ref, |
| 956 | Register obj, |
| 957 | uint32_t offset, |
| 958 | Location index, |
| 959 | size_t scale_factor, |
| 960 | bool needs_null_check, |
| 961 | bool use_load_acquire, |
| 962 | Register temp, |
| 963 | Location entrypoint) |
| 964 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 965 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 966 | offset_(offset), |
| 967 | index_(index), |
| 968 | scale_factor_(scale_factor), |
| 969 | needs_null_check_(needs_null_check), |
| 970 | use_load_acquire_(use_load_acquire), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 971 | temp_(temp) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 972 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 973 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 977 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64"; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 981 | LocationSummary* locations = instruction_->GetLocations(); |
| 982 | Register ref_reg = WRegisterFrom(ref_); |
| 983 | DCHECK(locations->CanCall()); |
| 984 | DCHECK(ref_.IsRegister()) << ref_; |
| 985 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 986 | DCHECK(obj_.IsW()); |
| 987 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
| 988 | |
| 989 | // 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] | 990 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 991 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 992 | << instruction_->DebugName(); |
| 993 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 994 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 995 | DCHECK_EQ(offset_, 0u); |
| 996 | DCHECK_EQ(scale_factor_, 0u); |
| 997 | DCHECK_EQ(use_load_acquire_, false); |
| 998 | // The location of the offset of the marked reference field within `obj_`. |
| 999 | Location field_offset = index_; |
| 1000 | DCHECK(field_offset.IsRegister()) << field_offset; |
| 1001 | |
| 1002 | // Temporary register `temp_`, used to store the lock word, must |
| 1003 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 1004 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 1005 | // need the lock word to still be in `temp_` after the reference |
| 1006 | // load. |
| 1007 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1008 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1009 | |
| 1010 | __ Bind(GetEntryLabel()); |
| 1011 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 1012 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM64's: |
| 1013 | // |
| 1014 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 1015 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 1016 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 1017 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 1018 | // if (is_gray) { |
| 1019 | // old_ref = ref; |
| 1020 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 1021 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1022 | // } |
| 1023 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1024 | // /* int32_t */ monitor = obj->monitor_ |
| 1025 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1026 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 1027 | if (needs_null_check_) { |
| 1028 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1029 | } |
| 1030 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1031 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1032 | "art::LockWord and int32_t have different sizes."); |
| 1033 | |
| 1034 | // Introduce a dependency on the lock_word including rb_state, |
| 1035 | // to prevent load-load reordering, and without using |
| 1036 | // a memory barrier (which would be more expensive). |
| 1037 | // `obj` is unchanged by this operation, but its value now depends |
| 1038 | // on `temp`. |
| 1039 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 1040 | |
| 1041 | // The actual reference load. |
| 1042 | // A possible implicit null check has already been handled above. |
| 1043 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1044 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 1045 | ref_, |
| 1046 | obj_, |
| 1047 | offset_, |
| 1048 | index_, |
| 1049 | scale_factor_, |
| 1050 | /* needs_null_check */ false, |
| 1051 | use_load_acquire_); |
| 1052 | |
| 1053 | // Mark the object `ref` when `obj` is gray. |
| 1054 | // |
| 1055 | // if (rb_state == ReadBarrier::GrayState()) |
| 1056 | // ref = ReadBarrier::Mark(ref); |
| 1057 | // |
| 1058 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 1059 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1060 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1061 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 1062 | |
| 1063 | // Save the old value of the reference before marking it. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1064 | // Note that we cannot use IP to save the old reference, as IP is |
| 1065 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1066 | // need the old reference after the call to that entry point. |
| 1067 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1068 | __ Mov(temp_.W(), ref_reg); |
| 1069 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1070 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1071 | |
| 1072 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1073 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1074 | // |
| 1075 | // Note that this field could also hold a different object, if |
| 1076 | // another thread had concurrently changed it. In that case, the |
| 1077 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 1078 | // (CAS) operation below would abort the CAS, leaving the field |
| 1079 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1080 | __ Cmp(temp_.W(), ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1081 | __ B(eq, GetExitLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1082 | |
| 1083 | // Update the the holder's field atomically. This may fail if |
| 1084 | // mutator updates before us, but it's OK. This is achieved |
| 1085 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1086 | // memory synchronization ordering, where the expected value is |
| 1087 | // the old reference and the desired value is the new reference. |
| 1088 | |
| 1089 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 1090 | UseScratchRegisterScope temps(masm); |
| 1091 | |
| 1092 | // Convenience aliases. |
| 1093 | Register base = obj_.W(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1094 | Register offset = XRegisterFrom(field_offset); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1095 | Register expected = temp_.W(); |
| 1096 | Register value = ref_reg; |
| 1097 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1098 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 1099 | |
| 1100 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1101 | |
| 1102 | if (kPoisonHeapReferences) { |
| 1103 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1104 | if (value.Is(expected)) { |
| 1105 | // Do not poison `value`, as it is the same register as |
| 1106 | // `expected`, which has just been poisoned. |
| 1107 | } else { |
| 1108 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | // do { |
| 1113 | // tmp_value = [tmp_ptr] - expected; |
| 1114 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1115 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1116 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1117 | __ Bind(&loop_head); |
| 1118 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 1119 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1120 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1121 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 1122 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1123 | __ B(&exit_loop); |
| 1124 | __ Bind(&comparison_failed); |
| 1125 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1126 | __ Bind(&exit_loop); |
| 1127 | |
| 1128 | if (kPoisonHeapReferences) { |
| 1129 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1130 | if (value.Is(expected)) { |
| 1131 | // Do not unpoison `value`, as it is the same register as |
| 1132 | // `expected`, which has just been unpoisoned. |
| 1133 | } else { |
| 1134 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1135 | } |
| 1136 | } |
| 1137 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1138 | __ B(GetExitLabel()); |
| 1139 | } |
| 1140 | |
| 1141 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1142 | // The register containing the object holding the marked object reference field. |
| 1143 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1144 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1145 | uint32_t offset_; |
| 1146 | Location index_; |
| 1147 | size_t scale_factor_; |
| 1148 | // Is a null check required? |
| 1149 | bool needs_null_check_; |
| 1150 | // Should this reference load use Load-Acquire semantics? |
| 1151 | bool use_load_acquire_; |
| 1152 | // A temporary register used to hold the lock word of `obj_`; and |
| 1153 | // also to hold the original reference value, when the reference is |
| 1154 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1155 | const Register temp_; |
| 1156 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1157 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1158 | }; |
| 1159 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1160 | // Slow path generating a read barrier for a heap reference. |
| 1161 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 1162 | public: |
| 1163 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 1164 | Location out, |
| 1165 | Location ref, |
| 1166 | Location obj, |
| 1167 | uint32_t offset, |
| 1168 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1169 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1170 | out_(out), |
| 1171 | ref_(ref), |
| 1172 | obj_(obj), |
| 1173 | offset_(offset), |
| 1174 | index_(index) { |
| 1175 | DCHECK(kEmitCompilerReadBarrier); |
| 1176 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1177 | // has been overwritten by (or after) the heap object reference load |
| 1178 | // to be instrumented, e.g.: |
| 1179 | // |
| 1180 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1181 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1182 | // |
| 1183 | // In that case, we have lost the information about the original |
| 1184 | // object, and the emitted read barrier cannot work properly. |
| 1185 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1186 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1187 | } |
| 1188 | |
| 1189 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1190 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1191 | LocationSummary* locations = instruction_->GetLocations(); |
| 1192 | Primitive::Type type = Primitive::kPrimNot; |
| 1193 | DCHECK(locations->CanCall()); |
| 1194 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1195 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1196 | instruction_->IsStaticFieldGet() || |
| 1197 | instruction_->IsArrayGet() || |
| 1198 | instruction_->IsInstanceOf() || |
| 1199 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1200 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1201 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1202 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1203 | // The read barrier instrumentation of object ArrayGet |
| 1204 | // instructions does not support the HIntermediateAddress |
| 1205 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1206 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1207 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1208 | |
| 1209 | __ Bind(GetEntryLabel()); |
| 1210 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1211 | SaveLiveRegisters(codegen, locations); |
| 1212 | |
| 1213 | // We may have to change the index's value, but as `index_` is a |
| 1214 | // constant member (like other "inputs" of this slow path), |
| 1215 | // introduce a copy of it, `index`. |
| 1216 | Location index = index_; |
| 1217 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1218 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1219 | if (instruction_->IsArrayGet()) { |
| 1220 | // Compute the actual memory offset and store it in `index`. |
| 1221 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 1222 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 1223 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 1224 | // We are about to change the value of `index_reg` (see the |
| 1225 | // calls to vixl::MacroAssembler::Lsl and |
| 1226 | // vixl::MacroAssembler::Mov below), but it has |
| 1227 | // not been saved by the previous call to |
| 1228 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1229 | // callee-save register -- |
| 1230 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1231 | // callee-save registers, as it has been designed with the |
| 1232 | // assumption that callee-save registers are supposed to be |
| 1233 | // handled by the called function. So, as a callee-save |
| 1234 | // register, `index_reg` _would_ eventually be saved onto |
| 1235 | // the stack, but it would be too late: we would have |
| 1236 | // changed its value earlier. Therefore, we manually save |
| 1237 | // it here into another freely available register, |
| 1238 | // `free_reg`, chosen of course among the caller-save |
| 1239 | // registers (as a callee-save `free_reg` register would |
| 1240 | // exhibit the same problem). |
| 1241 | // |
| 1242 | // Note we could have requested a temporary register from |
| 1243 | // the register allocator instead; but we prefer not to, as |
| 1244 | // this is a slow path, and we know we can find a |
| 1245 | // caller-save register that is available. |
| 1246 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1247 | __ Mov(free_reg.W(), index_reg); |
| 1248 | index_reg = free_reg; |
| 1249 | index = LocationFrom(index_reg); |
| 1250 | } else { |
| 1251 | // The initial register stored in `index_` has already been |
| 1252 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1253 | // (as it is not a callee-save register), so we can freely |
| 1254 | // use it. |
| 1255 | } |
| 1256 | // Shifting the index value contained in `index_reg` by the scale |
| 1257 | // factor (2) cannot overflow in practice, as the runtime is |
| 1258 | // unable to allocate object arrays with a size larger than |
| 1259 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1260 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 1261 | static_assert( |
| 1262 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1263 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1264 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1265 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1266 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1267 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1268 | // (as in the case of ArrayGet), as it is actually an offset |
| 1269 | // to an object field within an object. |
| 1270 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1271 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1272 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1273 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1274 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1275 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1276 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | // We're moving two or three locations to locations that could |
| 1281 | // overlap, so we need a parallel move resolver. |
| 1282 | InvokeRuntimeCallingConvention calling_convention; |
| 1283 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1284 | parallel_move.AddMove(ref_, |
| 1285 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1286 | type, |
| 1287 | nullptr); |
| 1288 | parallel_move.AddMove(obj_, |
| 1289 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1290 | type, |
| 1291 | nullptr); |
| 1292 | if (index.IsValid()) { |
| 1293 | parallel_move.AddMove(index, |
| 1294 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 1295 | Primitive::kPrimInt, |
| 1296 | nullptr); |
| 1297 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1298 | } else { |
| 1299 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1300 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1301 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1302 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1303 | instruction_, |
| 1304 | instruction_->GetDexPc(), |
| 1305 | this); |
| 1306 | CheckEntrypointTypes< |
| 1307 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1308 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1309 | |
| 1310 | RestoreLiveRegisters(codegen, locations); |
| 1311 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1312 | __ B(GetExitLabel()); |
| 1313 | } |
| 1314 | |
| 1315 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1316 | |
| 1317 | private: |
| 1318 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1319 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1320 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1321 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1322 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1323 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1324 | } |
| 1325 | } |
| 1326 | // We shall never fail to find a free caller-save register, as |
| 1327 | // there are more than two core caller-save registers on ARM64 |
| 1328 | // (meaning it is possible to find one which is different from |
| 1329 | // `ref` and `obj`). |
| 1330 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1331 | LOG(FATAL) << "Could not find a free register"; |
| 1332 | UNREACHABLE(); |
| 1333 | } |
| 1334 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1335 | const Location out_; |
| 1336 | const Location ref_; |
| 1337 | const Location obj_; |
| 1338 | const uint32_t offset_; |
| 1339 | // An additional location containing an index to an array. |
| 1340 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1341 | // UnsafeGetObjectVolatile intrinsics. |
| 1342 | const Location index_; |
| 1343 | |
| 1344 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1345 | }; |
| 1346 | |
| 1347 | // Slow path generating a read barrier for a GC root. |
| 1348 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1349 | public: |
| 1350 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1351 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1352 | DCHECK(kEmitCompilerReadBarrier); |
| 1353 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1354 | |
| 1355 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1356 | LocationSummary* locations = instruction_->GetLocations(); |
| 1357 | Primitive::Type type = Primitive::kPrimNot; |
| 1358 | DCHECK(locations->CanCall()); |
| 1359 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1360 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1361 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1362 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1363 | |
| 1364 | __ Bind(GetEntryLabel()); |
| 1365 | SaveLiveRegisters(codegen, locations); |
| 1366 | |
| 1367 | InvokeRuntimeCallingConvention calling_convention; |
| 1368 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1369 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1370 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1371 | // thus we need a 64-bit move here, and we cannot use |
| 1372 | // |
| 1373 | // arm64_codegen->MoveLocation( |
| 1374 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1375 | // root_, |
| 1376 | // type); |
| 1377 | // |
| 1378 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 1379 | // reference type (`Primitive::kPrimNot`). |
| 1380 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1381 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1382 | instruction_, |
| 1383 | instruction_->GetDexPc(), |
| 1384 | this); |
| 1385 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1386 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1387 | |
| 1388 | RestoreLiveRegisters(codegen, locations); |
| 1389 | __ B(GetExitLabel()); |
| 1390 | } |
| 1391 | |
| 1392 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1393 | |
| 1394 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1395 | const Location out_; |
| 1396 | const Location root_; |
| 1397 | |
| 1398 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1399 | }; |
| 1400 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1401 | #undef __ |
| 1402 | |
| 1403 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
| 1404 | Location next_location; |
| 1405 | if (type == Primitive::kPrimVoid) { |
| 1406 | LOG(FATAL) << "Unreachable type " << type; |
| 1407 | } |
| 1408 | |
| 1409 | if (Primitive::IsFloatingPointType(type) && |
| 1410 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1411 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1412 | } else if (!Primitive::IsFloatingPointType(type) && |
| 1413 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 1414 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1415 | } else { |
| 1416 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1417 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1418 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1419 | } |
| 1420 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1421 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1422 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1423 | return next_location; |
| 1424 | } |
| 1425 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1426 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1427 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1428 | } |
| 1429 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1430 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1431 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1432 | const CompilerOptions& compiler_options, |
| 1433 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1434 | : CodeGenerator(graph, |
| 1435 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1436 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1437 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1438 | callee_saved_core_registers.GetList(), |
| 1439 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1440 | compiler_options, |
| 1441 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1442 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1443 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1444 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1445 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1446 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1447 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1448 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1449 | uint32_literals_(std::less<uint32_t>(), |
| 1450 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1451 | uint64_literals_(std::less<uint64_t>(), |
| 1452 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1453 | pc_relative_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1454 | method_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1455 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1456 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1457 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1458 | baker_read_barrier_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1459 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1460 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1461 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1462 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1463 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1464 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1465 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1466 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1467 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1468 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1469 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1470 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1471 | jump_table->EmitTable(this); |
| 1472 | } |
| 1473 | } |
| 1474 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1475 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1476 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1477 | // Ensure we emit the literal pool. |
| 1478 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1479 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1480 | CodeGenerator::Finalize(allocator); |
| 1481 | } |
| 1482 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1483 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1484 | // Note: There are 6 kinds of moves: |
| 1485 | // 1. constant -> GPR/FPR (non-cycle) |
| 1486 | // 2. constant -> stack (non-cycle) |
| 1487 | // 3. GPR/FPR -> GPR/FPR |
| 1488 | // 4. GPR/FPR -> stack |
| 1489 | // 5. stack -> GPR/FPR |
| 1490 | // 6. stack -> stack (non-cycle) |
| 1491 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1492 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1493 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1494 | // dependency. |
| 1495 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1496 | } |
| 1497 | |
| 1498 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1499 | vixl_temps_.Close(); |
| 1500 | } |
| 1501 | |
| 1502 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1503 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1504 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1505 | || kind == Location::kSIMDStackSlot); |
| 1506 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1507 | ? Location::kFpuRegister |
| 1508 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1509 | Location scratch = GetScratchLocation(kind); |
| 1510 | if (!scratch.Equals(Location::NoLocation())) { |
| 1511 | return scratch; |
| 1512 | } |
| 1513 | // Allocate from VIXL temp registers. |
| 1514 | if (kind == Location::kRegister) { |
| 1515 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1516 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1517 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1518 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1519 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1520 | : vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1521 | } |
| 1522 | AddScratchLocation(scratch); |
| 1523 | return scratch; |
| 1524 | } |
| 1525 | |
| 1526 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1527 | if (loc.IsRegister()) { |
| 1528 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1529 | } else { |
| 1530 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1531 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1532 | } |
| 1533 | RemoveScratchLocation(loc); |
| 1534 | } |
| 1535 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1536 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1537 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1538 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1539 | } |
| 1540 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1541 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1542 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1543 | __ Bind(&frame_entry_label_); |
| 1544 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1545 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1546 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1547 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1548 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1549 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1550 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1551 | { |
| 1552 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1553 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1554 | kInstructionSize, |
| 1555 | CodeBufferCheckScope::kExactSize); |
| 1556 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1557 | RecordPcInfo(nullptr, 0); |
| 1558 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1559 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1560 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1561 | if (!HasEmptyFrame()) { |
| 1562 | int frame_size = GetFrameSize(); |
| 1563 | // Stack layout: |
| 1564 | // sp[frame_size - 8] : lr. |
| 1565 | // ... : other preserved core registers. |
| 1566 | // ... : other preserved fp registers. |
| 1567 | // ... : reserved frame space. |
| 1568 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1569 | |
| 1570 | // Save the current method if we need it. Note that we do not |
| 1571 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1572 | // in the SSA graph. |
| 1573 | if (RequiresCurrentMethod()) { |
| 1574 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1575 | } else { |
| 1576 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1577 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1578 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1579 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1580 | frame_size - GetCoreSpillSize()); |
| 1581 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1582 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1583 | |
| 1584 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1585 | // Initialize should_deoptimize flag to 0. |
| 1586 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1587 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1588 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1589 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1593 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1594 | if (!HasEmptyFrame()) { |
| 1595 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1596 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1597 | frame_size - FrameEntrySpillSize()); |
| 1598 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1599 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1600 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1601 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1602 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1603 | __ Ret(); |
| 1604 | GetAssembler()->cfi().RestoreState(); |
| 1605 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1606 | } |
| 1607 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1608 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1609 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1610 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1611 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1612 | } |
| 1613 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1614 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1615 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1616 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1617 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1618 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1619 | } |
| 1620 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1621 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1622 | __ Bind(GetLabelOf(block)); |
| 1623 | } |
| 1624 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1625 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1626 | DCHECK(location.IsRegister()); |
| 1627 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1628 | } |
| 1629 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1630 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1631 | if (location.IsRegister()) { |
| 1632 | locations->AddTemp(location); |
| 1633 | } else { |
| 1634 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1635 | } |
| 1636 | } |
| 1637 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1638 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1639 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1640 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1641 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1642 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1643 | if (value_can_be_null) { |
| 1644 | __ Cbz(value, &done); |
| 1645 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1646 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1647 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1648 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1649 | if (value_can_be_null) { |
| 1650 | __ Bind(&done); |
| 1651 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1652 | } |
| 1653 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1654 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1655 | // Blocked core registers: |
| 1656 | // lr : Runtime reserved. |
| 1657 | // tr : Runtime reserved. |
| 1658 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1659 | // ip1 : VIXL core temp. |
| 1660 | // ip0 : VIXL core temp. |
| 1661 | // |
| 1662 | // Blocked fp registers: |
| 1663 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1664 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1665 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1666 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1667 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1668 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1669 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1670 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1671 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1672 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1673 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1674 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1675 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1676 | // Stubs do not save callee-save floating point registers. If the graph |
| 1677 | // is debuggable, we need to deal with these registers differently. For |
| 1678 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1679 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1680 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1681 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1682 | } |
| 1683 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1684 | } |
| 1685 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1686 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1687 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1688 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1689 | return kArm64WordSize; |
| 1690 | } |
| 1691 | |
| 1692 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1693 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1694 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1695 | return kArm64WordSize; |
| 1696 | } |
| 1697 | |
| 1698 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1699 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1700 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1701 | return kArm64WordSize; |
| 1702 | } |
| 1703 | |
| 1704 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1705 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1706 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1707 | return kArm64WordSize; |
| 1708 | } |
| 1709 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1710 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1711 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1715 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1716 | } |
| 1717 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1718 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1719 | if (constant->IsIntConstant()) { |
| 1720 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1721 | } else if (constant->IsLongConstant()) { |
| 1722 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1723 | } else if (constant->IsNullConstant()) { |
| 1724 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1725 | } else if (constant->IsFloatConstant()) { |
| 1726 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1727 | } else { |
| 1728 | DCHECK(constant->IsDoubleConstant()); |
| 1729 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1730 | } |
| 1731 | } |
| 1732 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1733 | |
| 1734 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1735 | DCHECK(constant.IsConstant()); |
| 1736 | HConstant* cst = constant.GetConstant(); |
| 1737 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1738 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1739 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1740 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1741 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1742 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1743 | } |
| 1744 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1745 | // Allocate a scratch register from the VIXL pool, querying first |
| 1746 | // the floating-point register pool, and then the core register |
| 1747 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1748 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1749 | // using a different allocation strategy. |
| 1750 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1751 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1752 | int size_in_bits) { |
| 1753 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1754 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1755 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1756 | } |
| 1757 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1758 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1759 | Location source, |
| 1760 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1761 | if (source.Equals(destination)) { |
| 1762 | return; |
| 1763 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1764 | |
| 1765 | // A valid move can always be inferred from the destination and source |
| 1766 | // locations. When moving from and to a register, the argument type can be |
| 1767 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1768 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1769 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1770 | |
| 1771 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1772 | if (unspecified_type) { |
| 1773 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1774 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1775 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1776 | || src_cst->IsFloatConstant() |
| 1777 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1778 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1779 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1780 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1781 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1782 | // type is appropriate. Else the source is a register, and since the |
| 1783 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1784 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1785 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1786 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1787 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1788 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1789 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1790 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1791 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1792 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1793 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1794 | } else if (source.IsSIMDStackSlot()) { |
| 1795 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1796 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1797 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1798 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1799 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1800 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1801 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1802 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1803 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1804 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1805 | ? Primitive::kPrimLong |
| 1806 | : Primitive::kPrimInt; |
| 1807 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1808 | } |
| 1809 | } else { |
| 1810 | DCHECK(source.IsFpuRegister()); |
| 1811 | if (destination.IsRegister()) { |
| 1812 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1813 | ? Primitive::kPrimDouble |
| 1814 | : Primitive::kPrimFloat; |
| 1815 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1816 | } else { |
| 1817 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1818 | if (GetGraph()->HasSIMD()) { |
| 1819 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1820 | } else { |
| 1821 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1822 | } |
| 1823 | } |
| 1824 | } |
| 1825 | } else if (destination.IsSIMDStackSlot()) { |
| 1826 | if (source.IsFpuRegister()) { |
| 1827 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1828 | } else { |
| 1829 | DCHECK(source.IsSIMDStackSlot()); |
| 1830 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1831 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1832 | Register temp = temps.AcquireX(); |
| 1833 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1834 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1835 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1836 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1837 | } else { |
| 1838 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1839 | __ Ldr(temp, StackOperandFrom(source)); |
| 1840 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1841 | } |
| 1842 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1843 | } else { // The destination is not a register. It must be a stack slot. |
| 1844 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1845 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1846 | if (unspecified_type) { |
| 1847 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1848 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1849 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1850 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1851 | } |
| 1852 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1853 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1854 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1855 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1856 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1857 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1858 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1859 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1860 | HConstant* src_cst = source.GetConstant(); |
| 1861 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1862 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1863 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1864 | ? Register(xzr) |
| 1865 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1866 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1867 | if (src_cst->IsIntConstant()) { |
| 1868 | temp = temps.AcquireW(); |
| 1869 | } else if (src_cst->IsLongConstant()) { |
| 1870 | temp = temps.AcquireX(); |
| 1871 | } else if (src_cst->IsFloatConstant()) { |
| 1872 | temp = temps.AcquireS(); |
| 1873 | } else { |
| 1874 | DCHECK(src_cst->IsDoubleConstant()); |
| 1875 | temp = temps.AcquireD(); |
| 1876 | } |
| 1877 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1878 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1879 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1880 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1881 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1882 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1883 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1884 | // Use any scratch register (a core or a floating-point one) |
| 1885 | // from VIXL scratch register pools as a temporary. |
| 1886 | // |
| 1887 | // We used to only use the FP scratch register pool, but in some |
| 1888 | // rare cases the only register from this pool (D31) would |
| 1889 | // already be used (e.g. within a ParallelMove instruction, when |
| 1890 | // a move is blocked by a another move requiring a scratch FP |
| 1891 | // register, which would reserve D31). To prevent this issue, we |
| 1892 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1893 | // |
| 1894 | // 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] | 1895 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1896 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1897 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1898 | // allocates core scratch registers first. |
| 1899 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1900 | GetVIXLAssembler(), |
| 1901 | &temps, |
| 1902 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1903 | __ Ldr(temp, StackOperandFrom(source)); |
| 1904 | __ Str(temp, StackOperandFrom(destination)); |
| 1905 | } |
| 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1910 | CPURegister dst, |
| 1911 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1912 | switch (type) { |
| 1913 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1914 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1915 | break; |
| 1916 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1917 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1918 | break; |
| 1919 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1920 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1921 | break; |
| 1922 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1923 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1924 | break; |
| 1925 | case Primitive::kPrimInt: |
| 1926 | case Primitive::kPrimNot: |
| 1927 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1928 | case Primitive::kPrimFloat: |
| 1929 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1930 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1931 | __ Ldr(dst, src); |
| 1932 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1933 | case Primitive::kPrimVoid: |
| 1934 | LOG(FATAL) << "Unreachable type " << type; |
| 1935 | } |
| 1936 | } |
| 1937 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1938 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1939 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1940 | const MemOperand& src, |
| 1941 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1942 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1943 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1944 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1945 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1946 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1947 | DCHECK(!src.IsPreIndex()); |
| 1948 | DCHECK(!src.IsPostIndex()); |
| 1949 | |
| 1950 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1951 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1952 | { |
| 1953 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1954 | MemOperand base = MemOperand(temp_base); |
| 1955 | switch (type) { |
| 1956 | case Primitive::kPrimBoolean: |
| 1957 | { |
| 1958 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1959 | __ ldarb(Register(dst), base); |
| 1960 | if (needs_null_check) { |
| 1961 | MaybeRecordImplicitNullCheck(instruction); |
| 1962 | } |
| 1963 | } |
| 1964 | break; |
| 1965 | case Primitive::kPrimByte: |
| 1966 | { |
| 1967 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1968 | __ ldarb(Register(dst), base); |
| 1969 | if (needs_null_check) { |
| 1970 | MaybeRecordImplicitNullCheck(instruction); |
| 1971 | } |
| 1972 | } |
| 1973 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1974 | break; |
| 1975 | case Primitive::kPrimChar: |
| 1976 | { |
| 1977 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1978 | __ ldarh(Register(dst), base); |
| 1979 | if (needs_null_check) { |
| 1980 | MaybeRecordImplicitNullCheck(instruction); |
| 1981 | } |
| 1982 | } |
| 1983 | break; |
| 1984 | case Primitive::kPrimShort: |
| 1985 | { |
| 1986 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1987 | __ ldarh(Register(dst), base); |
| 1988 | if (needs_null_check) { |
| 1989 | MaybeRecordImplicitNullCheck(instruction); |
| 1990 | } |
| 1991 | } |
| 1992 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1993 | break; |
| 1994 | case Primitive::kPrimInt: |
| 1995 | case Primitive::kPrimNot: |
| 1996 | case Primitive::kPrimLong: |
| 1997 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
| 1998 | { |
| 1999 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2000 | __ ldar(Register(dst), base); |
| 2001 | if (needs_null_check) { |
| 2002 | MaybeRecordImplicitNullCheck(instruction); |
| 2003 | } |
| 2004 | } |
| 2005 | break; |
| 2006 | case Primitive::kPrimFloat: |
| 2007 | case Primitive::kPrimDouble: { |
| 2008 | DCHECK(dst.IsFPRegister()); |
| 2009 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2010 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2011 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2012 | { |
| 2013 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2014 | __ ldar(temp, base); |
| 2015 | if (needs_null_check) { |
| 2016 | MaybeRecordImplicitNullCheck(instruction); |
| 2017 | } |
| 2018 | } |
| 2019 | __ Fmov(FPRegister(dst), temp); |
| 2020 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2021 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2022 | case Primitive::kPrimVoid: |
| 2023 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2024 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2025 | } |
| 2026 | } |
| 2027 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2028 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2029 | CPURegister src, |
| 2030 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2031 | switch (type) { |
| 2032 | case Primitive::kPrimBoolean: |
| 2033 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2034 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2035 | break; |
| 2036 | case Primitive::kPrimChar: |
| 2037 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2038 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2039 | break; |
| 2040 | case Primitive::kPrimInt: |
| 2041 | case Primitive::kPrimNot: |
| 2042 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2043 | case Primitive::kPrimFloat: |
| 2044 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2045 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2046 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2047 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2048 | case Primitive::kPrimVoid: |
| 2049 | LOG(FATAL) << "Unreachable type " << type; |
| 2050 | } |
| 2051 | } |
| 2052 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2053 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
| 2054 | Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2055 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2056 | const MemOperand& dst, |
| 2057 | bool needs_null_check) { |
| 2058 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2059 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2060 | Register temp_base = temps.AcquireX(); |
| 2061 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2062 | DCHECK(!dst.IsPreIndex()); |
| 2063 | DCHECK(!dst.IsPostIndex()); |
| 2064 | |
| 2065 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2066 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2067 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2068 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2069 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2070 | switch (type) { |
| 2071 | case Primitive::kPrimBoolean: |
| 2072 | case Primitive::kPrimByte: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2073 | { |
| 2074 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2075 | __ stlrb(Register(src), base); |
| 2076 | if (needs_null_check) { |
| 2077 | MaybeRecordImplicitNullCheck(instruction); |
| 2078 | } |
| 2079 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2080 | break; |
| 2081 | case Primitive::kPrimChar: |
| 2082 | case Primitive::kPrimShort: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2083 | { |
| 2084 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2085 | __ stlrh(Register(src), base); |
| 2086 | if (needs_null_check) { |
| 2087 | MaybeRecordImplicitNullCheck(instruction); |
| 2088 | } |
| 2089 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2090 | break; |
| 2091 | case Primitive::kPrimInt: |
| 2092 | case Primitive::kPrimNot: |
| 2093 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2094 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2095 | { |
| 2096 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2097 | __ stlr(Register(src), base); |
| 2098 | if (needs_null_check) { |
| 2099 | MaybeRecordImplicitNullCheck(instruction); |
| 2100 | } |
| 2101 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2102 | break; |
| 2103 | case Primitive::kPrimFloat: |
| 2104 | case Primitive::kPrimDouble: { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2105 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2106 | Register temp_src; |
| 2107 | if (src.IsZero()) { |
| 2108 | // The zero register is used to avoid synthesizing zero constants. |
| 2109 | temp_src = Register(src); |
| 2110 | } else { |
| 2111 | DCHECK(src.IsFPRegister()); |
| 2112 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2113 | __ Fmov(temp_src, FPRegister(src)); |
| 2114 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2115 | { |
| 2116 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2117 | __ stlr(temp_src, base); |
| 2118 | if (needs_null_check) { |
| 2119 | MaybeRecordImplicitNullCheck(instruction); |
| 2120 | } |
| 2121 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2122 | break; |
| 2123 | } |
| 2124 | case Primitive::kPrimVoid: |
| 2125 | LOG(FATAL) << "Unreachable type " << type; |
| 2126 | } |
| 2127 | } |
| 2128 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2129 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2130 | HInstruction* instruction, |
| 2131 | uint32_t dex_pc, |
| 2132 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2133 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2134 | |
| 2135 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 2136 | { |
| 2137 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 2138 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2139 | __ blr(lr); |
| 2140 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2141 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2142 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2143 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2146 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2147 | HInstruction* instruction, |
| 2148 | SlowPathCode* slow_path) { |
| 2149 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2150 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2151 | __ Blr(lr); |
| 2152 | } |
| 2153 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2154 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2155 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2156 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2157 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2158 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 2159 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2160 | // Even if the initialized flag is set, we need to ensure consistent memory ordering. |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2161 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 2162 | __ Add(temp, class_reg, status_offset); |
| 2163 | __ Ldar(temp, HeapOperand(temp)); |
| 2164 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 2165 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2166 | __ Bind(slow_path->GetExitLabel()); |
| 2167 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2168 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2169 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2170 | BarrierType type = BarrierAll; |
| 2171 | |
| 2172 | switch (kind) { |
| 2173 | case MemBarrierKind::kAnyAny: |
| 2174 | case MemBarrierKind::kAnyStore: { |
| 2175 | type = BarrierAll; |
| 2176 | break; |
| 2177 | } |
| 2178 | case MemBarrierKind::kLoadAny: { |
| 2179 | type = BarrierReads; |
| 2180 | break; |
| 2181 | } |
| 2182 | case MemBarrierKind::kStoreStore: { |
| 2183 | type = BarrierWrites; |
| 2184 | break; |
| 2185 | } |
| 2186 | default: |
| 2187 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2188 | } |
| 2189 | __ Dmb(InnerShareable, type); |
| 2190 | } |
| 2191 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2192 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2193 | HBasicBlock* successor) { |
| 2194 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2195 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2196 | if (slow_path == nullptr) { |
| 2197 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 2198 | instruction->SetSlowPath(slow_path); |
| 2199 | codegen_->AddSlowPath(slow_path); |
| 2200 | if (successor != nullptr) { |
| 2201 | DCHECK(successor->IsLoopHeader()); |
| 2202 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 2203 | } |
| 2204 | } else { |
| 2205 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2206 | } |
| 2207 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2208 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2209 | Register temp = temps.AcquireW(); |
| 2210 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2211 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2212 | if (successor == nullptr) { |
| 2213 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2214 | __ Bind(slow_path->GetReturnLabel()); |
| 2215 | } else { |
| 2216 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 2217 | __ B(slow_path->GetEntryLabel()); |
| 2218 | // slow_path will return to GetLabelOf(successor). |
| 2219 | } |
| 2220 | } |
| 2221 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2222 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2223 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2224 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2225 | assembler_(codegen->GetAssembler()), |
| 2226 | codegen_(codegen) {} |
| 2227 | |
| 2228 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2229 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2230 | |
| 2231 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 2232 | |
| 2233 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2234 | // Using a base helps identify when we hit such breakpoints. |
| 2235 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2236 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 2237 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 2238 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 2239 | }; |
| 2240 | |
| 2241 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2242 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2243 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 2244 | } \ |
| 2245 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 2246 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 2247 | locations->SetOut(Location::Any()); \ |
| 2248 | } |
| 2249 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 2250 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 2251 | |
| 2252 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2253 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2254 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2255 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2256 | DCHECK_EQ(instr->InputCount(), 2U); |
| 2257 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2258 | Primitive::Type type = instr->GetResultType(); |
| 2259 | switch (type) { |
| 2260 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2261 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2262 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2263 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2264 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2265 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2266 | |
| 2267 | case Primitive::kPrimFloat: |
| 2268 | case Primitive::kPrimDouble: |
| 2269 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2270 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2271 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2272 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2273 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2274 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2275 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2276 | } |
| 2277 | } |
| 2278 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2279 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2280 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2281 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2282 | |
| 2283 | bool object_field_get_with_read_barrier = |
| 2284 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2285 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2286 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2287 | object_field_get_with_read_barrier ? |
| 2288 | LocationSummary::kCallOnSlowPath : |
| 2289 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2290 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2291 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2292 | // We need a temporary register for the read barrier marking slow |
| 2293 | // path in CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2294 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2295 | !Runtime::Current()->UseJitCompilation() && |
| 2296 | !field_info.IsVolatile()) { |
| 2297 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2298 | // non-volatile loads we need a temporary only if the offset is too big. |
| 2299 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2300 | locations->AddTemp(FixedTempLocation()); |
| 2301 | } |
| 2302 | } else { |
| 2303 | locations->AddTemp(Location::RequiresRegister()); |
| 2304 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2305 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2306 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2307 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2308 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2309 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2310 | // The output overlaps for an object field get when read barriers |
| 2311 | // are enabled: we do not want the load to overwrite the object's |
| 2312 | // location, as we need it to emit the read barrier. |
| 2313 | locations->SetOut( |
| 2314 | Location::RequiresRegister(), |
| 2315 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2316 | } |
| 2317 | } |
| 2318 | |
| 2319 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2320 | const FieldInfo& field_info) { |
| 2321 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2322 | LocationSummary* locations = instruction->GetLocations(); |
| 2323 | Location base_loc = locations->InAt(0); |
| 2324 | Location out = locations->Out(); |
| 2325 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2326 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2327 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2328 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2329 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2330 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2331 | // /* HeapReference<Object> */ out = *(base + offset) |
| 2332 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2333 | Location maybe_temp = |
| 2334 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2335 | // Note that potential implicit null checks are handled in this |
| 2336 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2337 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2338 | instruction, |
| 2339 | out, |
| 2340 | base, |
| 2341 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2342 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2343 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2344 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2345 | } else { |
| 2346 | // General case. |
| 2347 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2348 | // Note that a potential implicit null check is handled in this |
| 2349 | // CodeGeneratorARM64::LoadAcquire call. |
| 2350 | // NB: LoadAcquire will record the pc info if needed. |
| 2351 | codegen_->LoadAcquire( |
| 2352 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2353 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2354 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2355 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2356 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2357 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2358 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2359 | if (field_type == Primitive::kPrimNot) { |
| 2360 | // If read barriers are enabled, emit read barriers other than |
| 2361 | // Baker's using a slow path (and also unpoison the loaded |
| 2362 | // reference, if heap poisoning is enabled). |
| 2363 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2364 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2365 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2369 | LocationSummary* locations = |
| 2370 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2371 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2372 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2373 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 2374 | } else if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2375 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2376 | } else { |
| 2377 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2378 | } |
| 2379 | } |
| 2380 | |
| 2381 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2382 | const FieldInfo& field_info, |
| 2383 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2384 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2385 | |
| 2386 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2387 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2388 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2389 | Offset offset = field_info.GetFieldOffset(); |
| 2390 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2391 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2392 | { |
| 2393 | // We use a block to end the scratch scope before the write barrier, thus |
| 2394 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2395 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2396 | |
| 2397 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 2398 | DCHECK(value.IsW()); |
| 2399 | Register temp = temps.AcquireW(); |
| 2400 | __ Mov(temp, value.W()); |
| 2401 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2402 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2403 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2404 | |
| 2405 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2406 | codegen_->StoreRelease( |
| 2407 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2408 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2409 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2410 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2411 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2412 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2413 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2417 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2418 | } |
| 2419 | } |
| 2420 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2421 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2422 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2423 | |
| 2424 | switch (type) { |
| 2425 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2426 | case Primitive::kPrimLong: { |
| 2427 | Register dst = OutputRegister(instr); |
| 2428 | Register lhs = InputRegisterAt(instr, 0); |
| 2429 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2430 | if (instr->IsAdd()) { |
| 2431 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2432 | } else if (instr->IsAnd()) { |
| 2433 | __ And(dst, lhs, rhs); |
| 2434 | } else if (instr->IsOr()) { |
| 2435 | __ Orr(dst, lhs, rhs); |
| 2436 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2437 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2438 | } else if (instr->IsRor()) { |
| 2439 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2440 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2441 | __ Ror(dst, lhs, shift); |
| 2442 | } else { |
| 2443 | // Ensure shift distance is in the same size register as the result. If |
| 2444 | // we are rotating a long and the shift comes in a w register originally, |
| 2445 | // we don't need to sxtw for use as an x since the shift distances are |
| 2446 | // all & reg_bits - 1. |
| 2447 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2448 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2449 | } else { |
| 2450 | DCHECK(instr->IsXor()); |
| 2451 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2452 | } |
| 2453 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2454 | } |
| 2455 | case Primitive::kPrimFloat: |
| 2456 | case Primitive::kPrimDouble: { |
| 2457 | FPRegister dst = OutputFPRegister(instr); |
| 2458 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2459 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2460 | if (instr->IsAdd()) { |
| 2461 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2462 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2463 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2464 | } else { |
| 2465 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2466 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2467 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2468 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2469 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2470 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2471 | } |
| 2472 | } |
| 2473 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2474 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2475 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2476 | |
| 2477 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2478 | Primitive::Type type = instr->GetResultType(); |
| 2479 | switch (type) { |
| 2480 | case Primitive::kPrimInt: |
| 2481 | case Primitive::kPrimLong: { |
| 2482 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2483 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2484 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2485 | break; |
| 2486 | } |
| 2487 | default: |
| 2488 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2489 | } |
| 2490 | } |
| 2491 | |
| 2492 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2493 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2494 | |
| 2495 | Primitive::Type type = instr->GetType(); |
| 2496 | switch (type) { |
| 2497 | case Primitive::kPrimInt: |
| 2498 | case Primitive::kPrimLong: { |
| 2499 | Register dst = OutputRegister(instr); |
| 2500 | Register lhs = InputRegisterAt(instr, 0); |
| 2501 | Operand rhs = InputOperandAt(instr, 1); |
| 2502 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2503 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2504 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2505 | if (instr->IsShl()) { |
| 2506 | __ Lsl(dst, lhs, shift_value); |
| 2507 | } else if (instr->IsShr()) { |
| 2508 | __ Asr(dst, lhs, shift_value); |
| 2509 | } else { |
| 2510 | __ Lsr(dst, lhs, shift_value); |
| 2511 | } |
| 2512 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2513 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2514 | |
| 2515 | if (instr->IsShl()) { |
| 2516 | __ Lsl(dst, lhs, rhs_reg); |
| 2517 | } else if (instr->IsShr()) { |
| 2518 | __ Asr(dst, lhs, rhs_reg); |
| 2519 | } else { |
| 2520 | __ Lsr(dst, lhs, rhs_reg); |
| 2521 | } |
| 2522 | } |
| 2523 | break; |
| 2524 | } |
| 2525 | default: |
| 2526 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2527 | } |
| 2528 | } |
| 2529 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2530 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2531 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2535 | HandleBinaryOp(instruction); |
| 2536 | } |
| 2537 | |
| 2538 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2539 | HandleBinaryOp(instruction); |
| 2540 | } |
| 2541 | |
| 2542 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2543 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2544 | } |
| 2545 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2546 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2547 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 2548 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2549 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2550 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2551 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2552 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2553 | } |
| 2554 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2555 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2556 | Register dst = OutputRegister(instr); |
| 2557 | Register lhs = InputRegisterAt(instr, 0); |
| 2558 | Register rhs = InputRegisterAt(instr, 1); |
| 2559 | |
| 2560 | switch (instr->GetOpKind()) { |
| 2561 | case HInstruction::kAnd: |
| 2562 | __ Bic(dst, lhs, rhs); |
| 2563 | break; |
| 2564 | case HInstruction::kOr: |
| 2565 | __ Orn(dst, lhs, rhs); |
| 2566 | break; |
| 2567 | case HInstruction::kXor: |
| 2568 | __ Eon(dst, lhs, rhs); |
| 2569 | break; |
| 2570 | default: |
| 2571 | LOG(FATAL) << "Unreachable"; |
| 2572 | } |
| 2573 | } |
| 2574 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2575 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2576 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2577 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 2578 | instruction->GetType() == Primitive::kPrimLong); |
| 2579 | LocationSummary* locations = |
| 2580 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2581 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2582 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2583 | } else { |
| 2584 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2585 | } |
| 2586 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2587 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2588 | } |
| 2589 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2590 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2591 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2592 | Primitive::Type type = instruction->GetType(); |
| 2593 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 2594 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2595 | Register out = OutputRegister(instruction); |
| 2596 | Register left; |
| 2597 | if (kind != HInstruction::kNeg) { |
| 2598 | left = InputRegisterAt(instruction, 0); |
| 2599 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2600 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2601 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2602 | // conversion) can have a different type from the current instruction's type, |
| 2603 | // so we manually indicate the type. |
| 2604 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2605 | Operand right_operand(0); |
| 2606 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2607 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2608 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2609 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2610 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2611 | right_operand = Operand(right_reg, |
| 2612 | helpers::ShiftFromOpKind(op_kind), |
| 2613 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | // Logical binary operations do not support extension operations in the |
| 2617 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2618 | // the extension as a separate instruction. |
| 2619 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2620 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2621 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2622 | kind != HInstruction::kNeg)); |
| 2623 | switch (kind) { |
| 2624 | case HInstruction::kAdd: |
| 2625 | __ Add(out, left, right_operand); |
| 2626 | break; |
| 2627 | case HInstruction::kAnd: |
| 2628 | __ And(out, left, right_operand); |
| 2629 | break; |
| 2630 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2631 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2632 | __ Neg(out, right_operand); |
| 2633 | break; |
| 2634 | case HInstruction::kOr: |
| 2635 | __ Orr(out, left, right_operand); |
| 2636 | break; |
| 2637 | case HInstruction::kSub: |
| 2638 | __ Sub(out, left, right_operand); |
| 2639 | break; |
| 2640 | case HInstruction::kXor: |
| 2641 | __ Eor(out, left, right_operand); |
| 2642 | break; |
| 2643 | default: |
| 2644 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2645 | UNREACHABLE(); |
| 2646 | } |
| 2647 | } |
| 2648 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2649 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2650 | LocationSummary* locations = |
| 2651 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2652 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2653 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2654 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2655 | } |
| 2656 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2657 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2658 | __ Add(OutputRegister(instruction), |
| 2659 | InputRegisterAt(instruction, 0), |
| 2660 | Operand(InputOperandAt(instruction, 1))); |
| 2661 | } |
| 2662 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2663 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2664 | LocationSummary* locations = |
| 2665 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2666 | |
| 2667 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2668 | |
| 2669 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2670 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2671 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2672 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2673 | // loop. |
| 2674 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2675 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2676 | : Location::RequiresRegister()); |
| 2677 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2678 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2679 | } |
| 2680 | |
| 2681 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2682 | HIntermediateAddressIndex* instruction) { |
| 2683 | Register index_reg = InputRegisterAt(instruction, 0); |
| 2684 | uint32_t shift = Int64ConstantFrom(instruction->GetLocations()->InAt(2)); |
| 2685 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2686 | |
| 2687 | if (shift == 0) { |
| 2688 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2689 | } else { |
| 2690 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2691 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2692 | } |
| 2693 | } |
| 2694 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2695 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2696 | LocationSummary* locations = |
| 2697 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2698 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2699 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2700 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2701 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2702 | // Don't allocate register for Mneg instruction. |
| 2703 | } else { |
| 2704 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2705 | Location::RequiresRegister()); |
| 2706 | } |
| 2707 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2708 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2709 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2710 | } |
| 2711 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2712 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2713 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2714 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2715 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2716 | |
| 2717 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2718 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2719 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2720 | if (instr->GetType() == Primitive::kPrimLong && |
| 2721 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2722 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2723 | vixl::aarch64::Instruction* prev = |
| 2724 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2725 | if (prev->IsLoadOrStore()) { |
| 2726 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2727 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2728 | __ nop(); |
| 2729 | } |
| 2730 | } |
| 2731 | |
| 2732 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2733 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2734 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2735 | } else { |
| 2736 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2737 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2738 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2739 | __ Mneg(res, mul_left, mul_right); |
| 2740 | } else { |
| 2741 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2742 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2743 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2744 | } |
| 2745 | } |
| 2746 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2747 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2748 | bool object_array_get_with_read_barrier = |
| 2749 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2750 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2751 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2752 | object_array_get_with_read_barrier ? |
| 2753 | LocationSummary::kCallOnSlowPath : |
| 2754 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2755 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2756 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 2757 | // We need a temporary register for the read barrier marking slow |
| 2758 | // path in CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2759 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2760 | !Runtime::Current()->UseJitCompilation() && |
| 2761 | instruction->GetIndex()->IsConstant()) { |
| 2762 | // Array loads with constant index are treated as field loads. |
| 2763 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2764 | // constant index loads we need a temporary only if the offset is too big. |
| 2765 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2766 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| 2767 | offset += index << Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 2768 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2769 | locations->AddTemp(FixedTempLocation()); |
| 2770 | } |
| 2771 | } else { |
| 2772 | locations->AddTemp(Location::RequiresRegister()); |
| 2773 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2774 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2775 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2776 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2777 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2778 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2779 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2780 | // The output overlaps in the case of an object array get with |
| 2781 | // read barriers enabled: we do not want the move to overwrite the |
| 2782 | // array's location, as we need it to emit the read barrier. |
| 2783 | locations->SetOut( |
| 2784 | Location::RequiresRegister(), |
| 2785 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2786 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2790 | Primitive::Type type = instruction->GetType(); |
| 2791 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2792 | LocationSummary* locations = instruction->GetLocations(); |
| 2793 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2794 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2795 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2796 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2797 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2798 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2799 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2800 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2801 | // The read barrier instrumentation of object ArrayGet instructions |
| 2802 | // does not support the HIntermediateAddress instruction. |
| 2803 | DCHECK(!((type == Primitive::kPrimNot) && |
| 2804 | instruction->GetArray()->IsIntermediateAddress() && |
| 2805 | kEmitCompilerReadBarrier)); |
| 2806 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2807 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2808 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2809 | // Note that a potential implicit null check is handled in the |
| 2810 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2811 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2812 | if (index.IsConstant()) { |
| 2813 | // Array load with a constant index can be treated as a field load. |
| 2814 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2815 | Location maybe_temp = |
| 2816 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2817 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2818 | out, |
| 2819 | obj.W(), |
| 2820 | offset, |
| 2821 | maybe_temp, |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2822 | /* needs_null_check */ false, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2823 | /* use_load_acquire */ false); |
| 2824 | } else { |
| 2825 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
| 2826 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2827 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2828 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2829 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2830 | // General case. |
| 2831 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2832 | Register length; |
| 2833 | if (maybe_compressed_char_at) { |
| 2834 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2835 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2836 | { |
| 2837 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2838 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2839 | |
| 2840 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2841 | DCHECK_LT(count_offset, offset); |
| 2842 | int64_t adjusted_offset = |
| 2843 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2844 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2845 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2846 | } else { |
| 2847 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2848 | } |
| 2849 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2850 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2851 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2852 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2853 | if (maybe_compressed_char_at) { |
| 2854 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2855 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2856 | "Expecting 0=compressed, 1=uncompressed"); |
| 2857 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2858 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2859 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2860 | __ B(&done); |
| 2861 | __ Bind(&uncompressed_load); |
| 2862 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2863 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2864 | __ Bind(&done); |
| 2865 | } else { |
| 2866 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2867 | source = HeapOperand(obj, offset); |
| 2868 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2869 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2870 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2871 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2872 | // We do not need to compute the intermediate address from the array: the |
| 2873 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2874 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2875 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2876 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2877 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2878 | } |
| 2879 | temp = obj; |
| 2880 | } else { |
| 2881 | __ Add(temp, obj, offset); |
| 2882 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2883 | if (maybe_compressed_char_at) { |
| 2884 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2885 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2886 | "Expecting 0=compressed, 1=uncompressed"); |
| 2887 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2888 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2889 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2890 | __ B(&done); |
| 2891 | __ Bind(&uncompressed_load); |
| 2892 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2893 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2894 | __ Bind(&done); |
| 2895 | } else { |
| 2896 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2897 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2898 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2899 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2900 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2901 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2902 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2903 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2904 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2905 | |
| 2906 | if (type == Primitive::kPrimNot) { |
| 2907 | static_assert( |
| 2908 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2909 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2910 | Location obj_loc = locations->InAt(0); |
| 2911 | if (index.IsConstant()) { |
| 2912 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2913 | } else { |
| 2914 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2915 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2916 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2917 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2918 | } |
| 2919 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2920 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2921 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2922 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2923 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2927 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2928 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2929 | { |
| 2930 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2931 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2932 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2933 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2934 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2935 | // Mask out compression flag from String's array length. |
| 2936 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2937 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2938 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2939 | } |
| 2940 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2941 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2942 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2943 | |
| 2944 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2945 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2946 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2947 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2948 | LocationSummary::kCallOnSlowPath : |
| 2949 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2950 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2951 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2952 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2953 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 2954 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2955 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2956 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2957 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2958 | } |
| 2959 | } |
| 2960 | |
| 2961 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2962 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2963 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2964 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2965 | bool needs_write_barrier = |
| 2966 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2967 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2968 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2969 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2970 | CPURegister source = value; |
| 2971 | Location index = locations->InAt(1); |
| 2972 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2973 | MemOperand destination = HeapOperand(array); |
| 2974 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2975 | |
| 2976 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2977 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2978 | if (index.IsConstant()) { |
| 2979 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2980 | destination = HeapOperand(array, offset); |
| 2981 | } else { |
| 2982 | UseScratchRegisterScope temps(masm); |
| 2983 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2984 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2985 | // We do not need to compute the intermediate address from the array: the |
| 2986 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2987 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2988 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2989 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2990 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2991 | } |
| 2992 | temp = array; |
| 2993 | } else { |
| 2994 | __ Add(temp, array, offset); |
| 2995 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2996 | destination = HeapOperand(temp, |
| 2997 | XRegisterFrom(index), |
| 2998 | LSL, |
| 2999 | Primitive::ComponentSizeShift(value_type)); |
| 3000 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3001 | { |
| 3002 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3003 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3004 | codegen_->Store(value_type, value, destination); |
| 3005 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3006 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3007 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3008 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3009 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3010 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3011 | { |
| 3012 | // We use a block to end the scratch scope before the write barrier, thus |
| 3013 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 3014 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3015 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3016 | if (index.IsConstant()) { |
| 3017 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3018 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3019 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 3020 | destination = HeapOperand(temp, |
| 3021 | XRegisterFrom(index), |
| 3022 | LSL, |
| 3023 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3024 | } |
| 3025 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3026 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3027 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3028 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3029 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3030 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3031 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 3032 | codegen_->AddSlowPath(slow_path); |
| 3033 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3034 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3035 | __ Cbnz(Register(value), &non_zero); |
| 3036 | if (!index.IsConstant()) { |
| 3037 | __ Add(temp, array, offset); |
| 3038 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3039 | { |
| 3040 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 3041 | // emitted. |
| 3042 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3043 | __ Str(wzr, destination); |
| 3044 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3045 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3046 | __ B(&done); |
| 3047 | __ Bind(&non_zero); |
| 3048 | } |
| 3049 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3050 | // Note that when Baker read barriers are enabled, the type |
| 3051 | // checks are performed without read barriers. This is fine, |
| 3052 | // even in the case where a class object is in the from-space |
| 3053 | // after the flip, as a comparison involving such a type would |
| 3054 | // not produce a false positive; it may of course produce a |
| 3055 | // false negative, in which case we would take the ArraySet |
| 3056 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3057 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3058 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 3059 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3060 | { |
| 3061 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3062 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3063 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 3064 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3065 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3066 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3067 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3068 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 3069 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 3070 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3071 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 3072 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 3073 | // nor `temp2`, as we are comparing two poisoned references. |
| 3074 | __ Cmp(temp, temp2); |
| 3075 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3076 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3077 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3078 | vixl::aarch64::Label do_put; |
| 3079 | __ B(eq, &do_put); |
| 3080 | // If heap poisoning is enabled, the `temp` reference has |
| 3081 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3082 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3083 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3084 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 3085 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 3086 | // If heap poisoning is enabled, no need to unpoison |
| 3087 | // `temp`, as we are comparing against null below. |
| 3088 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 3089 | __ Bind(&do_put); |
| 3090 | } else { |
| 3091 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3092 | } |
| 3093 | } |
| 3094 | |
| 3095 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3096 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3097 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3098 | __ Mov(temp2, value.W()); |
| 3099 | GetAssembler()->PoisonHeapReference(temp2); |
| 3100 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | if (!index.IsConstant()) { |
| 3104 | __ Add(temp, array, offset); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 3105 | } else { |
| 3106 | // We no longer need the `temp` here so release it as the store below may |
| 3107 | // need a scratch register (if the constant index makes the offset too large) |
| 3108 | // and the poisoned `source` could be using the other scratch register. |
| 3109 | temps.Release(temp); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3110 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3111 | { |
| 3112 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3113 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3114 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3115 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3116 | if (!may_need_runtime_call_for_type_check) { |
| 3117 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3118 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3119 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3120 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3121 | |
| 3122 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 3123 | |
| 3124 | if (done.IsLinked()) { |
| 3125 | __ Bind(&done); |
| 3126 | } |
| 3127 | |
| 3128 | if (slow_path != nullptr) { |
| 3129 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3130 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3131 | } |
| 3132 | } |
| 3133 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3134 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3135 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3136 | InvokeRuntimeCallingConvention calling_convention; |
| 3137 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3138 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 3139 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3140 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 3141 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3142 | } |
| 3143 | |
| 3144 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3145 | BoundsCheckSlowPathARM64* slow_path = |
| 3146 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3147 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3148 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 3149 | __ B(slow_path->GetEntryLabel(), hs); |
| 3150 | } |
| 3151 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3152 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3153 | LocationSummary* locations = |
| 3154 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3155 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3156 | if (check->HasUses()) { |
| 3157 | locations->SetOut(Location::SameAsFirstInput()); |
| 3158 | } |
| 3159 | } |
| 3160 | |
| 3161 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3162 | // We assume the class is not null. |
| 3163 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 3164 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 3165 | codegen_->AddSlowPath(slow_path); |
| 3166 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3167 | } |
| 3168 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3169 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3170 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3171 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3172 | } |
| 3173 | |
| 3174 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 3175 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 3176 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3177 | if (rhs_loc.IsConstant()) { |
| 3178 | // 0.0 is the only immediate that can be encoded directly in |
| 3179 | // an FCMP instruction. |
| 3180 | // |
| 3181 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3182 | // specify that in a floating-point comparison, positive zero |
| 3183 | // and negative zero are considered equal, so we can use the |
| 3184 | // literal 0.0 for both cases here. |
| 3185 | // |
| 3186 | // Note however that some methods (Float.equal, Float.compare, |
| 3187 | // Float.compareTo, Double.equal, Double.compare, |
| 3188 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3189 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3190 | // -0.0. So if we ever translate calls to these methods into a |
| 3191 | // HCompare instruction, we must handle the -0.0 case with |
| 3192 | // care here. |
| 3193 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3194 | __ Fcmp(lhs_reg, 0.0); |
| 3195 | } else { |
| 3196 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3197 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3198 | } |
| 3199 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3200 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3201 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3202 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 3203 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3204 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3205 | case Primitive::kPrimBoolean: |
| 3206 | case Primitive::kPrimByte: |
| 3207 | case Primitive::kPrimShort: |
| 3208 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3209 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3210 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3211 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3212 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3213 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3214 | break; |
| 3215 | } |
| 3216 | case Primitive::kPrimFloat: |
| 3217 | case Primitive::kPrimDouble: { |
| 3218 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3219 | locations->SetInAt(1, |
| 3220 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3221 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3222 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3223 | locations->SetOut(Location::RequiresRegister()); |
| 3224 | break; |
| 3225 | } |
| 3226 | default: |
| 3227 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3228 | } |
| 3229 | } |
| 3230 | |
| 3231 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 3232 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 3233 | |
| 3234 | // 0 if: left == right |
| 3235 | // 1 if: left > right |
| 3236 | // -1 if: left < right |
| 3237 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3238 | case Primitive::kPrimBoolean: |
| 3239 | case Primitive::kPrimByte: |
| 3240 | case Primitive::kPrimShort: |
| 3241 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3242 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3243 | case Primitive::kPrimLong: { |
| 3244 | Register result = OutputRegister(compare); |
| 3245 | Register left = InputRegisterAt(compare, 0); |
| 3246 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3247 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3248 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3249 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3250 | break; |
| 3251 | } |
| 3252 | case Primitive::kPrimFloat: |
| 3253 | case Primitive::kPrimDouble: { |
| 3254 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3255 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3256 | __ Cset(result, ne); |
| 3257 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3258 | break; |
| 3259 | } |
| 3260 | default: |
| 3261 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3262 | } |
| 3263 | } |
| 3264 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3265 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3266 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3267 | |
| 3268 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 3269 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3270 | locations->SetInAt(1, |
| 3271 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3272 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3273 | : Location::RequiresFpuRegister()); |
| 3274 | } else { |
| 3275 | // Integer cases. |
| 3276 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3277 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3278 | } |
| 3279 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3280 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3281 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3282 | } |
| 3283 | } |
| 3284 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3285 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3286 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3287 | return; |
| 3288 | } |
| 3289 | |
| 3290 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3291 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3292 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3293 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3294 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3295 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3296 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3297 | } else { |
| 3298 | // Integer cases. |
| 3299 | Register lhs = InputRegisterAt(instruction, 0); |
| 3300 | Operand rhs = InputOperandAt(instruction, 1); |
| 3301 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3302 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3303 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3307 | M(Equal) \ |
| 3308 | M(NotEqual) \ |
| 3309 | M(LessThan) \ |
| 3310 | M(LessThanOrEqual) \ |
| 3311 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3312 | M(GreaterThanOrEqual) \ |
| 3313 | M(Below) \ |
| 3314 | M(BelowOrEqual) \ |
| 3315 | M(Above) \ |
| 3316 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3317 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3318 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3319 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3320 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3321 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3322 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3323 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3324 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3325 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3326 | |
| 3327 | LocationSummary* locations = instruction->GetLocations(); |
| 3328 | Location second = locations->InAt(1); |
| 3329 | DCHECK(second.IsConstant()); |
| 3330 | |
| 3331 | Register out = OutputRegister(instruction); |
| 3332 | Register dividend = InputRegisterAt(instruction, 0); |
| 3333 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3334 | DCHECK(imm == 1 || imm == -1); |
| 3335 | |
| 3336 | if (instruction->IsRem()) { |
| 3337 | __ Mov(out, 0); |
| 3338 | } else { |
| 3339 | if (imm == 1) { |
| 3340 | __ Mov(out, dividend); |
| 3341 | } else { |
| 3342 | __ Neg(out, dividend); |
| 3343 | } |
| 3344 | } |
| 3345 | } |
| 3346 | |
| 3347 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3348 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3349 | |
| 3350 | LocationSummary* locations = instruction->GetLocations(); |
| 3351 | Location second = locations->InAt(1); |
| 3352 | DCHECK(second.IsConstant()); |
| 3353 | |
| 3354 | Register out = OutputRegister(instruction); |
| 3355 | Register dividend = InputRegisterAt(instruction, 0); |
| 3356 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3357 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3358 | int ctz_imm = CTZ(abs_imm); |
| 3359 | |
| 3360 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3361 | Register temp = temps.AcquireSameSizeAs(out); |
| 3362 | |
| 3363 | if (instruction->IsDiv()) { |
| 3364 | __ Add(temp, dividend, abs_imm - 1); |
| 3365 | __ Cmp(dividend, 0); |
| 3366 | __ Csel(out, temp, dividend, lt); |
| 3367 | if (imm > 0) { |
| 3368 | __ Asr(out, out, ctz_imm); |
| 3369 | } else { |
| 3370 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 3371 | } |
| 3372 | } else { |
| 3373 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 3374 | __ Asr(temp, dividend, bits - 1); |
| 3375 | __ Lsr(temp, temp, bits - ctz_imm); |
| 3376 | __ Add(out, dividend, temp); |
| 3377 | __ And(out, out, abs_imm - 1); |
| 3378 | __ Sub(out, out, temp); |
| 3379 | } |
| 3380 | } |
| 3381 | |
| 3382 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3383 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3384 | |
| 3385 | LocationSummary* locations = instruction->GetLocations(); |
| 3386 | Location second = locations->InAt(1); |
| 3387 | DCHECK(second.IsConstant()); |
| 3388 | |
| 3389 | Register out = OutputRegister(instruction); |
| 3390 | Register dividend = InputRegisterAt(instruction, 0); |
| 3391 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3392 | |
| 3393 | Primitive::Type type = instruction->GetResultType(); |
| 3394 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 3395 | |
| 3396 | int64_t magic; |
| 3397 | int shift; |
| 3398 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 3399 | |
| 3400 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3401 | Register temp = temps.AcquireSameSizeAs(out); |
| 3402 | |
| 3403 | // temp = get_high(dividend * magic) |
| 3404 | __ Mov(temp, magic); |
| 3405 | if (type == Primitive::kPrimLong) { |
| 3406 | __ Smulh(temp, dividend, temp); |
| 3407 | } else { |
| 3408 | __ Smull(temp.X(), dividend, temp); |
| 3409 | __ Lsr(temp.X(), temp.X(), 32); |
| 3410 | } |
| 3411 | |
| 3412 | if (imm > 0 && magic < 0) { |
| 3413 | __ Add(temp, temp, dividend); |
| 3414 | } else if (imm < 0 && magic > 0) { |
| 3415 | __ Sub(temp, temp, dividend); |
| 3416 | } |
| 3417 | |
| 3418 | if (shift != 0) { |
| 3419 | __ Asr(temp, temp, shift); |
| 3420 | } |
| 3421 | |
| 3422 | if (instruction->IsDiv()) { |
| 3423 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3424 | } else { |
| 3425 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3426 | // TODO: Strength reduction for msub. |
| 3427 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3428 | __ Mov(temp_imm, imm); |
| 3429 | __ Msub(out, temp, temp_imm, dividend); |
| 3430 | } |
| 3431 | } |
| 3432 | |
| 3433 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3434 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3435 | Primitive::Type type = instruction->GetResultType(); |
Calin Juravle | c70d1d9 | 2017-03-27 18:10:04 -0700 | [diff] [blame] | 3436 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3437 | |
| 3438 | LocationSummary* locations = instruction->GetLocations(); |
| 3439 | Register out = OutputRegister(instruction); |
| 3440 | Location second = locations->InAt(1); |
| 3441 | |
| 3442 | if (second.IsConstant()) { |
| 3443 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3444 | |
| 3445 | if (imm == 0) { |
| 3446 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3447 | } else if (imm == 1 || imm == -1) { |
| 3448 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3449 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3450 | DivRemByPowerOfTwo(instruction); |
| 3451 | } else { |
| 3452 | DCHECK(imm <= -2 || imm >= 2); |
| 3453 | GenerateDivRemWithAnyConstant(instruction); |
| 3454 | } |
| 3455 | } else { |
| 3456 | Register dividend = InputRegisterAt(instruction, 0); |
| 3457 | Register divisor = InputRegisterAt(instruction, 1); |
| 3458 | if (instruction->IsDiv()) { |
| 3459 | __ Sdiv(out, dividend, divisor); |
| 3460 | } else { |
| 3461 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3462 | Register temp = temps.AcquireSameSizeAs(out); |
| 3463 | __ Sdiv(temp, dividend, divisor); |
| 3464 | __ Msub(out, temp, divisor, dividend); |
| 3465 | } |
| 3466 | } |
| 3467 | } |
| 3468 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3469 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3470 | LocationSummary* locations = |
| 3471 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3472 | switch (div->GetResultType()) { |
| 3473 | case Primitive::kPrimInt: |
| 3474 | case Primitive::kPrimLong: |
| 3475 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3476 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3477 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3478 | break; |
| 3479 | |
| 3480 | case Primitive::kPrimFloat: |
| 3481 | case Primitive::kPrimDouble: |
| 3482 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3483 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3484 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3485 | break; |
| 3486 | |
| 3487 | default: |
| 3488 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3489 | } |
| 3490 | } |
| 3491 | |
| 3492 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 3493 | Primitive::Type type = div->GetResultType(); |
| 3494 | switch (type) { |
| 3495 | case Primitive::kPrimInt: |
| 3496 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3497 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3498 | break; |
| 3499 | |
| 3500 | case Primitive::kPrimFloat: |
| 3501 | case Primitive::kPrimDouble: |
| 3502 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3503 | break; |
| 3504 | |
| 3505 | default: |
| 3506 | LOG(FATAL) << "Unexpected div type " << type; |
| 3507 | } |
| 3508 | } |
| 3509 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3510 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3511 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3512 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3516 | SlowPathCodeARM64* slow_path = |
| 3517 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 3518 | codegen_->AddSlowPath(slow_path); |
| 3519 | Location value = instruction->GetLocations()->InAt(0); |
| 3520 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3521 | Primitive::Type type = instruction->GetType(); |
| 3522 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3523 | if (!Primitive::IsIntegralType(type)) { |
| 3524 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3525 | return; |
| 3526 | } |
| 3527 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3528 | if (value.IsConstant()) { |
| 3529 | int64_t divisor = Int64ConstantFrom(value); |
| 3530 | if (divisor == 0) { |
| 3531 | __ B(slow_path->GetEntryLabel()); |
| 3532 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3533 | // A division by a non-null constant is valid. We don't need to perform |
| 3534 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3535 | } |
| 3536 | } else { |
| 3537 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3538 | } |
| 3539 | } |
| 3540 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3541 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3542 | LocationSummary* locations = |
| 3543 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3544 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3545 | } |
| 3546 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3547 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3548 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3549 | // Will be generated at use site. |
| 3550 | } |
| 3551 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3552 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3553 | exit->SetLocations(nullptr); |
| 3554 | } |
| 3555 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3556 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3557 | } |
| 3558 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3559 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3560 | LocationSummary* locations = |
| 3561 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3562 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3563 | } |
| 3564 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3565 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3566 | // Will be generated at use site. |
| 3567 | } |
| 3568 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3569 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3570 | DCHECK(!successor->IsExitBlock()); |
| 3571 | HBasicBlock* block = got->GetBlock(); |
| 3572 | HInstruction* previous = got->GetPrevious(); |
| 3573 | HLoopInformation* info = block->GetLoopInformation(); |
| 3574 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3575 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3576 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3577 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3578 | return; |
| 3579 | } |
| 3580 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3581 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3582 | } |
| 3583 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3584 | __ B(codegen_->GetLabelOf(successor)); |
| 3585 | } |
| 3586 | } |
| 3587 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3588 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3589 | got->SetLocations(nullptr); |
| 3590 | } |
| 3591 | |
| 3592 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3593 | HandleGoto(got, got->GetSuccessor()); |
| 3594 | } |
| 3595 | |
| 3596 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3597 | try_boundary->SetLocations(nullptr); |
| 3598 | } |
| 3599 | |
| 3600 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3601 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3602 | if (!successor->IsExitBlock()) { |
| 3603 | HandleGoto(try_boundary, successor); |
| 3604 | } |
| 3605 | } |
| 3606 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3607 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3608 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3609 | vixl::aarch64::Label* true_target, |
| 3610 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3611 | // FP branching requires both targets to be explicit. If either of the targets |
| 3612 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3613 | vixl::aarch64::Label fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3614 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3615 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3616 | if (true_target == nullptr && false_target == nullptr) { |
| 3617 | // Nothing to do. The code always falls through. |
| 3618 | return; |
| 3619 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3620 | // Constant condition, statically compared against "true" (integer value 1). |
| 3621 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3622 | if (true_target != nullptr) { |
| 3623 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3624 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3625 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3626 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3627 | if (false_target != nullptr) { |
| 3628 | __ B(false_target); |
| 3629 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3630 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3631 | return; |
| 3632 | } |
| 3633 | |
| 3634 | // The following code generates these patterns: |
| 3635 | // (1) true_target == nullptr && false_target != nullptr |
| 3636 | // - opposite condition true => branch to false_target |
| 3637 | // (2) true_target != nullptr && false_target == nullptr |
| 3638 | // - condition true => branch to true_target |
| 3639 | // (3) true_target != nullptr && false_target != nullptr |
| 3640 | // - condition true => branch to true_target |
| 3641 | // - branch to false_target |
| 3642 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3643 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3644 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3645 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3646 | if (true_target == nullptr) { |
| 3647 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3648 | } else { |
| 3649 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3650 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3651 | } else { |
| 3652 | // The condition instruction has not been materialized, use its inputs as |
| 3653 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3654 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3655 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3656 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3657 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3658 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3659 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3660 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3661 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3662 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3663 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3664 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3665 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3666 | // Integer cases. |
| 3667 | Register lhs = InputRegisterAt(condition, 0); |
| 3668 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3669 | |
| 3670 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3671 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3672 | if (true_target == nullptr) { |
| 3673 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3674 | non_fallthrough_target = false_target; |
| 3675 | } else { |
| 3676 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3677 | non_fallthrough_target = true_target; |
| 3678 | } |
| 3679 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3680 | 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] | 3681 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3682 | switch (arm64_cond) { |
| 3683 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3684 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3685 | break; |
| 3686 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3687 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3688 | break; |
| 3689 | case lt: |
| 3690 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3691 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3692 | break; |
| 3693 | case ge: |
| 3694 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3695 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3696 | break; |
| 3697 | default: |
| 3698 | // Without the `static_cast` the compiler throws an error for |
| 3699 | // `-Werror=sign-promo`. |
| 3700 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3701 | } |
| 3702 | } else { |
| 3703 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3704 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3705 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3706 | } |
| 3707 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3708 | |
| 3709 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3710 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3711 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3712 | __ B(false_target); |
| 3713 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3714 | |
| 3715 | if (fallthrough_target.IsLinked()) { |
| 3716 | __ Bind(&fallthrough_target); |
| 3717 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3718 | } |
| 3719 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3720 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 3721 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3722 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3723 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3724 | } |
| 3725 | } |
| 3726 | |
| 3727 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3728 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3729 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3730 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3731 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3732 | true_target = nullptr; |
| 3733 | } |
| 3734 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3735 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3736 | false_target = nullptr; |
| 3737 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3738 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3742 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3743 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3744 | InvokeRuntimeCallingConvention calling_convention; |
| 3745 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3746 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3747 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3748 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3749 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3750 | } |
| 3751 | } |
| 3752 | |
| 3753 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3754 | SlowPathCodeARM64* slow_path = |
| 3755 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3756 | GenerateTestAndBranch(deoptimize, |
| 3757 | /* condition_input_index */ 0, |
| 3758 | slow_path->GetEntryLabel(), |
| 3759 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3760 | } |
| 3761 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3762 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3763 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3764 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3765 | locations->SetOut(Location::RequiresRegister()); |
| 3766 | } |
| 3767 | |
| 3768 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3769 | __ Ldr(OutputRegister(flag), |
| 3770 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3771 | } |
| 3772 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3773 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3774 | return condition->IsCondition() && |
| 3775 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 3776 | } |
| 3777 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3778 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3779 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3780 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3781 | : ARM64Condition(cond); |
| 3782 | } |
| 3783 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3784 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3785 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3786 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3787 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3788 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3789 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3790 | } else { |
| 3791 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3792 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3793 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3794 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3795 | // Ask VIXL whether we should synthesize constants in registers. |
| 3796 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3797 | Operand true_op = is_true_value_constant ? |
| 3798 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3799 | Operand false_op = is_false_value_constant ? |
| 3800 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3801 | bool true_value_in_register = false; |
| 3802 | bool false_value_in_register = false; |
| 3803 | MacroAssembler::GetCselSynthesisInformation( |
| 3804 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3805 | true_value_in_register |= !is_true_value_constant; |
| 3806 | false_value_in_register |= !is_false_value_constant; |
| 3807 | |
| 3808 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3809 | : Location::ConstantLocation(cst_true_value)); |
| 3810 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3811 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3812 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3813 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3814 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3815 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3816 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3817 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3818 | } |
| 3819 | |
| 3820 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3821 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3822 | Condition csel_cond; |
| 3823 | |
| 3824 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3825 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3826 | // Use the condition flags set by the previous instruction. |
| 3827 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3828 | } else { |
| 3829 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3830 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3831 | } |
| 3832 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3833 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3834 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3835 | } else { |
| 3836 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3837 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3838 | } |
| 3839 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3840 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3841 | __ Fcsel(OutputFPRegister(select), |
| 3842 | InputFPRegisterAt(select, 1), |
| 3843 | InputFPRegisterAt(select, 0), |
| 3844 | csel_cond); |
| 3845 | } else { |
| 3846 | __ Csel(OutputRegister(select), |
| 3847 | InputOperandAt(select, 1), |
| 3848 | InputOperandAt(select, 0), |
| 3849 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3850 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3851 | } |
| 3852 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3853 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3854 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3855 | } |
| 3856 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3857 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3858 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | void CodeGeneratorARM64::GenerateNop() { |
| 3862 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3863 | } |
| 3864 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3865 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3866 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3870 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3871 | } |
| 3872 | |
| 3873 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3874 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3875 | } |
| 3876 | |
| 3877 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3878 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3879 | } |
| 3880 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3881 | // Temp is used for read barrier. |
| 3882 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3883 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3884 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3885 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3886 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3887 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3888 | return 1; |
| 3889 | } |
| 3890 | return 0; |
| 3891 | } |
| 3892 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3893 | // 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] | 3894 | // interface pointer, one for loading the current interface. |
| 3895 | // The other checks have one temp for loading the object's class. |
| 3896 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3897 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3898 | return 3; |
| 3899 | } |
| 3900 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3901 | } |
| 3902 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3903 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3904 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3905 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3906 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3907 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3908 | case TypeCheckKind::kExactCheck: |
| 3909 | case TypeCheckKind::kAbstractClassCheck: |
| 3910 | case TypeCheckKind::kClassHierarchyCheck: |
| 3911 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3912 | call_kind = |
| 3913 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3914 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3915 | break; |
| 3916 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3917 | case TypeCheckKind::kUnresolvedCheck: |
| 3918 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3919 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3920 | break; |
| 3921 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3922 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3923 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3924 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3925 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3926 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3927 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3928 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3929 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3930 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3931 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3932 | // Add temps if necessary for read barriers. |
| 3933 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3934 | } |
| 3935 | |
| 3936 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3937 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3938 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3939 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3940 | Register obj = InputRegisterAt(instruction, 0); |
| 3941 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3942 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3943 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3944 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3945 | DCHECK_LE(num_temps, 1u); |
| 3946 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3947 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3948 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3949 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3950 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3951 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3952 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3953 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3954 | |
| 3955 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3956 | // Avoid null check if we know `obj` is not null. |
| 3957 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3958 | __ Cbz(obj, &zero); |
| 3959 | } |
| 3960 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3961 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3962 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3963 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3964 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3965 | out_loc, |
| 3966 | obj_loc, |
| 3967 | class_offset, |
| 3968 | maybe_temp_loc, |
| 3969 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3970 | __ Cmp(out, cls); |
| 3971 | __ Cset(out, eq); |
| 3972 | if (zero.IsLinked()) { |
| 3973 | __ B(&done); |
| 3974 | } |
| 3975 | break; |
| 3976 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3977 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3978 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3979 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3980 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3981 | out_loc, |
| 3982 | obj_loc, |
| 3983 | class_offset, |
| 3984 | maybe_temp_loc, |
| 3985 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3986 | // If the class is abstract, we eagerly fetch the super class of the |
| 3987 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3988 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3989 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3990 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3991 | GenerateReferenceLoadOneRegister(instruction, |
| 3992 | out_loc, |
| 3993 | super_offset, |
| 3994 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3995 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3996 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3997 | __ Cbz(out, &done); |
| 3998 | __ Cmp(out, cls); |
| 3999 | __ B(ne, &loop); |
| 4000 | __ Mov(out, 1); |
| 4001 | if (zero.IsLinked()) { |
| 4002 | __ B(&done); |
| 4003 | } |
| 4004 | break; |
| 4005 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4006 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4007 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4008 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4009 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4010 | out_loc, |
| 4011 | obj_loc, |
| 4012 | class_offset, |
| 4013 | maybe_temp_loc, |
| 4014 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4015 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4016 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4017 | __ Bind(&loop); |
| 4018 | __ Cmp(out, cls); |
| 4019 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4020 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4021 | GenerateReferenceLoadOneRegister(instruction, |
| 4022 | out_loc, |
| 4023 | super_offset, |
| 4024 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4025 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4026 | __ Cbnz(out, &loop); |
| 4027 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4028 | __ B(&done); |
| 4029 | __ Bind(&success); |
| 4030 | __ Mov(out, 1); |
| 4031 | if (zero.IsLinked()) { |
| 4032 | __ B(&done); |
| 4033 | } |
| 4034 | break; |
| 4035 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4036 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4037 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4038 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4039 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4040 | out_loc, |
| 4041 | obj_loc, |
| 4042 | class_offset, |
| 4043 | maybe_temp_loc, |
| 4044 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4045 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4046 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4047 | __ Cmp(out, cls); |
| 4048 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4049 | // 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] | 4050 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4051 | GenerateReferenceLoadOneRegister(instruction, |
| 4052 | out_loc, |
| 4053 | component_offset, |
| 4054 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4055 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4056 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4057 | __ Cbz(out, &done); |
| 4058 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4059 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4060 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4061 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4062 | __ Mov(out, 1); |
| 4063 | __ B(&done); |
| 4064 | break; |
| 4065 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4066 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4067 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4068 | // No read barrier since the slow path will retry upon failure. |
| 4069 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4070 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4071 | out_loc, |
| 4072 | obj_loc, |
| 4073 | class_offset, |
| 4074 | maybe_temp_loc, |
| 4075 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4076 | __ Cmp(out, cls); |
| 4077 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4078 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4079 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4080 | codegen_->AddSlowPath(slow_path); |
| 4081 | __ B(ne, slow_path->GetEntryLabel()); |
| 4082 | __ Mov(out, 1); |
| 4083 | if (zero.IsLinked()) { |
| 4084 | __ B(&done); |
| 4085 | } |
| 4086 | break; |
| 4087 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4088 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4089 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4090 | case TypeCheckKind::kInterfaceCheck: { |
| 4091 | // Note that we indeed only call on slow path, but we always go |
| 4092 | // into the slow path for the unresolved and interface check |
| 4093 | // cases. |
| 4094 | // |
| 4095 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4096 | // entry point without resorting to a type checking slow path |
| 4097 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4098 | // require to assign fixed registers for the inputs of this |
| 4099 | // HInstanceOf instruction (following the runtime calling |
| 4100 | // convention), which might be cluttered by the potential first |
| 4101 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4102 | // |
| 4103 | // TODO: Introduce a new runtime entry point taking the object |
| 4104 | // to test (instead of its class) as argument, and let it deal |
| 4105 | // with the read barrier issues. This will let us refactor this |
| 4106 | // case of the `switch` code as it was previously (with a direct |
| 4107 | // call to the runtime not using a type checking slow path). |
| 4108 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4109 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4110 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4111 | /* is_fatal */ false); |
| 4112 | codegen_->AddSlowPath(slow_path); |
| 4113 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4114 | if (zero.IsLinked()) { |
| 4115 | __ B(&done); |
| 4116 | } |
| 4117 | break; |
| 4118 | } |
| 4119 | } |
| 4120 | |
| 4121 | if (zero.IsLinked()) { |
| 4122 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4123 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4124 | } |
| 4125 | |
| 4126 | if (done.IsLinked()) { |
| 4127 | __ Bind(&done); |
| 4128 | } |
| 4129 | |
| 4130 | if (slow_path != nullptr) { |
| 4131 | __ Bind(slow_path->GetExitLabel()); |
| 4132 | } |
| 4133 | } |
| 4134 | |
| 4135 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 4136 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4137 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 4138 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4139 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 4140 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4141 | case TypeCheckKind::kExactCheck: |
| 4142 | case TypeCheckKind::kAbstractClassCheck: |
| 4143 | case TypeCheckKind::kClassHierarchyCheck: |
| 4144 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4145 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 4146 | LocationSummary::kCallOnSlowPath : |
| 4147 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4148 | break; |
| 4149 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4150 | case TypeCheckKind::kUnresolvedCheck: |
| 4151 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4152 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4153 | break; |
| 4154 | } |
| 4155 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4156 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4157 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4158 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4159 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4160 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4164 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4165 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4166 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4167 | Register obj = InputRegisterAt(instruction, 0); |
| 4168 | Register cls = InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4169 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4170 | DCHECK_GE(num_temps, 1u); |
| 4171 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4172 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4173 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4174 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4175 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4176 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4177 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4178 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4179 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4180 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4181 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4182 | const uint32_t object_array_data_offset = |
| 4183 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4184 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4185 | bool is_type_check_slow_path_fatal = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4186 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 4187 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 4188 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4189 | if (!kEmitCompilerReadBarrier) { |
| 4190 | is_type_check_slow_path_fatal = |
| 4191 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 4192 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 4193 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 4194 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 4195 | !instruction->CanThrowIntoCatchBlock(); |
| 4196 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4197 | SlowPathCodeARM64* type_check_slow_path = |
| 4198 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4199 | is_type_check_slow_path_fatal); |
| 4200 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4201 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4202 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4203 | // Avoid null check if we know obj is not null. |
| 4204 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4205 | __ Cbz(obj, &done); |
| 4206 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4207 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4208 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4209 | case TypeCheckKind::kExactCheck: |
| 4210 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4211 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4212 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4213 | temp_loc, |
| 4214 | obj_loc, |
| 4215 | class_offset, |
| 4216 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4217 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4218 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4219 | __ Cmp(temp, cls); |
| 4220 | // Jump to slow path for throwing the exception or doing a |
| 4221 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4222 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4223 | break; |
| 4224 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4225 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4226 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4227 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4228 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4229 | temp_loc, |
| 4230 | obj_loc, |
| 4231 | class_offset, |
| 4232 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4233 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4234 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4235 | // If the class is abstract, we eagerly fetch the super class of the |
| 4236 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4237 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4238 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4239 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4240 | GenerateReferenceLoadOneRegister(instruction, |
| 4241 | temp_loc, |
| 4242 | super_offset, |
| 4243 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4244 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4245 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4246 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4247 | // exception. |
| 4248 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4249 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4250 | __ Cmp(temp, cls); |
| 4251 | __ B(ne, &loop); |
| 4252 | break; |
| 4253 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4254 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4255 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4256 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4257 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4258 | temp_loc, |
| 4259 | obj_loc, |
| 4260 | class_offset, |
| 4261 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4262 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4263 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4264 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4265 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4266 | __ Bind(&loop); |
| 4267 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4268 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4269 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4270 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4271 | GenerateReferenceLoadOneRegister(instruction, |
| 4272 | temp_loc, |
| 4273 | super_offset, |
| 4274 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4275 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4276 | |
| 4277 | // If the class reference currently in `temp` is not null, jump |
| 4278 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4279 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4280 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4281 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4282 | break; |
| 4283 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4284 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4285 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4286 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4287 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4288 | temp_loc, |
| 4289 | obj_loc, |
| 4290 | class_offset, |
| 4291 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4292 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4293 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4294 | // Do an exact check. |
| 4295 | __ Cmp(temp, cls); |
| 4296 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4297 | |
| 4298 | // 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] | 4299 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4300 | GenerateReferenceLoadOneRegister(instruction, |
| 4301 | temp_loc, |
| 4302 | component_offset, |
| 4303 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4304 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4305 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4306 | // If the component type is null, jump to the slow path to throw the exception. |
| 4307 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4308 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4309 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4310 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4311 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4312 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4313 | break; |
| 4314 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4315 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4316 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4317 | // 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] | 4318 | // |
| 4319 | // We cannot directly call the CheckCast runtime entry point |
| 4320 | // without resorting to a type checking slow path here (i.e. by |
| 4321 | // calling InvokeRuntime directly), as it would require to |
| 4322 | // assign fixed registers for the inputs of this HInstanceOf |
| 4323 | // instruction (following the runtime calling convention), which |
| 4324 | // might be cluttered by the potential first read barrier |
| 4325 | // emission at the beginning of this method. |
| 4326 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4327 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4328 | case TypeCheckKind::kInterfaceCheck: { |
| 4329 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4330 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4331 | temp_loc, |
| 4332 | obj_loc, |
| 4333 | class_offset, |
| 4334 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4335 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4336 | |
| 4337 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4338 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4339 | temp_loc, |
| 4340 | temp_loc, |
| 4341 | iftable_offset, |
| 4342 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4343 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4344 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4345 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4346 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4347 | vixl::aarch64::Label start_loop; |
| 4348 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4349 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4350 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4351 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4352 | // Go to next interface. |
| 4353 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4354 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4355 | // Compare the classes and continue the loop if they do not match. |
| 4356 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4357 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4358 | break; |
| 4359 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4360 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4361 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4362 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4363 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4364 | } |
| 4365 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4366 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 4367 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4368 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4369 | } |
| 4370 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4371 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4372 | // Will be generated at use site. |
| 4373 | } |
| 4374 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4375 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 4376 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4377 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4378 | } |
| 4379 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4380 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4381 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4382 | } |
| 4383 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4384 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4385 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4386 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4387 | // the method_idx. |
| 4388 | HandleInvoke(invoke); |
| 4389 | } |
| 4390 | |
| 4391 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4392 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 4393 | } |
| 4394 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4395 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4396 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4397 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4398 | } |
| 4399 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4400 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4401 | HandleInvoke(invoke); |
| 4402 | } |
| 4403 | |
| 4404 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4405 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4406 | LocationSummary* locations = invoke->GetLocations(); |
| 4407 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4408 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4409 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4410 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4411 | |
| 4412 | // The register ip1 is required to be used for the hidden argument in |
| 4413 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4414 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4415 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4416 | scratch_scope.Exclude(ip1); |
| 4417 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4418 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4419 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4420 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4421 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4422 | { |
| 4423 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4424 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4425 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4426 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4427 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4428 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4429 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4430 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4431 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4432 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4433 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4434 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4435 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4436 | // emit a read barrier for the previous class reference load. |
| 4437 | // However this is not required in practice, as this is an |
| 4438 | // intermediate/temporary reference and because the current |
| 4439 | // concurrent copying collector keeps the from-space memory |
| 4440 | // intact/accessible until the end of the marking phase (the |
| 4441 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4442 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4443 | __ Ldr(temp, |
| 4444 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4445 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4446 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4447 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4448 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4449 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4450 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4451 | |
| 4452 | { |
| 4453 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4454 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4455 | |
| 4456 | // lr(); |
| 4457 | __ blr(lr); |
| 4458 | DCHECK(!codegen_->IsLeafMethod()); |
| 4459 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4460 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4464 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4465 | if (intrinsic.TryDispatch(invoke)) { |
| 4466 | return; |
| 4467 | } |
| 4468 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4469 | HandleInvoke(invoke); |
| 4470 | } |
| 4471 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4472 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4473 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4474 | // art::PrepareForRegisterAllocation. |
| 4475 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4476 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4477 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4478 | if (intrinsic.TryDispatch(invoke)) { |
| 4479 | return; |
| 4480 | } |
| 4481 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4482 | HandleInvoke(invoke); |
| 4483 | } |
| 4484 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4485 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4486 | if (invoke->GetLocations()->Intrinsified()) { |
| 4487 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4488 | intrinsic.Dispatch(invoke); |
| 4489 | return true; |
| 4490 | } |
| 4491 | return false; |
| 4492 | } |
| 4493 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4494 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4495 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4496 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4497 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4498 | return desired_dispatch_info; |
| 4499 | } |
| 4500 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4501 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4502 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4503 | // 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] | 4504 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4505 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4506 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4507 | uint32_t offset = |
| 4508 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4509 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4510 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4511 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4512 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4513 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4514 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4515 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4516 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4517 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4518 | // Add ADRP with its PC-relative method patch. |
| 4519 | vixl::aarch64::Label* adrp_label = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 4520 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4521 | // Add ADD with its PC-relative method patch. |
| 4522 | vixl::aarch64::Label* add_label = |
| 4523 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), adrp_label); |
| 4524 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4525 | break; |
| 4526 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4527 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4528 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4529 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4530 | break; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4531 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4532 | // Add ADRP with its PC-relative DexCache access patch. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4533 | MethodReference target_method(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 4534 | vixl::aarch64::Label* adrp_label = NewMethodBssEntryPatch(target_method); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4535 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4536 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4537 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4538 | NewMethodBssEntryPatch(target_method, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4539 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4540 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4541 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4542 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4543 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4544 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4545 | } |
| 4546 | } |
| 4547 | |
| 4548 | switch (invoke->GetCodePtrLocation()) { |
| 4549 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4550 | { |
| 4551 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4552 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4553 | kInstructionSize, |
| 4554 | CodeBufferCheckScope::kExactSize); |
| 4555 | __ bl(&frame_entry_label_); |
| 4556 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4557 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4558 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4559 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4560 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4561 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4562 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4563 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4564 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4565 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4566 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4567 | kInstructionSize, |
| 4568 | CodeBufferCheckScope::kExactSize); |
| 4569 | // lr() |
| 4570 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4571 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4572 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4573 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4574 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4575 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4576 | DCHECK(!IsLeafMethod()); |
| 4577 | } |
| 4578 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4579 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4580 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4581 | // Use the calling convention instead of the location of the receiver, as |
| 4582 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4583 | // slow path, the arguments have been moved to the right place, so here we are |
| 4584 | // guaranteed that the receiver is the first register of the calling convention. |
| 4585 | InvokeDexCallingConvention calling_convention; |
| 4586 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4587 | Register temp = XRegisterFrom(temp_in); |
| 4588 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4589 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4590 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4591 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4592 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4593 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4594 | |
| 4595 | { |
| 4596 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4597 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4598 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4599 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4600 | MaybeRecordImplicitNullCheck(invoke); |
| 4601 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4602 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4603 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4604 | // intermediate/temporary reference and because the current |
| 4605 | // concurrent copying collector keeps the from-space memory |
| 4606 | // intact/accessible until the end of the marking phase (the |
| 4607 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4608 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4609 | // temp = temp->GetMethodAt(method_offset); |
| 4610 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4611 | // lr = temp->GetEntryPoint(); |
| 4612 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4613 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4614 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4615 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4616 | // lr(); |
| 4617 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4618 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4619 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4620 | } |
| 4621 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4622 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4623 | HandleInvoke(invoke); |
| 4624 | } |
| 4625 | |
| 4626 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4627 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 4628 | } |
| 4629 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4630 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeMethodPatch( |
| 4631 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4632 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4633 | return NewPcRelativePatch(*target_method.dex_file, |
| 4634 | target_method.dex_method_index, |
| 4635 | adrp_label, |
| 4636 | &pc_relative_method_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4637 | } |
| 4638 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4639 | vixl::aarch64::Label* CodeGeneratorARM64::NewMethodBssEntryPatch( |
| 4640 | MethodReference target_method, |
| 4641 | vixl::aarch64::Label* adrp_label) { |
| 4642 | return NewPcRelativePatch(*target_method.dex_file, |
| 4643 | target_method.dex_method_index, |
| 4644 | adrp_label, |
| 4645 | &method_bss_entry_patches_); |
| 4646 | } |
| 4647 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4648 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 4649 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4650 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4651 | vixl::aarch64::Label* adrp_label) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4652 | 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] | 4653 | } |
| 4654 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4655 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4656 | const DexFile& dex_file, |
| 4657 | dex::TypeIndex type_index, |
| 4658 | vixl::aarch64::Label* adrp_label) { |
| 4659 | return NewPcRelativePatch(dex_file, type_index.index_, adrp_label, &type_bss_entry_patches_); |
| 4660 | } |
| 4661 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4662 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 4663 | const DexFile& dex_file, |
| 4664 | dex::StringIndex string_index, |
| 4665 | vixl::aarch64::Label* adrp_label) { |
| 4666 | return |
| 4667 | NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &pc_relative_string_patches_); |
| 4668 | } |
| 4669 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4670 | vixl::aarch64::Label* CodeGeneratorARM64::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 4671 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4672 | return &baker_read_barrier_patches_.back().label; |
| 4673 | } |
| 4674 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4675 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 4676 | const DexFile& dex_file, |
| 4677 | uint32_t offset_or_index, |
| 4678 | vixl::aarch64::Label* adrp_label, |
| 4679 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4680 | // Add a patch entry and return the label. |
| 4681 | patches->emplace_back(dex_file, offset_or_index); |
| 4682 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4683 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4684 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4685 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4686 | return label; |
| 4687 | } |
| 4688 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4689 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4690 | uint64_t address) { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4691 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4692 | } |
| 4693 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4694 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4695 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
| 4696 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 4697 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4698 | return jit_string_patches_.GetOrCreate( |
| 4699 | StringReference(&dex_file, string_index), |
| 4700 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4701 | } |
| 4702 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4703 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4704 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
| 4705 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 4706 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4707 | return jit_class_patches_.GetOrCreate( |
| 4708 | TypeReference(&dex_file, type_index), |
| 4709 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4710 | } |
| 4711 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4712 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4713 | vixl::aarch64::Register reg) { |
| 4714 | DCHECK(reg.IsX()); |
| 4715 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4716 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4717 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4721 | vixl::aarch64::Register out, |
| 4722 | vixl::aarch64::Register base) { |
| 4723 | DCHECK(out.IsX()); |
| 4724 | DCHECK(base.IsX()); |
| 4725 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4726 | __ Bind(fixup_label); |
| 4727 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4728 | } |
| 4729 | |
| 4730 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4731 | vixl::aarch64::Register out, |
| 4732 | vixl::aarch64::Register base) { |
| 4733 | DCHECK(base.IsX()); |
| 4734 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4735 | __ Bind(fixup_label); |
| 4736 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4737 | } |
| 4738 | |
| 4739 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4740 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4741 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 4742 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4743 | for (const PcRelativePatchInfo& info : infos) { |
| 4744 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 4745 | &info.target_dex_file, |
| 4746 | info.pc_insn_label->GetLocation(), |
| 4747 | info.offset_or_index)); |
| 4748 | } |
| 4749 | } |
| 4750 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4751 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4752 | DCHECK(linker_patches->empty()); |
| 4753 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4754 | pc_relative_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4755 | method_bss_entry_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4756 | pc_relative_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4757 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4758 | pc_relative_string_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4759 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4760 | linker_patches->reserve(size); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4761 | if (GetCompilerOptions().IsBootImage()) { |
| 4762 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeMethodPatch>(pc_relative_method_patches_, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4763 | linker_patches); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4764 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 4765 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4766 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 4767 | linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4768 | } else { |
| 4769 | DCHECK(pc_relative_method_patches_.empty()); |
| 4770 | DCHECK(pc_relative_type_patches_.empty()); |
| 4771 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 4772 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4773 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4774 | EmitPcRelativeLinkerPatches<LinkerPatch::MethodBssEntryPatch>(method_bss_entry_patches_, |
| 4775 | linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4776 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 4777 | linker_patches); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4778 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 4779 | linker_patches->push_back(LinkerPatch::BakerReadBarrierBranchPatch(info.label.GetLocation(), |
| 4780 | info.custom_data)); |
| 4781 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4782 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4783 | } |
| 4784 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4785 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value) { |
| 4786 | return uint32_literals_.GetOrCreate( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4787 | value, |
| 4788 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4789 | } |
| 4790 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4791 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4792 | return uint64_literals_.GetOrCreate( |
| 4793 | value, |
| 4794 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4795 | } |
| 4796 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4797 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4798 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4799 | // art::PrepareForRegisterAllocation. |
| 4800 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4801 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4802 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4803 | return; |
| 4804 | } |
| 4805 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4806 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4807 | // are no pools emitted. |
| 4808 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4809 | LocationSummary* locations = invoke->GetLocations(); |
| 4810 | codegen_->GenerateStaticOrDirectCall( |
| 4811 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4812 | } |
| 4813 | |
| 4814 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4815 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4816 | return; |
| 4817 | } |
| 4818 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4819 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4820 | // are no pools emitted. |
| 4821 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4822 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4823 | DCHECK(!codegen_->IsLeafMethod()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4824 | } |
| 4825 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4826 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4827 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4828 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4829 | case HLoadClass::LoadKind::kInvalid: |
| 4830 | LOG(FATAL) << "UNREACHABLE"; |
| 4831 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4832 | case HLoadClass::LoadKind::kReferrersClass: |
| 4833 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4834 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4835 | case HLoadClass::LoadKind::kBssEntry: |
| 4836 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4837 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4838 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4839 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4840 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4841 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4842 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4843 | break; |
| 4844 | } |
| 4845 | return desired_class_load_kind; |
| 4846 | } |
| 4847 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4848 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4849 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4850 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4851 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4852 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4853 | cls, |
| 4854 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4855 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4856 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4857 | return; |
| 4858 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4859 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4860 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4861 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4862 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4863 | ? LocationSummary::kCallOnSlowPath |
| 4864 | : LocationSummary::kNoCall; |
| 4865 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4866 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4867 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4868 | } |
| 4869 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4870 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4871 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4872 | } |
| 4873 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4874 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 4875 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4876 | // 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] | 4877 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4878 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4879 | InvokeRuntimeCallingConvention calling_convention; |
| 4880 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4881 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 4882 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 4883 | Primitive::kPrimNot).GetCode()); |
| 4884 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4885 | } else { |
| 4886 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4887 | } |
| 4888 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4889 | } |
| 4890 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4891 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4892 | // move. |
| 4893 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4894 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4895 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4896 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4897 | return; |
| 4898 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4899 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4900 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4901 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4902 | Register out = OutputRegister(cls); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4903 | Register bss_entry_temp; |
| 4904 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4905 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4906 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4907 | ? kWithoutReadBarrier |
| 4908 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4909 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4910 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4911 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4912 | DCHECK(!cls->CanCallRuntime()); |
| 4913 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4914 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4915 | Register current_method = InputRegisterAt(cls, 0); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4916 | GenerateGcRootFieldLoad(cls, |
| 4917 | out_loc, |
| 4918 | current_method, |
| 4919 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4920 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4921 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4922 | break; |
| 4923 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4924 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4925 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4926 | // Add ADRP with its PC-relative type patch. |
| 4927 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4928 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4929 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4930 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4931 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4932 | vixl::aarch64::Label* add_label = |
| 4933 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4934 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4935 | break; |
| 4936 | } |
| 4937 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4938 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4939 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 4940 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 4941 | DCHECK_NE(address, 0u); |
| 4942 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4943 | break; |
| 4944 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4945 | case HLoadClass::LoadKind::kBssEntry: { |
| 4946 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 4947 | const DexFile& dex_file = cls->GetDexFile(); |
| 4948 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4949 | bss_entry_temp = XRegisterFrom(cls->GetLocations()->GetTemp(0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4950 | bss_entry_adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 4951 | codegen_->EmitAdrpPlaceholder(bss_entry_adrp_label, bss_entry_temp); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4952 | // Add LDR with its PC-relative Class patch. |
| 4953 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4954 | codegen_->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4955 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 4956 | GenerateGcRootFieldLoad(cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4957 | out_loc, |
| 4958 | bss_entry_temp, |
| 4959 | /* offset placeholder */ 0u, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4960 | ldr_label, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4961 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4962 | generate_null_check = true; |
| 4963 | break; |
| 4964 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4965 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 4966 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 4967 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4968 | cls->GetClass())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4969 | GenerateGcRootFieldLoad(cls, |
| 4970 | out_loc, |
| 4971 | out.X(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4972 | /* offset */ 0, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4973 | /* fixup_label */ nullptr, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4974 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4975 | break; |
| 4976 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 4977 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4978 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4979 | LOG(FATAL) << "UNREACHABLE"; |
| 4980 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4981 | } |
| 4982 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4983 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 4984 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4985 | DCHECK(cls->CanCallRuntime()); |
| 4986 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4987 | 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] | 4988 | codegen_->AddSlowPath(slow_path); |
| 4989 | if (generate_null_check) { |
| 4990 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4991 | } |
| 4992 | if (cls->MustGenerateClinitCheck()) { |
| 4993 | GenerateClassInitializationCheck(slow_path, out); |
| 4994 | } else { |
| 4995 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4996 | } |
| 4997 | } |
| 4998 | } |
| 4999 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5000 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5001 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5002 | } |
| 5003 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5004 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5005 | LocationSummary* locations = |
| 5006 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5007 | locations->SetOut(Location::RequiresRegister()); |
| 5008 | } |
| 5009 | |
| 5010 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5011 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5012 | } |
| 5013 | |
| 5014 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 5015 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5016 | } |
| 5017 | |
| 5018 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5019 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5020 | } |
| 5021 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5022 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5023 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5024 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5025 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5026 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5027 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5028 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5029 | case HLoadString::LoadKind::kJitTableAddress: |
| 5030 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5031 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5032 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5033 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5034 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5035 | } |
| 5036 | return desired_string_load_kind; |
| 5037 | } |
| 5038 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5039 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5040 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5041 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5042 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5043 | InvokeRuntimeCallingConvention calling_convention; |
| 5044 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5045 | } else { |
| 5046 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5047 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5048 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5049 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5050 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5051 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5052 | InvokeRuntimeCallingConvention calling_convention; |
| 5053 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 5054 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 5055 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 5056 | Primitive::kPrimNot).GetCode()); |
| 5057 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5058 | } else { |
| 5059 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5060 | } |
| 5061 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5062 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5063 | } |
| 5064 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5065 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5066 | // move. |
| 5067 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5068 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5069 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5070 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5071 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5072 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5073 | // Add ADRP with its PC-relative String patch. |
| 5074 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5075 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5076 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5077 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5078 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5079 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5080 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5081 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5082 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5083 | return; // No dex cache slow path. |
| 5084 | } |
| 5085 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5086 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5087 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5088 | DCHECK_NE(address, 0u); |
| 5089 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5090 | return; // No dex cache slow path. |
| 5091 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5092 | case HLoadString::LoadKind::kBssEntry: { |
| 5093 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5094 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5095 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5096 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5097 | Register temp = XRegisterFrom(load->GetLocations()->GetTemp(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5098 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5099 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5100 | // Add LDR with its PC-relative String patch. |
| 5101 | vixl::aarch64::Label* ldr_label = |
| 5102 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5103 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5104 | GenerateGcRootFieldLoad(load, |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5105 | out_loc, |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5106 | temp, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5107 | /* offset placeholder */ 0u, |
| 5108 | ldr_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5109 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5110 | SlowPathCodeARM64* slow_path = |
| 5111 | new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load, temp, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5112 | codegen_->AddSlowPath(slow_path); |
| 5113 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5114 | __ Bind(slow_path->GetExitLabel()); |
| 5115 | return; |
| 5116 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5117 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5118 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5119 | load->GetStringIndex(), |
| 5120 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5121 | GenerateGcRootFieldLoad(load, |
| 5122 | out_loc, |
| 5123 | out.X(), |
| 5124 | /* offset */ 0, |
| 5125 | /* fixup_label */ nullptr, |
| 5126 | kCompilerReadBarrierOption); |
| 5127 | return; |
| 5128 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5129 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5130 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5131 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5132 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5133 | // 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] | 5134 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5135 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5136 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5137 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5138 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5139 | } |
| 5140 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5141 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 5142 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5143 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5144 | } |
| 5145 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5146 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5147 | // Will be generated at use site. |
| 5148 | } |
| 5149 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5150 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5151 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5152 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5153 | InvokeRuntimeCallingConvention calling_convention; |
| 5154 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5155 | } |
| 5156 | |
| 5157 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5158 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5159 | instruction, |
| 5160 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5161 | if (instruction->IsEnter()) { |
| 5162 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5163 | } else { |
| 5164 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5165 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5166 | } |
| 5167 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5168 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5169 | LocationSummary* locations = |
| 5170 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 5171 | switch (mul->GetResultType()) { |
| 5172 | case Primitive::kPrimInt: |
| 5173 | case Primitive::kPrimLong: |
| 5174 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5175 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5176 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5177 | break; |
| 5178 | |
| 5179 | case Primitive::kPrimFloat: |
| 5180 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5181 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5182 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5183 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5184 | break; |
| 5185 | |
| 5186 | default: |
| 5187 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5188 | } |
| 5189 | } |
| 5190 | |
| 5191 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5192 | switch (mul->GetResultType()) { |
| 5193 | case Primitive::kPrimInt: |
| 5194 | case Primitive::kPrimLong: |
| 5195 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5196 | break; |
| 5197 | |
| 5198 | case Primitive::kPrimFloat: |
| 5199 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5200 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5201 | break; |
| 5202 | |
| 5203 | default: |
| 5204 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5205 | } |
| 5206 | } |
| 5207 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5208 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5209 | LocationSummary* locations = |
| 5210 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 5211 | switch (neg->GetResultType()) { |
| 5212 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5213 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5214 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5215 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5216 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5217 | |
| 5218 | case Primitive::kPrimFloat: |
| 5219 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5220 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5221 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5222 | break; |
| 5223 | |
| 5224 | default: |
| 5225 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5226 | } |
| 5227 | } |
| 5228 | |
| 5229 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5230 | switch (neg->GetResultType()) { |
| 5231 | case Primitive::kPrimInt: |
| 5232 | case Primitive::kPrimLong: |
| 5233 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5234 | break; |
| 5235 | |
| 5236 | case Primitive::kPrimFloat: |
| 5237 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5238 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5239 | break; |
| 5240 | |
| 5241 | default: |
| 5242 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5243 | } |
| 5244 | } |
| 5245 | |
| 5246 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 5247 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5248 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5249 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5250 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5251 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5252 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5253 | } |
| 5254 | |
| 5255 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5256 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5257 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5258 | QuickEntrypointEnum entrypoint = |
| 5259 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5260 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5261 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5262 | } |
| 5263 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5264 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 5265 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5266 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5267 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5268 | if (instruction->IsStringAlloc()) { |
| 5269 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 5270 | } else { |
| 5271 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5272 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5273 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5274 | } |
| 5275 | |
| 5276 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5277 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5278 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5279 | if (instruction->IsStringAlloc()) { |
| 5280 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5281 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5282 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5283 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 5284 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5285 | |
| 5286 | { |
| 5287 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 5288 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 5289 | kInstructionSize, |
| 5290 | CodeBufferCheckScope::kExactSize); |
| 5291 | __ blr(lr); |
| 5292 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5293 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5294 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5295 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5296 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5297 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5298 | } |
| 5299 | |
| 5300 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 5301 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5302 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5303 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5304 | } |
| 5305 | |
| 5306 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5307 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5308 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5309 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5310 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5311 | break; |
| 5312 | |
| 5313 | default: |
| 5314 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5315 | } |
| 5316 | } |
| 5317 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5318 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 5319 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5320 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5321 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5322 | } |
| 5323 | |
| 5324 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5325 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5326 | } |
| 5327 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5328 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5329 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5330 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5331 | } |
| 5332 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5333 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5334 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5335 | return; |
| 5336 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5337 | { |
| 5338 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5339 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5340 | Location obj = instruction->GetLocations()->InAt(0); |
| 5341 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5342 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5343 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5344 | } |
| 5345 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5346 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5347 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5348 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5349 | |
| 5350 | LocationSummary* locations = instruction->GetLocations(); |
| 5351 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5352 | |
| 5353 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5354 | } |
| 5355 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5356 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5357 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5358 | } |
| 5359 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5360 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5361 | HandleBinaryOp(instruction); |
| 5362 | } |
| 5363 | |
| 5364 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5365 | HandleBinaryOp(instruction); |
| 5366 | } |
| 5367 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5368 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5369 | LOG(FATAL) << "Unreachable"; |
| 5370 | } |
| 5371 | |
| 5372 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 5373 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5374 | } |
| 5375 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5376 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 5377 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5378 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5379 | if (location.IsStackSlot()) { |
| 5380 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5381 | } else if (location.IsDoubleStackSlot()) { |
| 5382 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5383 | } |
| 5384 | locations->SetOut(location); |
| 5385 | } |
| 5386 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5387 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5388 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5389 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5390 | } |
| 5391 | |
| 5392 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5393 | LocationSummary* locations = |
| 5394 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5395 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5396 | } |
| 5397 | |
| 5398 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5399 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5400 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5401 | } |
| 5402 | |
| 5403 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 5404 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5405 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5406 | locations->SetInAt(i, Location::Any()); |
| 5407 | } |
| 5408 | locations->SetOut(Location::Any()); |
| 5409 | } |
| 5410 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5411 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5412 | LOG(FATAL) << "Unreachable"; |
| 5413 | } |
| 5414 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5415 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5416 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5417 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5418 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 5419 | : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5420 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 5421 | |
| 5422 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5423 | case Primitive::kPrimInt: |
| 5424 | case Primitive::kPrimLong: |
| 5425 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5426 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5427 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5428 | break; |
| 5429 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5430 | case Primitive::kPrimFloat: |
| 5431 | case Primitive::kPrimDouble: { |
| 5432 | InvokeRuntimeCallingConvention calling_convention; |
| 5433 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5434 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5435 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5436 | |
| 5437 | break; |
| 5438 | } |
| 5439 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5440 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5441 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5442 | } |
| 5443 | } |
| 5444 | |
| 5445 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 5446 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5447 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5448 | switch (type) { |
| 5449 | case Primitive::kPrimInt: |
| 5450 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5451 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5452 | break; |
| 5453 | } |
| 5454 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5455 | case Primitive::kPrimFloat: |
| 5456 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5457 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 5458 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5459 | if (type == Primitive::kPrimFloat) { |
| 5460 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5461 | } else { |
| 5462 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5463 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5464 | break; |
| 5465 | } |
| 5466 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5467 | default: |
| 5468 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5469 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5470 | } |
| 5471 | } |
| 5472 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5473 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5474 | constructor_fence->SetLocations(nullptr); |
| 5475 | } |
| 5476 | |
| 5477 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5478 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5479 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5480 | } |
| 5481 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5482 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5483 | memory_barrier->SetLocations(nullptr); |
| 5484 | } |
| 5485 | |
| 5486 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5487 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5488 | } |
| 5489 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5490 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 5491 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5492 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5493 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5494 | } |
| 5495 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5496 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5497 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5498 | } |
| 5499 | |
| 5500 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5501 | instruction->SetLocations(nullptr); |
| 5502 | } |
| 5503 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5504 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5505 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5506 | } |
| 5507 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5508 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5509 | HandleBinaryOp(ror); |
| 5510 | } |
| 5511 | |
| 5512 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5513 | HandleBinaryOp(ror); |
| 5514 | } |
| 5515 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5516 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5517 | HandleShift(shl); |
| 5518 | } |
| 5519 | |
| 5520 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5521 | HandleShift(shl); |
| 5522 | } |
| 5523 | |
| 5524 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5525 | HandleShift(shr); |
| 5526 | } |
| 5527 | |
| 5528 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5529 | HandleShift(shr); |
| 5530 | } |
| 5531 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5532 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5533 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5534 | } |
| 5535 | |
| 5536 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5537 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5538 | } |
| 5539 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5540 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5541 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5545 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5546 | } |
| 5547 | |
| 5548 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5549 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5550 | } |
| 5551 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5552 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5553 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5554 | } |
| 5555 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5556 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5557 | HUnresolvedInstanceFieldGet* instruction) { |
| 5558 | FieldAccessCallingConventionARM64 calling_convention; |
| 5559 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5560 | instruction, instruction->GetFieldType(), calling_convention); |
| 5561 | } |
| 5562 | |
| 5563 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5564 | HUnresolvedInstanceFieldGet* instruction) { |
| 5565 | FieldAccessCallingConventionARM64 calling_convention; |
| 5566 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5567 | instruction->GetFieldType(), |
| 5568 | instruction->GetFieldIndex(), |
| 5569 | instruction->GetDexPc(), |
| 5570 | calling_convention); |
| 5571 | } |
| 5572 | |
| 5573 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5574 | HUnresolvedInstanceFieldSet* instruction) { |
| 5575 | FieldAccessCallingConventionARM64 calling_convention; |
| 5576 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5577 | instruction, instruction->GetFieldType(), calling_convention); |
| 5578 | } |
| 5579 | |
| 5580 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5581 | HUnresolvedInstanceFieldSet* instruction) { |
| 5582 | FieldAccessCallingConventionARM64 calling_convention; |
| 5583 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5584 | instruction->GetFieldType(), |
| 5585 | instruction->GetFieldIndex(), |
| 5586 | instruction->GetDexPc(), |
| 5587 | calling_convention); |
| 5588 | } |
| 5589 | |
| 5590 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5591 | HUnresolvedStaticFieldGet* instruction) { |
| 5592 | FieldAccessCallingConventionARM64 calling_convention; |
| 5593 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5594 | instruction, instruction->GetFieldType(), calling_convention); |
| 5595 | } |
| 5596 | |
| 5597 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5598 | HUnresolvedStaticFieldGet* instruction) { |
| 5599 | FieldAccessCallingConventionARM64 calling_convention; |
| 5600 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5601 | instruction->GetFieldType(), |
| 5602 | instruction->GetFieldIndex(), |
| 5603 | instruction->GetDexPc(), |
| 5604 | calling_convention); |
| 5605 | } |
| 5606 | |
| 5607 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5608 | HUnresolvedStaticFieldSet* instruction) { |
| 5609 | FieldAccessCallingConventionARM64 calling_convention; |
| 5610 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5611 | instruction, instruction->GetFieldType(), calling_convention); |
| 5612 | } |
| 5613 | |
| 5614 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5615 | HUnresolvedStaticFieldSet* instruction) { |
| 5616 | FieldAccessCallingConventionARM64 calling_convention; |
| 5617 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5618 | instruction->GetFieldType(), |
| 5619 | instruction->GetFieldIndex(), |
| 5620 | instruction->GetDexPc(), |
| 5621 | calling_convention); |
| 5622 | } |
| 5623 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5624 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5625 | LocationSummary* locations = |
| 5626 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5627 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5628 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5629 | // registers in full width (since the runtime only saves/restores lower part). |
| 5630 | locations->SetCustomSlowPathCallerSaves( |
| 5631 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5632 | } |
| 5633 | |
| 5634 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5635 | HBasicBlock* block = instruction->GetBlock(); |
| 5636 | if (block->GetLoopInformation() != nullptr) { |
| 5637 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5638 | // The back edge will generate the suspend check. |
| 5639 | return; |
| 5640 | } |
| 5641 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5642 | // The goto will generate the suspend check. |
| 5643 | return; |
| 5644 | } |
| 5645 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5646 | } |
| 5647 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5648 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 5649 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5650 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5651 | InvokeRuntimeCallingConvention calling_convention; |
| 5652 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5653 | } |
| 5654 | |
| 5655 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5656 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5657 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5658 | } |
| 5659 | |
| 5660 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5661 | LocationSummary* locations = |
| 5662 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 5663 | Primitive::Type input_type = conversion->GetInputType(); |
| 5664 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 5665 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5666 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 5667 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 5668 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5669 | } |
| 5670 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5671 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5672 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5673 | } else { |
| 5674 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5675 | } |
| 5676 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5677 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5678 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5679 | } else { |
| 5680 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5681 | } |
| 5682 | } |
| 5683 | |
| 5684 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5685 | Primitive::Type result_type = conversion->GetResultType(); |
| 5686 | Primitive::Type input_type = conversion->GetInputType(); |
| 5687 | |
| 5688 | DCHECK_NE(input_type, result_type); |
| 5689 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5690 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5691 | int result_size = Primitive::ComponentSize(result_type); |
| 5692 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5693 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5694 | Register output = OutputRegister(conversion); |
| 5695 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5696 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5697 | // 'int' values are used directly as W registers, discarding the top |
| 5698 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5699 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5700 | // top 32 bits of the target register. We theoretically could leave those |
| 5701 | // bits unchanged, but we would have to make sure that no code uses a |
| 5702 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5703 | // zero. |
| 5704 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5705 | } else if (result_type == Primitive::kPrimChar || |
| 5706 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 5707 | __ Ubfx(output, |
| 5708 | output.IsX() ? source.X() : source.W(), |
| 5709 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5710 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5711 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5712 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5713 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5714 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5715 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5716 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 5717 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5718 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 5719 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5720 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5721 | } else { |
| 5722 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5723 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5724 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5725 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5726 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5727 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5728 | HandleShift(ushr); |
| 5729 | } |
| 5730 | |
| 5731 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5732 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5733 | } |
| 5734 | |
| 5735 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5736 | HandleBinaryOp(instruction); |
| 5737 | } |
| 5738 | |
| 5739 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5740 | HandleBinaryOp(instruction); |
| 5741 | } |
| 5742 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5743 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5744 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5745 | LOG(FATAL) << "Unreachable"; |
| 5746 | } |
| 5747 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5748 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5749 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5750 | LOG(FATAL) << "Unreachable"; |
| 5751 | } |
| 5752 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5753 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5754 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5755 | LocationSummary* locations = |
| 5756 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5757 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5758 | } |
| 5759 | |
| 5760 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5761 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5762 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5763 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5764 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5765 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5766 | // 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] | 5767 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5768 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5769 | // make sure we don't emit it if the target may run out of range. |
| 5770 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5771 | // ranges and emit the tables only as required. |
| 5772 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5773 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5774 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5775 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5776 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5777 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5778 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5779 | Register temp = temps.AcquireW(); |
| 5780 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5781 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5782 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5783 | // Jump to successors[0] if value == lower_bound. |
| 5784 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5785 | int32_t last_index = 0; |
| 5786 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5787 | __ Subs(temp, temp, Operand(2)); |
| 5788 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5789 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5790 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5791 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5792 | } |
| 5793 | if (num_entries - last_index == 2) { |
| 5794 | // The last missing case_value. |
| 5795 | __ Cmp(temp, Operand(1)); |
| 5796 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5797 | } |
| 5798 | |
| 5799 | // And the default for any other value. |
| 5800 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5801 | __ B(codegen_->GetLabelOf(default_block)); |
| 5802 | } |
| 5803 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5804 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5805 | |
| 5806 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5807 | |
| 5808 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5809 | // registers, we are free to block one. |
| 5810 | Register temp_w = temps.AcquireW(); |
| 5811 | Register index; |
| 5812 | // Remove the bias. |
| 5813 | if (lower_bound != 0) { |
| 5814 | index = temp_w; |
| 5815 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5816 | } else { |
| 5817 | index = value_reg; |
| 5818 | } |
| 5819 | |
| 5820 | // Jump to default block if index is out of the range. |
| 5821 | __ Cmp(index, Operand(num_entries)); |
| 5822 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5823 | |
| 5824 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5825 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5826 | // register pressure. |
| 5827 | Register table_base = temps.AcquireX(); |
| 5828 | // Load jump offset from the table. |
| 5829 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5830 | Register jump_offset = temp_w; |
| 5831 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5832 | |
| 5833 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5834 | Register target_address = table_base; |
| 5835 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5836 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5837 | } |
| 5838 | } |
| 5839 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5840 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 5841 | HInstruction* instruction, |
| 5842 | Location out, |
| 5843 | uint32_t offset, |
| 5844 | Location maybe_temp, |
| 5845 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5846 | Primitive::Type type = Primitive::kPrimNot; |
| 5847 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5848 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5849 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5850 | if (kUseBakerReadBarrier) { |
| 5851 | // Load with fast path based Baker's read barrier. |
| 5852 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5853 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5854 | out, |
| 5855 | out_reg, |
| 5856 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5857 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5858 | /* needs_null_check */ false, |
| 5859 | /* use_load_acquire */ false); |
| 5860 | } else { |
| 5861 | // Load with slow path based read barrier. |
| 5862 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5863 | // in the following move operation, as we will need it for the |
| 5864 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5865 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5866 | __ Mov(temp_reg, out_reg); |
| 5867 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5868 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5869 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5870 | } |
| 5871 | } else { |
| 5872 | // Plain load with no read barrier. |
| 5873 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5874 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5875 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5876 | } |
| 5877 | } |
| 5878 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5879 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 5880 | HInstruction* instruction, |
| 5881 | Location out, |
| 5882 | Location obj, |
| 5883 | uint32_t offset, |
| 5884 | Location maybe_temp, |
| 5885 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5886 | Primitive::Type type = Primitive::kPrimNot; |
| 5887 | Register out_reg = RegisterFrom(out, type); |
| 5888 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5889 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5890 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5891 | if (kUseBakerReadBarrier) { |
| 5892 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5893 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5894 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5895 | out, |
| 5896 | obj_reg, |
| 5897 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5898 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5899 | /* needs_null_check */ false, |
| 5900 | /* use_load_acquire */ false); |
| 5901 | } else { |
| 5902 | // Load with slow path based read barrier. |
| 5903 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5904 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5905 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5906 | } |
| 5907 | } else { |
| 5908 | // Plain load with no read barrier. |
| 5909 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5910 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5911 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5912 | } |
| 5913 | } |
| 5914 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5915 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad( |
| 5916 | HInstruction* instruction, |
| 5917 | Location root, |
| 5918 | Register obj, |
| 5919 | uint32_t offset, |
| 5920 | vixl::aarch64::Label* fixup_label, |
| 5921 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5922 | DCHECK(fixup_label == nullptr || offset == 0u); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5923 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5924 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5925 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5926 | if (kUseBakerReadBarrier) { |
| 5927 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5928 | // Baker's read barrier are used. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5929 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 5930 | !Runtime::Current()->UseJitCompilation()) { |
| 5931 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5932 | // to decide whether to mark the loaded GC root or not. Instead, we |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 5933 | // load into `temp` (actually IP1) the read barrier mark introspection |
| 5934 | // entrypoint. If `temp` is null, it means that `GetIsGcMarking()` is |
| 5935 | // false, and vice versa. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5936 | // |
| 5937 | // We use link-time generated thunks for the slow path. That thunk |
| 5938 | // checks the reference and jumps to the entrypoint if needed. |
| 5939 | // |
| 5940 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 5941 | // lr = &return_address; |
| 5942 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5943 | // if (temp != nullptr) { |
| 5944 | // goto gc_root_thunk<root_reg>(lr) |
| 5945 | // } |
| 5946 | // return_address: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5947 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5948 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5949 | DCHECK(temps.IsAvailable(ip0)); |
| 5950 | DCHECK(temps.IsAvailable(ip1)); |
| 5951 | temps.Exclude(ip0, ip1); |
| 5952 | uint32_t custom_data = |
| 5953 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
| 5954 | vixl::aarch64::Label* cbnz_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5955 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5956 | // ip1 = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 5957 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 5958 | const int32_t entry_point_offset = |
| 5959 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 5960 | __ Ldr(ip1, MemOperand(tr, entry_point_offset)); |
| 5961 | EmissionCheckScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 5962 | vixl::aarch64::Label return_address; |
| 5963 | __ adr(lr, &return_address); |
| 5964 | if (fixup_label != nullptr) { |
| 5965 | __ Bind(fixup_label); |
| 5966 | } |
| 5967 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 5968 | "GC root LDR must be 2 instruction (8B) before the return address label."); |
| 5969 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 5970 | __ Bind(cbnz_label); |
| 5971 | __ cbnz(ip1, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 5972 | __ Bind(&return_address); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5973 | } else { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5974 | // Note that we do not actually check the value of |
| 5975 | // `GetIsGcMarking()` to decide whether to mark the loaded GC |
| 5976 | // root or not. Instead, we load into `temp` the read barrier |
| 5977 | // mark entry point corresponding to register `root`. If `temp` |
| 5978 | // is null, it means that `GetIsGcMarking()` is false, and vice |
| 5979 | // versa. |
| 5980 | // |
| 5981 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5982 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5983 | // if (temp != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 5984 | // // Slow path. |
| 5985 | // root = temp(root); // root = ReadBarrier::Mark(root); // Runtime entry point call. |
| 5986 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5987 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5988 | // Slow path marking the GC root `root`. The entrypoint will already be loaded in `temp`. |
| 5989 | Register temp = lr; |
| 5990 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64( |
| 5991 | instruction, root, /* entrypoint */ LocationFrom(temp)); |
| 5992 | codegen_->AddSlowPath(slow_path); |
| 5993 | |
| 5994 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5995 | const int32_t entry_point_offset = |
| 5996 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(root.reg()); |
| 5997 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 5998 | // threads are suspended or running a checkpoint. |
| 5999 | __ Ldr(temp, MemOperand(tr, entry_point_offset)); |
| 6000 | |
| 6001 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6002 | if (fixup_label == nullptr) { |
| 6003 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6004 | } else { |
| 6005 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
| 6006 | } |
| 6007 | static_assert( |
| 6008 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6009 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6010 | "have different sizes."); |
| 6011 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6012 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6013 | "have different sizes."); |
| 6014 | |
| 6015 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6016 | // checking GetIsGcMarking. |
| 6017 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 6018 | __ Bind(slow_path->GetExitLabel()); |
| 6019 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6020 | } else { |
| 6021 | // GC root loaded through a slow path for read barriers other |
| 6022 | // than Baker's. |
| 6023 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6024 | if (fixup_label == nullptr) { |
| 6025 | __ Add(root_reg.X(), obj.X(), offset); |
| 6026 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6027 | codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6028 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6029 | // /* mirror::Object* */ root = root->Read() |
| 6030 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6031 | } |
| 6032 | } else { |
| 6033 | // Plain GC root load with no read barrier. |
| 6034 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6035 | if (fixup_label == nullptr) { |
| 6036 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6037 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6038 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6039 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6040 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6041 | // do not have to unpoison `root_reg` here. |
| 6042 | } |
| 6043 | } |
| 6044 | |
| 6045 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6046 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6047 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6048 | uint32_t offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6049 | Location maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6050 | bool needs_null_check, |
| 6051 | bool use_load_acquire) { |
| 6052 | DCHECK(kEmitCompilerReadBarrier); |
| 6053 | DCHECK(kUseBakerReadBarrier); |
| 6054 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6055 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6056 | !use_load_acquire && |
| 6057 | !Runtime::Current()->UseJitCompilation()) { |
| 6058 | // Note that we do not actually check the value of `GetIsGcMarking()` |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6059 | // to decide whether to mark the loaded reference or not. Instead, we |
| 6060 | // load into `temp` (actually IP1) the read barrier mark introspection |
| 6061 | // entrypoint. If `temp` is null, it means that `GetIsGcMarking()` is |
| 6062 | // false, and vice versa. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6063 | // |
| 6064 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6065 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6066 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6067 | // |
| 6068 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6069 | // lr = &gray_return_address; |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6070 | // if (temp != nullptr) { |
| 6071 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 6072 | // } |
| 6073 | // not_gray_return_address: |
| 6074 | // // Original reference load. If the offset is too large to fit |
| 6075 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6076 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6077 | // gray_return_address: |
| 6078 | |
| 6079 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6080 | Register base = obj; |
| 6081 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6082 | DCHECK(maybe_temp.IsRegister()); |
| 6083 | base = WRegisterFrom(maybe_temp); |
| 6084 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6085 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6086 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 6087 | } |
| 6088 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6089 | DCHECK(temps.IsAvailable(ip0)); |
| 6090 | DCHECK(temps.IsAvailable(ip1)); |
| 6091 | temps.Exclude(ip0, ip1); |
| 6092 | uint32_t custom_data = linker::Arm64RelativePatcher::EncodeBakerReadBarrierFieldData( |
| 6093 | base.GetCode(), |
| 6094 | obj.GetCode()); |
| 6095 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6096 | |
| 6097 | // ip1 = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6098 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6099 | const int32_t entry_point_offset = |
| 6100 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6101 | __ Ldr(ip1, MemOperand(tr, entry_point_offset)); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 6102 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6103 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6104 | vixl::aarch64::Label return_address; |
| 6105 | __ adr(lr, &return_address); |
| 6106 | __ Bind(cbnz_label); |
| 6107 | __ cbnz(ip1, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 6108 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6109 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6110 | " 2 instructions (8B) for heap poisoning."); |
| 6111 | Register ref_reg = RegisterFrom(ref, Primitive::kPrimNot); |
| 6112 | __ ldr(ref_reg, MemOperand(base.X(), offset)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6113 | if (needs_null_check) { |
| 6114 | MaybeRecordImplicitNullCheck(instruction); |
| 6115 | } |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 6116 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6117 | __ Bind(&return_address); |
| 6118 | return; |
| 6119 | } |
| 6120 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6121 | // /* HeapReference<Object> */ ref = *(obj + offset) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6122 | Register temp = WRegisterFrom(maybe_temp); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6123 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6124 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6125 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6126 | ref, |
| 6127 | obj, |
| 6128 | offset, |
| 6129 | no_index, |
| 6130 | no_scale_factor, |
| 6131 | temp, |
| 6132 | needs_null_check, |
| 6133 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6134 | } |
| 6135 | |
| 6136 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6137 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6138 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6139 | uint32_t data_offset, |
| 6140 | Location index, |
| 6141 | Register temp, |
| 6142 | bool needs_null_check) { |
| 6143 | DCHECK(kEmitCompilerReadBarrier); |
| 6144 | DCHECK(kUseBakerReadBarrier); |
| 6145 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6146 | static_assert( |
| 6147 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6148 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6149 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 6150 | |
| 6151 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6152 | !Runtime::Current()->UseJitCompilation()) { |
| 6153 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6154 | // to decide whether to mark the loaded reference or not. Instead, we |
| 6155 | // load into `temp` (actually IP1) the read barrier mark introspection |
| 6156 | // entrypoint. If `temp` is null, it means that `GetIsGcMarking()` is |
| 6157 | // false, and vice versa. |
| 6158 | // |
| 6159 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6160 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6161 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6162 | // |
| 6163 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 6164 | // lr = &gray_return_address; |
| 6165 | // if (temp != nullptr) { |
| 6166 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 6167 | // } |
| 6168 | // not_gray_return_address: |
| 6169 | // // Original reference load. If the offset is too large to fit |
| 6170 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6171 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6172 | // gray_return_address: |
| 6173 | |
| 6174 | DCHECK(index.IsValid()); |
| 6175 | Register index_reg = RegisterFrom(index, Primitive::kPrimInt); |
| 6176 | Register ref_reg = RegisterFrom(ref, Primitive::kPrimNot); |
| 6177 | |
| 6178 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6179 | DCHECK(temps.IsAvailable(ip0)); |
| 6180 | DCHECK(temps.IsAvailable(ip1)); |
| 6181 | temps.Exclude(ip0, ip1); |
| 6182 | uint32_t custom_data = |
| 6183 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierArrayData(temp.GetCode()); |
| 6184 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6185 | |
| 6186 | // ip1 = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6187 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6188 | const int32_t entry_point_offset = |
| 6189 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6190 | __ Ldr(ip1, MemOperand(tr, entry_point_offset)); |
| 6191 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
| 6192 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6193 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6194 | vixl::aarch64::Label return_address; |
| 6195 | __ adr(lr, &return_address); |
| 6196 | __ Bind(cbnz_label); |
| 6197 | __ cbnz(ip1, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6198 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6199 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6200 | " 2 instructions (8B) for heap poisoning."); |
| 6201 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6202 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6203 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6204 | __ Bind(&return_address); |
| 6205 | return; |
| 6206 | } |
| 6207 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6208 | // Array cells are never volatile variables, therefore array loads |
| 6209 | // never use Load-Acquire instructions on ARM64. |
| 6210 | const bool use_load_acquire = false; |
| 6211 | |
| 6212 | // /* HeapReference<Object> */ ref = |
| 6213 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6214 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6215 | ref, |
| 6216 | obj, |
| 6217 | data_offset, |
| 6218 | index, |
| 6219 | scale_factor, |
| 6220 | temp, |
| 6221 | needs_null_check, |
| 6222 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6226 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6227 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6228 | uint32_t offset, |
| 6229 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6230 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6231 | Register temp, |
| 6232 | bool needs_null_check, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6233 | bool use_load_acquire) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6234 | DCHECK(kEmitCompilerReadBarrier); |
| 6235 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6236 | // If we are emitting an array load, we should not be using a |
| 6237 | // Load Acquire instruction. In other words: |
| 6238 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6239 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6240 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6241 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 6242 | // whether we need to enter the slow path to mark the reference. |
| 6243 | // Then, in the slow path, check the gray bit in the lock word of |
| 6244 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 6245 | // not. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6246 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6247 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
| 6248 | // instead, we load into `temp2` the read barrier mark entry point |
| 6249 | // corresponding to register `ref`. If `temp2` is null, it means |
| 6250 | // that `GetIsGcMarking()` is false, and vice versa. |
| 6251 | // |
| 6252 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6253 | // if (temp2 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 6254 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6255 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6256 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6257 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 6258 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6259 | // if (is_gray) { |
| 6260 | // ref = temp2(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 6261 | // } |
| 6262 | // } else { |
| 6263 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6264 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6265 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6266 | // Slow path marking the object `ref` when the GC is marking. The |
| 6267 | // entrypoint will already be loaded in `temp2`. |
| 6268 | Register temp2 = lr; |
| 6269 | Location temp2_loc = LocationFrom(temp2); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6270 | SlowPathCodeARM64* slow_path = |
| 6271 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM64( |
| 6272 | instruction, |
| 6273 | ref, |
| 6274 | obj, |
| 6275 | offset, |
| 6276 | index, |
| 6277 | scale_factor, |
| 6278 | needs_null_check, |
| 6279 | use_load_acquire, |
| 6280 | temp, |
| 6281 | /* entrypoint */ temp2_loc); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6282 | AddSlowPath(slow_path); |
| 6283 | |
| 6284 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 6285 | const int32_t entry_point_offset = |
| 6286 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref.reg()); |
| 6287 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6288 | // threads are suspended or running a checkpoint. |
| 6289 | __ Ldr(temp2, MemOperand(tr, entry_point_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6290 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6291 | // checking GetIsGcMarking. |
| 6292 | __ Cbnz(temp2, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6293 | // Fast path: the GC is not marking: just load the reference. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6294 | GenerateRawReferenceLoad( |
| 6295 | 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] | 6296 | __ Bind(slow_path->GetExitLabel()); |
| 6297 | } |
| 6298 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6299 | void CodeGeneratorARM64::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 6300 | Location ref, |
| 6301 | Register obj, |
| 6302 | Location field_offset, |
| 6303 | Register temp, |
| 6304 | bool needs_null_check, |
| 6305 | bool use_load_acquire) { |
| 6306 | DCHECK(kEmitCompilerReadBarrier); |
| 6307 | DCHECK(kUseBakerReadBarrier); |
| 6308 | // If we are emitting an array load, we should not be using a |
| 6309 | // Load Acquire instruction. In other words: |
| 6310 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6311 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
| 6312 | |
| 6313 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 6314 | // whether we need to enter the slow path to update the reference |
| 6315 | // field within `obj`. Then, in the slow path, check the gray bit |
| 6316 | // in the lock word of the reference's holder (`obj`) to decide |
| 6317 | // whether to mark `ref` and update the field or not. |
| 6318 | // |
| 6319 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
| 6320 | // instead, we load into `temp2` the read barrier mark entry point |
| 6321 | // corresponding to register `ref`. If `temp2` is null, it means |
| 6322 | // that `GetIsGcMarking()` is false, and vice versa. |
| 6323 | // |
| 6324 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6325 | // if (temp2 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 6326 | // // Slow path. |
| 6327 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6328 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6329 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
| 6330 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6331 | // if (is_gray) { |
| 6332 | // old_ref = ref; |
| 6333 | // ref = temp2(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 6334 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 6335 | // } |
| 6336 | // } |
| 6337 | |
| 6338 | // Slow path updating the object reference at address `obj + field_offset` |
| 6339 | // when the GC is marking. The entrypoint will already be loaded in `temp2`. |
| 6340 | Register temp2 = lr; |
| 6341 | Location temp2_loc = LocationFrom(temp2); |
| 6342 | SlowPathCodeARM64* slow_path = |
| 6343 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 6344 | instruction, |
| 6345 | ref, |
| 6346 | obj, |
| 6347 | /* offset */ 0u, |
| 6348 | /* index */ field_offset, |
| 6349 | /* scale_factor */ 0u /* "times 1" */, |
| 6350 | needs_null_check, |
| 6351 | use_load_acquire, |
| 6352 | temp, |
| 6353 | /* entrypoint */ temp2_loc); |
| 6354 | AddSlowPath(slow_path); |
| 6355 | |
| 6356 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 6357 | const int32_t entry_point_offset = |
| 6358 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref.reg()); |
| 6359 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6360 | // threads are suspended or running a checkpoint. |
| 6361 | __ Ldr(temp2, MemOperand(tr, entry_point_offset)); |
| 6362 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6363 | // checking GetIsGcMarking. |
| 6364 | __ Cbnz(temp2, slow_path->GetEntryLabel()); |
| 6365 | // Fast path: the GC is not marking: nothing to do (the field is |
| 6366 | // up-to-date, and we don't need to load the reference). |
| 6367 | __ Bind(slow_path->GetExitLabel()); |
| 6368 | } |
| 6369 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6370 | void CodeGeneratorARM64::GenerateRawReferenceLoad(HInstruction* instruction, |
| 6371 | Location ref, |
| 6372 | Register obj, |
| 6373 | uint32_t offset, |
| 6374 | Location index, |
| 6375 | size_t scale_factor, |
| 6376 | bool needs_null_check, |
| 6377 | bool use_load_acquire) { |
| 6378 | DCHECK(obj.IsW()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6379 | Primitive::Type type = Primitive::kPrimNot; |
| 6380 | Register ref_reg = RegisterFrom(ref, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6381 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6382 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 6383 | // that no pools are emitted between the load (macro) instruction |
| 6384 | // and MaybeRecordImplicitNullCheck. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6385 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6386 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6387 | // Load types involving an "index": ArrayGet, |
| 6388 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6389 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6390 | if (use_load_acquire) { |
| 6391 | // UnsafeGetObjectVolatile intrinsic case. |
| 6392 | // Register `index` is not an index in an object array, but an |
| 6393 | // offset to an object reference field within object `obj`. |
| 6394 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 6395 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 6396 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 6397 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6398 | DCHECK_EQ(offset, 0u); |
| 6399 | DCHECK_EQ(scale_factor, 0u); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6400 | DCHECK_EQ(needs_null_check, false); |
| 6401 | // /* HeapReference<mirror::Object> */ ref = *(obj + index) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6402 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 6403 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6404 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6405 | // ArrayGet and UnsafeGetObject and UnsafeCASObject intrinsics cases. |
| 6406 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6407 | if (index.IsConstant()) { |
| 6408 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6409 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6410 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6411 | if (needs_null_check) { |
| 6412 | MaybeRecordImplicitNullCheck(instruction); |
| 6413 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6414 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6415 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6416 | Register temp = temps.AcquireW(); |
| 6417 | __ Add(temp, obj, offset); |
| 6418 | { |
| 6419 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6420 | Load(type, ref_reg, HeapOperand(temp, XRegisterFrom(index), LSL, scale_factor)); |
| 6421 | if (needs_null_check) { |
| 6422 | MaybeRecordImplicitNullCheck(instruction); |
| 6423 | } |
| 6424 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6425 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6426 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6427 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6428 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6429 | MemOperand field = HeapOperand(obj, offset); |
| 6430 | if (use_load_acquire) { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6431 | // Implicit null checks are handled by CodeGeneratorARM64::LoadAcquire. |
| 6432 | LoadAcquire(instruction, ref_reg, field, needs_null_check); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6433 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6434 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6435 | Load(type, ref_reg, field); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6436 | if (needs_null_check) { |
| 6437 | MaybeRecordImplicitNullCheck(instruction); |
| 6438 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6439 | } |
| 6440 | } |
| 6441 | |
| 6442 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6443 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6444 | } |
| 6445 | |
| 6446 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6447 | Location out, |
| 6448 | Location ref, |
| 6449 | Location obj, |
| 6450 | uint32_t offset, |
| 6451 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6452 | DCHECK(kEmitCompilerReadBarrier); |
| 6453 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6454 | // Insert a slow path based read barrier *after* the reference load. |
| 6455 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6456 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6457 | // reference will be carried out by the runtime within the slow |
| 6458 | // path. |
| 6459 | // |
| 6460 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6461 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6462 | // not used by the artReadBarrierSlow entry point. |
| 6463 | // |
| 6464 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6465 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 6466 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6467 | AddSlowPath(slow_path); |
| 6468 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6469 | __ B(slow_path->GetEntryLabel()); |
| 6470 | __ Bind(slow_path->GetExitLabel()); |
| 6471 | } |
| 6472 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6473 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6474 | Location out, |
| 6475 | Location ref, |
| 6476 | Location obj, |
| 6477 | uint32_t offset, |
| 6478 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6479 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6480 | // Baker's read barriers shall be handled by the fast path |
| 6481 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6482 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6483 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6484 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6485 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6486 | } else if (kPoisonHeapReferences) { |
| 6487 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6488 | } |
| 6489 | } |
| 6490 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6491 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6492 | Location out, |
| 6493 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6494 | DCHECK(kEmitCompilerReadBarrier); |
| 6495 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6496 | // Insert a slow path based read barrier *after* the GC root load. |
| 6497 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6498 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6499 | // not need to do anything special for this here. |
| 6500 | SlowPathCodeARM64* slow_path = |
| 6501 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 6502 | AddSlowPath(slow_path); |
| 6503 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6504 | __ B(slow_path->GetEntryLabel()); |
| 6505 | __ Bind(slow_path->GetExitLabel()); |
| 6506 | } |
| 6507 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6508 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6509 | LocationSummary* locations = |
| 6510 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6511 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6512 | locations->SetOut(Location::RequiresRegister()); |
| 6513 | } |
| 6514 | |
| 6515 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6516 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6517 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6518 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6519 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6520 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6521 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6522 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6523 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6524 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6525 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6526 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6527 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6528 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6529 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6530 | } |
| 6531 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6532 | static void PatchJitRootUse(uint8_t* code, |
| 6533 | const uint8_t* roots_data, |
| 6534 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6535 | uint64_t index_in_table) { |
| 6536 | uint32_t literal_offset = literal->GetOffset(); |
| 6537 | uintptr_t address = |
| 6538 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6539 | uint8_t* data = code + literal_offset; |
| 6540 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6541 | } |
| 6542 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6543 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6544 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6545 | const StringReference& string_reference = entry.first; |
| 6546 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| 6547 | const auto it = jit_string_roots_.find(string_reference); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6548 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6549 | uint64_t index_in_table = it->second; |
| 6550 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6551 | } |
| 6552 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6553 | const TypeReference& type_reference = entry.first; |
| 6554 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| 6555 | const auto it = jit_class_roots_.find(type_reference); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6556 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6557 | uint64_t index_in_table = it->second; |
| 6558 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6559 | } |
| 6560 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6561 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6562 | #undef __ |
| 6563 | #undef QUICK_ENTRY_POINT |
| 6564 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6565 | } // namespace arm64 |
| 6566 | } // namespace art |