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" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 22 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 23 | #include "compiled_method.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 25 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 26 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 27 | #include "intrinsics.h" |
| 28 | #include "intrinsics_arm64.h" |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 29 | #include "linker/arm64/relative_patcher_arm64.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 30 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 31 | #include "mirror/class-inl.h" |
Andreas Gampe | d490129 | 2017-05-30 18:41:34 -0700 | [diff] [blame] | 32 | #include "lock_word.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 33 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 34 | #include "thread.h" |
| 35 | #include "utils/arm64/assembler_arm64.h" |
| 36 | #include "utils/assembler.h" |
| 37 | #include "utils/stack_checks.h" |
| 38 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 39 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 40 | using vixl::ExactAssemblyScope; |
| 41 | using vixl::CodeBufferCheckScope; |
| 42 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 43 | |
| 44 | #ifdef __ |
| 45 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 46 | #endif |
| 47 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 48 | namespace art { |
| 49 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 50 | template<class MirrorType> |
| 51 | class GcRoot; |
| 52 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 53 | namespace arm64 { |
| 54 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 55 | using helpers::ARM64EncodableConstantOrRegister; |
| 56 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 57 | using helpers::CPURegisterFrom; |
| 58 | using helpers::DRegisterFrom; |
| 59 | using helpers::FPRegisterFrom; |
| 60 | using helpers::HeapOperand; |
| 61 | using helpers::HeapOperandFrom; |
| 62 | using helpers::InputCPURegisterAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 63 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 64 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 65 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 66 | using helpers::InputRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 67 | using helpers::Int64ConstantFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 68 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 69 | using helpers::LocationFrom; |
| 70 | using helpers::OperandFromMemOperand; |
| 71 | using helpers::OutputCPURegister; |
| 72 | using helpers::OutputFPRegister; |
| 73 | using helpers::OutputRegister; |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 74 | using helpers::QRegisterFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 75 | using helpers::RegisterFrom; |
| 76 | using helpers::StackOperandFrom; |
| 77 | using helpers::VIXLRegCodeFromART; |
| 78 | using helpers::WRegisterFrom; |
| 79 | using helpers::XRegisterFrom; |
| 80 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 81 | // 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] | 82 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 83 | // generates less code/data with a small num_entries. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 84 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 85 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 86 | // Reference load (except object array loads) is using LDR Wt, [Xn, #offset] which can handle |
| 87 | // offset < 16KiB. For offsets >= 16KiB, the load shall be emitted as two or more instructions. |
| 88 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 89 | // the offset explicitly. |
| 90 | constexpr uint32_t kReferenceLoadMinFarOffset = 16 * KB; |
| 91 | |
| 92 | // 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] | 93 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 94 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 95 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 96 | |
| 97 | // Some instructions have special requirements for a temporary, for example |
| 98 | // LoadClass/kBssEntry and LoadString/kBssEntry for Baker read barrier require |
| 99 | // temp that's not an R0 (to avoid an extra move) and Baker read barrier field |
| 100 | // loads with large offsets need a fixed register to limit the number of link-time |
| 101 | // thunks we generate. For these and similar cases, we want to reserve a specific |
| 102 | // register that's neither callee-save nor an argument register. We choose x15. |
| 103 | inline Location FixedTempLocation() { |
| 104 | return Location::RegisterLocation(x15.GetCode()); |
| 105 | } |
| 106 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 107 | inline Condition ARM64Condition(IfCondition cond) { |
| 108 | switch (cond) { |
| 109 | case kCondEQ: return eq; |
| 110 | case kCondNE: return ne; |
| 111 | case kCondLT: return lt; |
| 112 | case kCondLE: return le; |
| 113 | case kCondGT: return gt; |
| 114 | case kCondGE: return ge; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 115 | case kCondB: return lo; |
| 116 | case kCondBE: return ls; |
| 117 | case kCondA: return hi; |
| 118 | case kCondAE: return hs; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 119 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 120 | LOG(FATAL) << "Unreachable"; |
| 121 | UNREACHABLE(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 122 | } |
| 123 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 124 | inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) { |
| 125 | // The ARM64 condition codes can express all the necessary branches, see the |
| 126 | // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual. |
| 127 | // There is no dex instruction or HIR that would need the missing conditions |
| 128 | // "equal or unordered" or "not equal". |
| 129 | switch (cond) { |
| 130 | case kCondEQ: return eq; |
| 131 | case kCondNE: return ne /* unordered */; |
| 132 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 133 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 134 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 135 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 136 | default: |
| 137 | LOG(FATAL) << "UNREACHABLE"; |
| 138 | UNREACHABLE(); |
| 139 | } |
| 140 | } |
| 141 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 142 | Location ARM64ReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 143 | // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the |
| 144 | // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`, |
| 145 | // but we use the exact registers for clarity. |
| 146 | if (return_type == Primitive::kPrimFloat) { |
| 147 | return LocationFrom(s0); |
| 148 | } else if (return_type == Primitive::kPrimDouble) { |
| 149 | return LocationFrom(d0); |
| 150 | } else if (return_type == Primitive::kPrimLong) { |
| 151 | return LocationFrom(x0); |
Nicolas Geoffray | 925e562 | 2015-06-03 12:23:32 +0100 | [diff] [blame] | 152 | } else if (return_type == Primitive::kPrimVoid) { |
| 153 | return Location::NoLocation(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 154 | } else { |
| 155 | return LocationFrom(w0); |
| 156 | } |
| 157 | } |
| 158 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 159 | Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 160 | return ARM64ReturnLocation(return_type); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 163 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 164 | #define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 165 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value() |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 166 | |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 167 | // Calculate memory accessing operand for save/restore live registers. |
| 168 | static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen, |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 169 | LocationSummary* locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 170 | int64_t spill_offset, |
| 171 | bool is_save) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 172 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 173 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 174 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 175 | codegen->GetNumberOfCoreRegisters(), |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 176 | fp_spills, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 177 | codegen->GetNumberOfFloatingPointRegisters())); |
| 178 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 179 | CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 180 | unsigned v_reg_size = codegen->GetGraph()->HasSIMD() ? kQRegSize : kDRegSize; |
| 181 | CPURegList fp_list = CPURegList(CPURegister::kVRegister, v_reg_size, fp_spills); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 182 | |
| 183 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler(); |
| 184 | UseScratchRegisterScope temps(masm); |
| 185 | |
| 186 | Register base = masm->StackPointer(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 187 | int64_t core_spill_size = core_list.GetTotalSizeInBytes(); |
| 188 | int64_t fp_spill_size = fp_list.GetTotalSizeInBytes(); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 189 | int64_t reg_size = kXRegSizeInBytes; |
| 190 | int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size; |
| 191 | uint32_t ls_access_size = WhichPowerOf2(reg_size); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 192 | if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) && |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 193 | !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) { |
| 194 | // If the offset does not fit in the instruction's immediate field, use an alternate register |
| 195 | // to compute the base address(float point registers spill base address). |
| 196 | Register new_base = temps.AcquireSameSizeAs(base); |
| 197 | __ Add(new_base, base, Operand(spill_offset + core_spill_size)); |
| 198 | base = new_base; |
| 199 | spill_offset = -core_spill_size; |
| 200 | int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size; |
| 201 | DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size)); |
| 202 | DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size)); |
| 203 | } |
| 204 | |
| 205 | if (is_save) { |
| 206 | __ StoreCPURegList(core_list, MemOperand(base, spill_offset)); |
| 207 | __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 208 | } else { |
| 209 | __ LoadCPURegList(core_list, MemOperand(base, spill_offset)); |
| 210 | __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size)); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 215 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 216 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 217 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 218 | // If the register holds an object, update the stack mask. |
| 219 | if (locations->RegisterContainsObject(i)) { |
| 220 | locations->SetStackBit(stack_offset / kVRegSize); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 221 | } |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 222 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 223 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 224 | saved_core_stack_offsets_[i] = stack_offset; |
| 225 | stack_offset += kXRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 226 | } |
| 227 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 228 | const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 229 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 230 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 231 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 232 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 233 | stack_offset += kDRegSizeInBytes; |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 234 | } |
| 235 | |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 236 | SaveRestoreLiveRegistersHelper(codegen, |
| 237 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 238 | codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */); |
| 239 | } |
| 240 | |
| 241 | void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 242 | SaveRestoreLiveRegistersHelper(codegen, |
| 243 | locations, |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 244 | codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */); |
| 245 | } |
| 246 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 247 | class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 248 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 249 | explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 250 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 251 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 252 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 253 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 254 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 255 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 256 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 257 | // Live registers will be restored in the catch block if caught. |
| 258 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 259 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 260 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 261 | // move resolver. |
| 262 | InvokeRuntimeCallingConvention calling_convention; |
| 263 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 264 | locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt, |
| 265 | locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 266 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 267 | ? kQuickThrowStringBounds |
| 268 | : kQuickThrowArrayBounds; |
| 269 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 270 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 271 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 272 | } |
| 273 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 274 | bool IsFatal() const OVERRIDE { return true; } |
| 275 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 276 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; } |
| 277 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 278 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 279 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64); |
| 280 | }; |
| 281 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 282 | class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 283 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 284 | explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 285 | |
| 286 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 287 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 288 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 289 | arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 290 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 293 | bool IsFatal() const OVERRIDE { return true; } |
| 294 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 295 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; } |
| 296 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 297 | private: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 298 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64); |
| 299 | }; |
| 300 | |
| 301 | class LoadClassSlowPathARM64 : public SlowPathCodeARM64 { |
| 302 | public: |
| 303 | LoadClassSlowPathARM64(HLoadClass* cls, |
| 304 | HInstruction* at, |
| 305 | uint32_t dex_pc, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 306 | bool do_clinit, |
| 307 | vixl::aarch64::Register bss_entry_temp = vixl::aarch64::Register(), |
| 308 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr) |
| 309 | : SlowPathCodeARM64(at), |
| 310 | cls_(cls), |
| 311 | dex_pc_(dex_pc), |
| 312 | do_clinit_(do_clinit), |
| 313 | bss_entry_temp_(bss_entry_temp), |
| 314 | bss_entry_adrp_label_(bss_entry_adrp_label) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 315 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 316 | } |
| 317 | |
| 318 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 319 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 320 | Location out = locations->Out(); |
| 321 | constexpr bool call_saves_everything_except_r0_ip0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 322 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 323 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 324 | InvokeRuntimeCallingConvention calling_convention; |
| 325 | // For HLoadClass/kBssEntry/kSaveEverything, the page address of the entry is in a temp |
| 326 | // 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] | 327 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 328 | bool is_load_class_bss_entry = |
| 329 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 330 | if (is_load_class_bss_entry) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 331 | DCHECK(bss_entry_temp_.IsValid()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 332 | DCHECK(!bss_entry_temp_.Is(calling_convention.GetRegisterAt(0))); |
| 333 | DCHECK( |
| 334 | !UseScratchRegisterScope(arm64_codegen->GetVIXLAssembler()).IsAvailable(bss_entry_temp_)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 337 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 338 | SaveLiveRegisters(codegen, locations); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 339 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 340 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 341 | __ Mov(calling_convention.GetRegisterAt(0).W(), type_index.index_); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 342 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 343 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 344 | arm64_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 345 | if (do_clinit_) { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 346 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 347 | } else { |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 348 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 349 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 350 | |
| 351 | // Move the class to the desired location. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 352 | if (out.IsValid()) { |
| 353 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 354 | Primitive::Type type = instruction_->GetType(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 355 | arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 356 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 357 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 358 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 359 | if (is_load_class_bss_entry) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 360 | DCHECK(out.IsValid()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 361 | const DexFile& dex_file = cls_->GetDexFile(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 362 | if (call_saves_everything_except_r0_ip0) { |
| 363 | // The class entry page address was preserved in bss_entry_temp_ thanks to kSaveEverything. |
| 364 | } else { |
| 365 | // For non-Baker read barrier, we need to re-calculate the address of the class entry page. |
| 366 | bss_entry_adrp_label_ = arm64_codegen->NewBssEntryTypePatch(dex_file, type_index); |
| 367 | arm64_codegen->EmitAdrpPlaceholder(bss_entry_adrp_label_, bss_entry_temp_); |
| 368 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 369 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 370 | arm64_codegen->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label_); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 371 | { |
| 372 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 373 | __ Bind(strp_label); |
| 374 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 375 | MemOperand(bss_entry_temp_, /* offset placeholder */ 0)); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 376 | } |
| 377 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 378 | __ B(GetExitLabel()); |
| 379 | } |
| 380 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 381 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; } |
| 382 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 383 | private: |
| 384 | // The class this slow path will load. |
| 385 | HLoadClass* const cls_; |
| 386 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 387 | // The dex PC of `at_`. |
| 388 | const uint32_t dex_pc_; |
| 389 | |
| 390 | // Whether to initialize the class. |
| 391 | const bool do_clinit_; |
| 392 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 393 | // For HLoadClass/kBssEntry, the temp register and the label of the ADRP where it was loaded. |
| 394 | vixl::aarch64::Register bss_entry_temp_; |
| 395 | vixl::aarch64::Label* bss_entry_adrp_label_; |
| 396 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 397 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64); |
| 398 | }; |
| 399 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 400 | class LoadStringSlowPathARM64 : public SlowPathCodeARM64 { |
| 401 | public: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 402 | LoadStringSlowPathARM64(HLoadString* instruction, Register temp, vixl::aarch64::Label* adrp_label) |
| 403 | : SlowPathCodeARM64(instruction), |
| 404 | temp_(temp), |
| 405 | adrp_label_(adrp_label) {} |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 406 | |
| 407 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 408 | LocationSummary* locations = instruction_->GetLocations(); |
| 409 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 410 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 411 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 412 | InvokeRuntimeCallingConvention calling_convention; |
| 413 | // Make sure `temp_` is not clobbered by the call or by saving/restoring registers. |
| 414 | DCHECK(temp_.IsValid()); |
| 415 | DCHECK(!temp_.Is(calling_convention.GetRegisterAt(0))); |
| 416 | DCHECK(!UseScratchRegisterScope(arm64_codegen->GetVIXLAssembler()).IsAvailable(temp_)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 417 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 418 | __ Bind(GetEntryLabel()); |
| 419 | SaveLiveRegisters(codegen, locations); |
| 420 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 421 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 422 | __ Mov(calling_convention.GetRegisterAt(0).W(), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 423 | arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 424 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 425 | Primitive::Type type = instruction_->GetType(); |
| 426 | arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type); |
| 427 | |
| 428 | RestoreLiveRegisters(codegen, locations); |
| 429 | |
| 430 | // Store the resolved String to the BSS entry. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 431 | const DexFile& dex_file = instruction_->AsLoadString()->GetDexFile(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 432 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 433 | // The string entry page address was preserved in temp_ thanks to kSaveEverything. |
| 434 | } else { |
| 435 | // For non-Baker read barrier, we need to re-calculate the address of the string entry page. |
| 436 | adrp_label_ = arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index); |
| 437 | arm64_codegen->EmitAdrpPlaceholder(adrp_label_, temp_); |
| 438 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 439 | vixl::aarch64::Label* strp_label = |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 440 | arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index, adrp_label_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 441 | { |
| 442 | SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler()); |
| 443 | __ Bind(strp_label); |
| 444 | __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot), |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 445 | MemOperand(temp_, /* offset placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | __ B(GetExitLabel()); |
| 449 | } |
| 450 | |
| 451 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; } |
| 452 | |
| 453 | private: |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 454 | const Register temp_; |
| 455 | vixl::aarch64::Label* adrp_label_; |
| 456 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 457 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64); |
| 458 | }; |
| 459 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 460 | class NullCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 461 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 462 | explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 463 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 464 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 465 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 466 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 467 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 468 | // Live registers will be restored in the catch block if caught. |
| 469 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 470 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 471 | arm64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 472 | instruction_, |
| 473 | instruction_->GetDexPc(), |
| 474 | this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 475 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 476 | } |
| 477 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 478 | bool IsFatal() const OVERRIDE { return true; } |
| 479 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 480 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; } |
| 481 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 482 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 483 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64); |
| 484 | }; |
| 485 | |
| 486 | class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 487 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 488 | SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 489 | : SlowPathCodeARM64(instruction), successor_(successor) {} |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 490 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 491 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 492 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 493 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 494 | __ Bind(GetEntryLabel()); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 495 | SaveLiveRegisters(codegen, locations); // Only saves live 128-bit regs for SIMD. |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 496 | arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 497 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 498 | RestoreLiveRegisters(codegen, locations); // Only restores live 128-bit regs for SIMD. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 499 | if (successor_ == nullptr) { |
| 500 | __ B(GetReturnLabel()); |
| 501 | } else { |
| 502 | __ B(arm64_codegen->GetLabelOf(successor_)); |
| 503 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 504 | } |
| 505 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 506 | vixl::aarch64::Label* GetReturnLabel() { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 507 | DCHECK(successor_ == nullptr); |
| 508 | return &return_label_; |
| 509 | } |
| 510 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 511 | HBasicBlock* GetSuccessor() const { |
| 512 | return successor_; |
| 513 | } |
| 514 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 515 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; } |
| 516 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 517 | private: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 518 | // If not null, the block to branch to after the suspend check. |
| 519 | HBasicBlock* const successor_; |
| 520 | |
| 521 | // 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] | 522 | vixl::aarch64::Label return_label_; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 523 | |
| 524 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64); |
| 525 | }; |
| 526 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 527 | class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 { |
| 528 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 529 | TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 530 | : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {} |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 531 | |
| 532 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 533 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 534 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 535 | DCHECK(instruction_->IsCheckCast() |
| 536 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 537 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 538 | uint32_t dex_pc = instruction_->GetDexPc(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 539 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 540 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 541 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 542 | if (!is_fatal_) { |
| 543 | SaveLiveRegisters(codegen, locations); |
| 544 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 545 | |
| 546 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 547 | // move resolver. |
| 548 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 549 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 550 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 551 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 552 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 553 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 554 | Primitive::kPrimNot); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 555 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 556 | arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 557 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 558 | Primitive::Type ret_type = instruction_->GetType(); |
| 559 | Location ret_loc = calling_convention.GetReturnLocation(ret_type); |
| 560 | arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type); |
| 561 | } else { |
| 562 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 563 | arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 564 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 565 | } |
| 566 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 567 | if (!is_fatal_) { |
| 568 | RestoreLiveRegisters(codegen, locations); |
| 569 | __ B(GetExitLabel()); |
| 570 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 573 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; } |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 574 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 575 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 576 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 577 | const bool is_fatal_; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 578 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 579 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64); |
| 580 | }; |
| 581 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 582 | class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 { |
| 583 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 584 | explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 585 | : SlowPathCodeARM64(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 586 | |
| 587 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 588 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 589 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 590 | LocationSummary* locations = instruction_->GetLocations(); |
| 591 | SaveLiveRegisters(codegen, locations); |
| 592 | InvokeRuntimeCallingConvention calling_convention; |
| 593 | __ Mov(calling_convention.GetRegisterAt(0), |
| 594 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 595 | arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 596 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 599 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; } |
| 600 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 601 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 602 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64); |
| 603 | }; |
| 604 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 605 | class ArraySetSlowPathARM64 : public SlowPathCodeARM64 { |
| 606 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 607 | explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 608 | |
| 609 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 610 | LocationSummary* locations = instruction_->GetLocations(); |
| 611 | __ Bind(GetEntryLabel()); |
| 612 | SaveLiveRegisters(codegen, locations); |
| 613 | |
| 614 | InvokeRuntimeCallingConvention calling_convention; |
| 615 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 616 | parallel_move.AddMove( |
| 617 | locations->InAt(0), |
| 618 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 619 | Primitive::kPrimNot, |
| 620 | nullptr); |
| 621 | parallel_move.AddMove( |
| 622 | locations->InAt(1), |
| 623 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 624 | Primitive::kPrimInt, |
| 625 | nullptr); |
| 626 | parallel_move.AddMove( |
| 627 | locations->InAt(2), |
| 628 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 629 | Primitive::kPrimNot, |
| 630 | nullptr); |
| 631 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 632 | |
| 633 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 634 | arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 635 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 636 | RestoreLiveRegisters(codegen, locations); |
| 637 | __ B(GetExitLabel()); |
| 638 | } |
| 639 | |
| 640 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; } |
| 641 | |
| 642 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 643 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64); |
| 644 | }; |
| 645 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 646 | void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) { |
| 647 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 648 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 649 | |
| 650 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| 651 | // 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] | 652 | EmissionCheckScope scope(codegen->GetVIXLAssembler(), |
| 653 | num_entries * sizeof(int32_t), |
| 654 | CodeBufferCheckScope::kExactSize); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 655 | |
| 656 | __ Bind(&table_start_); |
| 657 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 658 | for (uint32_t i = 0; i < num_entries; i++) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 659 | vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 660 | DCHECK(target_label->IsBound()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 661 | ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 662 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 663 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| 664 | Literal<int32_t> literal(jump_offset); |
| 665 | __ place(&literal); |
| 666 | } |
| 667 | } |
| 668 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 669 | // Abstract base class for read barrier slow paths marking a reference |
| 670 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 671 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 672 | // Argument `entrypoint` must be a register location holding the read |
| 673 | // barrier marking runtime entry point to be invoked. |
| 674 | class ReadBarrierMarkSlowPathBaseARM64 : public SlowPathCodeARM64 { |
| 675 | protected: |
| 676 | ReadBarrierMarkSlowPathBaseARM64(HInstruction* instruction, Location ref, Location entrypoint) |
| 677 | : SlowPathCodeARM64(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 678 | DCHECK(kEmitCompilerReadBarrier); |
| 679 | } |
| 680 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 681 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM64"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 682 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 683 | // Generate assembly code calling the read barrier marking runtime |
| 684 | // entry point (ReadBarrierMarkRegX). |
| 685 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 686 | // No need to save live registers; it's taken care of by the |
| 687 | // entrypoint. Also, there is no need to update the stack mask, |
| 688 | // as this runtime call will not trigger a garbage collection. |
| 689 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 690 | DCHECK_NE(ref_.reg(), LR); |
| 691 | DCHECK_NE(ref_.reg(), WSP); |
| 692 | DCHECK_NE(ref_.reg(), WZR); |
| 693 | // IP0 is used internally by the ReadBarrierMarkRegX entry point |
| 694 | // as a temporary, it cannot be the entry point's input/output. |
| 695 | DCHECK_NE(ref_.reg(), IP0); |
| 696 | DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg(); |
| 697 | // "Compact" slow path, saving two moves. |
| 698 | // |
| 699 | // Instead of using the standard runtime calling convention (input |
| 700 | // and output in W0): |
| 701 | // |
| 702 | // W0 <- ref |
| 703 | // W0 <- ReadBarrierMark(W0) |
| 704 | // ref <- W0 |
| 705 | // |
| 706 | // we just use rX (the register containing `ref`) as input and output |
| 707 | // of a dedicated entrypoint: |
| 708 | // |
| 709 | // rX <- ReadBarrierMarkRegX(rX) |
| 710 | // |
| 711 | if (entrypoint_.IsValid()) { |
| 712 | arm64_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 713 | __ Blr(XRegisterFrom(entrypoint_)); |
| 714 | } else { |
| 715 | // Entrypoint is not already loaded, load from the thread. |
| 716 | int32_t entry_point_offset = |
| 717 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg()); |
| 718 | // This runtime call does not require a stack map. |
| 719 | arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | // The location (register) of the marked object reference. |
| 724 | const Location ref_; |
| 725 | |
| 726 | // The location of the entrypoint if it is already loaded. |
| 727 | const Location entrypoint_; |
| 728 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 729 | private: |
| 730 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM64); |
| 731 | }; |
| 732 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 733 | // Slow path marking an object reference `ref` during a read |
| 734 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 735 | // reference does not get updated by this slow path after marking. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 736 | // |
| 737 | // This means that after the execution of this slow path, `ref` will |
| 738 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 739 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 740 | // probably still be a from-space reference (unless it gets updated by |
| 741 | // another thread, or if another thread installed another object |
| 742 | // reference (different from `ref`) in `obj.field`). |
| 743 | // |
| 744 | // If `entrypoint` is a valid location it is assumed to already be |
| 745 | // holding the entrypoint. The case where the entrypoint is passed in |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 746 | // 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] | 747 | class ReadBarrierMarkSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 748 | public: |
| 749 | ReadBarrierMarkSlowPathARM64(HInstruction* instruction, |
| 750 | Location ref, |
| 751 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 752 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 753 | DCHECK(kEmitCompilerReadBarrier); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; } |
| 757 | |
| 758 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 759 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 760 | DCHECK(locations->CanCall()); |
| 761 | DCHECK(ref_.IsRegister()) << ref_; |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 762 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 763 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 764 | << "Unexpected instruction in read barrier marking slow path: " |
| 765 | << instruction_->DebugName(); |
| 766 | |
| 767 | __ Bind(GetEntryLabel()); |
| 768 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 769 | __ B(GetExitLabel()); |
| 770 | } |
| 771 | |
| 772 | private: |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 773 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64); |
| 774 | }; |
| 775 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 776 | // Slow path loading `obj`'s lock word, loading a reference from |
| 777 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 778 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 779 | // read barrier). The field `obj.field` in the object `obj` holding |
| 780 | // this reference does not get updated by this slow path after marking |
| 781 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 782 | // below for that). |
| 783 | // |
| 784 | // This means that after the execution of this slow path, `ref` will |
| 785 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 786 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 787 | // probably still be a from-space reference (unless it gets updated by |
| 788 | // another thread, or if another thread installed another object |
| 789 | // reference (different from `ref`) in `obj.field`). |
| 790 | // |
| 791 | // Argument `entrypoint` must be a register location holding the read |
| 792 | // barrier marking runtime entry point to be invoked. |
| 793 | class LoadReferenceWithBakerReadBarrierSlowPathARM64 : public ReadBarrierMarkSlowPathBaseARM64 { |
| 794 | public: |
| 795 | LoadReferenceWithBakerReadBarrierSlowPathARM64(HInstruction* instruction, |
| 796 | Location ref, |
| 797 | Register obj, |
| 798 | uint32_t offset, |
| 799 | Location index, |
| 800 | size_t scale_factor, |
| 801 | bool needs_null_check, |
| 802 | bool use_load_acquire, |
| 803 | Register temp, |
| 804 | Location entrypoint) |
| 805 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
| 806 | obj_(obj), |
| 807 | offset_(offset), |
| 808 | index_(index), |
| 809 | scale_factor_(scale_factor), |
| 810 | needs_null_check_(needs_null_check), |
| 811 | use_load_acquire_(use_load_acquire), |
| 812 | temp_(temp) { |
| 813 | DCHECK(kEmitCompilerReadBarrier); |
| 814 | DCHECK(kUseBakerReadBarrier); |
| 815 | } |
| 816 | |
| 817 | const char* GetDescription() const OVERRIDE { |
| 818 | return "LoadReferenceWithBakerReadBarrierSlowPathARM64"; |
| 819 | } |
| 820 | |
| 821 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 822 | LocationSummary* locations = instruction_->GetLocations(); |
| 823 | DCHECK(locations->CanCall()); |
| 824 | DCHECK(ref_.IsRegister()) << ref_; |
| 825 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
| 826 | DCHECK(obj_.IsW()); |
| 827 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 828 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 829 | instruction_->IsStaticFieldGet() || |
| 830 | instruction_->IsArrayGet() || |
| 831 | instruction_->IsArraySet() || |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 832 | instruction_->IsInstanceOf() || |
| 833 | instruction_->IsCheckCast() || |
| 834 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 835 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 836 | << "Unexpected instruction in read barrier marking slow path: " |
| 837 | << instruction_->DebugName(); |
| 838 | // The read barrier instrumentation of object ArrayGet |
| 839 | // instructions does not support the HIntermediateAddress |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 840 | // instruction. |
| 841 | DCHECK(!(instruction_->IsArrayGet() && |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 842 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 843 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 844 | // Temporary register `temp_`, used to store the lock word, must |
| 845 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 846 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 847 | // need the lock word to still be in `temp_` after the reference |
| 848 | // load. |
| 849 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 850 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
| 851 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 852 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 853 | |
| 854 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 855 | // inserted after the original load. However, in fast path based |
| 856 | // Baker's read barriers, we need to perform the load of |
| 857 | // mirror::Object::monitor_ *before* the original reference load. |
| 858 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 859 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 860 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 861 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 862 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 863 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 864 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 865 | // if (is_gray) { |
| 866 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 867 | // } |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 868 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 869 | // Note: the original implementation in ReadBarrier::Barrier is |
| 870 | // slightly more complex as it performs additional checks that we do |
| 871 | // not do here for performance reasons. |
| 872 | |
| 873 | // /* int32_t */ monitor = obj->monitor_ |
| 874 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 875 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 876 | if (needs_null_check_) { |
| 877 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 878 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 879 | // /* LockWord */ lock_word = LockWord(monitor) |
| 880 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 881 | "art::LockWord and int32_t have different sizes."); |
| 882 | |
| 883 | // Introduce a dependency on the lock_word including rb_state, |
| 884 | // to prevent load-load reordering, and without using |
| 885 | // a memory barrier (which would be more expensive). |
| 886 | // `obj` is unchanged by this operation, but its value now depends |
| 887 | // on `temp`. |
| 888 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 889 | |
| 890 | // The actual reference load. |
| 891 | // A possible implicit null check has already been handled above. |
| 892 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 893 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 894 | ref_, |
| 895 | obj_, |
| 896 | offset_, |
| 897 | index_, |
| 898 | scale_factor_, |
| 899 | /* needs_null_check */ false, |
| 900 | use_load_acquire_); |
| 901 | |
| 902 | // Mark the object `ref` when `obj` is gray. |
| 903 | // |
| 904 | // if (rb_state == ReadBarrier::GrayState()) |
| 905 | // ref = ReadBarrier::Mark(ref); |
| 906 | // |
| 907 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 908 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 909 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 910 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 911 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 912 | |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 913 | __ B(GetExitLabel()); |
| 914 | } |
| 915 | |
| 916 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 917 | // The register containing the object holding the marked object reference field. |
| 918 | Register obj_; |
| 919 | // The offset, index and scale factor to access the reference in `obj_`. |
| 920 | uint32_t offset_; |
| 921 | Location index_; |
| 922 | size_t scale_factor_; |
| 923 | // Is a null check required? |
| 924 | bool needs_null_check_; |
| 925 | // Should this reference load use Load-Acquire semantics? |
| 926 | bool use_load_acquire_; |
| 927 | // A temporary register used to hold the lock word of `obj_`. |
| 928 | Register temp_; |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 929 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 930 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM64); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 931 | }; |
| 932 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 933 | // Slow path loading `obj`'s lock word, loading a reference from |
| 934 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 935 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 936 | // read barrier). If needed, this slow path also atomically updates |
| 937 | // the field `obj.field` in the object `obj` holding this reference |
| 938 | // after marking (contrary to |
| 939 | // LoadReferenceWithBakerReadBarrierSlowPathARM64 above, which never |
| 940 | // tries to update `obj.field`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 941 | // |
| 942 | // This means that after the execution of this slow path, both `ref` |
| 943 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 944 | // hold the same to-space reference (unless another thread installed |
| 945 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 946 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 947 | // Argument `entrypoint` must be a register location holding the read |
| 948 | // barrier marking runtime entry point to be invoked. |
| 949 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 950 | : public ReadBarrierMarkSlowPathBaseARM64 { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 951 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 952 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64(HInstruction* instruction, |
| 953 | Location ref, |
| 954 | Register obj, |
| 955 | uint32_t offset, |
| 956 | Location index, |
| 957 | size_t scale_factor, |
| 958 | bool needs_null_check, |
| 959 | bool use_load_acquire, |
| 960 | Register temp, |
| 961 | Location entrypoint) |
| 962 | : ReadBarrierMarkSlowPathBaseARM64(instruction, ref, entrypoint), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 963 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 964 | offset_(offset), |
| 965 | index_(index), |
| 966 | scale_factor_(scale_factor), |
| 967 | needs_null_check_(needs_null_check), |
| 968 | use_load_acquire_(use_load_acquire), |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 969 | temp_(temp) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 970 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 971 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | const char* GetDescription() const OVERRIDE { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 975 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64"; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 979 | LocationSummary* locations = instruction_->GetLocations(); |
| 980 | Register ref_reg = WRegisterFrom(ref_); |
| 981 | DCHECK(locations->CanCall()); |
| 982 | DCHECK(ref_.IsRegister()) << ref_; |
| 983 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 984 | DCHECK(obj_.IsW()); |
| 985 | DCHECK_NE(ref_.reg(), LocationFrom(temp_).reg()); |
| 986 | |
| 987 | // 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] | 988 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 989 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 990 | << instruction_->DebugName(); |
| 991 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 992 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 993 | DCHECK_EQ(offset_, 0u); |
| 994 | DCHECK_EQ(scale_factor_, 0u); |
| 995 | DCHECK_EQ(use_load_acquire_, false); |
| 996 | // The location of the offset of the marked reference field within `obj_`. |
| 997 | Location field_offset = index_; |
| 998 | DCHECK(field_offset.IsRegister()) << field_offset; |
| 999 | |
| 1000 | // Temporary register `temp_`, used to store the lock word, must |
| 1001 | // not be IP0 nor IP1, as we may use them to emit the reference |
| 1002 | // load (in the call to GenerateRawReferenceLoad below), and we |
| 1003 | // need the lock word to still be in `temp_` after the reference |
| 1004 | // load. |
| 1005 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1006 | DCHECK_NE(LocationFrom(temp_).reg(), IP1); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1007 | |
| 1008 | __ Bind(GetEntryLabel()); |
| 1009 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 1010 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM64's: |
| 1011 | // |
| 1012 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 1013 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 1014 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 1015 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 1016 | // if (is_gray) { |
| 1017 | // old_ref = ref; |
| 1018 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 1019 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1020 | // } |
| 1021 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1022 | // /* int32_t */ monitor = obj->monitor_ |
| 1023 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1024 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 1025 | if (needs_null_check_) { |
| 1026 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1027 | } |
| 1028 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1029 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1030 | "art::LockWord and int32_t have different sizes."); |
| 1031 | |
| 1032 | // Introduce a dependency on the lock_word including rb_state, |
| 1033 | // to prevent load-load reordering, and without using |
| 1034 | // a memory barrier (which would be more expensive). |
| 1035 | // `obj` is unchanged by this operation, but its value now depends |
| 1036 | // on `temp`. |
| 1037 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 1038 | |
| 1039 | // The actual reference load. |
| 1040 | // A possible implicit null check has already been handled above. |
| 1041 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1042 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 1043 | ref_, |
| 1044 | obj_, |
| 1045 | offset_, |
| 1046 | index_, |
| 1047 | scale_factor_, |
| 1048 | /* needs_null_check */ false, |
| 1049 | use_load_acquire_); |
| 1050 | |
| 1051 | // Mark the object `ref` when `obj` is gray. |
| 1052 | // |
| 1053 | // if (rb_state == ReadBarrier::GrayState()) |
| 1054 | // ref = ReadBarrier::Mark(ref); |
| 1055 | // |
| 1056 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 1057 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1058 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1059 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 1060 | |
| 1061 | // Save the old value of the reference before marking it. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1062 | // Note that we cannot use IP to save the old reference, as IP is |
| 1063 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1064 | // need the old reference after the call to that entry point. |
| 1065 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1066 | __ Mov(temp_.W(), ref_reg); |
| 1067 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1068 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1069 | |
| 1070 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1071 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1072 | // |
| 1073 | // Note that this field could also hold a different object, if |
| 1074 | // another thread had concurrently changed it. In that case, the |
| 1075 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 1076 | // (CAS) operation below would abort the CAS, leaving the field |
| 1077 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1078 | __ Cmp(temp_.W(), ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1079 | __ B(eq, GetExitLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1080 | |
| 1081 | // Update the the holder's field atomically. This may fail if |
| 1082 | // mutator updates before us, but it's OK. This is achieved |
| 1083 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1084 | // memory synchronization ordering, where the expected value is |
| 1085 | // the old reference and the desired value is the new reference. |
| 1086 | |
| 1087 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 1088 | UseScratchRegisterScope temps(masm); |
| 1089 | |
| 1090 | // Convenience aliases. |
| 1091 | Register base = obj_.W(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1092 | Register offset = XRegisterFrom(field_offset); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1093 | Register expected = temp_.W(); |
| 1094 | Register value = ref_reg; |
| 1095 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1096 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 1097 | |
| 1098 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1099 | |
| 1100 | if (kPoisonHeapReferences) { |
| 1101 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1102 | if (value.Is(expected)) { |
| 1103 | // Do not poison `value`, as it is the same register as |
| 1104 | // `expected`, which has just been poisoned. |
| 1105 | } else { |
| 1106 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | // do { |
| 1111 | // tmp_value = [tmp_ptr] - expected; |
| 1112 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1113 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1114 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1115 | __ Bind(&loop_head); |
| 1116 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 1117 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1118 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1119 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 1120 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1121 | __ B(&exit_loop); |
| 1122 | __ Bind(&comparison_failed); |
| 1123 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1124 | __ Bind(&exit_loop); |
| 1125 | |
| 1126 | if (kPoisonHeapReferences) { |
| 1127 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1128 | if (value.Is(expected)) { |
| 1129 | // Do not unpoison `value`, as it is the same register as |
| 1130 | // `expected`, which has just been unpoisoned. |
| 1131 | } else { |
| 1132 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1133 | } |
| 1134 | } |
| 1135 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1136 | __ B(GetExitLabel()); |
| 1137 | } |
| 1138 | |
| 1139 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1140 | // The register containing the object holding the marked object reference field. |
| 1141 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1142 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1143 | uint32_t offset_; |
| 1144 | Location index_; |
| 1145 | size_t scale_factor_; |
| 1146 | // Is a null check required? |
| 1147 | bool needs_null_check_; |
| 1148 | // Should this reference load use Load-Acquire semantics? |
| 1149 | bool use_load_acquire_; |
| 1150 | // A temporary register used to hold the lock word of `obj_`; and |
| 1151 | // also to hold the original reference value, when the reference is |
| 1152 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1153 | const Register temp_; |
| 1154 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1155 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1156 | }; |
| 1157 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1158 | // Slow path generating a read barrier for a heap reference. |
| 1159 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 1160 | public: |
| 1161 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 1162 | Location out, |
| 1163 | Location ref, |
| 1164 | Location obj, |
| 1165 | uint32_t offset, |
| 1166 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1167 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1168 | out_(out), |
| 1169 | ref_(ref), |
| 1170 | obj_(obj), |
| 1171 | offset_(offset), |
| 1172 | index_(index) { |
| 1173 | DCHECK(kEmitCompilerReadBarrier); |
| 1174 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1175 | // has been overwritten by (or after) the heap object reference load |
| 1176 | // to be instrumented, e.g.: |
| 1177 | // |
| 1178 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1179 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1180 | // |
| 1181 | // In that case, we have lost the information about the original |
| 1182 | // object, and the emitted read barrier cannot work properly. |
| 1183 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1184 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1185 | } |
| 1186 | |
| 1187 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1188 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1189 | LocationSummary* locations = instruction_->GetLocations(); |
| 1190 | Primitive::Type type = Primitive::kPrimNot; |
| 1191 | DCHECK(locations->CanCall()); |
| 1192 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1193 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1194 | instruction_->IsStaticFieldGet() || |
| 1195 | instruction_->IsArrayGet() || |
| 1196 | instruction_->IsInstanceOf() || |
| 1197 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1198 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1199 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1200 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1201 | // The read barrier instrumentation of object ArrayGet |
| 1202 | // instructions does not support the HIntermediateAddress |
| 1203 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1204 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1205 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1206 | |
| 1207 | __ Bind(GetEntryLabel()); |
| 1208 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1209 | SaveLiveRegisters(codegen, locations); |
| 1210 | |
| 1211 | // We may have to change the index's value, but as `index_` is a |
| 1212 | // constant member (like other "inputs" of this slow path), |
| 1213 | // introduce a copy of it, `index`. |
| 1214 | Location index = index_; |
| 1215 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1216 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1217 | if (instruction_->IsArrayGet()) { |
| 1218 | // Compute the actual memory offset and store it in `index`. |
| 1219 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 1220 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 1221 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 1222 | // We are about to change the value of `index_reg` (see the |
| 1223 | // calls to vixl::MacroAssembler::Lsl and |
| 1224 | // vixl::MacroAssembler::Mov below), but it has |
| 1225 | // not been saved by the previous call to |
| 1226 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1227 | // callee-save register -- |
| 1228 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1229 | // callee-save registers, as it has been designed with the |
| 1230 | // assumption that callee-save registers are supposed to be |
| 1231 | // handled by the called function. So, as a callee-save |
| 1232 | // register, `index_reg` _would_ eventually be saved onto |
| 1233 | // the stack, but it would be too late: we would have |
| 1234 | // changed its value earlier. Therefore, we manually save |
| 1235 | // it here into another freely available register, |
| 1236 | // `free_reg`, chosen of course among the caller-save |
| 1237 | // registers (as a callee-save `free_reg` register would |
| 1238 | // exhibit the same problem). |
| 1239 | // |
| 1240 | // Note we could have requested a temporary register from |
| 1241 | // the register allocator instead; but we prefer not to, as |
| 1242 | // this is a slow path, and we know we can find a |
| 1243 | // caller-save register that is available. |
| 1244 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1245 | __ Mov(free_reg.W(), index_reg); |
| 1246 | index_reg = free_reg; |
| 1247 | index = LocationFrom(index_reg); |
| 1248 | } else { |
| 1249 | // The initial register stored in `index_` has already been |
| 1250 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1251 | // (as it is not a callee-save register), so we can freely |
| 1252 | // use it. |
| 1253 | } |
| 1254 | // Shifting the index value contained in `index_reg` by the scale |
| 1255 | // factor (2) cannot overflow in practice, as the runtime is |
| 1256 | // unable to allocate object arrays with a size larger than |
| 1257 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1258 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 1259 | static_assert( |
| 1260 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1261 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1262 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1263 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1264 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1265 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1266 | // (as in the case of ArrayGet), as it is actually an offset |
| 1267 | // to an object field within an object. |
| 1268 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1269 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1270 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1271 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1272 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1273 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1274 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | // We're moving two or three locations to locations that could |
| 1279 | // overlap, so we need a parallel move resolver. |
| 1280 | InvokeRuntimeCallingConvention calling_convention; |
| 1281 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1282 | parallel_move.AddMove(ref_, |
| 1283 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1284 | type, |
| 1285 | nullptr); |
| 1286 | parallel_move.AddMove(obj_, |
| 1287 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1288 | type, |
| 1289 | nullptr); |
| 1290 | if (index.IsValid()) { |
| 1291 | parallel_move.AddMove(index, |
| 1292 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 1293 | Primitive::kPrimInt, |
| 1294 | nullptr); |
| 1295 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1296 | } else { |
| 1297 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1298 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1299 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1300 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1301 | instruction_, |
| 1302 | instruction_->GetDexPc(), |
| 1303 | this); |
| 1304 | CheckEntrypointTypes< |
| 1305 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1306 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1307 | |
| 1308 | RestoreLiveRegisters(codegen, locations); |
| 1309 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1310 | __ B(GetExitLabel()); |
| 1311 | } |
| 1312 | |
| 1313 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1314 | |
| 1315 | private: |
| 1316 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1317 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1318 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1319 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1320 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1321 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1322 | } |
| 1323 | } |
| 1324 | // We shall never fail to find a free caller-save register, as |
| 1325 | // there are more than two core caller-save registers on ARM64 |
| 1326 | // (meaning it is possible to find one which is different from |
| 1327 | // `ref` and `obj`). |
| 1328 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1329 | LOG(FATAL) << "Could not find a free register"; |
| 1330 | UNREACHABLE(); |
| 1331 | } |
| 1332 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1333 | const Location out_; |
| 1334 | const Location ref_; |
| 1335 | const Location obj_; |
| 1336 | const uint32_t offset_; |
| 1337 | // An additional location containing an index to an array. |
| 1338 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1339 | // UnsafeGetObjectVolatile intrinsics. |
| 1340 | const Location index_; |
| 1341 | |
| 1342 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1343 | }; |
| 1344 | |
| 1345 | // Slow path generating a read barrier for a GC root. |
| 1346 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1347 | public: |
| 1348 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1349 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1350 | DCHECK(kEmitCompilerReadBarrier); |
| 1351 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1352 | |
| 1353 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1354 | LocationSummary* locations = instruction_->GetLocations(); |
| 1355 | Primitive::Type type = Primitive::kPrimNot; |
| 1356 | DCHECK(locations->CanCall()); |
| 1357 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1358 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1359 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1360 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1361 | |
| 1362 | __ Bind(GetEntryLabel()); |
| 1363 | SaveLiveRegisters(codegen, locations); |
| 1364 | |
| 1365 | InvokeRuntimeCallingConvention calling_convention; |
| 1366 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1367 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1368 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1369 | // thus we need a 64-bit move here, and we cannot use |
| 1370 | // |
| 1371 | // arm64_codegen->MoveLocation( |
| 1372 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1373 | // root_, |
| 1374 | // type); |
| 1375 | // |
| 1376 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 1377 | // reference type (`Primitive::kPrimNot`). |
| 1378 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1379 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1380 | instruction_, |
| 1381 | instruction_->GetDexPc(), |
| 1382 | this); |
| 1383 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1384 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1385 | |
| 1386 | RestoreLiveRegisters(codegen, locations); |
| 1387 | __ B(GetExitLabel()); |
| 1388 | } |
| 1389 | |
| 1390 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1391 | |
| 1392 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1393 | const Location out_; |
| 1394 | const Location root_; |
| 1395 | |
| 1396 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1397 | }; |
| 1398 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1399 | #undef __ |
| 1400 | |
| 1401 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
| 1402 | Location next_location; |
| 1403 | if (type == Primitive::kPrimVoid) { |
| 1404 | LOG(FATAL) << "Unreachable type " << type; |
| 1405 | } |
| 1406 | |
| 1407 | if (Primitive::IsFloatingPointType(type) && |
| 1408 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1409 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1410 | } else if (!Primitive::IsFloatingPointType(type) && |
| 1411 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 1412 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1413 | } else { |
| 1414 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1415 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1416 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1417 | } |
| 1418 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1419 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1420 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1421 | return next_location; |
| 1422 | } |
| 1423 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1424 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1425 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1426 | } |
| 1427 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1428 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1429 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1430 | const CompilerOptions& compiler_options, |
| 1431 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1432 | : CodeGenerator(graph, |
| 1433 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1434 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1435 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1436 | callee_saved_core_registers.GetList(), |
| 1437 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1438 | compiler_options, |
| 1439 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1440 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1441 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1442 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1443 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1444 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1445 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1446 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1447 | uint32_literals_(std::less<uint32_t>(), |
| 1448 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1449 | uint64_literals_(std::less<uint64_t>(), |
| 1450 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1451 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1452 | pc_relative_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1453 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1454 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1455 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1456 | baker_read_barrier_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1457 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1458 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1459 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1460 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1461 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1462 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1463 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1464 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1465 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1466 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1467 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1468 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1469 | jump_table->EmitTable(this); |
| 1470 | } |
| 1471 | } |
| 1472 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1473 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1474 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1475 | // Ensure we emit the literal pool. |
| 1476 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1477 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1478 | CodeGenerator::Finalize(allocator); |
| 1479 | } |
| 1480 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1481 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1482 | // Note: There are 6 kinds of moves: |
| 1483 | // 1. constant -> GPR/FPR (non-cycle) |
| 1484 | // 2. constant -> stack (non-cycle) |
| 1485 | // 3. GPR/FPR -> GPR/FPR |
| 1486 | // 4. GPR/FPR -> stack |
| 1487 | // 5. stack -> GPR/FPR |
| 1488 | // 6. stack -> stack (non-cycle) |
| 1489 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1490 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1491 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1492 | // dependency. |
| 1493 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1494 | } |
| 1495 | |
| 1496 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1497 | vixl_temps_.Close(); |
| 1498 | } |
| 1499 | |
| 1500 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1501 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1502 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1503 | || kind == Location::kSIMDStackSlot); |
| 1504 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1505 | ? Location::kFpuRegister |
| 1506 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1507 | Location scratch = GetScratchLocation(kind); |
| 1508 | if (!scratch.Equals(Location::NoLocation())) { |
| 1509 | return scratch; |
| 1510 | } |
| 1511 | // Allocate from VIXL temp registers. |
| 1512 | if (kind == Location::kRegister) { |
| 1513 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1514 | } else { |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1515 | DCHECK_EQ(kind, Location::kFpuRegister); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1516 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1517 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1518 | : vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1519 | } |
| 1520 | AddScratchLocation(scratch); |
| 1521 | return scratch; |
| 1522 | } |
| 1523 | |
| 1524 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1525 | if (loc.IsRegister()) { |
| 1526 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1527 | } else { |
| 1528 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1529 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1530 | } |
| 1531 | RemoveScratchLocation(loc); |
| 1532 | } |
| 1533 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1534 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1535 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1536 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1539 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1540 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1541 | __ Bind(&frame_entry_label_); |
| 1542 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1543 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1544 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1545 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1546 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1547 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1548 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1549 | { |
| 1550 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1551 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1552 | kInstructionSize, |
| 1553 | CodeBufferCheckScope::kExactSize); |
| 1554 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1555 | RecordPcInfo(nullptr, 0); |
| 1556 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1557 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1558 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1559 | if (!HasEmptyFrame()) { |
| 1560 | int frame_size = GetFrameSize(); |
| 1561 | // Stack layout: |
| 1562 | // sp[frame_size - 8] : lr. |
| 1563 | // ... : other preserved core registers. |
| 1564 | // ... : other preserved fp registers. |
| 1565 | // ... : reserved frame space. |
| 1566 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1567 | |
| 1568 | // Save the current method if we need it. Note that we do not |
| 1569 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1570 | // in the SSA graph. |
| 1571 | if (RequiresCurrentMethod()) { |
| 1572 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1573 | } else { |
| 1574 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1575 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1576 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1577 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1578 | frame_size - GetCoreSpillSize()); |
| 1579 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1580 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1581 | |
| 1582 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1583 | // Initialize should_deoptimize flag to 0. |
| 1584 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1585 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1586 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1587 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1591 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1592 | if (!HasEmptyFrame()) { |
| 1593 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1594 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1595 | frame_size - FrameEntrySpillSize()); |
| 1596 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1597 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1598 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1599 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1600 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1601 | __ Ret(); |
| 1602 | GetAssembler()->cfi().RestoreState(); |
| 1603 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1604 | } |
| 1605 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1606 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1607 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1608 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1609 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1610 | } |
| 1611 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1612 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1613 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1614 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1615 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1616 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1617 | } |
| 1618 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1619 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1620 | __ Bind(GetLabelOf(block)); |
| 1621 | } |
| 1622 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1623 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1624 | DCHECK(location.IsRegister()); |
| 1625 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1626 | } |
| 1627 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1628 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1629 | if (location.IsRegister()) { |
| 1630 | locations->AddTemp(location); |
| 1631 | } else { |
| 1632 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1633 | } |
| 1634 | } |
| 1635 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1636 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1637 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1638 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1639 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1640 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1641 | if (value_can_be_null) { |
| 1642 | __ Cbz(value, &done); |
| 1643 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1644 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1645 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1646 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1647 | if (value_can_be_null) { |
| 1648 | __ Bind(&done); |
| 1649 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1650 | } |
| 1651 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1652 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1653 | // Blocked core registers: |
| 1654 | // lr : Runtime reserved. |
| 1655 | // tr : Runtime reserved. |
| 1656 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1657 | // ip1 : VIXL core temp. |
| 1658 | // ip0 : VIXL core temp. |
| 1659 | // |
| 1660 | // Blocked fp registers: |
| 1661 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1662 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1663 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1664 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1665 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1666 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1667 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1668 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1669 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1670 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1671 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1672 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1673 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1674 | // Stubs do not save callee-save floating point registers. If the graph |
| 1675 | // is debuggable, we need to deal with these registers differently. For |
| 1676 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1677 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1678 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1679 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1680 | } |
| 1681 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1682 | } |
| 1683 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1684 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1685 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1686 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1687 | return kArm64WordSize; |
| 1688 | } |
| 1689 | |
| 1690 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1691 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1692 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1693 | return kArm64WordSize; |
| 1694 | } |
| 1695 | |
| 1696 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1697 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1698 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1699 | return kArm64WordSize; |
| 1700 | } |
| 1701 | |
| 1702 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1703 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1704 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1705 | return kArm64WordSize; |
| 1706 | } |
| 1707 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1708 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1709 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1713 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1714 | } |
| 1715 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1716 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1717 | if (constant->IsIntConstant()) { |
| 1718 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1719 | } else if (constant->IsLongConstant()) { |
| 1720 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1721 | } else if (constant->IsNullConstant()) { |
| 1722 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1723 | } else if (constant->IsFloatConstant()) { |
| 1724 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1725 | } else { |
| 1726 | DCHECK(constant->IsDoubleConstant()); |
| 1727 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1728 | } |
| 1729 | } |
| 1730 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1731 | |
| 1732 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1733 | DCHECK(constant.IsConstant()); |
| 1734 | HConstant* cst = constant.GetConstant(); |
| 1735 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1736 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1737 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1738 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1739 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1740 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1741 | } |
| 1742 | |
Roland Levillain | 952b235 | 2017-05-03 19:49:14 +0100 | [diff] [blame] | 1743 | // Allocate a scratch register from the VIXL pool, querying first |
| 1744 | // the floating-point register pool, and then the core register |
| 1745 | // pool. This is essentially a reimplementation of |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1746 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1747 | // using a different allocation strategy. |
| 1748 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1749 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1750 | int size_in_bits) { |
| 1751 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1752 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1753 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1754 | } |
| 1755 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1756 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1757 | Location source, |
| 1758 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1759 | if (source.Equals(destination)) { |
| 1760 | return; |
| 1761 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1762 | |
| 1763 | // A valid move can always be inferred from the destination and source |
| 1764 | // locations. When moving from and to a register, the argument type can be |
| 1765 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1766 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1767 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1768 | |
| 1769 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1770 | if (unspecified_type) { |
| 1771 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1772 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1773 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1774 | || src_cst->IsFloatConstant() |
| 1775 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1776 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1777 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1778 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1779 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1780 | // type is appropriate. Else the source is a register, and since the |
| 1781 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1782 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1783 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1784 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1785 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1786 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1787 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1788 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1789 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1790 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1791 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1792 | } else if (source.IsSIMDStackSlot()) { |
| 1793 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1794 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1795 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1796 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1797 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1798 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1799 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1800 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1801 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1802 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1803 | ? Primitive::kPrimLong |
| 1804 | : Primitive::kPrimInt; |
| 1805 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1806 | } |
| 1807 | } else { |
| 1808 | DCHECK(source.IsFpuRegister()); |
| 1809 | if (destination.IsRegister()) { |
| 1810 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1811 | ? Primitive::kPrimDouble |
| 1812 | : Primitive::kPrimFloat; |
| 1813 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1814 | } else { |
| 1815 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1816 | if (GetGraph()->HasSIMD()) { |
| 1817 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1818 | } else { |
| 1819 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1820 | } |
| 1821 | } |
| 1822 | } |
| 1823 | } else if (destination.IsSIMDStackSlot()) { |
| 1824 | if (source.IsFpuRegister()) { |
| 1825 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1826 | } else { |
| 1827 | DCHECK(source.IsSIMDStackSlot()); |
| 1828 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1829 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1830 | Register temp = temps.AcquireX(); |
| 1831 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1832 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1833 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1834 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1835 | } else { |
| 1836 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1837 | __ Ldr(temp, StackOperandFrom(source)); |
| 1838 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1839 | } |
| 1840 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1841 | } else { // The destination is not a register. It must be a stack slot. |
| 1842 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1843 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1844 | if (unspecified_type) { |
| 1845 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1846 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1847 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1848 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1849 | } |
| 1850 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1851 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1852 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1853 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1854 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1855 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1856 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1857 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1858 | HConstant* src_cst = source.GetConstant(); |
| 1859 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1860 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1861 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1862 | ? Register(xzr) |
| 1863 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1864 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1865 | if (src_cst->IsIntConstant()) { |
| 1866 | temp = temps.AcquireW(); |
| 1867 | } else if (src_cst->IsLongConstant()) { |
| 1868 | temp = temps.AcquireX(); |
| 1869 | } else if (src_cst->IsFloatConstant()) { |
| 1870 | temp = temps.AcquireS(); |
| 1871 | } else { |
| 1872 | DCHECK(src_cst->IsDoubleConstant()); |
| 1873 | temp = temps.AcquireD(); |
| 1874 | } |
| 1875 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1876 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1877 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1878 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1879 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1880 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1881 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1882 | // Use any scratch register (a core or a floating-point one) |
| 1883 | // from VIXL scratch register pools as a temporary. |
| 1884 | // |
| 1885 | // We used to only use the FP scratch register pool, but in some |
| 1886 | // rare cases the only register from this pool (D31) would |
| 1887 | // already be used (e.g. within a ParallelMove instruction, when |
| 1888 | // a move is blocked by a another move requiring a scratch FP |
| 1889 | // register, which would reserve D31). To prevent this issue, we |
| 1890 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1891 | // |
| 1892 | // 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] | 1893 | // demand of scratch core registers is higher. This is why we |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1894 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1895 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1896 | // allocates core scratch registers first. |
| 1897 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1898 | GetVIXLAssembler(), |
| 1899 | &temps, |
| 1900 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1901 | __ Ldr(temp, StackOperandFrom(source)); |
| 1902 | __ Str(temp, StackOperandFrom(destination)); |
| 1903 | } |
| 1904 | } |
| 1905 | } |
| 1906 | |
| 1907 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1908 | CPURegister dst, |
| 1909 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1910 | switch (type) { |
| 1911 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1912 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1913 | break; |
| 1914 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1915 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1916 | break; |
| 1917 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1918 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1919 | break; |
| 1920 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1921 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1922 | break; |
| 1923 | case Primitive::kPrimInt: |
| 1924 | case Primitive::kPrimNot: |
| 1925 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1926 | case Primitive::kPrimFloat: |
| 1927 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1928 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1929 | __ Ldr(dst, src); |
| 1930 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1931 | case Primitive::kPrimVoid: |
| 1932 | LOG(FATAL) << "Unreachable type " << type; |
| 1933 | } |
| 1934 | } |
| 1935 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1936 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1937 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1938 | const MemOperand& src, |
| 1939 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1940 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1941 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1942 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1943 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1944 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1945 | DCHECK(!src.IsPreIndex()); |
| 1946 | DCHECK(!src.IsPostIndex()); |
| 1947 | |
| 1948 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1949 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1950 | { |
| 1951 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1952 | MemOperand base = MemOperand(temp_base); |
| 1953 | switch (type) { |
| 1954 | case Primitive::kPrimBoolean: |
| 1955 | { |
| 1956 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1957 | __ ldarb(Register(dst), base); |
| 1958 | if (needs_null_check) { |
| 1959 | MaybeRecordImplicitNullCheck(instruction); |
| 1960 | } |
| 1961 | } |
| 1962 | break; |
| 1963 | case Primitive::kPrimByte: |
| 1964 | { |
| 1965 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1966 | __ ldarb(Register(dst), base); |
| 1967 | if (needs_null_check) { |
| 1968 | MaybeRecordImplicitNullCheck(instruction); |
| 1969 | } |
| 1970 | } |
| 1971 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1972 | break; |
| 1973 | case Primitive::kPrimChar: |
| 1974 | { |
| 1975 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1976 | __ ldarh(Register(dst), base); |
| 1977 | if (needs_null_check) { |
| 1978 | MaybeRecordImplicitNullCheck(instruction); |
| 1979 | } |
| 1980 | } |
| 1981 | break; |
| 1982 | case Primitive::kPrimShort: |
| 1983 | { |
| 1984 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1985 | __ ldarh(Register(dst), base); |
| 1986 | if (needs_null_check) { |
| 1987 | MaybeRecordImplicitNullCheck(instruction); |
| 1988 | } |
| 1989 | } |
| 1990 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1991 | break; |
| 1992 | case Primitive::kPrimInt: |
| 1993 | case Primitive::kPrimNot: |
| 1994 | case Primitive::kPrimLong: |
| 1995 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
| 1996 | { |
| 1997 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1998 | __ ldar(Register(dst), base); |
| 1999 | if (needs_null_check) { |
| 2000 | MaybeRecordImplicitNullCheck(instruction); |
| 2001 | } |
| 2002 | } |
| 2003 | break; |
| 2004 | case Primitive::kPrimFloat: |
| 2005 | case Primitive::kPrimDouble: { |
| 2006 | DCHECK(dst.IsFPRegister()); |
| 2007 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2008 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2009 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2010 | { |
| 2011 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2012 | __ ldar(temp, base); |
| 2013 | if (needs_null_check) { |
| 2014 | MaybeRecordImplicitNullCheck(instruction); |
| 2015 | } |
| 2016 | } |
| 2017 | __ Fmov(FPRegister(dst), temp); |
| 2018 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2019 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2020 | case Primitive::kPrimVoid: |
| 2021 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2022 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2023 | } |
| 2024 | } |
| 2025 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2026 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2027 | CPURegister src, |
| 2028 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2029 | switch (type) { |
| 2030 | case Primitive::kPrimBoolean: |
| 2031 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2032 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2033 | break; |
| 2034 | case Primitive::kPrimChar: |
| 2035 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2036 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2037 | break; |
| 2038 | case Primitive::kPrimInt: |
| 2039 | case Primitive::kPrimNot: |
| 2040 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2041 | case Primitive::kPrimFloat: |
| 2042 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2043 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2044 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2045 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2046 | case Primitive::kPrimVoid: |
| 2047 | LOG(FATAL) << "Unreachable type " << type; |
| 2048 | } |
| 2049 | } |
| 2050 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2051 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
| 2052 | Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2053 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2054 | const MemOperand& dst, |
| 2055 | bool needs_null_check) { |
| 2056 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2057 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2058 | Register temp_base = temps.AcquireX(); |
| 2059 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2060 | DCHECK(!dst.IsPreIndex()); |
| 2061 | DCHECK(!dst.IsPostIndex()); |
| 2062 | |
| 2063 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2064 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2065 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2066 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2067 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2068 | switch (type) { |
| 2069 | case Primitive::kPrimBoolean: |
| 2070 | case Primitive::kPrimByte: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2071 | { |
| 2072 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2073 | __ stlrb(Register(src), base); |
| 2074 | if (needs_null_check) { |
| 2075 | MaybeRecordImplicitNullCheck(instruction); |
| 2076 | } |
| 2077 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2078 | break; |
| 2079 | case Primitive::kPrimChar: |
| 2080 | case Primitive::kPrimShort: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2081 | { |
| 2082 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2083 | __ stlrh(Register(src), base); |
| 2084 | if (needs_null_check) { |
| 2085 | MaybeRecordImplicitNullCheck(instruction); |
| 2086 | } |
| 2087 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2088 | break; |
| 2089 | case Primitive::kPrimInt: |
| 2090 | case Primitive::kPrimNot: |
| 2091 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2092 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2093 | { |
| 2094 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2095 | __ stlr(Register(src), base); |
| 2096 | if (needs_null_check) { |
| 2097 | MaybeRecordImplicitNullCheck(instruction); |
| 2098 | } |
| 2099 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2100 | break; |
| 2101 | case Primitive::kPrimFloat: |
| 2102 | case Primitive::kPrimDouble: { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2103 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2104 | Register temp_src; |
| 2105 | if (src.IsZero()) { |
| 2106 | // The zero register is used to avoid synthesizing zero constants. |
| 2107 | temp_src = Register(src); |
| 2108 | } else { |
| 2109 | DCHECK(src.IsFPRegister()); |
| 2110 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2111 | __ Fmov(temp_src, FPRegister(src)); |
| 2112 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2113 | { |
| 2114 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2115 | __ stlr(temp_src, base); |
| 2116 | if (needs_null_check) { |
| 2117 | MaybeRecordImplicitNullCheck(instruction); |
| 2118 | } |
| 2119 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2120 | break; |
| 2121 | } |
| 2122 | case Primitive::kPrimVoid: |
| 2123 | LOG(FATAL) << "Unreachable type " << type; |
| 2124 | } |
| 2125 | } |
| 2126 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2127 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2128 | HInstruction* instruction, |
| 2129 | uint32_t dex_pc, |
| 2130 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2131 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2132 | |
| 2133 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 2134 | { |
| 2135 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 2136 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2137 | __ blr(lr); |
| 2138 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2139 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2140 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2141 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2142 | } |
| 2143 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2144 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2145 | HInstruction* instruction, |
| 2146 | SlowPathCode* slow_path) { |
| 2147 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2148 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2149 | __ Blr(lr); |
| 2150 | } |
| 2151 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2152 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2153 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2154 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2155 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2156 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 2157 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2158 | // 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] | 2159 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 2160 | __ Add(temp, class_reg, status_offset); |
| 2161 | __ Ldar(temp, HeapOperand(temp)); |
| 2162 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 2163 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2164 | __ Bind(slow_path->GetExitLabel()); |
| 2165 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2166 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2167 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2168 | BarrierType type = BarrierAll; |
| 2169 | |
| 2170 | switch (kind) { |
| 2171 | case MemBarrierKind::kAnyAny: |
| 2172 | case MemBarrierKind::kAnyStore: { |
| 2173 | type = BarrierAll; |
| 2174 | break; |
| 2175 | } |
| 2176 | case MemBarrierKind::kLoadAny: { |
| 2177 | type = BarrierReads; |
| 2178 | break; |
| 2179 | } |
| 2180 | case MemBarrierKind::kStoreStore: { |
| 2181 | type = BarrierWrites; |
| 2182 | break; |
| 2183 | } |
| 2184 | default: |
| 2185 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2186 | } |
| 2187 | __ Dmb(InnerShareable, type); |
| 2188 | } |
| 2189 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2190 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2191 | HBasicBlock* successor) { |
| 2192 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2193 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2194 | if (slow_path == nullptr) { |
| 2195 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 2196 | instruction->SetSlowPath(slow_path); |
| 2197 | codegen_->AddSlowPath(slow_path); |
| 2198 | if (successor != nullptr) { |
| 2199 | DCHECK(successor->IsLoopHeader()); |
| 2200 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 2201 | } |
| 2202 | } else { |
| 2203 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2204 | } |
| 2205 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2206 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2207 | Register temp = temps.AcquireW(); |
| 2208 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2209 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2210 | if (successor == nullptr) { |
| 2211 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2212 | __ Bind(slow_path->GetReturnLabel()); |
| 2213 | } else { |
| 2214 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 2215 | __ B(slow_path->GetEntryLabel()); |
| 2216 | // slow_path will return to GetLabelOf(successor). |
| 2217 | } |
| 2218 | } |
| 2219 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2220 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2221 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2222 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2223 | assembler_(codegen->GetAssembler()), |
| 2224 | codegen_(codegen) {} |
| 2225 | |
| 2226 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2227 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2228 | |
| 2229 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 2230 | |
| 2231 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2232 | // Using a base helps identify when we hit such breakpoints. |
| 2233 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2234 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 2235 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 2236 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 2237 | }; |
| 2238 | |
| 2239 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2240 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2241 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 2242 | } \ |
| 2243 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 2244 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 2245 | locations->SetOut(Location::Any()); \ |
| 2246 | } |
| 2247 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 2248 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 2249 | |
| 2250 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2251 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2252 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2253 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2254 | DCHECK_EQ(instr->InputCount(), 2U); |
| 2255 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2256 | Primitive::Type type = instr->GetResultType(); |
| 2257 | switch (type) { |
| 2258 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2259 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2260 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2261 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2262 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2263 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2264 | |
| 2265 | case Primitive::kPrimFloat: |
| 2266 | case Primitive::kPrimDouble: |
| 2267 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2268 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2269 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2270 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2271 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2272 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2273 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2274 | } |
| 2275 | } |
| 2276 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2277 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2278 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2279 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2280 | |
| 2281 | bool object_field_get_with_read_barrier = |
| 2282 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2283 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2284 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2285 | object_field_get_with_read_barrier ? |
| 2286 | LocationSummary::kCallOnSlowPath : |
| 2287 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2288 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2289 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2290 | // We need a temporary register for the read barrier marking slow |
| 2291 | // path in CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2292 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2293 | !Runtime::Current()->UseJitCompilation() && |
| 2294 | !field_info.IsVolatile()) { |
| 2295 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2296 | // non-volatile loads we need a temporary only if the offset is too big. |
| 2297 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2298 | locations->AddTemp(FixedTempLocation()); |
| 2299 | } |
| 2300 | } else { |
| 2301 | locations->AddTemp(Location::RequiresRegister()); |
| 2302 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2303 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2304 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2305 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2306 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2307 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2308 | // The output overlaps for an object field get when read barriers |
| 2309 | // are enabled: we do not want the load to overwrite the object's |
| 2310 | // location, as we need it to emit the read barrier. |
| 2311 | locations->SetOut( |
| 2312 | Location::RequiresRegister(), |
| 2313 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2314 | } |
| 2315 | } |
| 2316 | |
| 2317 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2318 | const FieldInfo& field_info) { |
| 2319 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2320 | LocationSummary* locations = instruction->GetLocations(); |
| 2321 | Location base_loc = locations->InAt(0); |
| 2322 | Location out = locations->Out(); |
| 2323 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2324 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2325 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2326 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2327 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2328 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2329 | // /* HeapReference<Object> */ out = *(base + offset) |
| 2330 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2331 | Location maybe_temp = |
| 2332 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2333 | // Note that potential implicit null checks are handled in this |
| 2334 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2335 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2336 | instruction, |
| 2337 | out, |
| 2338 | base, |
| 2339 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2340 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2341 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2342 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2343 | } else { |
| 2344 | // General case. |
| 2345 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2346 | // Note that a potential implicit null check is handled in this |
| 2347 | // CodeGeneratorARM64::LoadAcquire call. |
| 2348 | // NB: LoadAcquire will record the pc info if needed. |
| 2349 | codegen_->LoadAcquire( |
| 2350 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2351 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2352 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2353 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2354 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2355 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2356 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2357 | if (field_type == Primitive::kPrimNot) { |
| 2358 | // If read barriers are enabled, emit read barriers other than |
| 2359 | // Baker's using a slow path (and also unpoison the loaded |
| 2360 | // reference, if heap poisoning is enabled). |
| 2361 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2362 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2363 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2367 | LocationSummary* locations = |
| 2368 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2369 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2370 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2371 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 2372 | } else if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2373 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2374 | } else { |
| 2375 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2376 | } |
| 2377 | } |
| 2378 | |
| 2379 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2380 | const FieldInfo& field_info, |
| 2381 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2382 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2383 | |
| 2384 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2385 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2386 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2387 | Offset offset = field_info.GetFieldOffset(); |
| 2388 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2389 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2390 | { |
| 2391 | // We use a block to end the scratch scope before the write barrier, thus |
| 2392 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2393 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2394 | |
| 2395 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 2396 | DCHECK(value.IsW()); |
| 2397 | Register temp = temps.AcquireW(); |
| 2398 | __ Mov(temp, value.W()); |
| 2399 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2400 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2401 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2402 | |
| 2403 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2404 | codegen_->StoreRelease( |
| 2405 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2406 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2407 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2408 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2409 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2410 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2411 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2415 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2416 | } |
| 2417 | } |
| 2418 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2419 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2420 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2421 | |
| 2422 | switch (type) { |
| 2423 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2424 | case Primitive::kPrimLong: { |
| 2425 | Register dst = OutputRegister(instr); |
| 2426 | Register lhs = InputRegisterAt(instr, 0); |
| 2427 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2428 | if (instr->IsAdd()) { |
| 2429 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2430 | } else if (instr->IsAnd()) { |
| 2431 | __ And(dst, lhs, rhs); |
| 2432 | } else if (instr->IsOr()) { |
| 2433 | __ Orr(dst, lhs, rhs); |
| 2434 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2435 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2436 | } else if (instr->IsRor()) { |
| 2437 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2438 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2439 | __ Ror(dst, lhs, shift); |
| 2440 | } else { |
| 2441 | // Ensure shift distance is in the same size register as the result. If |
| 2442 | // we are rotating a long and the shift comes in a w register originally, |
| 2443 | // we don't need to sxtw for use as an x since the shift distances are |
| 2444 | // all & reg_bits - 1. |
| 2445 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2446 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2447 | } else { |
| 2448 | DCHECK(instr->IsXor()); |
| 2449 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2450 | } |
| 2451 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2452 | } |
| 2453 | case Primitive::kPrimFloat: |
| 2454 | case Primitive::kPrimDouble: { |
| 2455 | FPRegister dst = OutputFPRegister(instr); |
| 2456 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2457 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2458 | if (instr->IsAdd()) { |
| 2459 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2460 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2461 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2462 | } else { |
| 2463 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2464 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2465 | break; |
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 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2468 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2469 | } |
| 2470 | } |
| 2471 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2472 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2473 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2474 | |
| 2475 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2476 | Primitive::Type type = instr->GetResultType(); |
| 2477 | switch (type) { |
| 2478 | case Primitive::kPrimInt: |
| 2479 | case Primitive::kPrimLong: { |
| 2480 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2481 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2482 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2483 | break; |
| 2484 | } |
| 2485 | default: |
| 2486 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2487 | } |
| 2488 | } |
| 2489 | |
| 2490 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2491 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2492 | |
| 2493 | Primitive::Type type = instr->GetType(); |
| 2494 | switch (type) { |
| 2495 | case Primitive::kPrimInt: |
| 2496 | case Primitive::kPrimLong: { |
| 2497 | Register dst = OutputRegister(instr); |
| 2498 | Register lhs = InputRegisterAt(instr, 0); |
| 2499 | Operand rhs = InputOperandAt(instr, 1); |
| 2500 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2501 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2502 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2503 | if (instr->IsShl()) { |
| 2504 | __ Lsl(dst, lhs, shift_value); |
| 2505 | } else if (instr->IsShr()) { |
| 2506 | __ Asr(dst, lhs, shift_value); |
| 2507 | } else { |
| 2508 | __ Lsr(dst, lhs, shift_value); |
| 2509 | } |
| 2510 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2511 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2512 | |
| 2513 | if (instr->IsShl()) { |
| 2514 | __ Lsl(dst, lhs, rhs_reg); |
| 2515 | } else if (instr->IsShr()) { |
| 2516 | __ Asr(dst, lhs, rhs_reg); |
| 2517 | } else { |
| 2518 | __ Lsr(dst, lhs, rhs_reg); |
| 2519 | } |
| 2520 | } |
| 2521 | break; |
| 2522 | } |
| 2523 | default: |
| 2524 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2525 | } |
| 2526 | } |
| 2527 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2528 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2529 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2533 | HandleBinaryOp(instruction); |
| 2534 | } |
| 2535 | |
| 2536 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2537 | HandleBinaryOp(instruction); |
| 2538 | } |
| 2539 | |
| 2540 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2541 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2542 | } |
| 2543 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2544 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2545 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 2546 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2547 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2548 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2549 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2550 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2551 | } |
| 2552 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2553 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2554 | Register dst = OutputRegister(instr); |
| 2555 | Register lhs = InputRegisterAt(instr, 0); |
| 2556 | Register rhs = InputRegisterAt(instr, 1); |
| 2557 | |
| 2558 | switch (instr->GetOpKind()) { |
| 2559 | case HInstruction::kAnd: |
| 2560 | __ Bic(dst, lhs, rhs); |
| 2561 | break; |
| 2562 | case HInstruction::kOr: |
| 2563 | __ Orn(dst, lhs, rhs); |
| 2564 | break; |
| 2565 | case HInstruction::kXor: |
| 2566 | __ Eon(dst, lhs, rhs); |
| 2567 | break; |
| 2568 | default: |
| 2569 | LOG(FATAL) << "Unreachable"; |
| 2570 | } |
| 2571 | } |
| 2572 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2573 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2574 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2575 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 2576 | instruction->GetType() == Primitive::kPrimLong); |
| 2577 | LocationSummary* locations = |
| 2578 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2579 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2580 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2581 | } else { |
| 2582 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2583 | } |
| 2584 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2585 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2586 | } |
| 2587 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2588 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2589 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2590 | Primitive::Type type = instruction->GetType(); |
| 2591 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 2592 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2593 | Register out = OutputRegister(instruction); |
| 2594 | Register left; |
| 2595 | if (kind != HInstruction::kNeg) { |
| 2596 | left = InputRegisterAt(instruction, 0); |
| 2597 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2598 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2599 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2600 | // conversion) can have a different type from the current instruction's type, |
| 2601 | // so we manually indicate the type. |
| 2602 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2603 | Operand right_operand(0); |
| 2604 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2605 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2606 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2607 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2608 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2609 | right_operand = Operand(right_reg, |
| 2610 | helpers::ShiftFromOpKind(op_kind), |
| 2611 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | // Logical binary operations do not support extension operations in the |
| 2615 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2616 | // the extension as a separate instruction. |
| 2617 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2618 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2619 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2620 | kind != HInstruction::kNeg)); |
| 2621 | switch (kind) { |
| 2622 | case HInstruction::kAdd: |
| 2623 | __ Add(out, left, right_operand); |
| 2624 | break; |
| 2625 | case HInstruction::kAnd: |
| 2626 | __ And(out, left, right_operand); |
| 2627 | break; |
| 2628 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2629 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2630 | __ Neg(out, right_operand); |
| 2631 | break; |
| 2632 | case HInstruction::kOr: |
| 2633 | __ Orr(out, left, right_operand); |
| 2634 | break; |
| 2635 | case HInstruction::kSub: |
| 2636 | __ Sub(out, left, right_operand); |
| 2637 | break; |
| 2638 | case HInstruction::kXor: |
| 2639 | __ Eor(out, left, right_operand); |
| 2640 | break; |
| 2641 | default: |
| 2642 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2643 | UNREACHABLE(); |
| 2644 | } |
| 2645 | } |
| 2646 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2647 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2648 | LocationSummary* locations = |
| 2649 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2650 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2651 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2652 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2653 | } |
| 2654 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2655 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2656 | __ Add(OutputRegister(instruction), |
| 2657 | InputRegisterAt(instruction, 0), |
| 2658 | Operand(InputOperandAt(instruction, 1))); |
| 2659 | } |
| 2660 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 2661 | void LocationsBuilderARM64::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 2662 | LocationSummary* locations = |
| 2663 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2664 | |
| 2665 | HIntConstant* shift = instruction->GetShift()->AsIntConstant(); |
| 2666 | |
| 2667 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2668 | // For byte case we don't need to shift the index variable so we can encode the data offset into |
| 2669 | // ADD instruction. For other cases we prefer the data_offset to be in register; that will hoist |
| 2670 | // data offset constant generation out of the loop and reduce the critical path length in the |
| 2671 | // loop. |
| 2672 | locations->SetInAt(1, shift->GetValue() == 0 |
| 2673 | ? Location::ConstantLocation(instruction->GetOffset()->AsIntConstant()) |
| 2674 | : Location::RequiresRegister()); |
| 2675 | locations->SetInAt(2, Location::ConstantLocation(shift)); |
| 2676 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2677 | } |
| 2678 | |
| 2679 | void InstructionCodeGeneratorARM64::VisitIntermediateAddressIndex( |
| 2680 | HIntermediateAddressIndex* instruction) { |
| 2681 | Register index_reg = InputRegisterAt(instruction, 0); |
| 2682 | uint32_t shift = Int64ConstantFrom(instruction->GetLocations()->InAt(2)); |
| 2683 | uint32_t offset = instruction->GetOffset()->AsIntConstant()->GetValue(); |
| 2684 | |
| 2685 | if (shift == 0) { |
| 2686 | __ Add(OutputRegister(instruction), index_reg, offset); |
| 2687 | } else { |
| 2688 | Register offset_reg = InputRegisterAt(instruction, 1); |
| 2689 | __ Add(OutputRegister(instruction), offset_reg, Operand(index_reg, LSL, shift)); |
| 2690 | } |
| 2691 | } |
| 2692 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2693 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2694 | LocationSummary* locations = |
| 2695 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2696 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2697 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2698 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2699 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2700 | // Don't allocate register for Mneg instruction. |
| 2701 | } else { |
| 2702 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2703 | Location::RequiresRegister()); |
| 2704 | } |
| 2705 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2706 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2707 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2708 | } |
| 2709 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2710 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2711 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2712 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2713 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2714 | |
| 2715 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2716 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2717 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2718 | if (instr->GetType() == Primitive::kPrimLong && |
| 2719 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2720 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2721 | vixl::aarch64::Instruction* prev = |
| 2722 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2723 | if (prev->IsLoadOrStore()) { |
| 2724 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2725 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2726 | __ nop(); |
| 2727 | } |
| 2728 | } |
| 2729 | |
| 2730 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2731 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2732 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2733 | } else { |
| 2734 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2735 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2736 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2737 | __ Mneg(res, mul_left, mul_right); |
| 2738 | } else { |
| 2739 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2740 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2741 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2742 | } |
| 2743 | } |
| 2744 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2745 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2746 | bool object_array_get_with_read_barrier = |
| 2747 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2748 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2749 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2750 | object_array_get_with_read_barrier ? |
| 2751 | LocationSummary::kCallOnSlowPath : |
| 2752 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2753 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2754 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 2755 | // We need a temporary register for the read barrier marking slow |
| 2756 | // path in CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2757 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2758 | !Runtime::Current()->UseJitCompilation() && |
| 2759 | instruction->GetIndex()->IsConstant()) { |
| 2760 | // Array loads with constant index are treated as field loads. |
| 2761 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2762 | // constant index loads we need a temporary only if the offset is too big. |
| 2763 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2764 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| 2765 | offset += index << Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 2766 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2767 | locations->AddTemp(FixedTempLocation()); |
| 2768 | } |
| 2769 | } else { |
| 2770 | locations->AddTemp(Location::RequiresRegister()); |
| 2771 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2772 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2773 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2774 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2775 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2776 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2777 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2778 | // The output overlaps in the case of an object array get with |
| 2779 | // read barriers enabled: we do not want the move to overwrite the |
| 2780 | // array's location, as we need it to emit the read barrier. |
| 2781 | locations->SetOut( |
| 2782 | Location::RequiresRegister(), |
| 2783 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2784 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2788 | Primitive::Type type = instruction->GetType(); |
| 2789 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2790 | LocationSummary* locations = instruction->GetLocations(); |
| 2791 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2792 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2793 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2794 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2795 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2796 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2797 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2798 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2799 | // The read barrier instrumentation of object ArrayGet instructions |
| 2800 | // does not support the HIntermediateAddress instruction. |
| 2801 | DCHECK(!((type == Primitive::kPrimNot) && |
| 2802 | instruction->GetArray()->IsIntermediateAddress() && |
| 2803 | kEmitCompilerReadBarrier)); |
| 2804 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2805 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2806 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2807 | // Note that a potential implicit null check is handled in the |
| 2808 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2809 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2810 | if (index.IsConstant()) { |
| 2811 | // Array load with a constant index can be treated as a field load. |
| 2812 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2813 | Location maybe_temp = |
| 2814 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2815 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2816 | out, |
| 2817 | obj.W(), |
| 2818 | offset, |
| 2819 | maybe_temp, |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2820 | /* needs_null_check */ false, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2821 | /* use_load_acquire */ false); |
| 2822 | } else { |
| 2823 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
| 2824 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2825 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2826 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2827 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2828 | // General case. |
| 2829 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2830 | Register length; |
| 2831 | if (maybe_compressed_char_at) { |
| 2832 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2833 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2834 | { |
| 2835 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2836 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2837 | |
| 2838 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2839 | DCHECK_LT(count_offset, offset); |
| 2840 | int64_t adjusted_offset = |
| 2841 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2842 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2843 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2844 | } else { |
| 2845 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2846 | } |
| 2847 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2848 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2849 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2850 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2851 | if (maybe_compressed_char_at) { |
| 2852 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2853 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2854 | "Expecting 0=compressed, 1=uncompressed"); |
| 2855 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2856 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2857 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2858 | __ B(&done); |
| 2859 | __ Bind(&uncompressed_load); |
| 2860 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2861 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2862 | __ Bind(&done); |
| 2863 | } else { |
| 2864 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2865 | source = HeapOperand(obj, offset); |
| 2866 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2867 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2868 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2869 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2870 | // We do not need to compute the intermediate address from the array: the |
| 2871 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2872 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2873 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2874 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2875 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2876 | } |
| 2877 | temp = obj; |
| 2878 | } else { |
| 2879 | __ Add(temp, obj, offset); |
| 2880 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2881 | if (maybe_compressed_char_at) { |
| 2882 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2883 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2884 | "Expecting 0=compressed, 1=uncompressed"); |
| 2885 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2886 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2887 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2888 | __ B(&done); |
| 2889 | __ Bind(&uncompressed_load); |
| 2890 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2891 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2892 | __ Bind(&done); |
| 2893 | } else { |
| 2894 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2895 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2896 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2897 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2898 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2899 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2900 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2901 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2902 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2903 | |
| 2904 | if (type == Primitive::kPrimNot) { |
| 2905 | static_assert( |
| 2906 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2907 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2908 | Location obj_loc = locations->InAt(0); |
| 2909 | if (index.IsConstant()) { |
| 2910 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2911 | } else { |
| 2912 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2913 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2914 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2915 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2916 | } |
| 2917 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2918 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2919 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2920 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2921 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2925 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2926 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2927 | { |
| 2928 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2929 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2930 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2931 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2932 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2933 | // Mask out compression flag from String's array length. |
| 2934 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2935 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2936 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2937 | } |
| 2938 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2939 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2940 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2941 | |
| 2942 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2943 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2944 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2945 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2946 | LocationSummary::kCallOnSlowPath : |
| 2947 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2948 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2949 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2950 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2951 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 2952 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2953 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2954 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2955 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2956 | } |
| 2957 | } |
| 2958 | |
| 2959 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2960 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2961 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2962 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2963 | bool needs_write_barrier = |
| 2964 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2965 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2966 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2967 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2968 | CPURegister source = value; |
| 2969 | Location index = locations->InAt(1); |
| 2970 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2971 | MemOperand destination = HeapOperand(array); |
| 2972 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2973 | |
| 2974 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2975 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2976 | if (index.IsConstant()) { |
| 2977 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2978 | destination = HeapOperand(array, offset); |
| 2979 | } else { |
| 2980 | UseScratchRegisterScope temps(masm); |
| 2981 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2982 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2983 | // We do not need to compute the intermediate address from the array: the |
| 2984 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2985 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2986 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2987 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2988 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2989 | } |
| 2990 | temp = array; |
| 2991 | } else { |
| 2992 | __ Add(temp, array, offset); |
| 2993 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2994 | destination = HeapOperand(temp, |
| 2995 | XRegisterFrom(index), |
| 2996 | LSL, |
| 2997 | Primitive::ComponentSizeShift(value_type)); |
| 2998 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2999 | { |
| 3000 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3001 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3002 | codegen_->Store(value_type, value, destination); |
| 3003 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3004 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3005 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 3006 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3007 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3008 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3009 | { |
| 3010 | // We use a block to end the scratch scope before the write barrier, thus |
| 3011 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 3012 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3013 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3014 | if (index.IsConstant()) { |
| 3015 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3016 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3017 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 3018 | destination = HeapOperand(temp, |
| 3019 | XRegisterFrom(index), |
| 3020 | LSL, |
| 3021 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3022 | } |
| 3023 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3024 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3025 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3026 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3027 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3028 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3029 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 3030 | codegen_->AddSlowPath(slow_path); |
| 3031 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3032 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3033 | __ Cbnz(Register(value), &non_zero); |
| 3034 | if (!index.IsConstant()) { |
| 3035 | __ Add(temp, array, offset); |
| 3036 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3037 | { |
| 3038 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 3039 | // emitted. |
| 3040 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3041 | __ Str(wzr, destination); |
| 3042 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3043 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3044 | __ B(&done); |
| 3045 | __ Bind(&non_zero); |
| 3046 | } |
| 3047 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3048 | // Note that when Baker read barriers are enabled, the type |
| 3049 | // checks are performed without read barriers. This is fine, |
| 3050 | // even in the case where a class object is in the from-space |
| 3051 | // after the flip, as a comparison involving such a type would |
| 3052 | // not produce a false positive; it may of course produce a |
| 3053 | // false negative, in which case we would take the ArraySet |
| 3054 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3055 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3056 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 3057 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3058 | { |
| 3059 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3060 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3061 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 3062 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3063 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3064 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3065 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3066 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 3067 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 3068 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3069 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 3070 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 3071 | // nor `temp2`, as we are comparing two poisoned references. |
| 3072 | __ Cmp(temp, temp2); |
| 3073 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3074 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3075 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3076 | vixl::aarch64::Label do_put; |
| 3077 | __ B(eq, &do_put); |
| 3078 | // If heap poisoning is enabled, the `temp` reference has |
| 3079 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3080 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3081 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3082 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 3083 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 3084 | // If heap poisoning is enabled, no need to unpoison |
| 3085 | // `temp`, as we are comparing against null below. |
| 3086 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 3087 | __ Bind(&do_put); |
| 3088 | } else { |
| 3089 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3090 | } |
| 3091 | } |
| 3092 | |
| 3093 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3094 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3095 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3096 | __ Mov(temp2, value.W()); |
| 3097 | GetAssembler()->PoisonHeapReference(temp2); |
| 3098 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | if (!index.IsConstant()) { |
| 3102 | __ Add(temp, array, offset); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 3103 | } else { |
| 3104 | // We no longer need the `temp` here so release it as the store below may |
| 3105 | // need a scratch register (if the constant index makes the offset too large) |
| 3106 | // and the poisoned `source` could be using the other scratch register. |
| 3107 | temps.Release(temp); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3108 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3109 | { |
| 3110 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3111 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3112 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3113 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3114 | if (!may_need_runtime_call_for_type_check) { |
| 3115 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3116 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3117 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3118 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3119 | |
| 3120 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 3121 | |
| 3122 | if (done.IsLinked()) { |
| 3123 | __ Bind(&done); |
| 3124 | } |
| 3125 | |
| 3126 | if (slow_path != nullptr) { |
| 3127 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3128 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3129 | } |
| 3130 | } |
| 3131 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3132 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3133 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3134 | InvokeRuntimeCallingConvention calling_convention; |
| 3135 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3136 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 3137 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3138 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 3139 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3143 | BoundsCheckSlowPathARM64* slow_path = |
| 3144 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3145 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3146 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 3147 | __ B(slow_path->GetEntryLabel(), hs); |
| 3148 | } |
| 3149 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3150 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3151 | LocationSummary* locations = |
| 3152 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3153 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3154 | if (check->HasUses()) { |
| 3155 | locations->SetOut(Location::SameAsFirstInput()); |
| 3156 | } |
| 3157 | } |
| 3158 | |
| 3159 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3160 | // We assume the class is not null. |
| 3161 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 3162 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 3163 | codegen_->AddSlowPath(slow_path); |
| 3164 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3165 | } |
| 3166 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3167 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3168 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3169 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3170 | } |
| 3171 | |
| 3172 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 3173 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 3174 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3175 | if (rhs_loc.IsConstant()) { |
| 3176 | // 0.0 is the only immediate that can be encoded directly in |
| 3177 | // an FCMP instruction. |
| 3178 | // |
| 3179 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3180 | // specify that in a floating-point comparison, positive zero |
| 3181 | // and negative zero are considered equal, so we can use the |
| 3182 | // literal 0.0 for both cases here. |
| 3183 | // |
| 3184 | // Note however that some methods (Float.equal, Float.compare, |
| 3185 | // Float.compareTo, Double.equal, Double.compare, |
| 3186 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3187 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3188 | // -0.0. So if we ever translate calls to these methods into a |
| 3189 | // HCompare instruction, we must handle the -0.0 case with |
| 3190 | // care here. |
| 3191 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3192 | __ Fcmp(lhs_reg, 0.0); |
| 3193 | } else { |
| 3194 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3195 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3196 | } |
| 3197 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3198 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3199 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3200 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 3201 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3202 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3203 | case Primitive::kPrimBoolean: |
| 3204 | case Primitive::kPrimByte: |
| 3205 | case Primitive::kPrimShort: |
| 3206 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3207 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3208 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3209 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3210 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3211 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3212 | break; |
| 3213 | } |
| 3214 | case Primitive::kPrimFloat: |
| 3215 | case Primitive::kPrimDouble: { |
| 3216 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3217 | locations->SetInAt(1, |
| 3218 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3219 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3220 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3221 | locations->SetOut(Location::RequiresRegister()); |
| 3222 | break; |
| 3223 | } |
| 3224 | default: |
| 3225 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3226 | } |
| 3227 | } |
| 3228 | |
| 3229 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 3230 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 3231 | |
| 3232 | // 0 if: left == right |
| 3233 | // 1 if: left > right |
| 3234 | // -1 if: left < right |
| 3235 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3236 | case Primitive::kPrimBoolean: |
| 3237 | case Primitive::kPrimByte: |
| 3238 | case Primitive::kPrimShort: |
| 3239 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3240 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3241 | case Primitive::kPrimLong: { |
| 3242 | Register result = OutputRegister(compare); |
| 3243 | Register left = InputRegisterAt(compare, 0); |
| 3244 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3245 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3246 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3247 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3248 | break; |
| 3249 | } |
| 3250 | case Primitive::kPrimFloat: |
| 3251 | case Primitive::kPrimDouble: { |
| 3252 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3253 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3254 | __ Cset(result, ne); |
| 3255 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3256 | break; |
| 3257 | } |
| 3258 | default: |
| 3259 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3260 | } |
| 3261 | } |
| 3262 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3263 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3264 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3265 | |
| 3266 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 3267 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3268 | locations->SetInAt(1, |
| 3269 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3270 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3271 | : Location::RequiresFpuRegister()); |
| 3272 | } else { |
| 3273 | // Integer cases. |
| 3274 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3275 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3276 | } |
| 3277 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3278 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3279 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3280 | } |
| 3281 | } |
| 3282 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3283 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3284 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3285 | return; |
| 3286 | } |
| 3287 | |
| 3288 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3289 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3290 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3291 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3292 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3293 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3294 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3295 | } else { |
| 3296 | // Integer cases. |
| 3297 | Register lhs = InputRegisterAt(instruction, 0); |
| 3298 | Operand rhs = InputOperandAt(instruction, 1); |
| 3299 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3300 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3301 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3302 | } |
| 3303 | |
| 3304 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3305 | M(Equal) \ |
| 3306 | M(NotEqual) \ |
| 3307 | M(LessThan) \ |
| 3308 | M(LessThanOrEqual) \ |
| 3309 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3310 | M(GreaterThanOrEqual) \ |
| 3311 | M(Below) \ |
| 3312 | M(BelowOrEqual) \ |
| 3313 | M(Above) \ |
| 3314 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3315 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3316 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3317 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3318 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3319 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3320 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3321 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3322 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3323 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3324 | |
| 3325 | LocationSummary* locations = instruction->GetLocations(); |
| 3326 | Location second = locations->InAt(1); |
| 3327 | DCHECK(second.IsConstant()); |
| 3328 | |
| 3329 | Register out = OutputRegister(instruction); |
| 3330 | Register dividend = InputRegisterAt(instruction, 0); |
| 3331 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3332 | DCHECK(imm == 1 || imm == -1); |
| 3333 | |
| 3334 | if (instruction->IsRem()) { |
| 3335 | __ Mov(out, 0); |
| 3336 | } else { |
| 3337 | if (imm == 1) { |
| 3338 | __ Mov(out, dividend); |
| 3339 | } else { |
| 3340 | __ Neg(out, dividend); |
| 3341 | } |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3346 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3347 | |
| 3348 | LocationSummary* locations = instruction->GetLocations(); |
| 3349 | Location second = locations->InAt(1); |
| 3350 | DCHECK(second.IsConstant()); |
| 3351 | |
| 3352 | Register out = OutputRegister(instruction); |
| 3353 | Register dividend = InputRegisterAt(instruction, 0); |
| 3354 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3355 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3356 | int ctz_imm = CTZ(abs_imm); |
| 3357 | |
| 3358 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3359 | Register temp = temps.AcquireSameSizeAs(out); |
| 3360 | |
| 3361 | if (instruction->IsDiv()) { |
| 3362 | __ Add(temp, dividend, abs_imm - 1); |
| 3363 | __ Cmp(dividend, 0); |
| 3364 | __ Csel(out, temp, dividend, lt); |
| 3365 | if (imm > 0) { |
| 3366 | __ Asr(out, out, ctz_imm); |
| 3367 | } else { |
| 3368 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 3369 | } |
| 3370 | } else { |
| 3371 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 3372 | __ Asr(temp, dividend, bits - 1); |
| 3373 | __ Lsr(temp, temp, bits - ctz_imm); |
| 3374 | __ Add(out, dividend, temp); |
| 3375 | __ And(out, out, abs_imm - 1); |
| 3376 | __ Sub(out, out, temp); |
| 3377 | } |
| 3378 | } |
| 3379 | |
| 3380 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3381 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3382 | |
| 3383 | LocationSummary* locations = instruction->GetLocations(); |
| 3384 | Location second = locations->InAt(1); |
| 3385 | DCHECK(second.IsConstant()); |
| 3386 | |
| 3387 | Register out = OutputRegister(instruction); |
| 3388 | Register dividend = InputRegisterAt(instruction, 0); |
| 3389 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3390 | |
| 3391 | Primitive::Type type = instruction->GetResultType(); |
| 3392 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 3393 | |
| 3394 | int64_t magic; |
| 3395 | int shift; |
| 3396 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 3397 | |
| 3398 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3399 | Register temp = temps.AcquireSameSizeAs(out); |
| 3400 | |
| 3401 | // temp = get_high(dividend * magic) |
| 3402 | __ Mov(temp, magic); |
| 3403 | if (type == Primitive::kPrimLong) { |
| 3404 | __ Smulh(temp, dividend, temp); |
| 3405 | } else { |
| 3406 | __ Smull(temp.X(), dividend, temp); |
| 3407 | __ Lsr(temp.X(), temp.X(), 32); |
| 3408 | } |
| 3409 | |
| 3410 | if (imm > 0 && magic < 0) { |
| 3411 | __ Add(temp, temp, dividend); |
| 3412 | } else if (imm < 0 && magic > 0) { |
| 3413 | __ Sub(temp, temp, dividend); |
| 3414 | } |
| 3415 | |
| 3416 | if (shift != 0) { |
| 3417 | __ Asr(temp, temp, shift); |
| 3418 | } |
| 3419 | |
| 3420 | if (instruction->IsDiv()) { |
| 3421 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3422 | } else { |
| 3423 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3424 | // TODO: Strength reduction for msub. |
| 3425 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3426 | __ Mov(temp_imm, imm); |
| 3427 | __ Msub(out, temp, temp_imm, dividend); |
| 3428 | } |
| 3429 | } |
| 3430 | |
| 3431 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3432 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3433 | Primitive::Type type = instruction->GetResultType(); |
Calin Juravle | c70d1d9 | 2017-03-27 18:10:04 -0700 | [diff] [blame] | 3434 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3435 | |
| 3436 | LocationSummary* locations = instruction->GetLocations(); |
| 3437 | Register out = OutputRegister(instruction); |
| 3438 | Location second = locations->InAt(1); |
| 3439 | |
| 3440 | if (second.IsConstant()) { |
| 3441 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3442 | |
| 3443 | if (imm == 0) { |
| 3444 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3445 | } else if (imm == 1 || imm == -1) { |
| 3446 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3447 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3448 | DivRemByPowerOfTwo(instruction); |
| 3449 | } else { |
| 3450 | DCHECK(imm <= -2 || imm >= 2); |
| 3451 | GenerateDivRemWithAnyConstant(instruction); |
| 3452 | } |
| 3453 | } else { |
| 3454 | Register dividend = InputRegisterAt(instruction, 0); |
| 3455 | Register divisor = InputRegisterAt(instruction, 1); |
| 3456 | if (instruction->IsDiv()) { |
| 3457 | __ Sdiv(out, dividend, divisor); |
| 3458 | } else { |
| 3459 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3460 | Register temp = temps.AcquireSameSizeAs(out); |
| 3461 | __ Sdiv(temp, dividend, divisor); |
| 3462 | __ Msub(out, temp, divisor, dividend); |
| 3463 | } |
| 3464 | } |
| 3465 | } |
| 3466 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3467 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3468 | LocationSummary* locations = |
| 3469 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3470 | switch (div->GetResultType()) { |
| 3471 | case Primitive::kPrimInt: |
| 3472 | case Primitive::kPrimLong: |
| 3473 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3474 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3475 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3476 | break; |
| 3477 | |
| 3478 | case Primitive::kPrimFloat: |
| 3479 | case Primitive::kPrimDouble: |
| 3480 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3481 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3482 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3483 | break; |
| 3484 | |
| 3485 | default: |
| 3486 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3487 | } |
| 3488 | } |
| 3489 | |
| 3490 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 3491 | Primitive::Type type = div->GetResultType(); |
| 3492 | switch (type) { |
| 3493 | case Primitive::kPrimInt: |
| 3494 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3495 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3496 | break; |
| 3497 | |
| 3498 | case Primitive::kPrimFloat: |
| 3499 | case Primitive::kPrimDouble: |
| 3500 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3501 | break; |
| 3502 | |
| 3503 | default: |
| 3504 | LOG(FATAL) << "Unexpected div type " << type; |
| 3505 | } |
| 3506 | } |
| 3507 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3508 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3509 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3510 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3514 | SlowPathCodeARM64* slow_path = |
| 3515 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 3516 | codegen_->AddSlowPath(slow_path); |
| 3517 | Location value = instruction->GetLocations()->InAt(0); |
| 3518 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3519 | Primitive::Type type = instruction->GetType(); |
| 3520 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3521 | if (!Primitive::IsIntegralType(type)) { |
| 3522 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3523 | return; |
| 3524 | } |
| 3525 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3526 | if (value.IsConstant()) { |
| 3527 | int64_t divisor = Int64ConstantFrom(value); |
| 3528 | if (divisor == 0) { |
| 3529 | __ B(slow_path->GetEntryLabel()); |
| 3530 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3531 | // A division by a non-null constant is valid. We don't need to perform |
| 3532 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3533 | } |
| 3534 | } else { |
| 3535 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3536 | } |
| 3537 | } |
| 3538 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3539 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3540 | LocationSummary* locations = |
| 3541 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3542 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3543 | } |
| 3544 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3545 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3546 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3547 | // Will be generated at use site. |
| 3548 | } |
| 3549 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3550 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3551 | exit->SetLocations(nullptr); |
| 3552 | } |
| 3553 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3554 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3555 | } |
| 3556 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3557 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3558 | LocationSummary* locations = |
| 3559 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3560 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3561 | } |
| 3562 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3563 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3564 | // Will be generated at use site. |
| 3565 | } |
| 3566 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3567 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3568 | DCHECK(!successor->IsExitBlock()); |
| 3569 | HBasicBlock* block = got->GetBlock(); |
| 3570 | HInstruction* previous = got->GetPrevious(); |
| 3571 | HLoopInformation* info = block->GetLoopInformation(); |
| 3572 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3573 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3574 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3575 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3576 | return; |
| 3577 | } |
| 3578 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3579 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3580 | } |
| 3581 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3582 | __ B(codegen_->GetLabelOf(successor)); |
| 3583 | } |
| 3584 | } |
| 3585 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3586 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3587 | got->SetLocations(nullptr); |
| 3588 | } |
| 3589 | |
| 3590 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3591 | HandleGoto(got, got->GetSuccessor()); |
| 3592 | } |
| 3593 | |
| 3594 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3595 | try_boundary->SetLocations(nullptr); |
| 3596 | } |
| 3597 | |
| 3598 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3599 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3600 | if (!successor->IsExitBlock()) { |
| 3601 | HandleGoto(try_boundary, successor); |
| 3602 | } |
| 3603 | } |
| 3604 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3605 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3606 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3607 | vixl::aarch64::Label* true_target, |
| 3608 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3609 | // FP branching requires both targets to be explicit. If either of the targets |
| 3610 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3611 | vixl::aarch64::Label fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3612 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3613 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3614 | if (true_target == nullptr && false_target == nullptr) { |
| 3615 | // Nothing to do. The code always falls through. |
| 3616 | return; |
| 3617 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3618 | // Constant condition, statically compared against "true" (integer value 1). |
| 3619 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3620 | if (true_target != nullptr) { |
| 3621 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3622 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3623 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3624 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3625 | if (false_target != nullptr) { |
| 3626 | __ B(false_target); |
| 3627 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3628 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3629 | return; |
| 3630 | } |
| 3631 | |
| 3632 | // The following code generates these patterns: |
| 3633 | // (1) true_target == nullptr && false_target != nullptr |
| 3634 | // - opposite condition true => branch to false_target |
| 3635 | // (2) true_target != nullptr && false_target == nullptr |
| 3636 | // - condition true => branch to true_target |
| 3637 | // (3) true_target != nullptr && false_target != nullptr |
| 3638 | // - condition true => branch to true_target |
| 3639 | // - branch to false_target |
| 3640 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3641 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3642 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3643 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3644 | if (true_target == nullptr) { |
| 3645 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3646 | } else { |
| 3647 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3648 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3649 | } else { |
| 3650 | // The condition instruction has not been materialized, use its inputs as |
| 3651 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3652 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3653 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3654 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3655 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3656 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3657 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3658 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3659 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3660 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3661 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3662 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3663 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3664 | // Integer cases. |
| 3665 | Register lhs = InputRegisterAt(condition, 0); |
| 3666 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3667 | |
| 3668 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3669 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3670 | if (true_target == nullptr) { |
| 3671 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3672 | non_fallthrough_target = false_target; |
| 3673 | } else { |
| 3674 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3675 | non_fallthrough_target = true_target; |
| 3676 | } |
| 3677 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3678 | 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] | 3679 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3680 | switch (arm64_cond) { |
| 3681 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3682 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3683 | break; |
| 3684 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3685 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3686 | break; |
| 3687 | case lt: |
| 3688 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3689 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3690 | break; |
| 3691 | case ge: |
| 3692 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3693 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3694 | break; |
| 3695 | default: |
| 3696 | // Without the `static_cast` the compiler throws an error for |
| 3697 | // `-Werror=sign-promo`. |
| 3698 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3699 | } |
| 3700 | } else { |
| 3701 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3702 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3703 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3704 | } |
| 3705 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3706 | |
| 3707 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3708 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3709 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3710 | __ B(false_target); |
| 3711 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3712 | |
| 3713 | if (fallthrough_target.IsLinked()) { |
| 3714 | __ Bind(&fallthrough_target); |
| 3715 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3716 | } |
| 3717 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3718 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 3719 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3720 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3721 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3722 | } |
| 3723 | } |
| 3724 | |
| 3725 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3726 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3727 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3728 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3729 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3730 | true_target = nullptr; |
| 3731 | } |
| 3732 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3733 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3734 | false_target = nullptr; |
| 3735 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3736 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3737 | } |
| 3738 | |
| 3739 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3740 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3741 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3742 | InvokeRuntimeCallingConvention calling_convention; |
| 3743 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3744 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3745 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3746 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3747 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3748 | } |
| 3749 | } |
| 3750 | |
| 3751 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3752 | SlowPathCodeARM64* slow_path = |
| 3753 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3754 | GenerateTestAndBranch(deoptimize, |
| 3755 | /* condition_input_index */ 0, |
| 3756 | slow_path->GetEntryLabel(), |
| 3757 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3758 | } |
| 3759 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3760 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3761 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3762 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3763 | locations->SetOut(Location::RequiresRegister()); |
| 3764 | } |
| 3765 | |
| 3766 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3767 | __ Ldr(OutputRegister(flag), |
| 3768 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3769 | } |
| 3770 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3771 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3772 | return condition->IsCondition() && |
| 3773 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 3774 | } |
| 3775 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3776 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3777 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3778 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3779 | : ARM64Condition(cond); |
| 3780 | } |
| 3781 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3782 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3783 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3784 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3785 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3786 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3787 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3788 | } else { |
| 3789 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3790 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3791 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3792 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3793 | // Ask VIXL whether we should synthesize constants in registers. |
| 3794 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3795 | Operand true_op = is_true_value_constant ? |
| 3796 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3797 | Operand false_op = is_false_value_constant ? |
| 3798 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3799 | bool true_value_in_register = false; |
| 3800 | bool false_value_in_register = false; |
| 3801 | MacroAssembler::GetCselSynthesisInformation( |
| 3802 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3803 | true_value_in_register |= !is_true_value_constant; |
| 3804 | false_value_in_register |= !is_false_value_constant; |
| 3805 | |
| 3806 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3807 | : Location::ConstantLocation(cst_true_value)); |
| 3808 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3809 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3810 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3811 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3812 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3813 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3814 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3815 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3819 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3820 | Condition csel_cond; |
| 3821 | |
| 3822 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3823 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3824 | // Use the condition flags set by the previous instruction. |
| 3825 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3826 | } else { |
| 3827 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3828 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3829 | } |
| 3830 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3831 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3832 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3833 | } else { |
| 3834 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3835 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3836 | } |
| 3837 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3838 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3839 | __ Fcsel(OutputFPRegister(select), |
| 3840 | InputFPRegisterAt(select, 1), |
| 3841 | InputFPRegisterAt(select, 0), |
| 3842 | csel_cond); |
| 3843 | } else { |
| 3844 | __ Csel(OutputRegister(select), |
| 3845 | InputOperandAt(select, 1), |
| 3846 | InputOperandAt(select, 0), |
| 3847 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3848 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3849 | } |
| 3850 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3851 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3852 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3853 | } |
| 3854 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3855 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3856 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3857 | } |
| 3858 | |
| 3859 | void CodeGeneratorARM64::GenerateNop() { |
| 3860 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3861 | } |
| 3862 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3863 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3864 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3868 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3872 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3873 | } |
| 3874 | |
| 3875 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3876 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3877 | } |
| 3878 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3879 | // Temp is used for read barrier. |
| 3880 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3881 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3882 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3883 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3884 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3885 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3886 | return 1; |
| 3887 | } |
| 3888 | return 0; |
| 3889 | } |
| 3890 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3891 | // 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] | 3892 | // interface pointer, one for loading the current interface. |
| 3893 | // The other checks have one temp for loading the object's class. |
| 3894 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3895 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3896 | return 3; |
| 3897 | } |
| 3898 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3899 | } |
| 3900 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3901 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3902 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3903 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3904 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3905 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3906 | case TypeCheckKind::kExactCheck: |
| 3907 | case TypeCheckKind::kAbstractClassCheck: |
| 3908 | case TypeCheckKind::kClassHierarchyCheck: |
| 3909 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3910 | call_kind = |
| 3911 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3912 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3913 | break; |
| 3914 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3915 | case TypeCheckKind::kUnresolvedCheck: |
| 3916 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3917 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3918 | break; |
| 3919 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3920 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3921 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3922 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3923 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3924 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3925 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3926 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3927 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3928 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3929 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3930 | // Add temps if necessary for read barriers. |
| 3931 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3932 | } |
| 3933 | |
| 3934 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3935 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3936 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3937 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3938 | Register obj = InputRegisterAt(instruction, 0); |
| 3939 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3940 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3941 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3942 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3943 | DCHECK_LE(num_temps, 1u); |
| 3944 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3945 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3946 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3947 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3948 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3949 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3950 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3951 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3952 | |
| 3953 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3954 | // Avoid null check if we know `obj` is not null. |
| 3955 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3956 | __ Cbz(obj, &zero); |
| 3957 | } |
| 3958 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3959 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3960 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3961 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3962 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3963 | out_loc, |
| 3964 | obj_loc, |
| 3965 | class_offset, |
| 3966 | maybe_temp_loc, |
| 3967 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3968 | __ Cmp(out, cls); |
| 3969 | __ Cset(out, eq); |
| 3970 | if (zero.IsLinked()) { |
| 3971 | __ B(&done); |
| 3972 | } |
| 3973 | break; |
| 3974 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3975 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3976 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3977 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3978 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3979 | out_loc, |
| 3980 | obj_loc, |
| 3981 | class_offset, |
| 3982 | maybe_temp_loc, |
| 3983 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3984 | // If the class is abstract, we eagerly fetch the super class of the |
| 3985 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3986 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3987 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3988 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3989 | GenerateReferenceLoadOneRegister(instruction, |
| 3990 | out_loc, |
| 3991 | super_offset, |
| 3992 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3993 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3994 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3995 | __ Cbz(out, &done); |
| 3996 | __ Cmp(out, cls); |
| 3997 | __ B(ne, &loop); |
| 3998 | __ Mov(out, 1); |
| 3999 | if (zero.IsLinked()) { |
| 4000 | __ B(&done); |
| 4001 | } |
| 4002 | break; |
| 4003 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4004 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4005 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4006 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4007 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4008 | out_loc, |
| 4009 | obj_loc, |
| 4010 | class_offset, |
| 4011 | maybe_temp_loc, |
| 4012 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4013 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4014 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4015 | __ Bind(&loop); |
| 4016 | __ Cmp(out, cls); |
| 4017 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4018 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4019 | GenerateReferenceLoadOneRegister(instruction, |
| 4020 | out_loc, |
| 4021 | super_offset, |
| 4022 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4023 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4024 | __ Cbnz(out, &loop); |
| 4025 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4026 | __ B(&done); |
| 4027 | __ Bind(&success); |
| 4028 | __ Mov(out, 1); |
| 4029 | if (zero.IsLinked()) { |
| 4030 | __ B(&done); |
| 4031 | } |
| 4032 | break; |
| 4033 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4034 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4035 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4036 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4037 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4038 | out_loc, |
| 4039 | obj_loc, |
| 4040 | class_offset, |
| 4041 | maybe_temp_loc, |
| 4042 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4043 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4044 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4045 | __ Cmp(out, cls); |
| 4046 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4047 | // 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] | 4048 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4049 | GenerateReferenceLoadOneRegister(instruction, |
| 4050 | out_loc, |
| 4051 | component_offset, |
| 4052 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4053 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4054 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4055 | __ Cbz(out, &done); |
| 4056 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4057 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4058 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4059 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4060 | __ Mov(out, 1); |
| 4061 | __ B(&done); |
| 4062 | break; |
| 4063 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4064 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4065 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4066 | // No read barrier since the slow path will retry upon failure. |
| 4067 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4068 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4069 | out_loc, |
| 4070 | obj_loc, |
| 4071 | class_offset, |
| 4072 | maybe_temp_loc, |
| 4073 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4074 | __ Cmp(out, cls); |
| 4075 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4076 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4077 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4078 | codegen_->AddSlowPath(slow_path); |
| 4079 | __ B(ne, slow_path->GetEntryLabel()); |
| 4080 | __ Mov(out, 1); |
| 4081 | if (zero.IsLinked()) { |
| 4082 | __ B(&done); |
| 4083 | } |
| 4084 | break; |
| 4085 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4086 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4087 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4088 | case TypeCheckKind::kInterfaceCheck: { |
| 4089 | // Note that we indeed only call on slow path, but we always go |
| 4090 | // into the slow path for the unresolved and interface check |
| 4091 | // cases. |
| 4092 | // |
| 4093 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4094 | // entry point without resorting to a type checking slow path |
| 4095 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4096 | // require to assign fixed registers for the inputs of this |
| 4097 | // HInstanceOf instruction (following the runtime calling |
| 4098 | // convention), which might be cluttered by the potential first |
| 4099 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4100 | // |
| 4101 | // TODO: Introduce a new runtime entry point taking the object |
| 4102 | // to test (instead of its class) as argument, and let it deal |
| 4103 | // with the read barrier issues. This will let us refactor this |
| 4104 | // case of the `switch` code as it was previously (with a direct |
| 4105 | // call to the runtime not using a type checking slow path). |
| 4106 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4107 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4108 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4109 | /* is_fatal */ false); |
| 4110 | codegen_->AddSlowPath(slow_path); |
| 4111 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4112 | if (zero.IsLinked()) { |
| 4113 | __ B(&done); |
| 4114 | } |
| 4115 | break; |
| 4116 | } |
| 4117 | } |
| 4118 | |
| 4119 | if (zero.IsLinked()) { |
| 4120 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4121 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4122 | } |
| 4123 | |
| 4124 | if (done.IsLinked()) { |
| 4125 | __ Bind(&done); |
| 4126 | } |
| 4127 | |
| 4128 | if (slow_path != nullptr) { |
| 4129 | __ Bind(slow_path->GetExitLabel()); |
| 4130 | } |
| 4131 | } |
| 4132 | |
| 4133 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 4134 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4135 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 4136 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4137 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 4138 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4139 | case TypeCheckKind::kExactCheck: |
| 4140 | case TypeCheckKind::kAbstractClassCheck: |
| 4141 | case TypeCheckKind::kClassHierarchyCheck: |
| 4142 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4143 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 4144 | LocationSummary::kCallOnSlowPath : |
| 4145 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4146 | break; |
| 4147 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4148 | case TypeCheckKind::kUnresolvedCheck: |
| 4149 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4150 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4151 | break; |
| 4152 | } |
| 4153 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4154 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4155 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4156 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4157 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4158 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4159 | } |
| 4160 | |
| 4161 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4162 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4163 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4164 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4165 | Register obj = InputRegisterAt(instruction, 0); |
| 4166 | Register cls = InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4167 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4168 | DCHECK_GE(num_temps, 1u); |
| 4169 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4170 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4171 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4172 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4173 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4174 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4175 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4176 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4177 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4178 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4179 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4180 | const uint32_t object_array_data_offset = |
| 4181 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4182 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4183 | bool is_type_check_slow_path_fatal = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4184 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 4185 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 4186 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4187 | if (!kEmitCompilerReadBarrier) { |
| 4188 | is_type_check_slow_path_fatal = |
| 4189 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 4190 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 4191 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 4192 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 4193 | !instruction->CanThrowIntoCatchBlock(); |
| 4194 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4195 | SlowPathCodeARM64* type_check_slow_path = |
| 4196 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4197 | is_type_check_slow_path_fatal); |
| 4198 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4199 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4200 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4201 | // Avoid null check if we know obj is not null. |
| 4202 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4203 | __ Cbz(obj, &done); |
| 4204 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4205 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4206 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4207 | case TypeCheckKind::kExactCheck: |
| 4208 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4209 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4210 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4211 | temp_loc, |
| 4212 | obj_loc, |
| 4213 | class_offset, |
| 4214 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4215 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4216 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4217 | __ Cmp(temp, cls); |
| 4218 | // Jump to slow path for throwing the exception or doing a |
| 4219 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4220 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4221 | break; |
| 4222 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4223 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4224 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4225 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4226 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4227 | temp_loc, |
| 4228 | obj_loc, |
| 4229 | class_offset, |
| 4230 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4231 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4232 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4233 | // If the class is abstract, we eagerly fetch the super class of the |
| 4234 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4235 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4236 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4237 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4238 | GenerateReferenceLoadOneRegister(instruction, |
| 4239 | temp_loc, |
| 4240 | super_offset, |
| 4241 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4242 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4243 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4244 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4245 | // exception. |
| 4246 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4247 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4248 | __ Cmp(temp, cls); |
| 4249 | __ B(ne, &loop); |
| 4250 | break; |
| 4251 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4252 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4253 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4254 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4255 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4256 | temp_loc, |
| 4257 | obj_loc, |
| 4258 | class_offset, |
| 4259 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4260 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4261 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4262 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4263 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4264 | __ Bind(&loop); |
| 4265 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4266 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4267 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4268 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4269 | GenerateReferenceLoadOneRegister(instruction, |
| 4270 | temp_loc, |
| 4271 | super_offset, |
| 4272 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4273 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4274 | |
| 4275 | // If the class reference currently in `temp` is not null, jump |
| 4276 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4277 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4278 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4279 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4280 | break; |
| 4281 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4282 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4283 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4284 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4285 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4286 | temp_loc, |
| 4287 | obj_loc, |
| 4288 | class_offset, |
| 4289 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4290 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4291 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4292 | // Do an exact check. |
| 4293 | __ Cmp(temp, cls); |
| 4294 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4295 | |
| 4296 | // 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] | 4297 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4298 | GenerateReferenceLoadOneRegister(instruction, |
| 4299 | temp_loc, |
| 4300 | component_offset, |
| 4301 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4302 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4303 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4304 | // If the component type is null, jump to the slow path to throw the exception. |
| 4305 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4306 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4307 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4308 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4309 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4310 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4311 | break; |
| 4312 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4313 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4314 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4315 | // 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] | 4316 | // |
| 4317 | // We cannot directly call the CheckCast runtime entry point |
| 4318 | // without resorting to a type checking slow path here (i.e. by |
| 4319 | // calling InvokeRuntime directly), as it would require to |
| 4320 | // assign fixed registers for the inputs of this HInstanceOf |
| 4321 | // instruction (following the runtime calling convention), which |
| 4322 | // might be cluttered by the potential first read barrier |
| 4323 | // emission at the beginning of this method. |
| 4324 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4325 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4326 | case TypeCheckKind::kInterfaceCheck: { |
| 4327 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4328 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4329 | temp_loc, |
| 4330 | obj_loc, |
| 4331 | class_offset, |
| 4332 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4333 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4334 | |
| 4335 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4336 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4337 | temp_loc, |
| 4338 | temp_loc, |
| 4339 | iftable_offset, |
| 4340 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4341 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4342 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4343 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4344 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4345 | vixl::aarch64::Label start_loop; |
| 4346 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4347 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4348 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4349 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4350 | // Go to next interface. |
| 4351 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4352 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4353 | // Compare the classes and continue the loop if they do not match. |
| 4354 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4355 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4356 | break; |
| 4357 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4358 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4359 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4360 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4361 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4362 | } |
| 4363 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4364 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 4365 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4366 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4367 | } |
| 4368 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4369 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4370 | // Will be generated at use site. |
| 4371 | } |
| 4372 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4373 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 4374 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4375 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4376 | } |
| 4377 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4378 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4379 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4380 | } |
| 4381 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4382 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4383 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4384 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4385 | // the method_idx. |
| 4386 | HandleInvoke(invoke); |
| 4387 | } |
| 4388 | |
| 4389 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4390 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 4391 | } |
| 4392 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4393 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4394 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4395 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4396 | } |
| 4397 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4398 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4399 | HandleInvoke(invoke); |
| 4400 | } |
| 4401 | |
| 4402 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4403 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4404 | LocationSummary* locations = invoke->GetLocations(); |
| 4405 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4406 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4407 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4408 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4409 | |
| 4410 | // The register ip1 is required to be used for the hidden argument in |
| 4411 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4412 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4413 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4414 | scratch_scope.Exclude(ip1); |
| 4415 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4416 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4417 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4418 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4419 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4420 | { |
| 4421 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4422 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4423 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4424 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4425 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4426 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4427 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4428 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4429 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4430 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4431 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4432 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4433 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4434 | // emit a read barrier for the previous class reference load. |
| 4435 | // However this is not required in practice, as this is an |
| 4436 | // intermediate/temporary reference and because the current |
| 4437 | // concurrent copying collector keeps the from-space memory |
| 4438 | // intact/accessible until the end of the marking phase (the |
| 4439 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4440 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4441 | __ Ldr(temp, |
| 4442 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4443 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4444 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4445 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4446 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4447 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4448 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4449 | |
| 4450 | { |
| 4451 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4452 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4453 | |
| 4454 | // lr(); |
| 4455 | __ blr(lr); |
| 4456 | DCHECK(!codegen_->IsLeafMethod()); |
| 4457 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4458 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4459 | } |
| 4460 | |
| 4461 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4462 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4463 | if (intrinsic.TryDispatch(invoke)) { |
| 4464 | return; |
| 4465 | } |
| 4466 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4467 | HandleInvoke(invoke); |
| 4468 | } |
| 4469 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4470 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4471 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4472 | // art::PrepareForRegisterAllocation. |
| 4473 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4474 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4475 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4476 | if (intrinsic.TryDispatch(invoke)) { |
| 4477 | return; |
| 4478 | } |
| 4479 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4480 | HandleInvoke(invoke); |
| 4481 | } |
| 4482 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4483 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4484 | if (invoke->GetLocations()->Intrinsified()) { |
| 4485 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4486 | intrinsic.Dispatch(invoke); |
| 4487 | return true; |
| 4488 | } |
| 4489 | return false; |
| 4490 | } |
| 4491 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4492 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4493 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4494 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4495 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4496 | return desired_dispatch_info; |
| 4497 | } |
| 4498 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame^] | 4499 | void CodeGeneratorARM64::GenerateStaticOrDirectCall( |
| 4500 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4501 | // 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] | 4502 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4503 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4504 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4505 | uint32_t offset = |
| 4506 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4507 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4508 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4509 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4510 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4511 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4512 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4513 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4514 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 4515 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 4516 | // Add ADRP with its PC-relative method patch. |
| 4517 | vixl::aarch64::Label* adrp_label = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 4518 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
| 4519 | // Add ADD with its PC-relative method patch. |
| 4520 | vixl::aarch64::Label* add_label = |
| 4521 | NewPcRelativeMethodPatch(invoke->GetTargetMethod(), adrp_label); |
| 4522 | EmitAddPlaceholder(add_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
| 4523 | break; |
| 4524 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4525 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4526 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4527 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4528 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4529 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4530 | // Add ADRP with its PC-relative DexCache access patch. |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4531 | const DexFile& dex_file = invoke->GetDexFileForPcRelativeDexCache(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4532 | uint32_t element_offset = invoke->GetDexCacheArrayOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4533 | vixl::aarch64::Label* adrp_label = NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4534 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4535 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4536 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4537 | NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4538 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4539 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4540 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame^] | 4541 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 4542 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 4543 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4544 | } |
| 4545 | } |
| 4546 | |
| 4547 | switch (invoke->GetCodePtrLocation()) { |
| 4548 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame^] | 4549 | { |
| 4550 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 4551 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4552 | kInstructionSize, |
| 4553 | CodeBufferCheckScope::kExactSize); |
| 4554 | __ bl(&frame_entry_label_); |
| 4555 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 4556 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4557 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4558 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4559 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4560 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4561 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4562 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4563 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame^] | 4564 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4565 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4566 | kInstructionSize, |
| 4567 | CodeBufferCheckScope::kExactSize); |
| 4568 | // lr() |
| 4569 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame^] | 4570 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4571 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4572 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4573 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4574 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4575 | DCHECK(!IsLeafMethod()); |
| 4576 | } |
| 4577 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame^] | 4578 | void CodeGeneratorARM64::GenerateVirtualCall( |
| 4579 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4580 | // Use the calling convention instead of the location of the receiver, as |
| 4581 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4582 | // slow path, the arguments have been moved to the right place, so here we are |
| 4583 | // guaranteed that the receiver is the first register of the calling convention. |
| 4584 | InvokeDexCallingConvention calling_convention; |
| 4585 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4586 | Register temp = XRegisterFrom(temp_in); |
| 4587 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4588 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4589 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4590 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4591 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4592 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4593 | |
| 4594 | { |
| 4595 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4596 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4597 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4598 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4599 | MaybeRecordImplicitNullCheck(invoke); |
| 4600 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4601 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4602 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4603 | // intermediate/temporary reference and because the current |
| 4604 | // concurrent copying collector keeps the from-space memory |
| 4605 | // intact/accessible until the end of the marking phase (the |
| 4606 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4607 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4608 | // temp = temp->GetMethodAt(method_offset); |
| 4609 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4610 | // lr = temp->GetEntryPoint(); |
| 4611 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4612 | { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame^] | 4613 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4614 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4615 | // lr(); |
| 4616 | __ blr(lr); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame^] | 4617 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4618 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4619 | } |
| 4620 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4621 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4622 | HandleInvoke(invoke); |
| 4623 | } |
| 4624 | |
| 4625 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4626 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 4627 | } |
| 4628 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4629 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeMethodPatch( |
| 4630 | MethodReference target_method, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4631 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4632 | return NewPcRelativePatch(*target_method.dex_file, |
| 4633 | target_method.dex_method_index, |
| 4634 | adrp_label, |
| 4635 | &pc_relative_method_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4636 | } |
| 4637 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4638 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 4639 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4640 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4641 | vixl::aarch64::Label* adrp_label) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4642 | 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] | 4643 | } |
| 4644 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4645 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4646 | const DexFile& dex_file, |
| 4647 | dex::TypeIndex type_index, |
| 4648 | vixl::aarch64::Label* adrp_label) { |
| 4649 | return NewPcRelativePatch(dex_file, type_index.index_, adrp_label, &type_bss_entry_patches_); |
| 4650 | } |
| 4651 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4652 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 4653 | const DexFile& dex_file, |
| 4654 | dex::StringIndex string_index, |
| 4655 | vixl::aarch64::Label* adrp_label) { |
| 4656 | return |
| 4657 | NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &pc_relative_string_patches_); |
| 4658 | } |
| 4659 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4660 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeDexCacheArrayPatch( |
| 4661 | const DexFile& dex_file, |
| 4662 | uint32_t element_offset, |
| 4663 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4664 | return NewPcRelativePatch(dex_file, element_offset, adrp_label, &pc_relative_dex_cache_patches_); |
| 4665 | } |
| 4666 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4667 | vixl::aarch64::Label* CodeGeneratorARM64::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 4668 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4669 | return &baker_read_barrier_patches_.back().label; |
| 4670 | } |
| 4671 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4672 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 4673 | const DexFile& dex_file, |
| 4674 | uint32_t offset_or_index, |
| 4675 | vixl::aarch64::Label* adrp_label, |
| 4676 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4677 | // Add a patch entry and return the label. |
| 4678 | patches->emplace_back(dex_file, offset_or_index); |
| 4679 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4680 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4681 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4682 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4683 | return label; |
| 4684 | } |
| 4685 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4686 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4687 | uint64_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 4688 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4689 | } |
| 4690 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4691 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4692 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
| 4693 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 4694 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4695 | return jit_string_patches_.GetOrCreate( |
| 4696 | StringReference(&dex_file, string_index), |
| 4697 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4698 | } |
| 4699 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4700 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4701 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
| 4702 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 4703 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4704 | return jit_class_patches_.GetOrCreate( |
| 4705 | TypeReference(&dex_file, type_index), |
| 4706 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4707 | } |
| 4708 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4709 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4710 | vixl::aarch64::Register reg) { |
| 4711 | DCHECK(reg.IsX()); |
| 4712 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4713 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4714 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4718 | vixl::aarch64::Register out, |
| 4719 | vixl::aarch64::Register base) { |
| 4720 | DCHECK(out.IsX()); |
| 4721 | DCHECK(base.IsX()); |
| 4722 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4723 | __ Bind(fixup_label); |
| 4724 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4725 | } |
| 4726 | |
| 4727 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4728 | vixl::aarch64::Register out, |
| 4729 | vixl::aarch64::Register base) { |
| 4730 | DCHECK(base.IsX()); |
| 4731 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4732 | __ Bind(fixup_label); |
| 4733 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4734 | } |
| 4735 | |
| 4736 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4737 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4738 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 4739 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4740 | for (const PcRelativePatchInfo& info : infos) { |
| 4741 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 4742 | &info.target_dex_file, |
| 4743 | info.pc_insn_label->GetLocation(), |
| 4744 | info.offset_or_index)); |
| 4745 | } |
| 4746 | } |
| 4747 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4748 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4749 | DCHECK(linker_patches->empty()); |
| 4750 | size_t size = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4751 | pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4752 | pc_relative_method_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4753 | pc_relative_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4754 | type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4755 | pc_relative_string_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4756 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4757 | linker_patches->reserve(size); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4758 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4759 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.GetLocation(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4760 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4761 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4762 | info.offset_or_index)); |
| 4763 | } |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4764 | if (GetCompilerOptions().IsBootImage()) { |
| 4765 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeMethodPatch>(pc_relative_method_patches_, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4766 | linker_patches); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4767 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 4768 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4769 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 4770 | linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4771 | } else { |
| 4772 | DCHECK(pc_relative_method_patches_.empty()); |
| 4773 | DCHECK(pc_relative_type_patches_.empty()); |
| 4774 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 4775 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4776 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4777 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 4778 | linker_patches); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4779 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 4780 | linker_patches->push_back(LinkerPatch::BakerReadBarrierBranchPatch(info.label.GetLocation(), |
| 4781 | info.custom_data)); |
| 4782 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4783 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4784 | } |
| 4785 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4786 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4787 | Uint32ToLiteralMap* map) { |
| 4788 | return map->GetOrCreate( |
| 4789 | value, |
| 4790 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4791 | } |
| 4792 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4793 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4794 | return uint64_literals_.GetOrCreate( |
| 4795 | value, |
| 4796 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4797 | } |
| 4798 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4799 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4800 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4801 | // art::PrepareForRegisterAllocation. |
| 4802 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4803 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4804 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4805 | return; |
| 4806 | } |
| 4807 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4808 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4809 | // are no pools emitted. |
| 4810 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4811 | LocationSummary* locations = invoke->GetLocations(); |
| 4812 | codegen_->GenerateStaticOrDirectCall( |
| 4813 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4814 | } |
| 4815 | |
| 4816 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4817 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4818 | return; |
| 4819 | } |
| 4820 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4821 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4822 | // are no pools emitted. |
| 4823 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4824 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4825 | DCHECK(!codegen_->IsLeafMethod()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4826 | } |
| 4827 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4828 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4829 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4830 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4831 | case HLoadClass::LoadKind::kInvalid: |
| 4832 | LOG(FATAL) << "UNREACHABLE"; |
| 4833 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4834 | case HLoadClass::LoadKind::kReferrersClass: |
| 4835 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4836 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4837 | case HLoadClass::LoadKind::kBssEntry: |
| 4838 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4839 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4840 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4841 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4842 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 4843 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4844 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 4845 | break; |
| 4846 | } |
| 4847 | return desired_class_load_kind; |
| 4848 | } |
| 4849 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4850 | void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4851 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 4852 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4853 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4854 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4855 | cls, |
| 4856 | LocationFrom(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4857 | LocationFrom(vixl::aarch64::x0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4858 | DCHECK(calling_convention.GetRegisterAt(0).Is(vixl::aarch64::x0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4859 | return; |
| 4860 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4861 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4862 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4863 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 4864 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4865 | ? LocationSummary::kCallOnSlowPath |
| 4866 | : LocationSummary::kNoCall; |
| 4867 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4868 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4869 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4870 | } |
| 4871 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4872 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4873 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4874 | } |
| 4875 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4876 | if (cls->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 4877 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 4878 | // 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] | 4879 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4880 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4881 | InvokeRuntimeCallingConvention calling_convention; |
| 4882 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 4883 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 4884 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 4885 | Primitive::kPrimNot).GetCode()); |
| 4886 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 4887 | } else { |
| 4888 | // For non-Baker read barrier we have a temp-clobbering call. |
| 4889 | } |
| 4890 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4891 | } |
| 4892 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4893 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 4894 | // move. |
| 4895 | void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4896 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 4897 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 4898 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4899 | return; |
| 4900 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4901 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4902 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4903 | Location out_loc = cls->GetLocations()->Out(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4904 | Register out = OutputRegister(cls); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4905 | Register bss_entry_temp; |
| 4906 | vixl::aarch64::Label* bss_entry_adrp_label = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4907 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4908 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 4909 | ? kWithoutReadBarrier |
| 4910 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4911 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4912 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4913 | case HLoadClass::LoadKind::kReferrersClass: { |
| 4914 | DCHECK(!cls->CanCallRuntime()); |
| 4915 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 4916 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 4917 | Register current_method = InputRegisterAt(cls, 0); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4918 | GenerateGcRootFieldLoad(cls, |
| 4919 | out_loc, |
| 4920 | current_method, |
| 4921 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4922 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4923 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4924 | break; |
| 4925 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4926 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4927 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4928 | // Add ADRP with its PC-relative type patch. |
| 4929 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4930 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4931 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4932 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4933 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4934 | vixl::aarch64::Label* add_label = |
| 4935 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4936 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4937 | break; |
| 4938 | } |
| 4939 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4940 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4941 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 4942 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 4943 | DCHECK_NE(address, 0u); |
| 4944 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4945 | break; |
| 4946 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4947 | case HLoadClass::LoadKind::kBssEntry: { |
| 4948 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 4949 | const DexFile& dex_file = cls->GetDexFile(); |
| 4950 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4951 | bss_entry_temp = XRegisterFrom(cls->GetLocations()->GetTemp(0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4952 | bss_entry_adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 4953 | codegen_->EmitAdrpPlaceholder(bss_entry_adrp_label, bss_entry_temp); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4954 | // Add LDR with its PC-relative Class patch. |
| 4955 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4956 | codegen_->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4957 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 4958 | GenerateGcRootFieldLoad(cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4959 | out_loc, |
| 4960 | bss_entry_temp, |
| 4961 | /* offset placeholder */ 0u, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4962 | ldr_label, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4963 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4964 | generate_null_check = true; |
| 4965 | break; |
| 4966 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4967 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 4968 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 4969 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4970 | cls->GetClass())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4971 | GenerateGcRootFieldLoad(cls, |
| 4972 | out_loc, |
| 4973 | out.X(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4974 | /* offset */ 0, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4975 | /* fixup_label */ nullptr, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4976 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4977 | break; |
| 4978 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4979 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4980 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4981 | LOG(FATAL) << "UNREACHABLE"; |
| 4982 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4983 | } |
| 4984 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4985 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 4986 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4987 | DCHECK(cls->CanCallRuntime()); |
| 4988 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4989 | 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] | 4990 | codegen_->AddSlowPath(slow_path); |
| 4991 | if (generate_null_check) { |
| 4992 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4993 | } |
| 4994 | if (cls->MustGenerateClinitCheck()) { |
| 4995 | GenerateClassInitializationCheck(slow_path, out); |
| 4996 | } else { |
| 4997 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4998 | } |
| 4999 | } |
| 5000 | } |
| 5001 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5002 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5003 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5004 | } |
| 5005 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5006 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5007 | LocationSummary* locations = |
| 5008 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5009 | locations->SetOut(Location::RequiresRegister()); |
| 5010 | } |
| 5011 | |
| 5012 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5013 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5014 | } |
| 5015 | |
| 5016 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 5017 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5018 | } |
| 5019 | |
| 5020 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5021 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5022 | } |
| 5023 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5024 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5025 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5026 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5027 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5028 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5029 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5030 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5031 | case HLoadString::LoadKind::kJitTableAddress: |
| 5032 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5033 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5034 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5035 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5036 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5037 | } |
| 5038 | return desired_string_load_kind; |
| 5039 | } |
| 5040 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5041 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5042 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5043 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5044 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5045 | InvokeRuntimeCallingConvention calling_convention; |
| 5046 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5047 | } else { |
| 5048 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5049 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5050 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5051 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5052 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5053 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5054 | InvokeRuntimeCallingConvention calling_convention; |
| 5055 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 5056 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 5057 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 5058 | Primitive::kPrimNot).GetCode()); |
| 5059 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5060 | } else { |
| 5061 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5062 | } |
| 5063 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5064 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5065 | } |
| 5066 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5067 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5068 | // move. |
| 5069 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5070 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5071 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5072 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5073 | switch (load->GetLoadKind()) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5074 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5075 | // Add ADRP with its PC-relative String patch. |
| 5076 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5077 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5078 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5079 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5080 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5081 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5082 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5083 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5084 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5085 | return; // No dex cache slow path. |
| 5086 | } |
| 5087 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5088 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5089 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5090 | DCHECK_NE(address, 0u); |
| 5091 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5092 | return; // No dex cache slow path. |
| 5093 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5094 | case HLoadString::LoadKind::kBssEntry: { |
| 5095 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5096 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5097 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5098 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5099 | Register temp = XRegisterFrom(load->GetLocations()->GetTemp(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5100 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5101 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5102 | // Add LDR with its PC-relative String patch. |
| 5103 | vixl::aarch64::Label* ldr_label = |
| 5104 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5105 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5106 | GenerateGcRootFieldLoad(load, |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5107 | out_loc, |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5108 | temp, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5109 | /* offset placeholder */ 0u, |
| 5110 | ldr_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5111 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5112 | SlowPathCodeARM64* slow_path = |
| 5113 | new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load, temp, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5114 | codegen_->AddSlowPath(slow_path); |
| 5115 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5116 | __ Bind(slow_path->GetExitLabel()); |
| 5117 | return; |
| 5118 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5119 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5120 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5121 | load->GetStringIndex(), |
| 5122 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5123 | GenerateGcRootFieldLoad(load, |
| 5124 | out_loc, |
| 5125 | out.X(), |
| 5126 | /* offset */ 0, |
| 5127 | /* fixup_label */ nullptr, |
| 5128 | kCompilerReadBarrierOption); |
| 5129 | return; |
| 5130 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5131 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5132 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5133 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5134 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5135 | // 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] | 5136 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5137 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5138 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5139 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5140 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5141 | } |
| 5142 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5143 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 5144 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5145 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5146 | } |
| 5147 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5148 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5149 | // Will be generated at use site. |
| 5150 | } |
| 5151 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5152 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5153 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5154 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5155 | InvokeRuntimeCallingConvention calling_convention; |
| 5156 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5157 | } |
| 5158 | |
| 5159 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5160 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5161 | instruction, |
| 5162 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5163 | if (instruction->IsEnter()) { |
| 5164 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5165 | } else { |
| 5166 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5167 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5168 | } |
| 5169 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5170 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5171 | LocationSummary* locations = |
| 5172 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 5173 | switch (mul->GetResultType()) { |
| 5174 | case Primitive::kPrimInt: |
| 5175 | case Primitive::kPrimLong: |
| 5176 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5177 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5178 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5179 | break; |
| 5180 | |
| 5181 | case Primitive::kPrimFloat: |
| 5182 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5183 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5184 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5185 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5186 | break; |
| 5187 | |
| 5188 | default: |
| 5189 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5190 | } |
| 5191 | } |
| 5192 | |
| 5193 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5194 | switch (mul->GetResultType()) { |
| 5195 | case Primitive::kPrimInt: |
| 5196 | case Primitive::kPrimLong: |
| 5197 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5198 | break; |
| 5199 | |
| 5200 | case Primitive::kPrimFloat: |
| 5201 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5202 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5203 | break; |
| 5204 | |
| 5205 | default: |
| 5206 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5207 | } |
| 5208 | } |
| 5209 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5210 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5211 | LocationSummary* locations = |
| 5212 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 5213 | switch (neg->GetResultType()) { |
| 5214 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5215 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5216 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5217 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5218 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5219 | |
| 5220 | case Primitive::kPrimFloat: |
| 5221 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5222 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5223 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5224 | break; |
| 5225 | |
| 5226 | default: |
| 5227 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5228 | } |
| 5229 | } |
| 5230 | |
| 5231 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5232 | switch (neg->GetResultType()) { |
| 5233 | case Primitive::kPrimInt: |
| 5234 | case Primitive::kPrimLong: |
| 5235 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5236 | break; |
| 5237 | |
| 5238 | case Primitive::kPrimFloat: |
| 5239 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5240 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5241 | break; |
| 5242 | |
| 5243 | default: |
| 5244 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5245 | } |
| 5246 | } |
| 5247 | |
| 5248 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 5249 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5250 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5251 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5252 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5253 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5254 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5255 | } |
| 5256 | |
| 5257 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5258 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5259 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5260 | QuickEntrypointEnum entrypoint = |
| 5261 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5262 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5263 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5264 | } |
| 5265 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5266 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 5267 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5268 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5269 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5270 | if (instruction->IsStringAlloc()) { |
| 5271 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 5272 | } else { |
| 5273 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5274 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5275 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5276 | } |
| 5277 | |
| 5278 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5279 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5280 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5281 | if (instruction->IsStringAlloc()) { |
| 5282 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5283 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5284 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5285 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 5286 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5287 | |
| 5288 | { |
| 5289 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 5290 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 5291 | kInstructionSize, |
| 5292 | CodeBufferCheckScope::kExactSize); |
| 5293 | __ blr(lr); |
| 5294 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5295 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5296 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5297 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5298 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5299 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5300 | } |
| 5301 | |
| 5302 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 5303 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5304 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5305 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5306 | } |
| 5307 | |
| 5308 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5309 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5310 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5311 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5312 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5313 | break; |
| 5314 | |
| 5315 | default: |
| 5316 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5317 | } |
| 5318 | } |
| 5319 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5320 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 5321 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5322 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5323 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5324 | } |
| 5325 | |
| 5326 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5327 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5328 | } |
| 5329 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5330 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5331 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5332 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5333 | } |
| 5334 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5335 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5336 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5337 | return; |
| 5338 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5339 | { |
| 5340 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5341 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5342 | Location obj = instruction->GetLocations()->InAt(0); |
| 5343 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5344 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5345 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5346 | } |
| 5347 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5348 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5349 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5350 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5351 | |
| 5352 | LocationSummary* locations = instruction->GetLocations(); |
| 5353 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5354 | |
| 5355 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5356 | } |
| 5357 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5358 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5359 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5360 | } |
| 5361 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5362 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5363 | HandleBinaryOp(instruction); |
| 5364 | } |
| 5365 | |
| 5366 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5367 | HandleBinaryOp(instruction); |
| 5368 | } |
| 5369 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5370 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5371 | LOG(FATAL) << "Unreachable"; |
| 5372 | } |
| 5373 | |
| 5374 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 5375 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5376 | } |
| 5377 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5378 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 5379 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5380 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5381 | if (location.IsStackSlot()) { |
| 5382 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5383 | } else if (location.IsDoubleStackSlot()) { |
| 5384 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5385 | } |
| 5386 | locations->SetOut(location); |
| 5387 | } |
| 5388 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5389 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5390 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5391 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5392 | } |
| 5393 | |
| 5394 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5395 | LocationSummary* locations = |
| 5396 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5397 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5398 | } |
| 5399 | |
| 5400 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5401 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5402 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5403 | } |
| 5404 | |
| 5405 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 5406 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5407 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5408 | locations->SetInAt(i, Location::Any()); |
| 5409 | } |
| 5410 | locations->SetOut(Location::Any()); |
| 5411 | } |
| 5412 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5413 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5414 | LOG(FATAL) << "Unreachable"; |
| 5415 | } |
| 5416 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5417 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5418 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5419 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5420 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 5421 | : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5422 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 5423 | |
| 5424 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5425 | case Primitive::kPrimInt: |
| 5426 | case Primitive::kPrimLong: |
| 5427 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5428 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5429 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5430 | break; |
| 5431 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5432 | case Primitive::kPrimFloat: |
| 5433 | case Primitive::kPrimDouble: { |
| 5434 | InvokeRuntimeCallingConvention calling_convention; |
| 5435 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5436 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5437 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5438 | |
| 5439 | break; |
| 5440 | } |
| 5441 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5442 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5443 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5444 | } |
| 5445 | } |
| 5446 | |
| 5447 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 5448 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5449 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5450 | switch (type) { |
| 5451 | case Primitive::kPrimInt: |
| 5452 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5453 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5454 | break; |
| 5455 | } |
| 5456 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5457 | case Primitive::kPrimFloat: |
| 5458 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5459 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 5460 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5461 | if (type == Primitive::kPrimFloat) { |
| 5462 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5463 | } else { |
| 5464 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5465 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5466 | break; |
| 5467 | } |
| 5468 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5469 | default: |
| 5470 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5471 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5472 | } |
| 5473 | } |
| 5474 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5475 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5476 | constructor_fence->SetLocations(nullptr); |
| 5477 | } |
| 5478 | |
| 5479 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5480 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5481 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5482 | } |
| 5483 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5484 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5485 | memory_barrier->SetLocations(nullptr); |
| 5486 | } |
| 5487 | |
| 5488 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5489 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5490 | } |
| 5491 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5492 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 5493 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5494 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5495 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5496 | } |
| 5497 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5498 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5499 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5500 | } |
| 5501 | |
| 5502 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5503 | instruction->SetLocations(nullptr); |
| 5504 | } |
| 5505 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5506 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5507 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5508 | } |
| 5509 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5510 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5511 | HandleBinaryOp(ror); |
| 5512 | } |
| 5513 | |
| 5514 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5515 | HandleBinaryOp(ror); |
| 5516 | } |
| 5517 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5518 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5519 | HandleShift(shl); |
| 5520 | } |
| 5521 | |
| 5522 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5523 | HandleShift(shl); |
| 5524 | } |
| 5525 | |
| 5526 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5527 | HandleShift(shr); |
| 5528 | } |
| 5529 | |
| 5530 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5531 | HandleShift(shr); |
| 5532 | } |
| 5533 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5534 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5535 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5536 | } |
| 5537 | |
| 5538 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5539 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5540 | } |
| 5541 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5542 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5543 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5544 | } |
| 5545 | |
| 5546 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5547 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5548 | } |
| 5549 | |
| 5550 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5551 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5552 | } |
| 5553 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5554 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5555 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5556 | } |
| 5557 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5558 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5559 | HUnresolvedInstanceFieldGet* instruction) { |
| 5560 | FieldAccessCallingConventionARM64 calling_convention; |
| 5561 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5562 | instruction, instruction->GetFieldType(), calling_convention); |
| 5563 | } |
| 5564 | |
| 5565 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5566 | HUnresolvedInstanceFieldGet* instruction) { |
| 5567 | FieldAccessCallingConventionARM64 calling_convention; |
| 5568 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5569 | instruction->GetFieldType(), |
| 5570 | instruction->GetFieldIndex(), |
| 5571 | instruction->GetDexPc(), |
| 5572 | calling_convention); |
| 5573 | } |
| 5574 | |
| 5575 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5576 | HUnresolvedInstanceFieldSet* instruction) { |
| 5577 | FieldAccessCallingConventionARM64 calling_convention; |
| 5578 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5579 | instruction, instruction->GetFieldType(), calling_convention); |
| 5580 | } |
| 5581 | |
| 5582 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5583 | HUnresolvedInstanceFieldSet* instruction) { |
| 5584 | FieldAccessCallingConventionARM64 calling_convention; |
| 5585 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5586 | instruction->GetFieldType(), |
| 5587 | instruction->GetFieldIndex(), |
| 5588 | instruction->GetDexPc(), |
| 5589 | calling_convention); |
| 5590 | } |
| 5591 | |
| 5592 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5593 | HUnresolvedStaticFieldGet* instruction) { |
| 5594 | FieldAccessCallingConventionARM64 calling_convention; |
| 5595 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5596 | instruction, instruction->GetFieldType(), calling_convention); |
| 5597 | } |
| 5598 | |
| 5599 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5600 | HUnresolvedStaticFieldGet* instruction) { |
| 5601 | FieldAccessCallingConventionARM64 calling_convention; |
| 5602 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5603 | instruction->GetFieldType(), |
| 5604 | instruction->GetFieldIndex(), |
| 5605 | instruction->GetDexPc(), |
| 5606 | calling_convention); |
| 5607 | } |
| 5608 | |
| 5609 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5610 | HUnresolvedStaticFieldSet* instruction) { |
| 5611 | FieldAccessCallingConventionARM64 calling_convention; |
| 5612 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5613 | instruction, instruction->GetFieldType(), calling_convention); |
| 5614 | } |
| 5615 | |
| 5616 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5617 | HUnresolvedStaticFieldSet* instruction) { |
| 5618 | FieldAccessCallingConventionARM64 calling_convention; |
| 5619 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5620 | instruction->GetFieldType(), |
| 5621 | instruction->GetFieldIndex(), |
| 5622 | instruction->GetDexPc(), |
| 5623 | calling_convention); |
| 5624 | } |
| 5625 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5626 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5627 | LocationSummary* locations = |
| 5628 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5629 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5630 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5631 | // registers in full width (since the runtime only saves/restores lower part). |
| 5632 | locations->SetCustomSlowPathCallerSaves( |
| 5633 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5634 | } |
| 5635 | |
| 5636 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5637 | HBasicBlock* block = instruction->GetBlock(); |
| 5638 | if (block->GetLoopInformation() != nullptr) { |
| 5639 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5640 | // The back edge will generate the suspend check. |
| 5641 | return; |
| 5642 | } |
| 5643 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5644 | // The goto will generate the suspend check. |
| 5645 | return; |
| 5646 | } |
| 5647 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5648 | } |
| 5649 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5650 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 5651 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5652 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5653 | InvokeRuntimeCallingConvention calling_convention; |
| 5654 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5655 | } |
| 5656 | |
| 5657 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5658 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5659 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5660 | } |
| 5661 | |
| 5662 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5663 | LocationSummary* locations = |
| 5664 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 5665 | Primitive::Type input_type = conversion->GetInputType(); |
| 5666 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 5667 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5668 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 5669 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 5670 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5671 | } |
| 5672 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5673 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5674 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5675 | } else { |
| 5676 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5677 | } |
| 5678 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5679 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5680 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5681 | } else { |
| 5682 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5683 | } |
| 5684 | } |
| 5685 | |
| 5686 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5687 | Primitive::Type result_type = conversion->GetResultType(); |
| 5688 | Primitive::Type input_type = conversion->GetInputType(); |
| 5689 | |
| 5690 | DCHECK_NE(input_type, result_type); |
| 5691 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5692 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5693 | int result_size = Primitive::ComponentSize(result_type); |
| 5694 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5695 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5696 | Register output = OutputRegister(conversion); |
| 5697 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5698 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5699 | // 'int' values are used directly as W registers, discarding the top |
| 5700 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5701 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5702 | // top 32 bits of the target register. We theoretically could leave those |
| 5703 | // bits unchanged, but we would have to make sure that no code uses a |
| 5704 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5705 | // zero. |
| 5706 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5707 | } else if (result_type == Primitive::kPrimChar || |
| 5708 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 5709 | __ Ubfx(output, |
| 5710 | output.IsX() ? source.X() : source.W(), |
| 5711 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5712 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5713 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5714 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5715 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5716 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5717 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5718 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 5719 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5720 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 5721 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5722 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5723 | } else { |
| 5724 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5725 | << " to " << result_type; |
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 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5728 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5729 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5730 | HandleShift(ushr); |
| 5731 | } |
| 5732 | |
| 5733 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5734 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5735 | } |
| 5736 | |
| 5737 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5738 | HandleBinaryOp(instruction); |
| 5739 | } |
| 5740 | |
| 5741 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5742 | HandleBinaryOp(instruction); |
| 5743 | } |
| 5744 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5745 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5746 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5747 | LOG(FATAL) << "Unreachable"; |
| 5748 | } |
| 5749 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5750 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5751 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5752 | LOG(FATAL) << "Unreachable"; |
| 5753 | } |
| 5754 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5755 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5756 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5757 | LocationSummary* locations = |
| 5758 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5759 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5760 | } |
| 5761 | |
| 5762 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5763 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5764 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5765 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5766 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5767 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5768 | // 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] | 5769 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5770 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5771 | // make sure we don't emit it if the target may run out of range. |
| 5772 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5773 | // ranges and emit the tables only as required. |
| 5774 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5775 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5776 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5777 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5778 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5779 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5780 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5781 | Register temp = temps.AcquireW(); |
| 5782 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5783 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5784 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5785 | // Jump to successors[0] if value == lower_bound. |
| 5786 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5787 | int32_t last_index = 0; |
| 5788 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5789 | __ Subs(temp, temp, Operand(2)); |
| 5790 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5791 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5792 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5793 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5794 | } |
| 5795 | if (num_entries - last_index == 2) { |
| 5796 | // The last missing case_value. |
| 5797 | __ Cmp(temp, Operand(1)); |
| 5798 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5799 | } |
| 5800 | |
| 5801 | // And the default for any other value. |
| 5802 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5803 | __ B(codegen_->GetLabelOf(default_block)); |
| 5804 | } |
| 5805 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5806 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5807 | |
| 5808 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5809 | |
| 5810 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5811 | // registers, we are free to block one. |
| 5812 | Register temp_w = temps.AcquireW(); |
| 5813 | Register index; |
| 5814 | // Remove the bias. |
| 5815 | if (lower_bound != 0) { |
| 5816 | index = temp_w; |
| 5817 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5818 | } else { |
| 5819 | index = value_reg; |
| 5820 | } |
| 5821 | |
| 5822 | // Jump to default block if index is out of the range. |
| 5823 | __ Cmp(index, Operand(num_entries)); |
| 5824 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5825 | |
| 5826 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5827 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5828 | // register pressure. |
| 5829 | Register table_base = temps.AcquireX(); |
| 5830 | // Load jump offset from the table. |
| 5831 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5832 | Register jump_offset = temp_w; |
| 5833 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5834 | |
| 5835 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5836 | Register target_address = table_base; |
| 5837 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5838 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5839 | } |
| 5840 | } |
| 5841 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5842 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 5843 | HInstruction* instruction, |
| 5844 | Location out, |
| 5845 | uint32_t offset, |
| 5846 | Location maybe_temp, |
| 5847 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5848 | Primitive::Type type = Primitive::kPrimNot; |
| 5849 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5850 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5851 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5852 | if (kUseBakerReadBarrier) { |
| 5853 | // Load with fast path based Baker's read barrier. |
| 5854 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5855 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5856 | out, |
| 5857 | out_reg, |
| 5858 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5859 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5860 | /* needs_null_check */ false, |
| 5861 | /* use_load_acquire */ false); |
| 5862 | } else { |
| 5863 | // Load with slow path based read barrier. |
| 5864 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5865 | // in the following move operation, as we will need it for the |
| 5866 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5867 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5868 | __ Mov(temp_reg, out_reg); |
| 5869 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5870 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5871 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5872 | } |
| 5873 | } else { |
| 5874 | // Plain load with no read barrier. |
| 5875 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5876 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5877 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5878 | } |
| 5879 | } |
| 5880 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5881 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 5882 | HInstruction* instruction, |
| 5883 | Location out, |
| 5884 | Location obj, |
| 5885 | uint32_t offset, |
| 5886 | Location maybe_temp, |
| 5887 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5888 | Primitive::Type type = Primitive::kPrimNot; |
| 5889 | Register out_reg = RegisterFrom(out, type); |
| 5890 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5891 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5892 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5893 | if (kUseBakerReadBarrier) { |
| 5894 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5895 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5896 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5897 | out, |
| 5898 | obj_reg, |
| 5899 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5900 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5901 | /* needs_null_check */ false, |
| 5902 | /* use_load_acquire */ false); |
| 5903 | } else { |
| 5904 | // Load with slow path based read barrier. |
| 5905 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5906 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5907 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5908 | } |
| 5909 | } else { |
| 5910 | // Plain load with no read barrier. |
| 5911 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5912 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5913 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5914 | } |
| 5915 | } |
| 5916 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5917 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad( |
| 5918 | HInstruction* instruction, |
| 5919 | Location root, |
| 5920 | Register obj, |
| 5921 | uint32_t offset, |
| 5922 | vixl::aarch64::Label* fixup_label, |
| 5923 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5924 | DCHECK(fixup_label == nullptr || offset == 0u); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5925 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5926 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5927 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5928 | if (kUseBakerReadBarrier) { |
| 5929 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5930 | // Baker's read barrier are used. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5931 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 5932 | !Runtime::Current()->UseJitCompilation()) { |
| 5933 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5934 | // 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] | 5935 | // load into `temp` (actually IP1) the read barrier mark introspection |
| 5936 | // entrypoint. If `temp` is null, it means that `GetIsGcMarking()` is |
| 5937 | // false, and vice versa. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5938 | // |
| 5939 | // We use link-time generated thunks for the slow path. That thunk |
| 5940 | // checks the reference and jumps to the entrypoint if needed. |
| 5941 | // |
| 5942 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 5943 | // lr = &return_address; |
| 5944 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5945 | // if (temp != nullptr) { |
| 5946 | // goto gc_root_thunk<root_reg>(lr) |
| 5947 | // } |
| 5948 | // return_address: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5949 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5950 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5951 | DCHECK(temps.IsAvailable(ip0)); |
| 5952 | DCHECK(temps.IsAvailable(ip1)); |
| 5953 | temps.Exclude(ip0, ip1); |
| 5954 | uint32_t custom_data = |
| 5955 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
| 5956 | vixl::aarch64::Label* cbnz_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5957 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5958 | // ip1 = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 5959 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 5960 | const int32_t entry_point_offset = |
| 5961 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 5962 | __ Ldr(ip1, MemOperand(tr, entry_point_offset)); |
| 5963 | EmissionCheckScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 5964 | vixl::aarch64::Label return_address; |
| 5965 | __ adr(lr, &return_address); |
| 5966 | if (fixup_label != nullptr) { |
| 5967 | __ Bind(fixup_label); |
| 5968 | } |
| 5969 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 5970 | "GC root LDR must be 2 instruction (8B) before the return address label."); |
| 5971 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 5972 | __ Bind(cbnz_label); |
| 5973 | __ cbnz(ip1, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 5974 | __ Bind(&return_address); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5975 | } else { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5976 | // Note that we do not actually check the value of |
| 5977 | // `GetIsGcMarking()` to decide whether to mark the loaded GC |
| 5978 | // root or not. Instead, we load into `temp` the read barrier |
| 5979 | // mark entry point corresponding to register `root`. If `temp` |
| 5980 | // is null, it means that `GetIsGcMarking()` is false, and vice |
| 5981 | // versa. |
| 5982 | // |
| 5983 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5984 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5985 | // if (temp != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 5986 | // // Slow path. |
| 5987 | // root = temp(root); // root = ReadBarrier::Mark(root); // Runtime entry point call. |
| 5988 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5989 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5990 | // Slow path marking the GC root `root`. The entrypoint will already be loaded in `temp`. |
| 5991 | Register temp = lr; |
| 5992 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64( |
| 5993 | instruction, root, /* entrypoint */ LocationFrom(temp)); |
| 5994 | codegen_->AddSlowPath(slow_path); |
| 5995 | |
| 5996 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5997 | const int32_t entry_point_offset = |
| 5998 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(root.reg()); |
| 5999 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6000 | // threads are suspended or running a checkpoint. |
| 6001 | __ Ldr(temp, MemOperand(tr, entry_point_offset)); |
| 6002 | |
| 6003 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6004 | if (fixup_label == nullptr) { |
| 6005 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6006 | } else { |
| 6007 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
| 6008 | } |
| 6009 | static_assert( |
| 6010 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6011 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6012 | "have different sizes."); |
| 6013 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6014 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6015 | "have different sizes."); |
| 6016 | |
| 6017 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6018 | // checking GetIsGcMarking. |
| 6019 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 6020 | __ Bind(slow_path->GetExitLabel()); |
| 6021 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6022 | } else { |
| 6023 | // GC root loaded through a slow path for read barriers other |
| 6024 | // than Baker's. |
| 6025 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6026 | if (fixup_label == nullptr) { |
| 6027 | __ Add(root_reg.X(), obj.X(), offset); |
| 6028 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6029 | codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6030 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6031 | // /* mirror::Object* */ root = root->Read() |
| 6032 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6033 | } |
| 6034 | } else { |
| 6035 | // Plain GC root load with no read barrier. |
| 6036 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6037 | if (fixup_label == nullptr) { |
| 6038 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6039 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6040 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6041 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6042 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6043 | // do not have to unpoison `root_reg` here. |
| 6044 | } |
| 6045 | } |
| 6046 | |
| 6047 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6048 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6049 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6050 | uint32_t offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6051 | Location maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6052 | bool needs_null_check, |
| 6053 | bool use_load_acquire) { |
| 6054 | DCHECK(kEmitCompilerReadBarrier); |
| 6055 | DCHECK(kUseBakerReadBarrier); |
| 6056 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6057 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6058 | !use_load_acquire && |
| 6059 | !Runtime::Current()->UseJitCompilation()) { |
| 6060 | // Note that we do not actually check the value of `GetIsGcMarking()` |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6061 | // to decide whether to mark the loaded reference or not. Instead, we |
| 6062 | // load into `temp` (actually IP1) the read barrier mark introspection |
| 6063 | // entrypoint. If `temp` is null, it means that `GetIsGcMarking()` is |
| 6064 | // false, and vice versa. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6065 | // |
| 6066 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6067 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6068 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6069 | // |
| 6070 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6071 | // lr = &gray_return_address; |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6072 | // if (temp != nullptr) { |
| 6073 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 6074 | // } |
| 6075 | // not_gray_return_address: |
| 6076 | // // Original reference load. If the offset is too large to fit |
| 6077 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6078 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6079 | // gray_return_address: |
| 6080 | |
| 6081 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6082 | Register base = obj; |
| 6083 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6084 | DCHECK(maybe_temp.IsRegister()); |
| 6085 | base = WRegisterFrom(maybe_temp); |
| 6086 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6087 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6088 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 6089 | } |
| 6090 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6091 | DCHECK(temps.IsAvailable(ip0)); |
| 6092 | DCHECK(temps.IsAvailable(ip1)); |
| 6093 | temps.Exclude(ip0, ip1); |
| 6094 | uint32_t custom_data = linker::Arm64RelativePatcher::EncodeBakerReadBarrierFieldData( |
| 6095 | base.GetCode(), |
| 6096 | obj.GetCode()); |
| 6097 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6098 | |
| 6099 | // ip1 = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6100 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6101 | const int32_t entry_point_offset = |
| 6102 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6103 | __ Ldr(ip1, MemOperand(tr, entry_point_offset)); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 6104 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6105 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6106 | vixl::aarch64::Label return_address; |
| 6107 | __ adr(lr, &return_address); |
| 6108 | __ Bind(cbnz_label); |
| 6109 | __ cbnz(ip1, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 6110 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6111 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6112 | " 2 instructions (8B) for heap poisoning."); |
| 6113 | Register ref_reg = RegisterFrom(ref, Primitive::kPrimNot); |
| 6114 | __ ldr(ref_reg, MemOperand(base.X(), offset)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6115 | if (needs_null_check) { |
| 6116 | MaybeRecordImplicitNullCheck(instruction); |
| 6117 | } |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 6118 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6119 | __ Bind(&return_address); |
| 6120 | return; |
| 6121 | } |
| 6122 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6123 | // /* HeapReference<Object> */ ref = *(obj + offset) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6124 | Register temp = WRegisterFrom(maybe_temp); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6125 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6126 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6127 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6128 | ref, |
| 6129 | obj, |
| 6130 | offset, |
| 6131 | no_index, |
| 6132 | no_scale_factor, |
| 6133 | temp, |
| 6134 | needs_null_check, |
| 6135 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6136 | } |
| 6137 | |
| 6138 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6139 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6140 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6141 | uint32_t data_offset, |
| 6142 | Location index, |
| 6143 | Register temp, |
| 6144 | bool needs_null_check) { |
| 6145 | DCHECK(kEmitCompilerReadBarrier); |
| 6146 | DCHECK(kUseBakerReadBarrier); |
| 6147 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6148 | static_assert( |
| 6149 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6150 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6151 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 6152 | |
| 6153 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6154 | !Runtime::Current()->UseJitCompilation()) { |
| 6155 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6156 | // to decide whether to mark the loaded reference or not. Instead, we |
| 6157 | // load into `temp` (actually IP1) the read barrier mark introspection |
| 6158 | // entrypoint. If `temp` is null, it means that `GetIsGcMarking()` is |
| 6159 | // false, and vice versa. |
| 6160 | // |
| 6161 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6162 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6163 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6164 | // |
| 6165 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 6166 | // lr = &gray_return_address; |
| 6167 | // if (temp != nullptr) { |
| 6168 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 6169 | // } |
| 6170 | // not_gray_return_address: |
| 6171 | // // Original reference load. If the offset is too large to fit |
| 6172 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 6173 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6174 | // gray_return_address: |
| 6175 | |
| 6176 | DCHECK(index.IsValid()); |
| 6177 | Register index_reg = RegisterFrom(index, Primitive::kPrimInt); |
| 6178 | Register ref_reg = RegisterFrom(ref, Primitive::kPrimNot); |
| 6179 | |
| 6180 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6181 | DCHECK(temps.IsAvailable(ip0)); |
| 6182 | DCHECK(temps.IsAvailable(ip1)); |
| 6183 | temps.Exclude(ip0, ip1); |
| 6184 | uint32_t custom_data = |
| 6185 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierArrayData(temp.GetCode()); |
| 6186 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6187 | |
| 6188 | // ip1 = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6189 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6190 | const int32_t entry_point_offset = |
| 6191 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6192 | __ Ldr(ip1, MemOperand(tr, entry_point_offset)); |
| 6193 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
| 6194 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6195 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6196 | vixl::aarch64::Label return_address; |
| 6197 | __ adr(lr, &return_address); |
| 6198 | __ Bind(cbnz_label); |
| 6199 | __ cbnz(ip1, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6200 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6201 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6202 | " 2 instructions (8B) for heap poisoning."); |
| 6203 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6204 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6205 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6206 | __ Bind(&return_address); |
| 6207 | return; |
| 6208 | } |
| 6209 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6210 | // Array cells are never volatile variables, therefore array loads |
| 6211 | // never use Load-Acquire instructions on ARM64. |
| 6212 | const bool use_load_acquire = false; |
| 6213 | |
| 6214 | // /* HeapReference<Object> */ ref = |
| 6215 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6216 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6217 | ref, |
| 6218 | obj, |
| 6219 | data_offset, |
| 6220 | index, |
| 6221 | scale_factor, |
| 6222 | temp, |
| 6223 | needs_null_check, |
| 6224 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6225 | } |
| 6226 | |
| 6227 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6228 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6229 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6230 | uint32_t offset, |
| 6231 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6232 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6233 | Register temp, |
| 6234 | bool needs_null_check, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6235 | bool use_load_acquire) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6236 | DCHECK(kEmitCompilerReadBarrier); |
| 6237 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6238 | // If we are emitting an array load, we should not be using a |
| 6239 | // Load Acquire instruction. In other words: |
| 6240 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6241 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6242 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6243 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 6244 | // whether we need to enter the slow path to mark the reference. |
| 6245 | // Then, in the slow path, check the gray bit in the lock word of |
| 6246 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 6247 | // not. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6248 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6249 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
| 6250 | // instead, we load into `temp2` the read barrier mark entry point |
| 6251 | // corresponding to register `ref`. If `temp2` is null, it means |
| 6252 | // that `GetIsGcMarking()` is false, and vice versa. |
| 6253 | // |
| 6254 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6255 | // if (temp2 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 6256 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6257 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6258 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6259 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 6260 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6261 | // if (is_gray) { |
| 6262 | // ref = temp2(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 6263 | // } |
| 6264 | // } else { |
| 6265 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6266 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6267 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6268 | // Slow path marking the object `ref` when the GC is marking. The |
| 6269 | // entrypoint will already be loaded in `temp2`. |
| 6270 | Register temp2 = lr; |
| 6271 | Location temp2_loc = LocationFrom(temp2); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6272 | SlowPathCodeARM64* slow_path = |
| 6273 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM64( |
| 6274 | instruction, |
| 6275 | ref, |
| 6276 | obj, |
| 6277 | offset, |
| 6278 | index, |
| 6279 | scale_factor, |
| 6280 | needs_null_check, |
| 6281 | use_load_acquire, |
| 6282 | temp, |
| 6283 | /* entrypoint */ temp2_loc); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6284 | AddSlowPath(slow_path); |
| 6285 | |
| 6286 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 6287 | const int32_t entry_point_offset = |
| 6288 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref.reg()); |
| 6289 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6290 | // threads are suspended or running a checkpoint. |
| 6291 | __ Ldr(temp2, MemOperand(tr, entry_point_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6292 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6293 | // checking GetIsGcMarking. |
| 6294 | __ Cbnz(temp2, slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6295 | // Fast path: the GC is not marking: just load the reference. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6296 | GenerateRawReferenceLoad( |
| 6297 | 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] | 6298 | __ Bind(slow_path->GetExitLabel()); |
| 6299 | } |
| 6300 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 6301 | void CodeGeneratorARM64::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 6302 | Location ref, |
| 6303 | Register obj, |
| 6304 | Location field_offset, |
| 6305 | Register temp, |
| 6306 | bool needs_null_check, |
| 6307 | bool use_load_acquire) { |
| 6308 | DCHECK(kEmitCompilerReadBarrier); |
| 6309 | DCHECK(kUseBakerReadBarrier); |
| 6310 | // If we are emitting an array load, we should not be using a |
| 6311 | // Load Acquire instruction. In other words: |
| 6312 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6313 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
| 6314 | |
| 6315 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 6316 | // whether we need to enter the slow path to update the reference |
| 6317 | // field within `obj`. Then, in the slow path, check the gray bit |
| 6318 | // in the lock word of the reference's holder (`obj`) to decide |
| 6319 | // whether to mark `ref` and update the field or not. |
| 6320 | // |
| 6321 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
| 6322 | // instead, we load into `temp2` the read barrier mark entry point |
| 6323 | // corresponding to register `ref`. If `temp2` is null, it means |
| 6324 | // that `GetIsGcMarking()` is false, and vice versa. |
| 6325 | // |
| 6326 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6327 | // if (temp2 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 6328 | // // Slow path. |
| 6329 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6330 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6331 | // HeapReference<mirror::Object> ref = *(obj + field_offset); // Reference load. |
| 6332 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6333 | // if (is_gray) { |
| 6334 | // old_ref = ref; |
| 6335 | // ref = temp2(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 6336 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 6337 | // } |
| 6338 | // } |
| 6339 | |
| 6340 | // Slow path updating the object reference at address `obj + field_offset` |
| 6341 | // when the GC is marking. The entrypoint will already be loaded in `temp2`. |
| 6342 | Register temp2 = lr; |
| 6343 | Location temp2_loc = LocationFrom(temp2); |
| 6344 | SlowPathCodeARM64* slow_path = |
| 6345 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 6346 | instruction, |
| 6347 | ref, |
| 6348 | obj, |
| 6349 | /* offset */ 0u, |
| 6350 | /* index */ field_offset, |
| 6351 | /* scale_factor */ 0u /* "times 1" */, |
| 6352 | needs_null_check, |
| 6353 | use_load_acquire, |
| 6354 | temp, |
| 6355 | /* entrypoint */ temp2_loc); |
| 6356 | AddSlowPath(slow_path); |
| 6357 | |
| 6358 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 6359 | const int32_t entry_point_offset = |
| 6360 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref.reg()); |
| 6361 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6362 | // threads are suspended or running a checkpoint. |
| 6363 | __ Ldr(temp2, MemOperand(tr, entry_point_offset)); |
| 6364 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6365 | // checking GetIsGcMarking. |
| 6366 | __ Cbnz(temp2, slow_path->GetEntryLabel()); |
| 6367 | // Fast path: the GC is not marking: nothing to do (the field is |
| 6368 | // up-to-date, and we don't need to load the reference). |
| 6369 | __ Bind(slow_path->GetExitLabel()); |
| 6370 | } |
| 6371 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6372 | void CodeGeneratorARM64::GenerateRawReferenceLoad(HInstruction* instruction, |
| 6373 | Location ref, |
| 6374 | Register obj, |
| 6375 | uint32_t offset, |
| 6376 | Location index, |
| 6377 | size_t scale_factor, |
| 6378 | bool needs_null_check, |
| 6379 | bool use_load_acquire) { |
| 6380 | DCHECK(obj.IsW()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6381 | Primitive::Type type = Primitive::kPrimNot; |
| 6382 | Register ref_reg = RegisterFrom(ref, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6383 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6384 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 6385 | // that no pools are emitted between the load (macro) instruction |
| 6386 | // and MaybeRecordImplicitNullCheck. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6387 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6388 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6389 | // Load types involving an "index": ArrayGet, |
| 6390 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6391 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6392 | if (use_load_acquire) { |
| 6393 | // UnsafeGetObjectVolatile intrinsic case. |
| 6394 | // Register `index` is not an index in an object array, but an |
| 6395 | // offset to an object reference field within object `obj`. |
| 6396 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 6397 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 6398 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 6399 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6400 | DCHECK_EQ(offset, 0u); |
| 6401 | DCHECK_EQ(scale_factor, 0u); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6402 | DCHECK_EQ(needs_null_check, false); |
| 6403 | // /* HeapReference<mirror::Object> */ ref = *(obj + index) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6404 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 6405 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6406 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6407 | // ArrayGet and UnsafeGetObject and UnsafeCASObject intrinsics cases. |
| 6408 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6409 | if (index.IsConstant()) { |
| 6410 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6411 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6412 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6413 | if (needs_null_check) { |
| 6414 | MaybeRecordImplicitNullCheck(instruction); |
| 6415 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6416 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6417 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6418 | Register temp = temps.AcquireW(); |
| 6419 | __ Add(temp, obj, offset); |
| 6420 | { |
| 6421 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6422 | Load(type, ref_reg, HeapOperand(temp, XRegisterFrom(index), LSL, scale_factor)); |
| 6423 | if (needs_null_check) { |
| 6424 | MaybeRecordImplicitNullCheck(instruction); |
| 6425 | } |
| 6426 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6427 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6428 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6429 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6430 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6431 | MemOperand field = HeapOperand(obj, offset); |
| 6432 | if (use_load_acquire) { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6433 | // Implicit null checks are handled by CodeGeneratorARM64::LoadAcquire. |
| 6434 | LoadAcquire(instruction, ref_reg, field, needs_null_check); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6435 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6436 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6437 | Load(type, ref_reg, field); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6438 | if (needs_null_check) { |
| 6439 | MaybeRecordImplicitNullCheck(instruction); |
| 6440 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6441 | } |
| 6442 | } |
| 6443 | |
| 6444 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6445 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6446 | } |
| 6447 | |
| 6448 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6449 | Location out, |
| 6450 | Location ref, |
| 6451 | Location obj, |
| 6452 | uint32_t offset, |
| 6453 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6454 | DCHECK(kEmitCompilerReadBarrier); |
| 6455 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6456 | // Insert a slow path based read barrier *after* the reference load. |
| 6457 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6458 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6459 | // reference will be carried out by the runtime within the slow |
| 6460 | // path. |
| 6461 | // |
| 6462 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6463 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6464 | // not used by the artReadBarrierSlow entry point. |
| 6465 | // |
| 6466 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6467 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 6468 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6469 | AddSlowPath(slow_path); |
| 6470 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6471 | __ B(slow_path->GetEntryLabel()); |
| 6472 | __ Bind(slow_path->GetExitLabel()); |
| 6473 | } |
| 6474 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6475 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6476 | Location out, |
| 6477 | Location ref, |
| 6478 | Location obj, |
| 6479 | uint32_t offset, |
| 6480 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6481 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6482 | // Baker's read barriers shall be handled by the fast path |
| 6483 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6484 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6485 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6486 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6487 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6488 | } else if (kPoisonHeapReferences) { |
| 6489 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6490 | } |
| 6491 | } |
| 6492 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6493 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6494 | Location out, |
| 6495 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6496 | DCHECK(kEmitCompilerReadBarrier); |
| 6497 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6498 | // Insert a slow path based read barrier *after* the GC root load. |
| 6499 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6500 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6501 | // not need to do anything special for this here. |
| 6502 | SlowPathCodeARM64* slow_path = |
| 6503 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 6504 | AddSlowPath(slow_path); |
| 6505 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6506 | __ B(slow_path->GetEntryLabel()); |
| 6507 | __ Bind(slow_path->GetExitLabel()); |
| 6508 | } |
| 6509 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6510 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6511 | LocationSummary* locations = |
| 6512 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6513 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6514 | locations->SetOut(Location::RequiresRegister()); |
| 6515 | } |
| 6516 | |
| 6517 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6518 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6519 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6520 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6521 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6522 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6523 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6524 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6525 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6526 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6527 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6528 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6529 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6530 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6531 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6532 | } |
| 6533 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6534 | static void PatchJitRootUse(uint8_t* code, |
| 6535 | const uint8_t* roots_data, |
| 6536 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6537 | uint64_t index_in_table) { |
| 6538 | uint32_t literal_offset = literal->GetOffset(); |
| 6539 | uintptr_t address = |
| 6540 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6541 | uint8_t* data = code + literal_offset; |
| 6542 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6543 | } |
| 6544 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6545 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6546 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6547 | const StringReference& string_reference = entry.first; |
| 6548 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| 6549 | const auto it = jit_string_roots_.find(string_reference); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6550 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6551 | uint64_t index_in_table = it->second; |
| 6552 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6553 | } |
| 6554 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6555 | const TypeReference& type_reference = entry.first; |
| 6556 | vixl::aarch64::Literal<uint32_t>* table_entry_literal = entry.second; |
| 6557 | const auto it = jit_class_roots_.find(type_reference); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6558 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 6559 | uint64_t index_in_table = it->second; |
| 6560 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6561 | } |
| 6562 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6563 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6564 | #undef __ |
| 6565 | #undef QUICK_ENTRY_POINT |
| 6566 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6567 | } // namespace arm64 |
| 6568 | } // namespace art |