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" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 32 | #include "offsets.h" |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 33 | #include "thread.h" |
| 34 | #include "utils/arm64/assembler_arm64.h" |
| 35 | #include "utils/assembler.h" |
| 36 | #include "utils/stack_checks.h" |
| 37 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 38 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 39 | using vixl::ExactAssemblyScope; |
| 40 | using vixl::CodeBufferCheckScope; |
| 41 | using vixl::EmissionCheckScope; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 42 | |
| 43 | #ifdef __ |
| 44 | #error "ARM64 Codegen VIXL macro-assembler macro already defined." |
| 45 | #endif |
| 46 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 47 | namespace art { |
| 48 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 49 | template<class MirrorType> |
| 50 | class GcRoot; |
| 51 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 52 | namespace arm64 { |
| 53 | |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 54 | using helpers::ARM64EncodableConstantOrRegister; |
| 55 | using helpers::ArtVixlRegCodeCoherentForRegSet; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 56 | using helpers::CPURegisterFrom; |
| 57 | using helpers::DRegisterFrom; |
| 58 | using helpers::FPRegisterFrom; |
| 59 | using helpers::HeapOperand; |
| 60 | using helpers::HeapOperandFrom; |
| 61 | using helpers::InputCPURegisterAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 62 | using helpers::InputCPURegisterOrZeroRegAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 63 | using helpers::InputFPRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 64 | using helpers::InputOperandAt; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 65 | using helpers::InputRegisterAt; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 66 | using helpers::Int64ConstantFrom; |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 67 | using helpers::IsConstantZeroBitPattern; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 68 | using helpers::LocationFrom; |
| 69 | using helpers::OperandFromMemOperand; |
| 70 | using helpers::OutputCPURegister; |
| 71 | using helpers::OutputFPRegister; |
| 72 | using helpers::OutputRegister; |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 73 | using helpers::QRegisterFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 74 | using helpers::RegisterFrom; |
| 75 | using helpers::StackOperandFrom; |
| 76 | using helpers::VIXLRegCodeFromART; |
| 77 | using helpers::WRegisterFrom; |
| 78 | using helpers::XRegisterFrom; |
| 79 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 80 | static constexpr int kCurrentMethodStackOffset = 0; |
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. |
| 859 | // The fast path/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 | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1010 | // /* int32_t */ monitor = obj->monitor_ |
| 1011 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1012 | __ Ldr(temp_, HeapOperand(obj_, monitor_offset)); |
| 1013 | if (needs_null_check_) { |
| 1014 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1015 | } |
| 1016 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1017 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1018 | "art::LockWord and int32_t have different sizes."); |
| 1019 | |
| 1020 | // Introduce a dependency on the lock_word including rb_state, |
| 1021 | // to prevent load-load reordering, and without using |
| 1022 | // a memory barrier (which would be more expensive). |
| 1023 | // `obj` is unchanged by this operation, but its value now depends |
| 1024 | // on `temp`. |
| 1025 | __ Add(obj_.X(), obj_.X(), Operand(temp_.X(), LSR, 32)); |
| 1026 | |
| 1027 | // The actual reference load. |
| 1028 | // A possible implicit null check has already been handled above. |
| 1029 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1030 | arm64_codegen->GenerateRawReferenceLoad(instruction_, |
| 1031 | ref_, |
| 1032 | obj_, |
| 1033 | offset_, |
| 1034 | index_, |
| 1035 | scale_factor_, |
| 1036 | /* needs_null_check */ false, |
| 1037 | use_load_acquire_); |
| 1038 | |
| 1039 | // Mark the object `ref` when `obj` is gray. |
| 1040 | // |
| 1041 | // if (rb_state == ReadBarrier::GrayState()) |
| 1042 | // ref = ReadBarrier::Mark(ref); |
| 1043 | // |
| 1044 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 1045 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1046 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1047 | __ Tbz(temp_, LockWord::kReadBarrierStateShift, GetExitLabel()); |
| 1048 | |
| 1049 | // Save the old value of the reference before marking it. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1050 | // Note that we cannot use IP to save the old reference, as IP is |
| 1051 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1052 | // need the old reference after the call to that entry point. |
| 1053 | DCHECK_NE(LocationFrom(temp_).reg(), IP0); |
| 1054 | __ Mov(temp_.W(), ref_reg); |
| 1055 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1056 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1057 | |
| 1058 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1059 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1060 | // |
| 1061 | // Note that this field could also hold a different object, if |
| 1062 | // another thread had concurrently changed it. In that case, the |
| 1063 | // LDXR/CMP/BNE sequence of instructions in the compare-and-set |
| 1064 | // (CAS) operation below would abort the CAS, leaving the field |
| 1065 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1066 | __ Cmp(temp_.W(), ref_reg); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1067 | __ B(eq, GetExitLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1068 | |
| 1069 | // Update the the holder's field atomically. This may fail if |
| 1070 | // mutator updates before us, but it's OK. This is achieved |
| 1071 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1072 | // memory synchronization ordering, where the expected value is |
| 1073 | // the old reference and the desired value is the new reference. |
| 1074 | |
| 1075 | MacroAssembler* masm = arm64_codegen->GetVIXLAssembler(); |
| 1076 | UseScratchRegisterScope temps(masm); |
| 1077 | |
| 1078 | // Convenience aliases. |
| 1079 | Register base = obj_.W(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1080 | Register offset = XRegisterFrom(field_offset); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1081 | Register expected = temp_.W(); |
| 1082 | Register value = ref_reg; |
| 1083 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1084 | Register tmp_value = temps.AcquireW(); // Value in memory. |
| 1085 | |
| 1086 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1087 | |
| 1088 | if (kPoisonHeapReferences) { |
| 1089 | arm64_codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1090 | if (value.Is(expected)) { |
| 1091 | // Do not poison `value`, as it is the same register as |
| 1092 | // `expected`, which has just been poisoned. |
| 1093 | } else { |
| 1094 | arm64_codegen->GetAssembler()->PoisonHeapReference(value); |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | // do { |
| 1099 | // tmp_value = [tmp_ptr] - expected; |
| 1100 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1101 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1102 | vixl::aarch64::Label loop_head, comparison_failed, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1103 | __ Bind(&loop_head); |
| 1104 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
| 1105 | __ Cmp(tmp_value, expected); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1106 | __ B(&comparison_failed, ne); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1107 | __ Stxr(tmp_value, value, MemOperand(tmp_ptr)); |
| 1108 | __ Cbnz(tmp_value, &loop_head); |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1109 | __ B(&exit_loop); |
| 1110 | __ Bind(&comparison_failed); |
| 1111 | __ Clrex(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1112 | __ Bind(&exit_loop); |
| 1113 | |
| 1114 | if (kPoisonHeapReferences) { |
| 1115 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1116 | if (value.Is(expected)) { |
| 1117 | // Do not unpoison `value`, as it is the same register as |
| 1118 | // `expected`, which has just been unpoisoned. |
| 1119 | } else { |
| 1120 | arm64_codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1121 | } |
| 1122 | } |
| 1123 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1124 | __ B(GetExitLabel()); |
| 1125 | } |
| 1126 | |
| 1127 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1128 | // The register containing the object holding the marked object reference field. |
| 1129 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1130 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1131 | uint32_t offset_; |
| 1132 | Location index_; |
| 1133 | size_t scale_factor_; |
| 1134 | // Is a null check required? |
| 1135 | bool needs_null_check_; |
| 1136 | // Should this reference load use Load-Acquire semantics? |
| 1137 | bool use_load_acquire_; |
| 1138 | // A temporary register used to hold the lock word of `obj_`; and |
| 1139 | // also to hold the original reference value, when the reference is |
| 1140 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1141 | const Register temp_; |
| 1142 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1143 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1144 | }; |
| 1145 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1146 | // Slow path generating a read barrier for a heap reference. |
| 1147 | class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 { |
| 1148 | public: |
| 1149 | ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction, |
| 1150 | Location out, |
| 1151 | Location ref, |
| 1152 | Location obj, |
| 1153 | uint32_t offset, |
| 1154 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1155 | : SlowPathCodeARM64(instruction), |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1156 | out_(out), |
| 1157 | ref_(ref), |
| 1158 | obj_(obj), |
| 1159 | offset_(offset), |
| 1160 | index_(index) { |
| 1161 | DCHECK(kEmitCompilerReadBarrier); |
| 1162 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1163 | // has been overwritten by (or after) the heap object reference load |
| 1164 | // to be instrumented, e.g.: |
| 1165 | // |
| 1166 | // __ Ldr(out, HeapOperand(out, class_offset); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1167 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1168 | // |
| 1169 | // In that case, we have lost the information about the original |
| 1170 | // object, and the emitted read barrier cannot work properly. |
| 1171 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1172 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1173 | } |
| 1174 | |
| 1175 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1176 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1177 | LocationSummary* locations = instruction_->GetLocations(); |
| 1178 | Primitive::Type type = Primitive::kPrimNot; |
| 1179 | DCHECK(locations->CanCall()); |
| 1180 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1181 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1182 | instruction_->IsStaticFieldGet() || |
| 1183 | instruction_->IsArrayGet() || |
| 1184 | instruction_->IsInstanceOf() || |
| 1185 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1186 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1187 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1188 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1189 | // The read barrier instrumentation of object ArrayGet |
| 1190 | // instructions does not support the HIntermediateAddress |
| 1191 | // instruction. |
Roland Levillain | cd3d0fb | 2016-01-15 19:26:48 +0000 | [diff] [blame] | 1192 | DCHECK(!(instruction_->IsArrayGet() && |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1193 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1194 | |
| 1195 | __ Bind(GetEntryLabel()); |
| 1196 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1197 | SaveLiveRegisters(codegen, locations); |
| 1198 | |
| 1199 | // We may have to change the index's value, but as `index_` is a |
| 1200 | // constant member (like other "inputs" of this slow path), |
| 1201 | // introduce a copy of it, `index`. |
| 1202 | Location index = index_; |
| 1203 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1204 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1205 | if (instruction_->IsArrayGet()) { |
| 1206 | // Compute the actual memory offset and store it in `index`. |
| 1207 | Register index_reg = RegisterFrom(index_, Primitive::kPrimInt); |
| 1208 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg())); |
| 1209 | if (codegen->IsCoreCalleeSaveRegister(index_.reg())) { |
| 1210 | // We are about to change the value of `index_reg` (see the |
| 1211 | // calls to vixl::MacroAssembler::Lsl and |
| 1212 | // vixl::MacroAssembler::Mov below), but it has |
| 1213 | // not been saved by the previous call to |
| 1214 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1215 | // callee-save register -- |
| 1216 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1217 | // callee-save registers, as it has been designed with the |
| 1218 | // assumption that callee-save registers are supposed to be |
| 1219 | // handled by the called function. So, as a callee-save |
| 1220 | // register, `index_reg` _would_ eventually be saved onto |
| 1221 | // the stack, but it would be too late: we would have |
| 1222 | // changed its value earlier. Therefore, we manually save |
| 1223 | // it here into another freely available register, |
| 1224 | // `free_reg`, chosen of course among the caller-save |
| 1225 | // registers (as a callee-save `free_reg` register would |
| 1226 | // exhibit the same problem). |
| 1227 | // |
| 1228 | // Note we could have requested a temporary register from |
| 1229 | // the register allocator instead; but we prefer not to, as |
| 1230 | // this is a slow path, and we know we can find a |
| 1231 | // caller-save register that is available. |
| 1232 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1233 | __ Mov(free_reg.W(), index_reg); |
| 1234 | index_reg = free_reg; |
| 1235 | index = LocationFrom(index_reg); |
| 1236 | } else { |
| 1237 | // The initial register stored in `index_` has already been |
| 1238 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1239 | // (as it is not a callee-save register), so we can freely |
| 1240 | // use it. |
| 1241 | } |
| 1242 | // Shifting the index value contained in `index_reg` by the scale |
| 1243 | // factor (2) cannot overflow in practice, as the runtime is |
| 1244 | // unable to allocate object arrays with a size larger than |
| 1245 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1246 | __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type)); |
| 1247 | static_assert( |
| 1248 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1249 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1250 | __ Add(index_reg, index_reg, Operand(offset_)); |
| 1251 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1252 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1253 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1254 | // (as in the case of ArrayGet), as it is actually an offset |
| 1255 | // to an object field within an object. |
| 1256 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1257 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1258 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1259 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1260 | << instruction_->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1261 | DCHECK_EQ(offset_, 0u); |
Roland Levillain | a7426c6 | 2016-08-03 15:02:10 +0100 | [diff] [blame] | 1262 | DCHECK(index_.IsRegister()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | // We're moving two or three locations to locations that could |
| 1267 | // overlap, so we need a parallel move resolver. |
| 1268 | InvokeRuntimeCallingConvention calling_convention; |
| 1269 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1270 | parallel_move.AddMove(ref_, |
| 1271 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1272 | type, |
| 1273 | nullptr); |
| 1274 | parallel_move.AddMove(obj_, |
| 1275 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| 1276 | type, |
| 1277 | nullptr); |
| 1278 | if (index.IsValid()) { |
| 1279 | parallel_move.AddMove(index, |
| 1280 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| 1281 | Primitive::kPrimInt, |
| 1282 | nullptr); |
| 1283 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1284 | } else { |
| 1285 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1286 | arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_); |
| 1287 | } |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1288 | arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1289 | instruction_, |
| 1290 | instruction_->GetDexPc(), |
| 1291 | this); |
| 1292 | CheckEntrypointTypes< |
| 1293 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1294 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1295 | |
| 1296 | RestoreLiveRegisters(codegen, locations); |
| 1297 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1298 | __ B(GetExitLabel()); |
| 1299 | } |
| 1300 | |
| 1301 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; } |
| 1302 | |
| 1303 | private: |
| 1304 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1305 | size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode()); |
| 1306 | size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1307 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1308 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1309 | return Register(VIXLRegCodeFromART(i), kXRegSize); |
| 1310 | } |
| 1311 | } |
| 1312 | // We shall never fail to find a free caller-save register, as |
| 1313 | // there are more than two core caller-save registers on ARM64 |
| 1314 | // (meaning it is possible to find one which is different from |
| 1315 | // `ref` and `obj`). |
| 1316 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1317 | LOG(FATAL) << "Could not find a free register"; |
| 1318 | UNREACHABLE(); |
| 1319 | } |
| 1320 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1321 | const Location out_; |
| 1322 | const Location ref_; |
| 1323 | const Location obj_; |
| 1324 | const uint32_t offset_; |
| 1325 | // An additional location containing an index to an array. |
| 1326 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1327 | // UnsafeGetObjectVolatile intrinsics. |
| 1328 | const Location index_; |
| 1329 | |
| 1330 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64); |
| 1331 | }; |
| 1332 | |
| 1333 | // Slow path generating a read barrier for a GC root. |
| 1334 | class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 { |
| 1335 | public: |
| 1336 | ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 1337 | : SlowPathCodeARM64(instruction), out_(out), root_(root) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1338 | DCHECK(kEmitCompilerReadBarrier); |
| 1339 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1340 | |
| 1341 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1342 | LocationSummary* locations = instruction_->GetLocations(); |
| 1343 | Primitive::Type type = Primitive::kPrimNot; |
| 1344 | DCHECK(locations->CanCall()); |
| 1345 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1346 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1347 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1348 | << instruction_->DebugName(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1349 | |
| 1350 | __ Bind(GetEntryLabel()); |
| 1351 | SaveLiveRegisters(codegen, locations); |
| 1352 | |
| 1353 | InvokeRuntimeCallingConvention calling_convention; |
| 1354 | CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen); |
| 1355 | // The argument of the ReadBarrierForRootSlow is not a managed |
| 1356 | // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`; |
| 1357 | // thus we need a 64-bit move here, and we cannot use |
| 1358 | // |
| 1359 | // arm64_codegen->MoveLocation( |
| 1360 | // LocationFrom(calling_convention.GetRegisterAt(0)), |
| 1361 | // root_, |
| 1362 | // type); |
| 1363 | // |
| 1364 | // which would emit a 32-bit move, as `type` is a (32-bit wide) |
| 1365 | // reference type (`Primitive::kPrimNot`). |
| 1366 | __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_)); |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 1367 | arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1368 | instruction_, |
| 1369 | instruction_->GetDexPc(), |
| 1370 | this); |
| 1371 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1372 | arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type); |
| 1373 | |
| 1374 | RestoreLiveRegisters(codegen, locations); |
| 1375 | __ B(GetExitLabel()); |
| 1376 | } |
| 1377 | |
| 1378 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; } |
| 1379 | |
| 1380 | private: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1381 | const Location out_; |
| 1382 | const Location root_; |
| 1383 | |
| 1384 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64); |
| 1385 | }; |
| 1386 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1387 | #undef __ |
| 1388 | |
| 1389 | Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) { |
| 1390 | Location next_location; |
| 1391 | if (type == Primitive::kPrimVoid) { |
| 1392 | LOG(FATAL) << "Unreachable type " << type; |
| 1393 | } |
| 1394 | |
| 1395 | if (Primitive::IsFloatingPointType(type) && |
| 1396 | (float_index_ < calling_convention.GetNumberOfFpuRegisters())) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1397 | next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1398 | } else if (!Primitive::IsFloatingPointType(type) && |
| 1399 | (gp_index_ < calling_convention.GetNumberOfRegisters())) { |
| 1400 | next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++)); |
| 1401 | } else { |
| 1402 | size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1403 | next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset) |
| 1404 | : Location::StackSlot(stack_offset); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1405 | } |
| 1406 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1407 | // Space on the stack is reserved for all arguments. |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1408 | stack_index_ += Primitive::Is64BitType(type) ? 2 : 1; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1409 | return next_location; |
| 1410 | } |
| 1411 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1412 | Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1413 | return LocationFrom(kArtMethodRegister); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1414 | } |
| 1415 | |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1416 | CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph, |
| 1417 | const Arm64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1418 | const CompilerOptions& compiler_options, |
| 1419 | OptimizingCompilerStats* stats) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1420 | : CodeGenerator(graph, |
| 1421 | kNumberOfAllocatableRegisters, |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1422 | kNumberOfAllocatableFPRegisters, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1423 | kNumberOfAllocatableRegisterPairs, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1424 | callee_saved_core_registers.GetList(), |
| 1425 | callee_saved_fp_registers.GetList(), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1426 | compiler_options, |
| 1427 | stats), |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1428 | block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1429 | jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1430 | location_builder_(graph, this), |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1431 | instruction_visitor_(graph, this), |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1432 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1433 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1434 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1435 | uint32_literals_(std::less<uint32_t>(), |
| 1436 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1437 | uint64_literals_(std::less<uint64_t>(), |
| 1438 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1439 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1440 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1441 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1442 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1443 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1444 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1445 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1446 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 1447 | baker_read_barrier_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1448 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1449 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1450 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1451 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1452 | // Save the link register (containing the return address) to mimic Quick. |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1453 | AddAllocatedRegister(LocationFrom(lr)); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1454 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1455 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1456 | #define __ GetVIXLAssembler()-> |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1457 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1458 | void CodeGeneratorARM64::EmitJumpTables() { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 1459 | for (auto&& jump_table : jump_tables_) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1460 | jump_table->EmitTable(this); |
| 1461 | } |
| 1462 | } |
| 1463 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1464 | void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) { |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 1465 | EmitJumpTables(); |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1466 | // Ensure we emit the literal pool. |
| 1467 | __ FinalizeCode(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1468 | |
Serban Constantinescu | 32f5b4d | 2014-11-25 20:05:46 +0000 | [diff] [blame] | 1469 | CodeGenerator::Finalize(allocator); |
| 1470 | } |
| 1471 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1472 | void ParallelMoveResolverARM64::PrepareForEmitNativeCode() { |
| 1473 | // Note: There are 6 kinds of moves: |
| 1474 | // 1. constant -> GPR/FPR (non-cycle) |
| 1475 | // 2. constant -> stack (non-cycle) |
| 1476 | // 3. GPR/FPR -> GPR/FPR |
| 1477 | // 4. GPR/FPR -> stack |
| 1478 | // 5. stack -> GPR/FPR |
| 1479 | // 6. stack -> stack (non-cycle) |
| 1480 | // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5 |
| 1481 | // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting |
| 1482 | // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the |
| 1483 | // dependency. |
| 1484 | vixl_temps_.Open(GetVIXLAssembler()); |
| 1485 | } |
| 1486 | |
| 1487 | void ParallelMoveResolverARM64::FinishEmitNativeCode() { |
| 1488 | vixl_temps_.Close(); |
| 1489 | } |
| 1490 | |
| 1491 | Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) { |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1492 | DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister |
| 1493 | || kind == Location::kStackSlot || kind == Location::kDoubleStackSlot |
| 1494 | || kind == Location::kSIMDStackSlot); |
| 1495 | kind = (kind == Location::kFpuRegister || kind == Location::kSIMDStackSlot) |
| 1496 | ? Location::kFpuRegister |
| 1497 | : Location::kRegister; |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1498 | Location scratch = GetScratchLocation(kind); |
| 1499 | if (!scratch.Equals(Location::NoLocation())) { |
| 1500 | return scratch; |
| 1501 | } |
| 1502 | // Allocate from VIXL temp registers. |
| 1503 | if (kind == Location::kRegister) { |
| 1504 | scratch = LocationFrom(vixl_temps_.AcquireX()); |
| 1505 | } else { |
| 1506 | DCHECK(kind == Location::kFpuRegister); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1507 | scratch = LocationFrom(codegen_->GetGraph()->HasSIMD() |
| 1508 | ? vixl_temps_.AcquireVRegisterOfSize(kQRegSize) |
| 1509 | : vixl_temps_.AcquireD()); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1510 | } |
| 1511 | AddScratchLocation(scratch); |
| 1512 | return scratch; |
| 1513 | } |
| 1514 | |
| 1515 | void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) { |
| 1516 | if (loc.IsRegister()) { |
| 1517 | vixl_temps_.Release(XRegisterFrom(loc)); |
| 1518 | } else { |
| 1519 | DCHECK(loc.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1520 | vixl_temps_.Release(codegen_->GetGraph()->HasSIMD() ? QRegisterFrom(loc) : DRegisterFrom(loc)); |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1521 | } |
| 1522 | RemoveScratchLocation(loc); |
| 1523 | } |
| 1524 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1525 | void ParallelMoveResolverARM64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1526 | MoveOperands* move = moves_[index]; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1527 | codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1530 | void CodeGeneratorARM64::GenerateFrameEntry() { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1531 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1532 | __ Bind(&frame_entry_label_); |
| 1533 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1534 | bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod(); |
| 1535 | if (do_overflow_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1536 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1537 | Register temp = temps.AcquireX(); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1538 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1539 | __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64))); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1540 | { |
| 1541 | // Ensure that between load and RecordPcInfo there are no pools emitted. |
| 1542 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 1543 | kInstructionSize, |
| 1544 | CodeBufferCheckScope::kExactSize); |
| 1545 | __ ldr(wzr, MemOperand(temp, 0)); |
| 1546 | RecordPcInfo(nullptr, 0); |
| 1547 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1548 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1549 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1550 | if (!HasEmptyFrame()) { |
| 1551 | int frame_size = GetFrameSize(); |
| 1552 | // Stack layout: |
| 1553 | // sp[frame_size - 8] : lr. |
| 1554 | // ... : other preserved core registers. |
| 1555 | // ... : other preserved fp registers. |
| 1556 | // ... : reserved frame space. |
| 1557 | // sp[0] : current method. |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1558 | |
| 1559 | // Save the current method if we need it. Note that we do not |
| 1560 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1561 | // in the SSA graph. |
| 1562 | if (RequiresCurrentMethod()) { |
| 1563 | __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex)); |
Nicolas Geoffray | 9989b16 | 2016-10-13 13:42:30 +0100 | [diff] [blame] | 1564 | } else { |
| 1565 | __ Claim(frame_size); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1566 | } |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1567 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1568 | GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(), |
| 1569 | frame_size - GetCoreSpillSize()); |
| 1570 | GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(), |
| 1571 | frame_size - FrameEntrySpillSize()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1572 | |
| 1573 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1574 | // Initialize should_deoptimize flag to 0. |
| 1575 | Register wzr = Register(VIXLRegCodeFromART(WZR), kWRegSize); |
| 1576 | __ Str(wzr, MemOperand(sp, GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1577 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1578 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | void CodeGeneratorARM64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1582 | GetAssembler()->cfi().RememberState(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1583 | if (!HasEmptyFrame()) { |
| 1584 | int frame_size = GetFrameSize(); |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 1585 | GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(), |
| 1586 | frame_size - FrameEntrySpillSize()); |
| 1587 | GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(), |
| 1588 | frame_size - GetCoreSpillSize()); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1589 | __ Drop(frame_size); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1590 | GetAssembler()->cfi().AdjustCFAOffset(-frame_size); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1591 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1592 | __ Ret(); |
| 1593 | GetAssembler()->cfi().RestoreState(); |
| 1594 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1595 | } |
| 1596 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1597 | CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1598 | DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0)); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1599 | return CPURegList(CPURegister::kRegister, kXRegSize, |
| 1600 | core_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1601 | } |
| 1602 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1603 | CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const { |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1604 | DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_, |
| 1605 | GetNumberOfFloatingPointRegisters())); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1606 | return CPURegList(CPURegister::kFPRegister, kDRegSize, |
| 1607 | fpu_spill_mask_); |
Zheng Xu | da40309 | 2015-04-24 17:35:39 +0800 | [diff] [blame] | 1608 | } |
| 1609 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1610 | void CodeGeneratorARM64::Bind(HBasicBlock* block) { |
| 1611 | __ Bind(GetLabelOf(block)); |
| 1612 | } |
| 1613 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1614 | void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) { |
| 1615 | DCHECK(location.IsRegister()); |
| 1616 | __ Mov(RegisterFrom(location, Primitive::kPrimInt), value); |
| 1617 | } |
| 1618 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1619 | void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1620 | if (location.IsRegister()) { |
| 1621 | locations->AddTemp(location); |
| 1622 | } else { |
| 1623 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1624 | } |
| 1625 | } |
| 1626 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1627 | void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1628 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1629 | Register card = temps.AcquireX(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1630 | Register temp = temps.AcquireW(); // Index within the CardTable - 32bit. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1631 | vixl::aarch64::Label done; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1632 | if (value_can_be_null) { |
| 1633 | __ Cbz(value, &done); |
| 1634 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1635 | __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1636 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 1637 | __ Strb(card, MemOperand(card, temp.X())); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1638 | if (value_can_be_null) { |
| 1639 | __ Bind(&done); |
| 1640 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1641 | } |
| 1642 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1643 | void CodeGeneratorARM64::SetupBlockedRegisters() const { |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1644 | // Blocked core registers: |
| 1645 | // lr : Runtime reserved. |
| 1646 | // tr : Runtime reserved. |
| 1647 | // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it. |
| 1648 | // ip1 : VIXL core temp. |
| 1649 | // ip0 : VIXL core temp. |
| 1650 | // |
| 1651 | // Blocked fp registers: |
| 1652 | // d31 : VIXL fp temp. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1653 | CPURegList reserved_core_registers = vixl_reserved_core_registers; |
| 1654 | reserved_core_registers.Combine(runtime_reserved_core_registers); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1655 | while (!reserved_core_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1656 | blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1657 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1658 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1659 | CPURegList reserved_fp_registers = vixl_reserved_fp_registers; |
Zheng Xu | a3ec394 | 2015-02-15 18:39:46 +0800 | [diff] [blame] | 1660 | while (!reserved_fp_registers.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1661 | blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 1662 | } |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1663 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1664 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1665 | // Stubs do not save callee-save floating point registers. If the graph |
| 1666 | // is debuggable, we need to deal with these registers differently. For |
| 1667 | // now, just block them. |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1668 | CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers; |
| 1669 | while (!reserved_fp_registers_debuggable.IsEmpty()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1670 | blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true; |
Serban Constantinescu | 3d087de | 2015-01-28 11:57:05 +0000 | [diff] [blame] | 1671 | } |
| 1672 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1673 | } |
| 1674 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1675 | size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1676 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1677 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1678 | return kArm64WordSize; |
| 1679 | } |
| 1680 | |
| 1681 | size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1682 | Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize); |
| 1683 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1684 | return kArm64WordSize; |
| 1685 | } |
| 1686 | |
| 1687 | size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1688 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1689 | __ Str(reg, MemOperand(sp, stack_index)); |
| 1690 | return kArm64WordSize; |
| 1691 | } |
| 1692 | |
| 1693 | size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1694 | FPRegister reg = FPRegister(reg_id, kDRegSize); |
| 1695 | __ Ldr(reg, MemOperand(sp, stack_index)); |
| 1696 | return kArm64WordSize; |
| 1697 | } |
| 1698 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1699 | void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1700 | stream << XRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1704 | stream << DRegister(reg); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 1705 | } |
| 1706 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1707 | void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1708 | if (constant->IsIntConstant()) { |
| 1709 | __ Mov(Register(destination), constant->AsIntConstant()->GetValue()); |
| 1710 | } else if (constant->IsLongConstant()) { |
| 1711 | __ Mov(Register(destination), constant->AsLongConstant()->GetValue()); |
| 1712 | } else if (constant->IsNullConstant()) { |
| 1713 | __ Mov(Register(destination), 0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1714 | } else if (constant->IsFloatConstant()) { |
| 1715 | __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue()); |
| 1716 | } else { |
| 1717 | DCHECK(constant->IsDoubleConstant()); |
| 1718 | __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue()); |
| 1719 | } |
| 1720 | } |
| 1721 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1722 | |
| 1723 | static bool CoherentConstantAndType(Location constant, Primitive::Type type) { |
| 1724 | DCHECK(constant.IsConstant()); |
| 1725 | HConstant* cst = constant.GetConstant(); |
| 1726 | return (cst->IsIntConstant() && type == Primitive::kPrimInt) || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1727 | // Null is mapped to a core W register, which we associate with kPrimInt. |
| 1728 | (cst->IsNullConstant() && type == Primitive::kPrimInt) || |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1729 | (cst->IsLongConstant() && type == Primitive::kPrimLong) || |
| 1730 | (cst->IsFloatConstant() && type == Primitive::kPrimFloat) || |
| 1731 | (cst->IsDoubleConstant() && type == Primitive::kPrimDouble); |
| 1732 | } |
| 1733 | |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1734 | // Allocate a scratch register from the VIXL pool, querying first into |
| 1735 | // the floating-point register pool, and then the the core register |
| 1736 | // pool. This is essentially a reimplementation of |
| 1737 | // vixl::aarch64::UseScratchRegisterScope::AcquireCPURegisterOfSize |
| 1738 | // using a different allocation strategy. |
| 1739 | static CPURegister AcquireFPOrCoreCPURegisterOfSize(vixl::aarch64::MacroAssembler* masm, |
| 1740 | vixl::aarch64::UseScratchRegisterScope* temps, |
| 1741 | int size_in_bits) { |
| 1742 | return masm->GetScratchFPRegisterList()->IsEmpty() |
| 1743 | ? CPURegister(temps->AcquireRegisterOfSize(size_in_bits)) |
| 1744 | : CPURegister(temps->AcquireVRegisterOfSize(size_in_bits)); |
| 1745 | } |
| 1746 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1747 | void CodeGeneratorARM64::MoveLocation(Location destination, |
| 1748 | Location source, |
| 1749 | Primitive::Type dst_type) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1750 | if (source.Equals(destination)) { |
| 1751 | return; |
| 1752 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1753 | |
| 1754 | // A valid move can always be inferred from the destination and source |
| 1755 | // locations. When moving from and to a register, the argument type can be |
| 1756 | // used to generate 32bit instead of 64bit moves. In debug mode we also |
| 1757 | // checks the coherency of the locations and the type. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1758 | bool unspecified_type = (dst_type == Primitive::kPrimVoid); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1759 | |
| 1760 | if (destination.IsRegister() || destination.IsFpuRegister()) { |
| 1761 | if (unspecified_type) { |
| 1762 | HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr; |
| 1763 | if (source.IsStackSlot() || |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1764 | (src_cst != nullptr && (src_cst->IsIntConstant() |
| 1765 | || src_cst->IsFloatConstant() |
| 1766 | || src_cst->IsNullConstant()))) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1767 | // For stack slots and 32bit constants, a 64bit type is appropriate. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1768 | dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1769 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1770 | // If the source is a double stack slot or a 64bit constant, a 64bit |
| 1771 | // type is appropriate. Else the source is a register, and since the |
| 1772 | // type has not been specified, we chose a 64bit type to force a 64bit |
| 1773 | // move. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1774 | dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1775 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1776 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1777 | DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) || |
| 1778 | (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type))); |
| 1779 | CPURegister dst = CPURegisterFrom(destination, dst_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1780 | if (source.IsStackSlot() || source.IsDoubleStackSlot()) { |
| 1781 | DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot()); |
| 1782 | __ Ldr(dst, StackOperandFrom(source)); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1783 | } else if (source.IsSIMDStackSlot()) { |
| 1784 | __ Ldr(QRegisterFrom(destination), StackOperandFrom(source)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1785 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1786 | DCHECK(CoherentConstantAndType(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1787 | MoveConstant(dst, source.GetConstant()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1788 | } else if (source.IsRegister()) { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1789 | if (destination.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1790 | __ Mov(Register(dst), RegisterFrom(source, dst_type)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1791 | } else { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 1792 | DCHECK(destination.IsFpuRegister()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1793 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1794 | ? Primitive::kPrimLong |
| 1795 | : Primitive::kPrimInt; |
| 1796 | __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type)); |
| 1797 | } |
| 1798 | } else { |
| 1799 | DCHECK(source.IsFpuRegister()); |
| 1800 | if (destination.IsRegister()) { |
| 1801 | Primitive::Type source_type = Primitive::Is64BitType(dst_type) |
| 1802 | ? Primitive::kPrimDouble |
| 1803 | : Primitive::kPrimFloat; |
| 1804 | __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type)); |
| 1805 | } else { |
| 1806 | DCHECK(destination.IsFpuRegister()); |
Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 1807 | if (GetGraph()->HasSIMD()) { |
| 1808 | __ Mov(QRegisterFrom(destination), QRegisterFrom(source)); |
| 1809 | } else { |
| 1810 | __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type)); |
| 1811 | } |
| 1812 | } |
| 1813 | } |
| 1814 | } else if (destination.IsSIMDStackSlot()) { |
| 1815 | if (source.IsFpuRegister()) { |
| 1816 | __ Str(QRegisterFrom(source), StackOperandFrom(destination)); |
| 1817 | } else { |
| 1818 | DCHECK(source.IsSIMDStackSlot()); |
| 1819 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1820 | if (GetVIXLAssembler()->GetScratchFPRegisterList()->IsEmpty()) { |
| 1821 | Register temp = temps.AcquireX(); |
| 1822 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex())); |
| 1823 | __ Str(temp, MemOperand(sp, destination.GetStackIndex())); |
| 1824 | __ Ldr(temp, MemOperand(sp, source.GetStackIndex() + kArm64WordSize)); |
| 1825 | __ Str(temp, MemOperand(sp, destination.GetStackIndex() + kArm64WordSize)); |
| 1826 | } else { |
| 1827 | FPRegister temp = temps.AcquireVRegisterOfSize(kQRegSize); |
| 1828 | __ Ldr(temp, StackOperandFrom(source)); |
| 1829 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1830 | } |
| 1831 | } |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1832 | } else { // The destination is not a register. It must be a stack slot. |
| 1833 | DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot()); |
| 1834 | if (source.IsRegister() || source.IsFpuRegister()) { |
| 1835 | if (unspecified_type) { |
| 1836 | if (source.IsRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1837 | dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1838 | } else { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1839 | dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1840 | } |
| 1841 | } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1842 | DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) && |
| 1843 | (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type))); |
| 1844 | __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination)); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1845 | } else if (source.IsConstant()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1846 | DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type)) |
| 1847 | << source << " " << dst_type; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1848 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 1849 | HConstant* src_cst = source.GetConstant(); |
| 1850 | CPURegister temp; |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1851 | if (src_cst->IsZeroBitPattern()) { |
Scott Wakeling | 79db997 | 2017-01-19 14:08:42 +0000 | [diff] [blame] | 1852 | temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) |
| 1853 | ? Register(xzr) |
| 1854 | : Register(wzr); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1855 | } else { |
Alexandre Rames | b2b753c | 2016-08-02 13:45:28 +0100 | [diff] [blame] | 1856 | if (src_cst->IsIntConstant()) { |
| 1857 | temp = temps.AcquireW(); |
| 1858 | } else if (src_cst->IsLongConstant()) { |
| 1859 | temp = temps.AcquireX(); |
| 1860 | } else if (src_cst->IsFloatConstant()) { |
| 1861 | temp = temps.AcquireS(); |
| 1862 | } else { |
| 1863 | DCHECK(src_cst->IsDoubleConstant()); |
| 1864 | temp = temps.AcquireD(); |
| 1865 | } |
| 1866 | MoveConstant(temp, src_cst); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1867 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1868 | __ Str(temp, StackOperandFrom(destination)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1869 | } else { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1870 | DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot()); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 1871 | DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1872 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
Roland Levillain | 78b3d5d | 2017-01-04 10:27:50 +0000 | [diff] [blame] | 1873 | // Use any scratch register (a core or a floating-point one) |
| 1874 | // from VIXL scratch register pools as a temporary. |
| 1875 | // |
| 1876 | // We used to only use the FP scratch register pool, but in some |
| 1877 | // rare cases the only register from this pool (D31) would |
| 1878 | // already be used (e.g. within a ParallelMove instruction, when |
| 1879 | // a move is blocked by a another move requiring a scratch FP |
| 1880 | // register, which would reserve D31). To prevent this issue, we |
| 1881 | // ask for a scratch register of any type (core or FP). |
Roland Levillain | 558dea1 | 2017-01-27 19:40:44 +0000 | [diff] [blame] | 1882 | // |
| 1883 | // Also, we start by asking for a FP scratch register first, as the |
| 1884 | // demand of scratch core registers is higher. This is why we |
| 1885 | // use AcquireFPOrCoreCPURegisterOfSize instead of |
| 1886 | // UseScratchRegisterScope::AcquireCPURegisterOfSize, which |
| 1887 | // allocates core scratch registers first. |
| 1888 | CPURegister temp = AcquireFPOrCoreCPURegisterOfSize( |
| 1889 | GetVIXLAssembler(), |
| 1890 | &temps, |
| 1891 | (destination.IsDoubleStackSlot() ? kXRegSize : kWRegSize)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1892 | __ Ldr(temp, StackOperandFrom(source)); |
| 1893 | __ Str(temp, StackOperandFrom(destination)); |
| 1894 | } |
| 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | void CodeGeneratorARM64::Load(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1899 | CPURegister dst, |
| 1900 | const MemOperand& src) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1901 | switch (type) { |
| 1902 | case Primitive::kPrimBoolean: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1903 | __ Ldrb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1904 | break; |
| 1905 | case Primitive::kPrimByte: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1906 | __ Ldrsb(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1907 | break; |
| 1908 | case Primitive::kPrimShort: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1909 | __ Ldrsh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1910 | break; |
| 1911 | case Primitive::kPrimChar: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1912 | __ Ldrh(Register(dst), src); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1913 | break; |
| 1914 | case Primitive::kPrimInt: |
| 1915 | case Primitive::kPrimNot: |
| 1916 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1917 | case Primitive::kPrimFloat: |
| 1918 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 1919 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 1920 | __ Ldr(dst, src); |
| 1921 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 1922 | case Primitive::kPrimVoid: |
| 1923 | LOG(FATAL) << "Unreachable type " << type; |
| 1924 | } |
| 1925 | } |
| 1926 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1927 | void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1928 | CPURegister dst, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 1929 | const MemOperand& src, |
| 1930 | bool needs_null_check) { |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1931 | MacroAssembler* masm = GetVIXLAssembler(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 1932 | UseScratchRegisterScope temps(masm); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1933 | Register temp_base = temps.AcquireX(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1934 | Primitive::Type type = instruction->GetType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1935 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1936 | DCHECK(!src.IsPreIndex()); |
| 1937 | DCHECK(!src.IsPostIndex()); |
| 1938 | |
| 1939 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1940 | __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 1941 | { |
| 1942 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 1943 | MemOperand base = MemOperand(temp_base); |
| 1944 | switch (type) { |
| 1945 | case Primitive::kPrimBoolean: |
| 1946 | { |
| 1947 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1948 | __ ldarb(Register(dst), base); |
| 1949 | if (needs_null_check) { |
| 1950 | MaybeRecordImplicitNullCheck(instruction); |
| 1951 | } |
| 1952 | } |
| 1953 | break; |
| 1954 | case Primitive::kPrimByte: |
| 1955 | { |
| 1956 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1957 | __ ldarb(Register(dst), base); |
| 1958 | if (needs_null_check) { |
| 1959 | MaybeRecordImplicitNullCheck(instruction); |
| 1960 | } |
| 1961 | } |
| 1962 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1963 | break; |
| 1964 | case Primitive::kPrimChar: |
| 1965 | { |
| 1966 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1967 | __ ldarh(Register(dst), base); |
| 1968 | if (needs_null_check) { |
| 1969 | MaybeRecordImplicitNullCheck(instruction); |
| 1970 | } |
| 1971 | } |
| 1972 | break; |
| 1973 | case Primitive::kPrimShort: |
| 1974 | { |
| 1975 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1976 | __ ldarh(Register(dst), base); |
| 1977 | if (needs_null_check) { |
| 1978 | MaybeRecordImplicitNullCheck(instruction); |
| 1979 | } |
| 1980 | } |
| 1981 | __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte); |
| 1982 | break; |
| 1983 | case Primitive::kPrimInt: |
| 1984 | case Primitive::kPrimNot: |
| 1985 | case Primitive::kPrimLong: |
| 1986 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
| 1987 | { |
| 1988 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 1989 | __ ldar(Register(dst), base); |
| 1990 | if (needs_null_check) { |
| 1991 | MaybeRecordImplicitNullCheck(instruction); |
| 1992 | } |
| 1993 | } |
| 1994 | break; |
| 1995 | case Primitive::kPrimFloat: |
| 1996 | case Primitive::kPrimDouble: { |
| 1997 | DCHECK(dst.IsFPRegister()); |
| 1998 | DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 1999 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2000 | Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2001 | { |
| 2002 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2003 | __ ldar(temp, base); |
| 2004 | if (needs_null_check) { |
| 2005 | MaybeRecordImplicitNullCheck(instruction); |
| 2006 | } |
| 2007 | } |
| 2008 | __ Fmov(FPRegister(dst), temp); |
| 2009 | break; |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2010 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2011 | case Primitive::kPrimVoid: |
| 2012 | LOG(FATAL) << "Unreachable type " << type; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2013 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2014 | } |
| 2015 | } |
| 2016 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2017 | void CodeGeneratorARM64::Store(Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2018 | CPURegister src, |
| 2019 | const MemOperand& dst) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2020 | switch (type) { |
| 2021 | case Primitive::kPrimBoolean: |
| 2022 | case Primitive::kPrimByte: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2023 | __ Strb(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2024 | break; |
| 2025 | case Primitive::kPrimChar: |
| 2026 | case Primitive::kPrimShort: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2027 | __ Strh(Register(src), dst); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2028 | break; |
| 2029 | case Primitive::kPrimInt: |
| 2030 | case Primitive::kPrimNot: |
| 2031 | case Primitive::kPrimLong: |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2032 | case Primitive::kPrimFloat: |
| 2033 | case Primitive::kPrimDouble: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2034 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2035 | __ Str(src, dst); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2036 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2037 | case Primitive::kPrimVoid: |
| 2038 | LOG(FATAL) << "Unreachable type " << type; |
| 2039 | } |
| 2040 | } |
| 2041 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2042 | void CodeGeneratorARM64::StoreRelease(HInstruction* instruction, |
| 2043 | Primitive::Type type, |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2044 | CPURegister src, |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2045 | const MemOperand& dst, |
| 2046 | bool needs_null_check) { |
| 2047 | MacroAssembler* masm = GetVIXLAssembler(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2048 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2049 | Register temp_base = temps.AcquireX(); |
| 2050 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2051 | DCHECK(!dst.IsPreIndex()); |
| 2052 | DCHECK(!dst.IsPostIndex()); |
| 2053 | |
| 2054 | // TODO(vixl): Let the MacroAssembler handle this. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2055 | Operand op = OperandFromMemOperand(dst); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2056 | __ Add(temp_base, dst.GetBaseRegister(), op); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2057 | MemOperand base = MemOperand(temp_base); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2058 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2059 | switch (type) { |
| 2060 | case Primitive::kPrimBoolean: |
| 2061 | case Primitive::kPrimByte: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2062 | { |
| 2063 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2064 | __ stlrb(Register(src), base); |
| 2065 | if (needs_null_check) { |
| 2066 | MaybeRecordImplicitNullCheck(instruction); |
| 2067 | } |
| 2068 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2069 | break; |
| 2070 | case Primitive::kPrimChar: |
| 2071 | case Primitive::kPrimShort: |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2072 | { |
| 2073 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2074 | __ stlrh(Register(src), base); |
| 2075 | if (needs_null_check) { |
| 2076 | MaybeRecordImplicitNullCheck(instruction); |
| 2077 | } |
| 2078 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2079 | break; |
| 2080 | case Primitive::kPrimInt: |
| 2081 | case Primitive::kPrimNot: |
| 2082 | case Primitive::kPrimLong: |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2083 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2084 | { |
| 2085 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2086 | __ stlr(Register(src), base); |
| 2087 | if (needs_null_check) { |
| 2088 | MaybeRecordImplicitNullCheck(instruction); |
| 2089 | } |
| 2090 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2091 | break; |
| 2092 | case Primitive::kPrimFloat: |
| 2093 | case Primitive::kPrimDouble: { |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 2094 | DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type)); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2095 | Register temp_src; |
| 2096 | if (src.IsZero()) { |
| 2097 | // The zero register is used to avoid synthesizing zero constants. |
| 2098 | temp_src = Register(src); |
| 2099 | } else { |
| 2100 | DCHECK(src.IsFPRegister()); |
| 2101 | temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW(); |
| 2102 | __ Fmov(temp_src, FPRegister(src)); |
| 2103 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2104 | { |
| 2105 | ExactAssemblyScope eas(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2106 | __ stlr(temp_src, base); |
| 2107 | if (needs_null_check) { |
| 2108 | MaybeRecordImplicitNullCheck(instruction); |
| 2109 | } |
| 2110 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2111 | break; |
| 2112 | } |
| 2113 | case Primitive::kPrimVoid: |
| 2114 | LOG(FATAL) << "Unreachable type " << type; |
| 2115 | } |
| 2116 | } |
| 2117 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2118 | void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2119 | HInstruction* instruction, |
| 2120 | uint32_t dex_pc, |
| 2121 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2122 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2123 | |
| 2124 | __ Ldr(lr, MemOperand(tr, GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value())); |
| 2125 | { |
| 2126 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 2127 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 2128 | __ blr(lr); |
| 2129 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2130 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2131 | } |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2132 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2133 | } |
| 2134 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2135 | void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2136 | HInstruction* instruction, |
| 2137 | SlowPathCode* slow_path) { |
| 2138 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2139 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| 2140 | __ Blr(lr); |
| 2141 | } |
| 2142 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2143 | void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2144 | Register class_reg) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2145 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2146 | Register temp = temps.AcquireW(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2147 | size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 2148 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2149 | // 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] | 2150 | // TODO(vixl): Let the MacroAssembler handle MemOperand. |
| 2151 | __ Add(temp, class_reg, status_offset); |
| 2152 | __ Ldar(temp, HeapOperand(temp)); |
| 2153 | __ Cmp(temp, mirror::Class::kStatusInitialized); |
| 2154 | __ B(lt, slow_path->GetEntryLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2155 | __ Bind(slow_path->GetExitLabel()); |
| 2156 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2157 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2158 | void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 2159 | BarrierType type = BarrierAll; |
| 2160 | |
| 2161 | switch (kind) { |
| 2162 | case MemBarrierKind::kAnyAny: |
| 2163 | case MemBarrierKind::kAnyStore: { |
| 2164 | type = BarrierAll; |
| 2165 | break; |
| 2166 | } |
| 2167 | case MemBarrierKind::kLoadAny: { |
| 2168 | type = BarrierReads; |
| 2169 | break; |
| 2170 | } |
| 2171 | case MemBarrierKind::kStoreStore: { |
| 2172 | type = BarrierWrites; |
| 2173 | break; |
| 2174 | } |
| 2175 | default: |
| 2176 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 2177 | } |
| 2178 | __ Dmb(InnerShareable, type); |
| 2179 | } |
| 2180 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2181 | void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2182 | HBasicBlock* successor) { |
| 2183 | SuspendCheckSlowPathARM64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 2184 | down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath()); |
| 2185 | if (slow_path == nullptr) { |
| 2186 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor); |
| 2187 | instruction->SetSlowPath(slow_path); |
| 2188 | codegen_->AddSlowPath(slow_path); |
| 2189 | if (successor != nullptr) { |
| 2190 | DCHECK(successor->IsLoopHeader()); |
| 2191 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 2192 | } |
| 2193 | } else { |
| 2194 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 2195 | } |
| 2196 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2197 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 2198 | Register temp = temps.AcquireW(); |
| 2199 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2200 | __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue())); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2201 | if (successor == nullptr) { |
| 2202 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 2203 | __ Bind(slow_path->GetReturnLabel()); |
| 2204 | } else { |
| 2205 | __ Cbz(temp, codegen_->GetLabelOf(successor)); |
| 2206 | __ B(slow_path->GetEntryLabel()); |
| 2207 | // slow_path will return to GetLabelOf(successor). |
| 2208 | } |
| 2209 | } |
| 2210 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2211 | InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph, |
| 2212 | CodeGeneratorARM64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2213 | : InstructionCodeGenerator(graph, codegen), |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2214 | assembler_(codegen->GetAssembler()), |
| 2215 | codegen_(codegen) {} |
| 2216 | |
| 2217 | #define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \ |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 2218 | /* No unimplemented IR. */ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2219 | |
| 2220 | #define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode |
| 2221 | |
| 2222 | enum UnimplementedInstructionBreakCode { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2223 | // Using a base helps identify when we hit such breakpoints. |
| 2224 | UnimplementedInstructionBreakCodeBaseCode = 0x900, |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2225 | #define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name), |
| 2226 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION) |
| 2227 | #undef ENUM_UNIMPLEMENTED_INSTRUCTION |
| 2228 | }; |
| 2229 | |
| 2230 | #define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \ |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2231 | void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \ |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2232 | __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \ |
| 2233 | } \ |
| 2234 | void LocationsBuilderARM64::Visit##name(H##name* instr) { \ |
| 2235 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \ |
| 2236 | locations->SetOut(Location::Any()); \ |
| 2237 | } |
| 2238 | FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS) |
| 2239 | #undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS |
| 2240 | |
| 2241 | #undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2242 | #undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2243 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2244 | void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2245 | DCHECK_EQ(instr->InputCount(), 2U); |
| 2246 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2247 | Primitive::Type type = instr->GetResultType(); |
| 2248 | switch (type) { |
| 2249 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2250 | case Primitive::kPrimLong: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2251 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 2252 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr)); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2253 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2254 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2255 | |
| 2256 | case Primitive::kPrimFloat: |
| 2257 | case Primitive::kPrimDouble: |
| 2258 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2259 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2260 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2261 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2262 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2263 | default: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2264 | LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2268 | void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction, |
| 2269 | const FieldInfo& field_info) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2270 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2271 | |
| 2272 | bool object_field_get_with_read_barrier = |
| 2273 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2274 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2275 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2276 | object_field_get_with_read_barrier ? |
| 2277 | LocationSummary::kCallOnSlowPath : |
| 2278 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2279 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2280 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | d0b5183 | 2017-01-26 19:04:23 +0000 | [diff] [blame] | 2281 | // We need a temporary register for the read barrier marking slow |
| 2282 | // path in CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2283 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2284 | !Runtime::Current()->UseJitCompilation() && |
| 2285 | !field_info.IsVolatile()) { |
| 2286 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2287 | // non-volatile loads we need a temporary only if the offset is too big. |
| 2288 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 2289 | locations->AddTemp(FixedTempLocation()); |
| 2290 | } |
| 2291 | } else { |
| 2292 | locations->AddTemp(Location::RequiresRegister()); |
| 2293 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2294 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2295 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2296 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2297 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2298 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2299 | // The output overlaps for an object field get when read barriers |
| 2300 | // are enabled: we do not want the load to overwrite the object's |
| 2301 | // location, as we need it to emit the read barrier. |
| 2302 | locations->SetOut( |
| 2303 | Location::RequiresRegister(), |
| 2304 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2305 | } |
| 2306 | } |
| 2307 | |
| 2308 | void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction, |
| 2309 | const FieldInfo& field_info) { |
| 2310 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2311 | LocationSummary* locations = instruction->GetLocations(); |
| 2312 | Location base_loc = locations->InAt(0); |
| 2313 | Location out = locations->Out(); |
| 2314 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2315 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2316 | MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset()); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2317 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2318 | if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2319 | // Object FieldGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2320 | // /* HeapReference<Object> */ out = *(base + offset) |
| 2321 | Register base = RegisterFrom(base_loc, Primitive::kPrimNot); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2322 | Location maybe_temp = |
| 2323 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2324 | // Note that potential implicit null checks are handled in this |
| 2325 | // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call. |
| 2326 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2327 | instruction, |
| 2328 | out, |
| 2329 | base, |
| 2330 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2331 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2332 | /* needs_null_check */ true, |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2333 | field_info.IsVolatile()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2334 | } else { |
| 2335 | // General case. |
| 2336 | if (field_info.IsVolatile()) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 2337 | // Note that a potential implicit null check is handled in this |
| 2338 | // CodeGeneratorARM64::LoadAcquire call. |
| 2339 | // NB: LoadAcquire will record the pc info if needed. |
| 2340 | codegen_->LoadAcquire( |
| 2341 | instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2342 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2343 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2344 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2345 | codegen_->Load(field_type, OutputCPURegister(instruction), field); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2346 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2347 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2348 | if (field_type == Primitive::kPrimNot) { |
| 2349 | // If read barriers are enabled, emit read barriers other than |
| 2350 | // Baker's using a slow path (and also unpoison the loaded |
| 2351 | // reference, if heap poisoning is enabled). |
| 2352 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 2353 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2354 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) { |
| 2358 | LocationSummary* locations = |
| 2359 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2360 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2361 | if (IsConstantZeroBitPattern(instruction->InputAt(1))) { |
| 2362 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 2363 | } else if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2364 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2365 | } else { |
| 2366 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2371 | const FieldInfo& field_info, |
| 2372 | bool value_can_be_null) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2373 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2374 | |
| 2375 | Register obj = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2376 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2377 | CPURegister source = value; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2378 | Offset offset = field_info.GetFieldOffset(); |
| 2379 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2380 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2381 | { |
| 2382 | // We use a block to end the scratch scope before the write barrier, thus |
| 2383 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2384 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2385 | |
| 2386 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 2387 | DCHECK(value.IsW()); |
| 2388 | Register temp = temps.AcquireW(); |
| 2389 | __ Mov(temp, value.W()); |
| 2390 | GetAssembler()->PoisonHeapReference(temp.W()); |
| 2391 | source = temp; |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2392 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2393 | |
| 2394 | if (field_info.IsVolatile()) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2395 | codegen_->StoreRelease( |
| 2396 | instruction, field_type, source, HeapOperand(obj, offset), /* needs_null_check */ true); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2397 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2398 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2399 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2400 | codegen_->Store(field_type, source, HeapOperand(obj, offset)); |
| 2401 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2402 | } |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 2406 | codegen_->MarkGCCard(obj, Register(value), value_can_be_null); |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 2407 | } |
| 2408 | } |
| 2409 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2410 | void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2411 | Primitive::Type type = instr->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2412 | |
| 2413 | switch (type) { |
| 2414 | case Primitive::kPrimInt: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2415 | case Primitive::kPrimLong: { |
| 2416 | Register dst = OutputRegister(instr); |
| 2417 | Register lhs = InputRegisterAt(instr, 0); |
| 2418 | Operand rhs = InputOperandAt(instr, 1); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2419 | if (instr->IsAdd()) { |
| 2420 | __ Add(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2421 | } else if (instr->IsAnd()) { |
| 2422 | __ And(dst, lhs, rhs); |
| 2423 | } else if (instr->IsOr()) { |
| 2424 | __ Orr(dst, lhs, rhs); |
| 2425 | } else if (instr->IsSub()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2426 | __ Sub(dst, lhs, rhs); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2427 | } else if (instr->IsRor()) { |
| 2428 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2429 | uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 2430 | __ Ror(dst, lhs, shift); |
| 2431 | } else { |
| 2432 | // Ensure shift distance is in the same size register as the result. If |
| 2433 | // we are rotating a long and the shift comes in a w register originally, |
| 2434 | // we don't need to sxtw for use as an x since the shift distances are |
| 2435 | // all & reg_bits - 1. |
| 2436 | __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type)); |
| 2437 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2438 | } else { |
| 2439 | DCHECK(instr->IsXor()); |
| 2440 | __ Eor(dst, lhs, rhs); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2441 | } |
| 2442 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2443 | } |
| 2444 | case Primitive::kPrimFloat: |
| 2445 | case Primitive::kPrimDouble: { |
| 2446 | FPRegister dst = OutputFPRegister(instr); |
| 2447 | FPRegister lhs = InputFPRegisterAt(instr, 0); |
| 2448 | FPRegister rhs = InputFPRegisterAt(instr, 1); |
| 2449 | if (instr->IsAdd()) { |
| 2450 | __ Fadd(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2451 | } else if (instr->IsSub()) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2452 | __ Fsub(dst, lhs, rhs); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2453 | } else { |
| 2454 | LOG(FATAL) << "Unexpected floating-point binary operation"; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2455 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2456 | break; |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 2457 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2458 | default: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2459 | LOG(FATAL) << "Unexpected binary operation type " << type; |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2460 | } |
| 2461 | } |
| 2462 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2463 | void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) { |
| 2464 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2465 | |
| 2466 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2467 | Primitive::Type type = instr->GetResultType(); |
| 2468 | switch (type) { |
| 2469 | case Primitive::kPrimInt: |
| 2470 | case Primitive::kPrimLong: { |
| 2471 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2472 | locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1))); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2473 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2474 | break; |
| 2475 | } |
| 2476 | default: |
| 2477 | LOG(FATAL) << "Unexpected shift type " << type; |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) { |
| 2482 | DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr()); |
| 2483 | |
| 2484 | Primitive::Type type = instr->GetType(); |
| 2485 | switch (type) { |
| 2486 | case Primitive::kPrimInt: |
| 2487 | case Primitive::kPrimLong: { |
| 2488 | Register dst = OutputRegister(instr); |
| 2489 | Register lhs = InputRegisterAt(instr, 0); |
| 2490 | Operand rhs = InputOperandAt(instr, 1); |
| 2491 | if (rhs.IsImmediate()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2492 | uint32_t shift_value = rhs.GetImmediate() & |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 2493 | (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2494 | if (instr->IsShl()) { |
| 2495 | __ Lsl(dst, lhs, shift_value); |
| 2496 | } else if (instr->IsShr()) { |
| 2497 | __ Asr(dst, lhs, shift_value); |
| 2498 | } else { |
| 2499 | __ Lsr(dst, lhs, shift_value); |
| 2500 | } |
| 2501 | } else { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2502 | Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 2503 | |
| 2504 | if (instr->IsShl()) { |
| 2505 | __ Lsl(dst, lhs, rhs_reg); |
| 2506 | } else if (instr->IsShr()) { |
| 2507 | __ Asr(dst, lhs, rhs_reg); |
| 2508 | } else { |
| 2509 | __ Lsr(dst, lhs, rhs_reg); |
| 2510 | } |
| 2511 | } |
| 2512 | break; |
| 2513 | } |
| 2514 | default: |
| 2515 | LOG(FATAL) << "Unexpected shift operation type " << type; |
| 2516 | } |
| 2517 | } |
| 2518 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2519 | void LocationsBuilderARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2520 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 2524 | HandleBinaryOp(instruction); |
| 2525 | } |
| 2526 | |
| 2527 | void LocationsBuilderARM64::VisitAnd(HAnd* instruction) { |
| 2528 | HandleBinaryOp(instruction); |
| 2529 | } |
| 2530 | |
| 2531 | void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) { |
| 2532 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2533 | } |
| 2534 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2535 | void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2536 | DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType(); |
| 2537 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); |
| 2538 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2539 | // There is no immediate variant of negated bitwise instructions in AArch64. |
| 2540 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2541 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2542 | } |
| 2543 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 2544 | void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) { |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 2545 | Register dst = OutputRegister(instr); |
| 2546 | Register lhs = InputRegisterAt(instr, 0); |
| 2547 | Register rhs = InputRegisterAt(instr, 1); |
| 2548 | |
| 2549 | switch (instr->GetOpKind()) { |
| 2550 | case HInstruction::kAnd: |
| 2551 | __ Bic(dst, lhs, rhs); |
| 2552 | break; |
| 2553 | case HInstruction::kOr: |
| 2554 | __ Orn(dst, lhs, rhs); |
| 2555 | break; |
| 2556 | case HInstruction::kXor: |
| 2557 | __ Eon(dst, lhs, rhs); |
| 2558 | break; |
| 2559 | default: |
| 2560 | LOG(FATAL) << "Unreachable"; |
| 2561 | } |
| 2562 | } |
| 2563 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2564 | void LocationsBuilderARM64::VisitDataProcWithShifterOp( |
| 2565 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2566 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 2567 | instruction->GetType() == Primitive::kPrimLong); |
| 2568 | LocationSummary* locations = |
| 2569 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2570 | if (instruction->GetInstrKind() == HInstruction::kNeg) { |
| 2571 | locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant())); |
| 2572 | } else { |
| 2573 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2574 | } |
| 2575 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2576 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2577 | } |
| 2578 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2579 | void InstructionCodeGeneratorARM64::VisitDataProcWithShifterOp( |
| 2580 | HDataProcWithShifterOp* instruction) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2581 | Primitive::Type type = instruction->GetType(); |
| 2582 | HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 2583 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 2584 | Register out = OutputRegister(instruction); |
| 2585 | Register left; |
| 2586 | if (kind != HInstruction::kNeg) { |
| 2587 | left = InputRegisterAt(instruction, 0); |
| 2588 | } |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2589 | // If this `HDataProcWithShifterOp` was created by merging a type conversion as the |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2590 | // shifter operand operation, the IR generating `right_reg` (input to the type |
| 2591 | // conversion) can have a different type from the current instruction's type, |
| 2592 | // so we manually indicate the type. |
| 2593 | Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2594 | Operand right_operand(0); |
| 2595 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2596 | HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 2597 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2598 | right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind)); |
| 2599 | } else { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2600 | right_operand = Operand(right_reg, |
| 2601 | helpers::ShiftFromOpKind(op_kind), |
| 2602 | instruction->GetShiftAmount()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2603 | } |
| 2604 | |
| 2605 | // Logical binary operations do not support extension operations in the |
| 2606 | // operand. Note that VIXL would still manage if it was passed by generating |
| 2607 | // the extension as a separate instruction. |
| 2608 | // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`. |
| 2609 | DCHECK(!right_operand.IsExtendedRegister() || |
| 2610 | (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor && |
| 2611 | kind != HInstruction::kNeg)); |
| 2612 | switch (kind) { |
| 2613 | case HInstruction::kAdd: |
| 2614 | __ Add(out, left, right_operand); |
| 2615 | break; |
| 2616 | case HInstruction::kAnd: |
| 2617 | __ And(out, left, right_operand); |
| 2618 | break; |
| 2619 | case HInstruction::kNeg: |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2620 | DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 2621 | __ Neg(out, right_operand); |
| 2622 | break; |
| 2623 | case HInstruction::kOr: |
| 2624 | __ Orr(out, left, right_operand); |
| 2625 | break; |
| 2626 | case HInstruction::kSub: |
| 2627 | __ Sub(out, left, right_operand); |
| 2628 | break; |
| 2629 | case HInstruction::kXor: |
| 2630 | __ Eor(out, left, right_operand); |
| 2631 | break; |
| 2632 | default: |
| 2633 | LOG(FATAL) << "Unexpected operation kind: " << kind; |
| 2634 | UNREACHABLE(); |
| 2635 | } |
| 2636 | } |
| 2637 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2638 | void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2639 | LocationSummary* locations = |
| 2640 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2641 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2642 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction)); |
Artem Serov | 87c9705 | 2016-09-23 13:34:31 +0100 | [diff] [blame] | 2643 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2644 | } |
| 2645 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2646 | void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2647 | __ Add(OutputRegister(instruction), |
| 2648 | InputRegisterAt(instruction, 0), |
| 2649 | Operand(InputOperandAt(instruction, 1))); |
| 2650 | } |
| 2651 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2652 | void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2653 | LocationSummary* locations = |
| 2654 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2655 | HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2656 | if (instr->GetOpKind() == HInstruction::kSub && |
| 2657 | accumulator->IsConstant() && |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2658 | accumulator->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2659 | // Don't allocate register for Mneg instruction. |
| 2660 | } else { |
| 2661 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 2662 | Location::RequiresRegister()); |
| 2663 | } |
| 2664 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 2665 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2666 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2667 | } |
| 2668 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2669 | void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2670 | Register res = OutputRegister(instr); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2671 | Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 2672 | Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2673 | |
| 2674 | // Avoid emitting code that could trigger Cortex A53's erratum 835769. |
| 2675 | // This fixup should be carried out for all multiply-accumulate instructions: |
| 2676 | // madd, msub, smaddl, smsubl, umaddl and umsubl. |
| 2677 | if (instr->GetType() == Primitive::kPrimLong && |
| 2678 | codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) { |
| 2679 | MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2680 | vixl::aarch64::Instruction* prev = |
| 2681 | masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize; |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2682 | if (prev->IsLoadOrStore()) { |
| 2683 | // Make sure we emit only exactly one nop. |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2684 | ExactAssemblyScope scope(masm, kInstructionSize, CodeBufferCheckScope::kExactSize); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2685 | __ nop(); |
| 2686 | } |
| 2687 | } |
| 2688 | |
| 2689 | if (instr->GetOpKind() == HInstruction::kAdd) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2690 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2691 | __ Madd(res, mul_left, mul_right, accumulator); |
| 2692 | } else { |
| 2693 | DCHECK(instr->GetOpKind() == HInstruction::kSub); |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2694 | HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2695 | if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) { |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 2696 | __ Mneg(res, mul_left, mul_right); |
| 2697 | } else { |
| 2698 | Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 2699 | __ Msub(res, mul_left, mul_right, accumulator); |
| 2700 | } |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 2701 | } |
| 2702 | } |
| 2703 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2704 | void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2705 | bool object_array_get_with_read_barrier = |
| 2706 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2707 | LocationSummary* locations = |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2708 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 2709 | object_array_get_with_read_barrier ? |
| 2710 | LocationSummary::kCallOnSlowPath : |
| 2711 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2712 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2713 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 2714 | // We need a temporary register for the read barrier marking slow |
| 2715 | // path in CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2716 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 2717 | !Runtime::Current()->UseJitCompilation() && |
| 2718 | instruction->GetIndex()->IsConstant()) { |
| 2719 | // Array loads with constant index are treated as field loads. |
| 2720 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 2721 | // constant index loads we need a temporary only if the offset is too big. |
| 2722 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 2723 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| 2724 | offset += index << Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 2725 | if (offset >= kReferenceLoadMinFarOffset) { |
| 2726 | locations->AddTemp(FixedTempLocation()); |
| 2727 | } |
| 2728 | } else { |
| 2729 | locations->AddTemp(Location::RequiresRegister()); |
| 2730 | } |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 2731 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2732 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2733 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2734 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 2735 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2736 | } else { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2737 | // The output overlaps in the case of an object array get with |
| 2738 | // read barriers enabled: we do not want the move to overwrite the |
| 2739 | // array's location, as we need it to emit the read barrier. |
| 2740 | locations->SetOut( |
| 2741 | Location::RequiresRegister(), |
| 2742 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 2743 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) { |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2747 | Primitive::Type type = instruction->GetType(); |
| 2748 | Register obj = InputRegisterAt(instruction, 0); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2749 | LocationSummary* locations = instruction->GetLocations(); |
| 2750 | Location index = locations->InAt(1); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2751 | Location out = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2752 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2753 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 2754 | instruction->IsStringCharAt(); |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 2755 | MacroAssembler* masm = GetVIXLAssembler(); |
| 2756 | UseScratchRegisterScope temps(masm); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2757 | |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 2758 | // The read barrier instrumentation of object ArrayGet instructions |
| 2759 | // does not support the HIntermediateAddress instruction. |
| 2760 | DCHECK(!((type == Primitive::kPrimNot) && |
| 2761 | instruction->GetArray()->IsIntermediateAddress() && |
| 2762 | kEmitCompilerReadBarrier)); |
| 2763 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2764 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2765 | // Object ArrayGet with Baker's read barrier case. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2766 | // Note that a potential implicit null check is handled in the |
| 2767 | // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2768 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2769 | if (index.IsConstant()) { |
| 2770 | // Array load with a constant index can be treated as a field load. |
| 2771 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2772 | Location maybe_temp = |
| 2773 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location::NoLocation(); |
| 2774 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 2775 | out, |
| 2776 | obj.W(), |
| 2777 | offset, |
| 2778 | maybe_temp, |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2779 | /* needs_null_check */ false, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2780 | /* use_load_acquire */ false); |
| 2781 | } else { |
| 2782 | Register temp = WRegisterFrom(locations->GetTemp(0)); |
| 2783 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 2784 | instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ false); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 2785 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2786 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2787 | // General case. |
| 2788 | MemOperand source = HeapOperand(obj); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2789 | Register length; |
| 2790 | if (maybe_compressed_char_at) { |
| 2791 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2792 | length = temps.AcquireW(); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2793 | { |
| 2794 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2795 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2796 | |
| 2797 | if (instruction->GetArray()->IsIntermediateAddress()) { |
| 2798 | DCHECK_LT(count_offset, offset); |
| 2799 | int64_t adjusted_offset = |
| 2800 | static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset); |
| 2801 | // Note that `adjusted_offset` is negative, so this will be a LDUR. |
| 2802 | __ Ldr(length, MemOperand(obj.X(), adjusted_offset)); |
| 2803 | } else { |
| 2804 | __ Ldr(length, HeapOperand(obj, count_offset)); |
| 2805 | } |
| 2806 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2807 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2808 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2809 | if (index.IsConstant()) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2810 | if (maybe_compressed_char_at) { |
| 2811 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2812 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2813 | "Expecting 0=compressed, 1=uncompressed"); |
| 2814 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2815 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2816 | HeapOperand(obj, offset + Int64ConstantFrom(index))); |
| 2817 | __ B(&done); |
| 2818 | __ Bind(&uncompressed_load); |
| 2819 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2820 | HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1))); |
| 2821 | __ Bind(&done); |
| 2822 | } else { |
| 2823 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 2824 | source = HeapOperand(obj, offset); |
| 2825 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2826 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2827 | Register temp = temps.AcquireSameSizeAs(obj); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2828 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2829 | // We do not need to compute the intermediate address from the array: the |
| 2830 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2831 | // `TryExtractArrayAccessAddress()`. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2832 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2833 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2834 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset); |
| 2835 | } |
| 2836 | temp = obj; |
| 2837 | } else { |
| 2838 | __ Add(temp, obj, offset); |
| 2839 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2840 | if (maybe_compressed_char_at) { |
| 2841 | vixl::aarch64::Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2842 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 2843 | "Expecting 0=compressed, 1=uncompressed"); |
| 2844 | __ Tbnz(length.W(), 0, &uncompressed_load); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2845 | __ Ldrb(Register(OutputCPURegister(instruction)), |
| 2846 | HeapOperand(temp, XRegisterFrom(index), LSL, 0)); |
| 2847 | __ B(&done); |
| 2848 | __ Bind(&uncompressed_load); |
| 2849 | __ Ldrh(Register(OutputCPURegister(instruction)), |
| 2850 | HeapOperand(temp, XRegisterFrom(index), LSL, 1)); |
| 2851 | __ Bind(&done); |
| 2852 | } else { |
| 2853 | source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type)); |
| 2854 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2855 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2856 | if (!maybe_compressed_char_at) { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2857 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2858 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2859 | codegen_->Load(type, OutputCPURegister(instruction), source); |
| 2860 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2861 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 2862 | |
| 2863 | if (type == Primitive::kPrimNot) { |
| 2864 | static_assert( |
| 2865 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 2866 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 2867 | Location obj_loc = locations->InAt(0); |
| 2868 | if (index.IsConstant()) { |
| 2869 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset); |
| 2870 | } else { |
| 2871 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index); |
| 2872 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2873 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2874 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2877 | void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) { |
| 2878 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 2879 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 2880 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2881 | } |
| 2882 | |
| 2883 | void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) { |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 2884 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2885 | vixl::aarch64::Register out = OutputRegister(instruction); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2886 | { |
| 2887 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2888 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2889 | __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset)); |
| 2890 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2891 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2892 | // Mask out compression flag from String's array length. |
| 2893 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2894 | __ Lsr(out.W(), out.W(), 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2895 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 2896 | } |
| 2897 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2898 | void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2899 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2900 | |
| 2901 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2902 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2903 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 2904 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2905 | LocationSummary::kCallOnSlowPath : |
| 2906 | LocationSummary::kNoCall); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2907 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2908 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2909 | if (IsConstantZeroBitPattern(instruction->InputAt(2))) { |
| 2910 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 2911 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2912 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2913 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2914 | locations->SetInAt(2, Location::RequiresRegister()); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2915 | } |
| 2916 | } |
| 2917 | |
| 2918 | void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) { |
| 2919 | Primitive::Type value_type = instruction->GetComponentType(); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2920 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2921 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2922 | bool needs_write_barrier = |
| 2923 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2924 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2925 | Register array = InputRegisterAt(instruction, 0); |
Alexandre Rames | be919d9 | 2016-08-23 18:33:36 +0100 | [diff] [blame] | 2926 | CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2927 | CPURegister source = value; |
| 2928 | Location index = locations->InAt(1); |
| 2929 | size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 2930 | MemOperand destination = HeapOperand(array); |
| 2931 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2932 | |
| 2933 | if (!needs_write_barrier) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2934 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2935 | if (index.IsConstant()) { |
| 2936 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
| 2937 | destination = HeapOperand(array, offset); |
| 2938 | } else { |
| 2939 | UseScratchRegisterScope temps(masm); |
| 2940 | Register temp = temps.AcquireSameSizeAs(array); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2941 | if (instruction->GetArray()->IsIntermediateAddress()) { |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2942 | // We do not need to compute the intermediate address from the array: the |
| 2943 | // input instruction has done it already. See the comment in |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2944 | // `TryExtractArrayAccessAddress()`. |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2945 | if (kIsDebugBuild) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2946 | HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2947 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset); |
| 2948 | } |
| 2949 | temp = array; |
| 2950 | } else { |
| 2951 | __ Add(temp, array, offset); |
| 2952 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2953 | destination = HeapOperand(temp, |
| 2954 | XRegisterFrom(index), |
| 2955 | LSL, |
| 2956 | Primitive::ComponentSizeShift(value_type)); |
| 2957 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2958 | { |
| 2959 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 2960 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 2961 | codegen_->Store(value_type, value, destination); |
| 2962 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2963 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 2964 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 2965 | DCHECK(!instruction->GetArray()->IsIntermediateAddress()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2966 | vixl::aarch64::Label done; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2967 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2968 | { |
| 2969 | // We use a block to end the scratch scope before the write barrier, thus |
| 2970 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2971 | UseScratchRegisterScope temps(masm); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2972 | Register temp = temps.AcquireSameSizeAs(array); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2973 | if (index.IsConstant()) { |
| 2974 | offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2975 | destination = HeapOperand(array, offset); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2976 | } else { |
Alexandre Rames | 82000b0 | 2015-07-07 11:34:16 +0100 | [diff] [blame] | 2977 | destination = HeapOperand(temp, |
| 2978 | XRegisterFrom(index), |
| 2979 | LSL, |
| 2980 | Primitive::ComponentSizeShift(value_type)); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 2981 | } |
| 2982 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2983 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2984 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2985 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2986 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 2987 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2988 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction); |
| 2989 | codegen_->AddSlowPath(slow_path); |
| 2990 | if (instruction->GetValueCanBeNull()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2991 | vixl::aarch64::Label non_zero; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 2992 | __ Cbnz(Register(value), &non_zero); |
| 2993 | if (!index.IsConstant()) { |
| 2994 | __ Add(temp, array, offset); |
| 2995 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 2996 | { |
| 2997 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools |
| 2998 | // emitted. |
| 2999 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3000 | __ Str(wzr, destination); |
| 3001 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3002 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3003 | __ B(&done); |
| 3004 | __ Bind(&non_zero); |
| 3005 | } |
| 3006 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3007 | // Note that when Baker read barriers are enabled, the type |
| 3008 | // checks are performed without read barriers. This is fine, |
| 3009 | // even in the case where a class object is in the from-space |
| 3010 | // after the flip, as a comparison involving such a type would |
| 3011 | // not produce a false positive; it may of course produce a |
| 3012 | // false negative, in which case we would take the ArraySet |
| 3013 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3014 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3015 | Register temp2 = temps.AcquireSameSizeAs(array); |
| 3016 | // /* HeapReference<Class> */ temp = array->klass_ |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3017 | { |
| 3018 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3019 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3020 | __ Ldr(temp, HeapOperand(array, class_offset)); |
| 3021 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3022 | } |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3023 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3024 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3025 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 3026 | __ Ldr(temp, HeapOperand(temp, component_offset)); |
| 3027 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 3028 | __ Ldr(temp2, HeapOperand(Register(value), class_offset)); |
| 3029 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 3030 | // nor `temp2`, as we are comparing two poisoned references. |
| 3031 | __ Cmp(temp, temp2); |
| 3032 | temps.Release(temp2); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 3033 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3034 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 3035 | vixl::aarch64::Label do_put; |
| 3036 | __ B(eq, &do_put); |
| 3037 | // If heap poisoning is enabled, the `temp` reference has |
| 3038 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3039 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 3040 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 3041 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 3042 | __ Ldr(temp, HeapOperand(temp, super_offset)); |
| 3043 | // If heap poisoning is enabled, no need to unpoison |
| 3044 | // `temp`, as we are comparing against null below. |
| 3045 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 3046 | __ Bind(&do_put); |
| 3047 | } else { |
| 3048 | __ B(ne, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | if (kPoisonHeapReferences) { |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3053 | Register temp2 = temps.AcquireSameSizeAs(array); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3054 | DCHECK(value.IsW()); |
Nicolas Geoffray | a8a0fe2 | 2015-10-01 15:50:27 +0100 | [diff] [blame] | 3055 | __ Mov(temp2, value.W()); |
| 3056 | GetAssembler()->PoisonHeapReference(temp2); |
| 3057 | source = temp2; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | if (!index.IsConstant()) { |
| 3061 | __ Add(temp, array, offset); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 3062 | } else { |
| 3063 | // We no longer need the `temp` here so release it as the store below may |
| 3064 | // need a scratch register (if the constant index makes the offset too large) |
| 3065 | // and the poisoned `source` could be using the other scratch register. |
| 3066 | temps.Release(temp); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3067 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3068 | { |
| 3069 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 3070 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 3071 | __ Str(source, destination); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3072 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 3073 | if (!may_need_runtime_call_for_type_check) { |
| 3074 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3075 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3076 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3077 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 3078 | |
| 3079 | codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull()); |
| 3080 | |
| 3081 | if (done.IsLinked()) { |
| 3082 | __ Bind(&done); |
| 3083 | } |
| 3084 | |
| 3085 | if (slow_path != nullptr) { |
| 3086 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 97833a0 | 2015-04-16 15:07:12 +0100 | [diff] [blame] | 3087 | } |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3088 | } |
| 3089 | } |
| 3090 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3091 | void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3092 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3093 | InvokeRuntimeCallingConvention calling_convention; |
| 3094 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3095 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode())); |
| 3096 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3097 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 760d8ef | 2015-03-28 18:09:56 +0000 | [diff] [blame] | 3098 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 3102 | BoundsCheckSlowPathARM64* slow_path = |
| 3103 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3104 | codegen_->AddSlowPath(slow_path); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3105 | __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1)); |
| 3106 | __ B(slow_path->GetEntryLabel(), hs); |
| 3107 | } |
| 3108 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3109 | void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3110 | LocationSummary* locations = |
| 3111 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3112 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3113 | if (check->HasUses()) { |
| 3114 | locations->SetOut(Location::SameAsFirstInput()); |
| 3115 | } |
| 3116 | } |
| 3117 | |
| 3118 | void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) { |
| 3119 | // We assume the class is not null. |
| 3120 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
| 3121 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| 3122 | codegen_->AddSlowPath(slow_path); |
| 3123 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 3124 | } |
| 3125 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3126 | static bool IsFloatingPointZeroConstant(HInstruction* inst) { |
| 3127 | return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero())) |
| 3128 | || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero())); |
| 3129 | } |
| 3130 | |
| 3131 | void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) { |
| 3132 | FPRegister lhs_reg = InputFPRegisterAt(instruction, 0); |
| 3133 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 3134 | if (rhs_loc.IsConstant()) { |
| 3135 | // 0.0 is the only immediate that can be encoded directly in |
| 3136 | // an FCMP instruction. |
| 3137 | // |
| 3138 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 3139 | // specify that in a floating-point comparison, positive zero |
| 3140 | // and negative zero are considered equal, so we can use the |
| 3141 | // literal 0.0 for both cases here. |
| 3142 | // |
| 3143 | // Note however that some methods (Float.equal, Float.compare, |
| 3144 | // Float.compareTo, Double.equal, Double.compare, |
| 3145 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 3146 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 3147 | // -0.0. So if we ever translate calls to these methods into a |
| 3148 | // HCompare instruction, we must handle the -0.0 case with |
| 3149 | // care here. |
| 3150 | DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant())); |
| 3151 | __ Fcmp(lhs_reg, 0.0); |
| 3152 | } else { |
| 3153 | __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1)); |
| 3154 | } |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3155 | } |
| 3156 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3157 | void LocationsBuilderARM64::VisitCompare(HCompare* compare) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3158 | LocationSummary* locations = |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3159 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| 3160 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3161 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3162 | case Primitive::kPrimBoolean: |
| 3163 | case Primitive::kPrimByte: |
| 3164 | case Primitive::kPrimShort: |
| 3165 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3166 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3167 | case Primitive::kPrimLong: { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3168 | locations->SetInAt(0, Location::RequiresRegister()); |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 3169 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare)); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3170 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3171 | break; |
| 3172 | } |
| 3173 | case Primitive::kPrimFloat: |
| 3174 | case Primitive::kPrimDouble: { |
| 3175 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3176 | locations->SetInAt(1, |
| 3177 | IsFloatingPointZeroConstant(compare->InputAt(1)) |
| 3178 | ? Location::ConstantLocation(compare->InputAt(1)->AsConstant()) |
| 3179 | : Location::RequiresFpuRegister()); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3180 | locations->SetOut(Location::RequiresRegister()); |
| 3181 | break; |
| 3182 | } |
| 3183 | default: |
| 3184 | LOG(FATAL) << "Unexpected type for compare operation " << in_type; |
| 3185 | } |
| 3186 | } |
| 3187 | |
| 3188 | void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) { |
| 3189 | Primitive::Type in_type = compare->InputAt(0)->GetType(); |
| 3190 | |
| 3191 | // 0 if: left == right |
| 3192 | // 1 if: left > right |
| 3193 | // -1 if: left < right |
| 3194 | switch (in_type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3195 | case Primitive::kPrimBoolean: |
| 3196 | case Primitive::kPrimByte: |
| 3197 | case Primitive::kPrimShort: |
| 3198 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3199 | case Primitive::kPrimInt: |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3200 | case Primitive::kPrimLong: { |
| 3201 | Register result = OutputRegister(compare); |
| 3202 | Register left = InputRegisterAt(compare, 0); |
| 3203 | Operand right = InputOperandAt(compare, 1); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3204 | __ Cmp(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 3205 | __ Cset(result, ne); // result == +1 if NE or 0 otherwise |
| 3206 | __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3207 | break; |
| 3208 | } |
| 3209 | case Primitive::kPrimFloat: |
| 3210 | case Primitive::kPrimDouble: { |
| 3211 | Register result = OutputRegister(compare); |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3212 | GenerateFcmp(compare); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3213 | __ Cset(result, ne); |
| 3214 | __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias())); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3215 | break; |
| 3216 | } |
| 3217 | default: |
| 3218 | LOG(FATAL) << "Unimplemented compare type " << in_type; |
| 3219 | } |
| 3220 | } |
| 3221 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3222 | void LocationsBuilderARM64::HandleCondition(HCondition* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3223 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3224 | |
| 3225 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
| 3226 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3227 | locations->SetInAt(1, |
| 3228 | IsFloatingPointZeroConstant(instruction->InputAt(1)) |
| 3229 | ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant()) |
| 3230 | : Location::RequiresFpuRegister()); |
| 3231 | } else { |
| 3232 | // Integer cases. |
| 3233 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3234 | locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction)); |
| 3235 | } |
| 3236 | |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3237 | if (!instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 3238 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3239 | } |
| 3240 | } |
| 3241 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3242 | void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3243 | if (instruction->IsEmittedAtUseSite()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3244 | return; |
| 3245 | } |
| 3246 | |
| 3247 | LocationSummary* locations = instruction->GetLocations(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3248 | Register res = RegisterFrom(locations->Out(), instruction->GetType()); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3249 | IfCondition if_cond = instruction->GetCondition(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3250 | |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3251 | if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3252 | GenerateFcmp(instruction); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3253 | __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias())); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3254 | } else { |
| 3255 | // Integer cases. |
| 3256 | Register lhs = InputRegisterAt(instruction, 0); |
| 3257 | Operand rhs = InputOperandAt(instruction, 1); |
| 3258 | __ Cmp(lhs, rhs); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3259 | __ Cset(res, ARM64Condition(if_cond)); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3260 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | #define FOR_EACH_CONDITION_INSTRUCTION(M) \ |
| 3264 | M(Equal) \ |
| 3265 | M(NotEqual) \ |
| 3266 | M(LessThan) \ |
| 3267 | M(LessThanOrEqual) \ |
| 3268 | M(GreaterThan) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3269 | M(GreaterThanOrEqual) \ |
| 3270 | M(Below) \ |
| 3271 | M(BelowOrEqual) \ |
| 3272 | M(Above) \ |
| 3273 | M(AboveOrEqual) |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3274 | #define DEFINE_CONDITION_VISITORS(Name) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3275 | void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \ |
| 3276 | void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3277 | FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS) |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3278 | #undef DEFINE_CONDITION_VISITORS |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3279 | #undef FOR_EACH_CONDITION_INSTRUCTION |
| 3280 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3281 | void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3282 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3283 | |
| 3284 | LocationSummary* locations = instruction->GetLocations(); |
| 3285 | Location second = locations->InAt(1); |
| 3286 | DCHECK(second.IsConstant()); |
| 3287 | |
| 3288 | Register out = OutputRegister(instruction); |
| 3289 | Register dividend = InputRegisterAt(instruction, 0); |
| 3290 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3291 | DCHECK(imm == 1 || imm == -1); |
| 3292 | |
| 3293 | if (instruction->IsRem()) { |
| 3294 | __ Mov(out, 0); |
| 3295 | } else { |
| 3296 | if (imm == 1) { |
| 3297 | __ Mov(out, dividend); |
| 3298 | } else { |
| 3299 | __ Neg(out, dividend); |
| 3300 | } |
| 3301 | } |
| 3302 | } |
| 3303 | |
| 3304 | void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3305 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3306 | |
| 3307 | LocationSummary* locations = instruction->GetLocations(); |
| 3308 | Location second = locations->InAt(1); |
| 3309 | DCHECK(second.IsConstant()); |
| 3310 | |
| 3311 | Register out = OutputRegister(instruction); |
| 3312 | Register dividend = InputRegisterAt(instruction, 0); |
| 3313 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3314 | uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3315 | int ctz_imm = CTZ(abs_imm); |
| 3316 | |
| 3317 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3318 | Register temp = temps.AcquireSameSizeAs(out); |
| 3319 | |
| 3320 | if (instruction->IsDiv()) { |
| 3321 | __ Add(temp, dividend, abs_imm - 1); |
| 3322 | __ Cmp(dividend, 0); |
| 3323 | __ Csel(out, temp, dividend, lt); |
| 3324 | if (imm > 0) { |
| 3325 | __ Asr(out, out, ctz_imm); |
| 3326 | } else { |
| 3327 | __ Neg(out, Operand(out, ASR, ctz_imm)); |
| 3328 | } |
| 3329 | } else { |
| 3330 | int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64; |
| 3331 | __ Asr(temp, dividend, bits - 1); |
| 3332 | __ Lsr(temp, temp, bits - ctz_imm); |
| 3333 | __ Add(out, dividend, temp); |
| 3334 | __ And(out, out, abs_imm - 1); |
| 3335 | __ Sub(out, out, temp); |
| 3336 | } |
| 3337 | } |
| 3338 | |
| 3339 | void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3340 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3341 | |
| 3342 | LocationSummary* locations = instruction->GetLocations(); |
| 3343 | Location second = locations->InAt(1); |
| 3344 | DCHECK(second.IsConstant()); |
| 3345 | |
| 3346 | Register out = OutputRegister(instruction); |
| 3347 | Register dividend = InputRegisterAt(instruction, 0); |
| 3348 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3349 | |
| 3350 | Primitive::Type type = instruction->GetResultType(); |
| 3351 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 3352 | |
| 3353 | int64_t magic; |
| 3354 | int shift; |
| 3355 | CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift); |
| 3356 | |
| 3357 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3358 | Register temp = temps.AcquireSameSizeAs(out); |
| 3359 | |
| 3360 | // temp = get_high(dividend * magic) |
| 3361 | __ Mov(temp, magic); |
| 3362 | if (type == Primitive::kPrimLong) { |
| 3363 | __ Smulh(temp, dividend, temp); |
| 3364 | } else { |
| 3365 | __ Smull(temp.X(), dividend, temp); |
| 3366 | __ Lsr(temp.X(), temp.X(), 32); |
| 3367 | } |
| 3368 | |
| 3369 | if (imm > 0 && magic < 0) { |
| 3370 | __ Add(temp, temp, dividend); |
| 3371 | } else if (imm < 0 && magic > 0) { |
| 3372 | __ Sub(temp, temp, dividend); |
| 3373 | } |
| 3374 | |
| 3375 | if (shift != 0) { |
| 3376 | __ Asr(temp, temp, shift); |
| 3377 | } |
| 3378 | |
| 3379 | if (instruction->IsDiv()) { |
| 3380 | __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3381 | } else { |
| 3382 | __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31)); |
| 3383 | // TODO: Strength reduction for msub. |
| 3384 | Register temp_imm = temps.AcquireSameSizeAs(out); |
| 3385 | __ Mov(temp_imm, imm); |
| 3386 | __ Msub(out, temp, temp_imm, dividend); |
| 3387 | } |
| 3388 | } |
| 3389 | |
| 3390 | void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3391 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3392 | Primitive::Type type = instruction->GetResultType(); |
Calin Juravle | c70d1d9 | 2017-03-27 18:10:04 -0700 | [diff] [blame] | 3393 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3394 | |
| 3395 | LocationSummary* locations = instruction->GetLocations(); |
| 3396 | Register out = OutputRegister(instruction); |
| 3397 | Location second = locations->InAt(1); |
| 3398 | |
| 3399 | if (second.IsConstant()) { |
| 3400 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3401 | |
| 3402 | if (imm == 0) { |
| 3403 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3404 | } else if (imm == 1 || imm == -1) { |
| 3405 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3406 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3407 | DivRemByPowerOfTwo(instruction); |
| 3408 | } else { |
| 3409 | DCHECK(imm <= -2 || imm >= 2); |
| 3410 | GenerateDivRemWithAnyConstant(instruction); |
| 3411 | } |
| 3412 | } else { |
| 3413 | Register dividend = InputRegisterAt(instruction, 0); |
| 3414 | Register divisor = InputRegisterAt(instruction, 1); |
| 3415 | if (instruction->IsDiv()) { |
| 3416 | __ Sdiv(out, dividend, divisor); |
| 3417 | } else { |
| 3418 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3419 | Register temp = temps.AcquireSameSizeAs(out); |
| 3420 | __ Sdiv(temp, dividend, divisor); |
| 3421 | __ Msub(out, temp, divisor, dividend); |
| 3422 | } |
| 3423 | } |
| 3424 | } |
| 3425 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3426 | void LocationsBuilderARM64::VisitDiv(HDiv* div) { |
| 3427 | LocationSummary* locations = |
| 3428 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3429 | switch (div->GetResultType()) { |
| 3430 | case Primitive::kPrimInt: |
| 3431 | case Primitive::kPrimLong: |
| 3432 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3433 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3434 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3435 | break; |
| 3436 | |
| 3437 | case Primitive::kPrimFloat: |
| 3438 | case Primitive::kPrimDouble: |
| 3439 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3440 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3441 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3442 | break; |
| 3443 | |
| 3444 | default: |
| 3445 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3446 | } |
| 3447 | } |
| 3448 | |
| 3449 | void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) { |
| 3450 | Primitive::Type type = div->GetResultType(); |
| 3451 | switch (type) { |
| 3452 | case Primitive::kPrimInt: |
| 3453 | case Primitive::kPrimLong: |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3454 | GenerateDivRemIntegral(div); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 3455 | break; |
| 3456 | |
| 3457 | case Primitive::kPrimFloat: |
| 3458 | case Primitive::kPrimDouble: |
| 3459 | __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1)); |
| 3460 | break; |
| 3461 | |
| 3462 | default: |
| 3463 | LOG(FATAL) << "Unexpected div type " << type; |
| 3464 | } |
| 3465 | } |
| 3466 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3467 | void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3468 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3469 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3470 | } |
| 3471 | |
| 3472 | void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3473 | SlowPathCodeARM64* slow_path = |
| 3474 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction); |
| 3475 | codegen_->AddSlowPath(slow_path); |
| 3476 | Location value = instruction->GetLocations()->InAt(0); |
| 3477 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3478 | Primitive::Type type = instruction->GetType(); |
| 3479 | |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3480 | if (!Primitive::IsIntegralType(type)) { |
| 3481 | LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3482 | return; |
| 3483 | } |
| 3484 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3485 | if (value.IsConstant()) { |
| 3486 | int64_t divisor = Int64ConstantFrom(value); |
| 3487 | if (divisor == 0) { |
| 3488 | __ B(slow_path->GetEntryLabel()); |
| 3489 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 3490 | // A division by a non-null constant is valid. We don't need to perform |
| 3491 | // any check, so simply fall through. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3492 | } |
| 3493 | } else { |
| 3494 | __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| 3495 | } |
| 3496 | } |
| 3497 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3498 | void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3499 | LocationSummary* locations = |
| 3500 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3501 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3502 | } |
| 3503 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3504 | void InstructionCodeGeneratorARM64::VisitDoubleConstant( |
| 3505 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3506 | // Will be generated at use site. |
| 3507 | } |
| 3508 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3509 | void LocationsBuilderARM64::VisitExit(HExit* exit) { |
| 3510 | exit->SetLocations(nullptr); |
| 3511 | } |
| 3512 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3513 | void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3514 | } |
| 3515 | |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3516 | void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) { |
| 3517 | LocationSummary* locations = |
| 3518 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3519 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3520 | } |
| 3521 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3522 | void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 3523 | // Will be generated at use site. |
| 3524 | } |
| 3525 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3526 | void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3527 | DCHECK(!successor->IsExitBlock()); |
| 3528 | HBasicBlock* block = got->GetBlock(); |
| 3529 | HInstruction* previous = got->GetPrevious(); |
| 3530 | HLoopInformation* info = block->GetLoopInformation(); |
| 3531 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3532 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3533 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 3534 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 3535 | return; |
| 3536 | } |
| 3537 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 3538 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 3539 | } |
| 3540 | if (!codegen_->GoesToNextBlock(block, successor)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3541 | __ B(codegen_->GetLabelOf(successor)); |
| 3542 | } |
| 3543 | } |
| 3544 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3545 | void LocationsBuilderARM64::VisitGoto(HGoto* got) { |
| 3546 | got->SetLocations(nullptr); |
| 3547 | } |
| 3548 | |
| 3549 | void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) { |
| 3550 | HandleGoto(got, got->GetSuccessor()); |
| 3551 | } |
| 3552 | |
| 3553 | void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3554 | try_boundary->SetLocations(nullptr); |
| 3555 | } |
| 3556 | |
| 3557 | void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 3558 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 3559 | if (!successor->IsExitBlock()) { |
| 3560 | HandleGoto(try_boundary, successor); |
| 3561 | } |
| 3562 | } |
| 3563 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3564 | void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3565 | size_t condition_input_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3566 | vixl::aarch64::Label* true_target, |
| 3567 | vixl::aarch64::Label* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3568 | // FP branching requires both targets to be explicit. If either of the targets |
| 3569 | // is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3570 | vixl::aarch64::Label fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3571 | HInstruction* cond = instruction->InputAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3572 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3573 | if (true_target == nullptr && false_target == nullptr) { |
| 3574 | // Nothing to do. The code always falls through. |
| 3575 | return; |
| 3576 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3577 | // Constant condition, statically compared against "true" (integer value 1). |
| 3578 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3579 | if (true_target != nullptr) { |
| 3580 | __ B(true_target); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3581 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3582 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3583 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3584 | if (false_target != nullptr) { |
| 3585 | __ B(false_target); |
| 3586 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 3587 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3588 | return; |
| 3589 | } |
| 3590 | |
| 3591 | // The following code generates these patterns: |
| 3592 | // (1) true_target == nullptr && false_target != nullptr |
| 3593 | // - opposite condition true => branch to false_target |
| 3594 | // (2) true_target != nullptr && false_target == nullptr |
| 3595 | // - condition true => branch to true_target |
| 3596 | // (3) true_target != nullptr && false_target != nullptr |
| 3597 | // - condition true => branch to true_target |
| 3598 | // - branch to false_target |
| 3599 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3600 | // The condition instruction has been materialized, compare the output to 0. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3601 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3602 | DCHECK(cond_val.IsRegister()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3603 | if (true_target == nullptr) { |
| 3604 | __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target); |
| 3605 | } else { |
| 3606 | __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target); |
| 3607 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3608 | } else { |
| 3609 | // The condition instruction has not been materialized, use its inputs as |
| 3610 | // the comparison and its condition as the branch condition. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3611 | HCondition* condition = cond->AsCondition(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3612 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3613 | Primitive::Type type = condition->InputAt(0)->GetType(); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3614 | if (Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3615 | GenerateFcmp(condition); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3616 | if (true_target == nullptr) { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3617 | IfCondition opposite_condition = condition->GetOppositeCondition(); |
| 3618 | __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3619 | } else { |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 3620 | __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3621 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3622 | } else { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3623 | // Integer cases. |
| 3624 | Register lhs = InputRegisterAt(condition, 0); |
| 3625 | Operand rhs = InputOperandAt(condition, 1); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3626 | |
| 3627 | Condition arm64_cond; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3628 | vixl::aarch64::Label* non_fallthrough_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3629 | if (true_target == nullptr) { |
| 3630 | arm64_cond = ARM64Condition(condition->GetOppositeCondition()); |
| 3631 | non_fallthrough_target = false_target; |
| 3632 | } else { |
| 3633 | arm64_cond = ARM64Condition(condition->GetCondition()); |
| 3634 | non_fallthrough_target = true_target; |
| 3635 | } |
| 3636 | |
Aart Bik | 086d27e | 2016-01-20 17:02:00 -0800 | [diff] [blame] | 3637 | 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] | 3638 | rhs.IsImmediate() && (rhs.GetImmediate() == 0)) { |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3639 | switch (arm64_cond) { |
| 3640 | case eq: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3641 | __ Cbz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3642 | break; |
| 3643 | case ne: |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3644 | __ Cbnz(lhs, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3645 | break; |
| 3646 | case lt: |
| 3647 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3648 | __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3649 | break; |
| 3650 | case ge: |
| 3651 | // Test the sign bit and branch accordingly. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3652 | __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3653 | break; |
| 3654 | default: |
| 3655 | // Without the `static_cast` the compiler throws an error for |
| 3656 | // `-Werror=sign-promo`. |
| 3657 | LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond); |
| 3658 | } |
| 3659 | } else { |
| 3660 | __ Cmp(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3661 | __ B(arm64_cond, non_fallthrough_target); |
Roland Levillain | 7f63c52 | 2015-07-13 15:54:55 +0000 | [diff] [blame] | 3662 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3663 | } |
| 3664 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3665 | |
| 3666 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3667 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3668 | if (true_target != nullptr && false_target != nullptr) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3669 | __ B(false_target); |
| 3670 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3671 | |
| 3672 | if (fallthrough_target.IsLinked()) { |
| 3673 | __ Bind(&fallthrough_target); |
| 3674 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3675 | } |
| 3676 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3677 | void LocationsBuilderARM64::VisitIf(HIf* if_instr) { |
| 3678 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3679 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3680 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3681 | } |
| 3682 | } |
| 3683 | |
| 3684 | void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3685 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3686 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3687 | vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor); |
| 3688 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) { |
| 3689 | true_target = nullptr; |
| 3690 | } |
| 3691 | vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor); |
| 3692 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) { |
| 3693 | false_target = nullptr; |
| 3694 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3695 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3699 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3700 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame^] | 3701 | InvokeRuntimeCallingConvention calling_convention; |
| 3702 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3703 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 3704 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3705 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3706 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3707 | } |
| 3708 | } |
| 3709 | |
| 3710 | void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 3711 | SlowPathCodeARM64* slow_path = |
| 3712 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3713 | GenerateTestAndBranch(deoptimize, |
| 3714 | /* condition_input_index */ 0, |
| 3715 | slow_path->GetEntryLabel(), |
| 3716 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3717 | } |
| 3718 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3719 | void LocationsBuilderARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3720 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3721 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3722 | locations->SetOut(Location::RequiresRegister()); |
| 3723 | } |
| 3724 | |
| 3725 | void InstructionCodeGeneratorARM64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3726 | __ Ldr(OutputRegister(flag), |
| 3727 | MemOperand(sp, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 3728 | } |
| 3729 | |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3730 | static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) { |
| 3731 | return condition->IsCondition() && |
| 3732 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType()); |
| 3733 | } |
| 3734 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3735 | static inline Condition GetConditionForSelect(HCondition* condition) { |
| 3736 | IfCondition cond = condition->AsCondition()->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3737 | return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias()) |
| 3738 | : ARM64Condition(cond); |
| 3739 | } |
| 3740 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3741 | void LocationsBuilderARM64::VisitSelect(HSelect* select) { |
| 3742 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3743 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3744 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3745 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3746 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3747 | } else { |
| 3748 | HConstant* cst_true_value = select->GetTrueValue()->AsConstant(); |
| 3749 | HConstant* cst_false_value = select->GetFalseValue()->AsConstant(); |
| 3750 | bool is_true_value_constant = cst_true_value != nullptr; |
| 3751 | bool is_false_value_constant = cst_false_value != nullptr; |
| 3752 | // Ask VIXL whether we should synthesize constants in registers. |
| 3753 | // We give an arbitrary register to VIXL when dealing with non-constant inputs. |
| 3754 | Operand true_op = is_true_value_constant ? |
| 3755 | Operand(Int64FromConstant(cst_true_value)) : Operand(x1); |
| 3756 | Operand false_op = is_false_value_constant ? |
| 3757 | Operand(Int64FromConstant(cst_false_value)) : Operand(x2); |
| 3758 | bool true_value_in_register = false; |
| 3759 | bool false_value_in_register = false; |
| 3760 | MacroAssembler::GetCselSynthesisInformation( |
| 3761 | x0, true_op, false_op, &true_value_in_register, &false_value_in_register); |
| 3762 | true_value_in_register |= !is_true_value_constant; |
| 3763 | false_value_in_register |= !is_false_value_constant; |
| 3764 | |
| 3765 | locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister() |
| 3766 | : Location::ConstantLocation(cst_true_value)); |
| 3767 | locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister() |
| 3768 | : Location::ConstantLocation(cst_false_value)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3769 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3770 | } |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3771 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3772 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 3773 | locations->SetInAt(2, Location::RequiresRegister()); |
| 3774 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3775 | } |
| 3776 | |
| 3777 | void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3778 | HInstruction* cond = select->GetCondition(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3779 | Condition csel_cond; |
| 3780 | |
| 3781 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 3782 | if (cond->IsCondition() && cond->GetNext() == select) { |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3783 | // Use the condition flags set by the previous instruction. |
| 3784 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3785 | } else { |
| 3786 | __ Cmp(InputRegisterAt(select, 2), 0); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3787 | csel_cond = ne; |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3788 | } |
| 3789 | } else if (IsConditionOnFloatingPointValues(cond)) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3790 | GenerateFcmp(cond); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3791 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3792 | } else { |
| 3793 | __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1)); |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3794 | csel_cond = GetConditionForSelect(cond->AsCondition()); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3795 | } |
| 3796 | |
Alexandre Rames | 880f119 | 2016-06-13 16:04:50 +0100 | [diff] [blame] | 3797 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 3798 | __ Fcsel(OutputFPRegister(select), |
| 3799 | InputFPRegisterAt(select, 1), |
| 3800 | InputFPRegisterAt(select, 0), |
| 3801 | csel_cond); |
| 3802 | } else { |
| 3803 | __ Csel(OutputRegister(select), |
| 3804 | InputOperandAt(select, 1), |
| 3805 | InputOperandAt(select, 0), |
| 3806 | csel_cond); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 3807 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3810 | void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3811 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3812 | } |
| 3813 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3814 | void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3815 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | void CodeGeneratorARM64::GenerateNop() { |
| 3819 | __ Nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3820 | } |
| 3821 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3822 | void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 3823 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3824 | } |
| 3825 | |
| 3826 | void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3827 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3828 | } |
| 3829 | |
| 3830 | void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 3831 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3835 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 3836 | } |
| 3837 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3838 | // Temp is used for read barrier. |
| 3839 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 3840 | if (kEmitCompilerReadBarrier && |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3841 | (kUseBakerReadBarrier || |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3842 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 3843 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 3844 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 3845 | return 1; |
| 3846 | } |
| 3847 | return 0; |
| 3848 | } |
| 3849 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3850 | // 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] | 3851 | // interface pointer, one for loading the current interface. |
| 3852 | // The other checks have one temp for loading the object's class. |
| 3853 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 3854 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 3855 | return 3; |
| 3856 | } |
| 3857 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3858 | } |
| 3859 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3860 | void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3861 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3862 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3863 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3864 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3865 | case TypeCheckKind::kExactCheck: |
| 3866 | case TypeCheckKind::kAbstractClassCheck: |
| 3867 | case TypeCheckKind::kClassHierarchyCheck: |
| 3868 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3869 | call_kind = |
| 3870 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3871 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3872 | break; |
| 3873 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3874 | case TypeCheckKind::kUnresolvedCheck: |
| 3875 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3876 | call_kind = LocationSummary::kCallOnSlowPath; |
| 3877 | break; |
| 3878 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3879 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3880 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3881 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3882 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 3883 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3884 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3885 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3886 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 3887 | // Note that TypeCheckSlowPathARM64 uses this register too. |
| 3888 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3889 | // Add temps if necessary for read barriers. |
| 3890 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3894 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3895 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3896 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3897 | Register obj = InputRegisterAt(instruction, 0); |
| 3898 | Register cls = InputRegisterAt(instruction, 1); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3899 | Location out_loc = locations->Out(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3900 | Register out = OutputRegister(instruction); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 3901 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 3902 | DCHECK_LE(num_temps, 1u); |
| 3903 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3904 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3905 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 3906 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 3907 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3908 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3909 | vixl::aarch64::Label done, zero; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3910 | SlowPathCodeARM64* slow_path = nullptr; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 3911 | |
| 3912 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 3913 | // Avoid null check if we know `obj` is not null. |
| 3914 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3915 | __ Cbz(obj, &zero); |
| 3916 | } |
| 3917 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 3918 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3919 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3920 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3921 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3922 | out_loc, |
| 3923 | obj_loc, |
| 3924 | class_offset, |
| 3925 | maybe_temp_loc, |
| 3926 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3927 | __ Cmp(out, cls); |
| 3928 | __ Cset(out, eq); |
| 3929 | if (zero.IsLinked()) { |
| 3930 | __ B(&done); |
| 3931 | } |
| 3932 | break; |
| 3933 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3934 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3935 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3936 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3937 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3938 | out_loc, |
| 3939 | obj_loc, |
| 3940 | class_offset, |
| 3941 | maybe_temp_loc, |
| 3942 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3943 | // If the class is abstract, we eagerly fetch the super class of the |
| 3944 | // object to avoid doing a comparison we know will fail. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3945 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3946 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3947 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3948 | GenerateReferenceLoadOneRegister(instruction, |
| 3949 | out_loc, |
| 3950 | super_offset, |
| 3951 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3952 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3953 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3954 | __ Cbz(out, &done); |
| 3955 | __ Cmp(out, cls); |
| 3956 | __ B(ne, &loop); |
| 3957 | __ Mov(out, 1); |
| 3958 | if (zero.IsLinked()) { |
| 3959 | __ B(&done); |
| 3960 | } |
| 3961 | break; |
| 3962 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3963 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3964 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3965 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3966 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3967 | out_loc, |
| 3968 | obj_loc, |
| 3969 | class_offset, |
| 3970 | maybe_temp_loc, |
| 3971 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3972 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 3973 | vixl::aarch64::Label loop, success; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3974 | __ Bind(&loop); |
| 3975 | __ Cmp(out, cls); |
| 3976 | __ B(eq, &success); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3977 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 3978 | GenerateReferenceLoadOneRegister(instruction, |
| 3979 | out_loc, |
| 3980 | super_offset, |
| 3981 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 3982 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3983 | __ Cbnz(out, &loop); |
| 3984 | // If `out` is null, we use it for the result, and jump to `done`. |
| 3985 | __ B(&done); |
| 3986 | __ Bind(&success); |
| 3987 | __ Mov(out, 1); |
| 3988 | if (zero.IsLinked()) { |
| 3989 | __ B(&done); |
| 3990 | } |
| 3991 | break; |
| 3992 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 3993 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 3994 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 3995 | // /* HeapReference<Class> */ out = obj->klass_ |
| 3996 | GenerateReferenceLoadTwoRegisters(instruction, |
| 3997 | out_loc, |
| 3998 | obj_loc, |
| 3999 | class_offset, |
| 4000 | maybe_temp_loc, |
| 4001 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4002 | // Do an exact check. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4003 | vixl::aarch64::Label exact_check; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4004 | __ Cmp(out, cls); |
| 4005 | __ B(eq, &exact_check); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4006 | // 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] | 4007 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4008 | GenerateReferenceLoadOneRegister(instruction, |
| 4009 | out_loc, |
| 4010 | component_offset, |
| 4011 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4012 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4013 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4014 | __ Cbz(out, &done); |
| 4015 | __ Ldrh(out, HeapOperand(out, primitive_offset)); |
| 4016 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 4017 | __ Cbnz(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4018 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4019 | __ Mov(out, 1); |
| 4020 | __ B(&done); |
| 4021 | break; |
| 4022 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4023 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4024 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 4025 | // No read barrier since the slow path will retry upon failure. |
| 4026 | // /* HeapReference<Class> */ out = obj->klass_ |
| 4027 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4028 | out_loc, |
| 4029 | obj_loc, |
| 4030 | class_offset, |
| 4031 | maybe_temp_loc, |
| 4032 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4033 | __ Cmp(out, cls); |
| 4034 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4035 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4036 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4037 | codegen_->AddSlowPath(slow_path); |
| 4038 | __ B(ne, slow_path->GetEntryLabel()); |
| 4039 | __ Mov(out, 1); |
| 4040 | if (zero.IsLinked()) { |
| 4041 | __ B(&done); |
| 4042 | } |
| 4043 | break; |
| 4044 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4045 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4046 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4047 | case TypeCheckKind::kInterfaceCheck: { |
| 4048 | // Note that we indeed only call on slow path, but we always go |
| 4049 | // into the slow path for the unresolved and interface check |
| 4050 | // cases. |
| 4051 | // |
| 4052 | // We cannot directly call the InstanceofNonTrivial runtime |
| 4053 | // entry point without resorting to a type checking slow path |
| 4054 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 4055 | // require to assign fixed registers for the inputs of this |
| 4056 | // HInstanceOf instruction (following the runtime calling |
| 4057 | // convention), which might be cluttered by the potential first |
| 4058 | // read barrier emission at the beginning of this method. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4059 | // |
| 4060 | // TODO: Introduce a new runtime entry point taking the object |
| 4061 | // to test (instead of its class) as argument, and let it deal |
| 4062 | // with the read barrier issues. This will let us refactor this |
| 4063 | // case of the `switch` code as it was previously (with a direct |
| 4064 | // call to the runtime not using a type checking slow path). |
| 4065 | // This should also be beneficial for the other cases above. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4066 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4067 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4068 | /* is_fatal */ false); |
| 4069 | codegen_->AddSlowPath(slow_path); |
| 4070 | __ B(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4071 | if (zero.IsLinked()) { |
| 4072 | __ B(&done); |
| 4073 | } |
| 4074 | break; |
| 4075 | } |
| 4076 | } |
| 4077 | |
| 4078 | if (zero.IsLinked()) { |
| 4079 | __ Bind(&zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4080 | __ Mov(out, 0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | if (done.IsLinked()) { |
| 4084 | __ Bind(&done); |
| 4085 | } |
| 4086 | |
| 4087 | if (slow_path != nullptr) { |
| 4088 | __ Bind(slow_path->GetExitLabel()); |
| 4089 | } |
| 4090 | } |
| 4091 | |
| 4092 | void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) { |
| 4093 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4094 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 4095 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4096 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 4097 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4098 | case TypeCheckKind::kExactCheck: |
| 4099 | case TypeCheckKind::kAbstractClassCheck: |
| 4100 | case TypeCheckKind::kClassHierarchyCheck: |
| 4101 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4102 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 4103 | LocationSummary::kCallOnSlowPath : |
| 4104 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4105 | break; |
| 4106 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4107 | case TypeCheckKind::kUnresolvedCheck: |
| 4108 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4109 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4110 | break; |
| 4111 | } |
| 4112 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4113 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4114 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4115 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4116 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64. |
| 4117 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4118 | } |
| 4119 | |
| 4120 | void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4121 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4122 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4123 | Location obj_loc = locations->InAt(0); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4124 | Register obj = InputRegisterAt(instruction, 0); |
| 4125 | Register cls = InputRegisterAt(instruction, 1); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4126 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 4127 | DCHECK_GE(num_temps, 1u); |
| 4128 | DCHECK_LE(num_temps, 3u); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4129 | Location temp_loc = locations->GetTemp(0); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4130 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 4131 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4132 | Register temp = WRegisterFrom(temp_loc); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4133 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4134 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4135 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4136 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 4137 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 4138 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 4139 | const uint32_t object_array_data_offset = |
| 4140 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4141 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4142 | bool is_type_check_slow_path_fatal = false; |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4143 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 4144 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 4145 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4146 | if (!kEmitCompilerReadBarrier) { |
| 4147 | is_type_check_slow_path_fatal = |
| 4148 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 4149 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 4150 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 4151 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 4152 | !instruction->CanThrowIntoCatchBlock(); |
| 4153 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4154 | SlowPathCodeARM64* type_check_slow_path = |
| 4155 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction, |
| 4156 | is_type_check_slow_path_fatal); |
| 4157 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4158 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4159 | vixl::aarch64::Label done; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4160 | // Avoid null check if we know obj is not null. |
| 4161 | if (instruction->MustDoNullCheck()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4162 | __ Cbz(obj, &done); |
| 4163 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4164 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4165 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4166 | case TypeCheckKind::kExactCheck: |
| 4167 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4168 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4169 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4170 | temp_loc, |
| 4171 | obj_loc, |
| 4172 | class_offset, |
| 4173 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4174 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4175 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4176 | __ Cmp(temp, cls); |
| 4177 | // Jump to slow path for throwing the exception or doing a |
| 4178 | // more involved array check. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4179 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4180 | break; |
| 4181 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4182 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4183 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4184 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4185 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4186 | temp_loc, |
| 4187 | obj_loc, |
| 4188 | class_offset, |
| 4189 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4190 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4191 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4192 | // If the class is abstract, we eagerly fetch the super class of the |
| 4193 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4194 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4195 | __ Bind(&loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4196 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4197 | GenerateReferenceLoadOneRegister(instruction, |
| 4198 | temp_loc, |
| 4199 | super_offset, |
| 4200 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4201 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4202 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4203 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 4204 | // exception. |
| 4205 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4206 | // Otherwise, compare classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4207 | __ Cmp(temp, cls); |
| 4208 | __ B(ne, &loop); |
| 4209 | break; |
| 4210 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4211 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4212 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4213 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4214 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4215 | temp_loc, |
| 4216 | obj_loc, |
| 4217 | class_offset, |
| 4218 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4219 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4220 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4221 | // Walk over the class hierarchy to find a match. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4222 | vixl::aarch64::Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4223 | __ Bind(&loop); |
| 4224 | __ Cmp(temp, cls); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4225 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4226 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4227 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4228 | GenerateReferenceLoadOneRegister(instruction, |
| 4229 | temp_loc, |
| 4230 | super_offset, |
| 4231 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4232 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4233 | |
| 4234 | // If the class reference currently in `temp` is not null, jump |
| 4235 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4236 | __ Cbnz(temp, &loop); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4237 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4238 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4239 | break; |
| 4240 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4241 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4242 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4243 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4244 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4245 | temp_loc, |
| 4246 | obj_loc, |
| 4247 | class_offset, |
| 4248 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4249 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4250 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4251 | // Do an exact check. |
| 4252 | __ Cmp(temp, cls); |
| 4253 | __ B(eq, &done); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4254 | |
| 4255 | // 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] | 4256 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 4257 | GenerateReferenceLoadOneRegister(instruction, |
| 4258 | temp_loc, |
| 4259 | component_offset, |
| 4260 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4261 | kWithoutReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4262 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4263 | // If the component type is null, jump to the slow path to throw the exception. |
| 4264 | __ Cbz(temp, type_check_slow_path->GetEntryLabel()); |
| 4265 | // Otherwise, the object is indeed an array. Further check that this component type is not a |
| 4266 | // primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4267 | __ Ldrh(temp, HeapOperand(temp, primitive_offset)); |
| 4268 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 4269 | __ Cbnz(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4270 | break; |
| 4271 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4272 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4273 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4274 | // 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] | 4275 | // |
| 4276 | // We cannot directly call the CheckCast runtime entry point |
| 4277 | // without resorting to a type checking slow path here (i.e. by |
| 4278 | // calling InvokeRuntime directly), as it would require to |
| 4279 | // assign fixed registers for the inputs of this HInstanceOf |
| 4280 | // instruction (following the runtime calling convention), which |
| 4281 | // might be cluttered by the potential first read barrier |
| 4282 | // emission at the beginning of this method. |
| 4283 | __ B(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4284 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4285 | case TypeCheckKind::kInterfaceCheck: { |
| 4286 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 4287 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4288 | temp_loc, |
| 4289 | obj_loc, |
| 4290 | class_offset, |
| 4291 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4292 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4293 | |
| 4294 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 4295 | GenerateReferenceLoadTwoRegisters(instruction, |
| 4296 | temp_loc, |
| 4297 | temp_loc, |
| 4298 | iftable_offset, |
| 4299 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4300 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4301 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4302 | __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 4303 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4304 | vixl::aarch64::Label start_loop; |
| 4305 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4306 | __ Cbz(WRegisterFrom(maybe_temp2_loc), type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4307 | __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset)); |
| 4308 | GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc)); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4309 | // Go to next interface. |
| 4310 | __ Add(temp, temp, 2 * kHeapReferenceSize); |
| 4311 | __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 4312 | // Compare the classes and continue the loop if they do not match. |
| 4313 | __ Cmp(cls, WRegisterFrom(maybe_temp3_loc)); |
| 4314 | __ B(ne, &start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 4315 | break; |
| 4316 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4317 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 4318 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4319 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4320 | __ Bind(type_check_slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4321 | } |
| 4322 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4323 | void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) { |
| 4324 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4325 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4326 | } |
| 4327 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4328 | void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4329 | // Will be generated at use site. |
| 4330 | } |
| 4331 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4332 | void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) { |
| 4333 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 4334 | locations->SetOut(Location::ConstantLocation(constant)); |
| 4335 | } |
| 4336 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4337 | void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4338 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4339 | } |
| 4340 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4341 | void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4342 | // The trampoline uses the same calling convention as dex calling conventions, |
| 4343 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 4344 | // the method_idx. |
| 4345 | HandleInvoke(invoke); |
| 4346 | } |
| 4347 | |
| 4348 | void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 4349 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 4350 | } |
| 4351 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4352 | void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 4353 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 4354 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4355 | } |
| 4356 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4357 | void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4358 | HandleInvoke(invoke); |
| 4359 | } |
| 4360 | |
| 4361 | void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 4362 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4363 | LocationSummary* locations = invoke->GetLocations(); |
| 4364 | Register temp = XRegisterFrom(locations->GetTemp(0)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4365 | Location receiver = locations->InAt(0); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4366 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4367 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4368 | |
| 4369 | // The register ip1 is required to be used for the hidden argument in |
| 4370 | // art_quick_imt_conflict_trampoline, so prevent VIXL from using it. |
Alexandre Rames | d921d64 | 2015-04-16 15:07:16 +0100 | [diff] [blame] | 4371 | MacroAssembler* masm = GetVIXLAssembler(); |
| 4372 | UseScratchRegisterScope scratch_scope(masm); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4373 | scratch_scope.Exclude(ip1); |
| 4374 | __ Mov(ip1, invoke->GetDexMethodIndex()); |
| 4375 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4376 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4377 | if (receiver.IsStackSlot()) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4378 | __ Ldr(temp.W(), StackOperandFrom(receiver)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4379 | { |
| 4380 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4381 | // /* HeapReference<Class> */ temp = temp->klass_ |
| 4382 | __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset)); |
| 4383 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 4384 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4385 | } else { |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4386 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4387 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4388 | __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset)); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4389 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4390 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4391 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4392 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4393 | // emit a read barrier for the previous class reference load. |
| 4394 | // However this is not required in practice, as this is an |
| 4395 | // intermediate/temporary reference and because the current |
| 4396 | // concurrent copying collector keeps the from-space memory |
| 4397 | // intact/accessible until the end of the marking phase (the |
| 4398 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4399 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4400 | __ Ldr(temp, |
| 4401 | MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
| 4402 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4403 | invoke->GetImtIndex(), kArm64PointerSize)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4404 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4405 | __ Ldr(temp, MemOperand(temp, method_offset)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4406 | // lr = temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4407 | __ Ldr(lr, MemOperand(temp, entry_point.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4408 | |
| 4409 | { |
| 4410 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 4411 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4412 | |
| 4413 | // lr(); |
| 4414 | __ blr(lr); |
| 4415 | DCHECK(!codegen_->IsLeafMethod()); |
| 4416 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4417 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4421 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4422 | if (intrinsic.TryDispatch(invoke)) { |
| 4423 | return; |
| 4424 | } |
| 4425 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4426 | HandleInvoke(invoke); |
| 4427 | } |
| 4428 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4429 | void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4430 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4431 | // art::PrepareForRegisterAllocation. |
| 4432 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4433 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 4434 | IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena(), codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4435 | if (intrinsic.TryDispatch(invoke)) { |
| 4436 | return; |
| 4437 | } |
| 4438 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 4439 | HandleInvoke(invoke); |
| 4440 | } |
| 4441 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4442 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
| 4443 | if (invoke->GetLocations()->Intrinsified()) { |
| 4444 | IntrinsicCodeGeneratorARM64 intrinsic(codegen); |
| 4445 | intrinsic.Dispatch(invoke); |
| 4446 | return true; |
| 4447 | } |
| 4448 | return false; |
| 4449 | } |
| 4450 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4451 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch( |
| 4452 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4453 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 4454 | // On ARM64 we support all dispatch types. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4455 | return desired_dispatch_info; |
| 4456 | } |
| 4457 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 4458 | Location CodeGeneratorARM64::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4459 | Location temp) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4460 | // 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] | 4461 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4462 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4463 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 4464 | uint32_t offset = |
| 4465 | GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4466 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4467 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4468 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4469 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4470 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4471 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4472 | break; |
| 4473 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4474 | // Load method address from literal pool. |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4475 | __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4476 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4477 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4478 | // Add ADRP with its PC-relative DexCache access patch. |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4479 | const DexFile& dex_file = invoke->GetDexFileForPcRelativeDexCache(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4480 | uint32_t element_offset = invoke->GetDexCacheArrayOffset(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4481 | vixl::aarch64::Label* adrp_label = NewPcRelativeDexCacheArrayPatch(dex_file, element_offset); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4482 | EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4483 | // Add LDR with its PC-relative DexCache access patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4484 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4485 | NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4486 | EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4487 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4488 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4489 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4490 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4491 | Register reg = XRegisterFrom(temp); |
| 4492 | Register method_reg; |
| 4493 | if (current_method.IsRegister()) { |
| 4494 | method_reg = XRegisterFrom(current_method); |
| 4495 | } else { |
| 4496 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 4497 | DCHECK(!current_method.IsValid()); |
| 4498 | method_reg = reg; |
| 4499 | __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset)); |
| 4500 | } |
Vladimir Marko | b2c431e | 2015-08-19 12:45:42 +0000 | [diff] [blame] | 4501 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4502 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4503 | __ Ldr(reg.X(), |
| 4504 | MemOperand(method_reg.X(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4505 | ArtMethod::DexCacheResolvedMethodsOffset(kArm64PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4506 | // temp = temp[index_in_cache]; |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4507 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4508 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4509 | __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache))); |
| 4510 | break; |
| 4511 | } |
| 4512 | } |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 4513 | return callee_method; |
| 4514 | } |
| 4515 | |
| 4516 | void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4517 | // All registers are assumed to be correctly set up. |
| 4518 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4519 | |
| 4520 | switch (invoke->GetCodePtrLocation()) { |
| 4521 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4522 | __ Bl(&frame_entry_label_); |
| 4523 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4524 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4525 | // LR = callee_method->entry_point_from_quick_compiled_code_; |
| 4526 | __ Ldr(lr, MemOperand( |
Alexandre Rames | 6dc0174 | 2015-11-12 14:44:19 +0000 | [diff] [blame] | 4527 | XRegisterFrom(callee_method), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4528 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4529 | { |
| 4530 | // To ensure that the pc position is recorded immediately after the `blr` instruction |
| 4531 | // BLR must be the last instruction emitted in this function. |
| 4532 | // Recording the pc will occur right after returning from this function. |
| 4533 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 4534 | kInstructionSize, |
| 4535 | CodeBufferCheckScope::kExactSize); |
| 4536 | // lr() |
| 4537 | __ blr(lr); |
| 4538 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4539 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 4540 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4541 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4542 | DCHECK(!IsLeafMethod()); |
| 4543 | } |
| 4544 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4545 | void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4546 | // Use the calling convention instead of the location of the receiver, as |
| 4547 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4548 | // slow path, the arguments have been moved to the right place, so here we are |
| 4549 | // guaranteed that the receiver is the first register of the calling convention. |
| 4550 | InvokeDexCallingConvention calling_convention; |
| 4551 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4552 | Register temp = XRegisterFrom(temp_in); |
| 4553 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4554 | invoke->GetVTableIndex(), kArm64PointerSize).SizeValue(); |
| 4555 | Offset class_offset = mirror::Object::ClassOffset(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4556 | Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4557 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4558 | DCHECK(receiver.IsRegister()); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4559 | |
| 4560 | { |
| 4561 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 4562 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 4563 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 4564 | __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset)); |
| 4565 | MaybeRecordImplicitNullCheck(invoke); |
| 4566 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4567 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4568 | // emit a read barrier for the previous class reference load. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 4569 | // intermediate/temporary reference and because the current |
| 4570 | // concurrent copying collector keeps the from-space memory |
| 4571 | // intact/accessible until the end of the marking phase (the |
| 4572 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4573 | GetAssembler()->MaybeUnpoisonHeapReference(temp.W()); |
| 4574 | // temp = temp->GetMethodAt(method_offset); |
| 4575 | __ Ldr(temp, MemOperand(temp, method_offset)); |
| 4576 | // lr = temp->GetEntryPoint(); |
| 4577 | __ Ldr(lr, MemOperand(temp, entry_point.SizeValue())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4578 | { |
| 4579 | // To ensure that the pc position is recorded immediately after the `blr` instruction |
| 4580 | // BLR should be the last instruction emitted in this function. |
| 4581 | // Recording the pc will occur right after returning from this function. |
| 4582 | ExactAssemblyScope eas(GetVIXLAssembler(), kInstructionSize, CodeBufferCheckScope::kExactSize); |
| 4583 | // lr(); |
| 4584 | __ blr(lr); |
| 4585 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4586 | } |
| 4587 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4588 | void LocationsBuilderARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4589 | HandleInvoke(invoke); |
| 4590 | } |
| 4591 | |
| 4592 | void InstructionCodeGeneratorARM64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 4593 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 4594 | } |
| 4595 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4596 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch( |
| 4597 | const DexFile& dex_file, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4598 | dex::StringIndex string_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4599 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4600 | return |
| 4601 | NewPcRelativePatch(dex_file, string_index.index_, adrp_label, &pc_relative_string_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4602 | } |
| 4603 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4604 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch( |
| 4605 | const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4606 | dex::TypeIndex type_index, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4607 | vixl::aarch64::Label* adrp_label) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4608 | 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] | 4609 | } |
| 4610 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4611 | vixl::aarch64::Label* CodeGeneratorARM64::NewBssEntryTypePatch( |
| 4612 | const DexFile& dex_file, |
| 4613 | dex::TypeIndex type_index, |
| 4614 | vixl::aarch64::Label* adrp_label) { |
| 4615 | return NewPcRelativePatch(dex_file, type_index.index_, adrp_label, &type_bss_entry_patches_); |
| 4616 | } |
| 4617 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4618 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeDexCacheArrayPatch( |
| 4619 | const DexFile& dex_file, |
| 4620 | uint32_t element_offset, |
| 4621 | vixl::aarch64::Label* adrp_label) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4622 | return NewPcRelativePatch(dex_file, element_offset, adrp_label, &pc_relative_dex_cache_patches_); |
| 4623 | } |
| 4624 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4625 | vixl::aarch64::Label* CodeGeneratorARM64::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 4626 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 4627 | return &baker_read_barrier_patches_.back().label; |
| 4628 | } |
| 4629 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4630 | vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch( |
| 4631 | const DexFile& dex_file, |
| 4632 | uint32_t offset_or_index, |
| 4633 | vixl::aarch64::Label* adrp_label, |
| 4634 | ArenaDeque<PcRelativePatchInfo>* patches) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4635 | // Add a patch entry and return the label. |
| 4636 | patches->emplace_back(dex_file, offset_or_index); |
| 4637 | PcRelativePatchInfo* info = &patches->back(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4638 | vixl::aarch64::Label* label = &info->label; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4639 | // If adrp_label is null, this is the ADRP patch and needs to point to its own label. |
| 4640 | info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label; |
| 4641 | return label; |
| 4642 | } |
| 4643 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4644 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageStringLiteral( |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 4645 | const DexFile& dex_file, dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4646 | return boot_image_string_patches_.GetOrCreate( |
| 4647 | StringReference(&dex_file, string_index), |
| 4648 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4649 | } |
| 4650 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4651 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageTypeLiteral( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4652 | const DexFile& dex_file, dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4653 | return boot_image_type_patches_.GetOrCreate( |
| 4654 | TypeReference(&dex_file, type_index), |
| 4655 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4656 | } |
| 4657 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4658 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral( |
| 4659 | uint64_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 4660 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4661 | } |
| 4662 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4663 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitStringLiteral( |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 4664 | const DexFile& dex_file, dex::StringIndex string_index, Handle<mirror::String> handle) { |
| 4665 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 4666 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 4667 | return jit_string_patches_.GetOrCreate( |
| 4668 | StringReference(&dex_file, string_index), |
| 4669 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4670 | } |
| 4671 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4672 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateJitClassLiteral( |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4673 | const DexFile& dex_file, dex::TypeIndex type_index, Handle<mirror::Class> handle) { |
| 4674 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 4675 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4676 | return jit_class_patches_.GetOrCreate( |
| 4677 | TypeReference(&dex_file, type_index), |
| 4678 | [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); }); |
| 4679 | } |
| 4680 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4681 | void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4682 | vixl::aarch64::Register reg) { |
| 4683 | DCHECK(reg.IsX()); |
| 4684 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4685 | __ Bind(fixup_label); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4686 | __ adrp(reg, /* offset placeholder */ static_cast<int64_t>(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4690 | vixl::aarch64::Register out, |
| 4691 | vixl::aarch64::Register base) { |
| 4692 | DCHECK(out.IsX()); |
| 4693 | DCHECK(base.IsX()); |
| 4694 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4695 | __ Bind(fixup_label); |
| 4696 | __ add(out, base, Operand(/* offset placeholder */ 0)); |
| 4697 | } |
| 4698 | |
| 4699 | void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label, |
| 4700 | vixl::aarch64::Register out, |
| 4701 | vixl::aarch64::Register base) { |
| 4702 | DCHECK(base.IsX()); |
| 4703 | SingleEmissionCheckScope guard(GetVIXLAssembler()); |
| 4704 | __ Bind(fixup_label); |
| 4705 | __ ldr(out, MemOperand(base, /* offset placeholder */ 0)); |
| 4706 | } |
| 4707 | |
| 4708 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4709 | inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches( |
| 4710 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 4711 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4712 | for (const PcRelativePatchInfo& info : infos) { |
| 4713 | linker_patches->push_back(Factory(info.label.GetLocation(), |
| 4714 | &info.target_dex_file, |
| 4715 | info.pc_insn_label->GetLocation(), |
| 4716 | info.offset_or_index)); |
| 4717 | } |
| 4718 | } |
| 4719 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4720 | void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4721 | DCHECK(linker_patches->empty()); |
| 4722 | size_t size = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4723 | pc_relative_dex_cache_patches_.size() + |
| 4724 | boot_image_string_patches_.size() + |
| 4725 | pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4726 | boot_image_type_patches_.size() + |
| 4727 | pc_relative_type_patches_.size() + |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4728 | type_bss_entry_patches_.size() + |
| 4729 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4730 | linker_patches->reserve(size); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4731 | for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4732 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.GetLocation(), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4733 | &info.target_dex_file, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4734 | info.pc_insn_label->GetLocation(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4735 | info.offset_or_index)); |
| 4736 | } |
| 4737 | for (const auto& entry : boot_image_string_patches_) { |
| 4738 | const StringReference& target_string = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4739 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4740 | linker_patches->push_back(LinkerPatch::StringPatch(literal->GetOffset(), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4741 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 4742 | target_string.string_index.index_)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4743 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4744 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4745 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4746 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 4747 | linker_patches); |
| 4748 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4749 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 4750 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4751 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 4752 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4753 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4754 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 4755 | linker_patches); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4756 | for (const auto& entry : boot_image_type_patches_) { |
| 4757 | const TypeReference& target_type = entry.first; |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4758 | vixl::aarch64::Literal<uint32_t>* literal = entry.second; |
| 4759 | linker_patches->push_back(LinkerPatch::TypePatch(literal->GetOffset(), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4760 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4761 | target_type.type_index.index_)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4762 | } |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4763 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 4764 | linker_patches->push_back(LinkerPatch::BakerReadBarrierBranchPatch(info.label.GetLocation(), |
| 4765 | info.custom_data)); |
| 4766 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4767 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4768 | } |
| 4769 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4770 | vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4771 | Uint32ToLiteralMap* map) { |
| 4772 | return map->GetOrCreate( |
| 4773 | value, |
| 4774 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); }); |
| 4775 | } |
| 4776 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4777 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4778 | return uint64_literals_.GetOrCreate( |
| 4779 | value, |
| 4780 | [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4781 | } |
| 4782 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4783 | vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral( |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4784 | MethodReference target_method, |
| 4785 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4786 | return map->GetOrCreate( |
| 4787 | target_method, |
| 4788 | [this]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4789 | } |
| 4790 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4791 | void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4792 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 4793 | // art::PrepareForRegisterAllocation. |
| 4794 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4795 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4796 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4797 | return; |
| 4798 | } |
| 4799 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4800 | // Ensure that between the BLR (emitted by GenerateStaticOrDirectCall) and RecordPcInfo there |
| 4801 | // are no pools emitted. |
| 4802 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 4803 | LocationSummary* locations = invoke->GetLocations(); |
| 4804 | codegen_->GenerateStaticOrDirectCall( |
| 4805 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 4806 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 4810 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 4811 | return; |
| 4812 | } |
| 4813 | |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 4814 | // Ensure that between the BLR (emitted by GenerateVirtualCall) and RecordPcInfo there |
| 4815 | // are no pools emitted. |
| 4816 | EmissionCheckScope guard(GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4817 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 4818 | DCHECK(!codegen_->IsLeafMethod()); |
| 4819 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 4820 | } |
| 4821 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4822 | HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind( |
| 4823 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4824 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4825 | case HLoadClass::LoadKind::kInvalid: |
| 4826 | LOG(FATAL) << "UNREACHABLE"; |
| 4827 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4828 | case HLoadClass::LoadKind::kReferrersClass: |
| 4829 | break; |
| 4830 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 4831 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 4832 | break; |
| 4833 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 4834 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 4835 | break; |
| 4836 | case HLoadClass::LoadKind::kBootImageAddress: |
| 4837 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4838 | case HLoadClass::LoadKind::kBssEntry: |
| 4839 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 4840 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4841 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4842 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 4843 | break; |
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 | } |
| 4926 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
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 | __ Ldr(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 4929 | cls->GetTypeIndex())); |
| 4930 | break; |
| 4931 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4932 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4933 | // Add ADRP with its PC-relative type patch. |
| 4934 | const DexFile& dex_file = cls->GetDexFile(); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4935 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4936 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4937 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4938 | // Add ADD with its PC-relative type patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 4939 | vixl::aarch64::Label* add_label = |
| 4940 | codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4941 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4942 | break; |
| 4943 | } |
| 4944 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 4945 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4946 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 4947 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 4948 | DCHECK_NE(address, 0u); |
| 4949 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4950 | break; |
| 4951 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4952 | case HLoadClass::LoadKind::kBssEntry: { |
| 4953 | // Add ADRP with its PC-relative Class .bss entry patch. |
| 4954 | const DexFile& dex_file = cls->GetDexFile(); |
| 4955 | dex::TypeIndex type_index = cls->GetTypeIndex(); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 4956 | bss_entry_temp = XRegisterFrom(cls->GetLocations()->GetTemp(0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4957 | bss_entry_adrp_label = codegen_->NewBssEntryTypePatch(dex_file, type_index); |
| 4958 | codegen_->EmitAdrpPlaceholder(bss_entry_adrp_label, bss_entry_temp); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4959 | // Add LDR with its PC-relative Class patch. |
| 4960 | vixl::aarch64::Label* ldr_label = |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4961 | codegen_->NewBssEntryTypePatch(dex_file, type_index, bss_entry_adrp_label); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4962 | // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */ |
| 4963 | GenerateGcRootFieldLoad(cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4964 | out_loc, |
| 4965 | bss_entry_temp, |
| 4966 | /* offset placeholder */ 0u, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4967 | ldr_label, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4968 | read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4969 | generate_null_check = true; |
| 4970 | break; |
| 4971 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4972 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 4973 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 4974 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4975 | cls->GetClass())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 4976 | GenerateGcRootFieldLoad(cls, |
| 4977 | out_loc, |
| 4978 | out.X(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 4979 | /* offset */ 0, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 4980 | /* fixup_label */ nullptr, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4981 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4982 | break; |
| 4983 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4984 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 4985 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 4986 | LOG(FATAL) << "UNREACHABLE"; |
| 4987 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4988 | } |
| 4989 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4990 | bool do_clinit = cls->MustGenerateClinitCheck(); |
| 4991 | if (generate_null_check || do_clinit) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4992 | DCHECK(cls->CanCallRuntime()); |
| 4993 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64( |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 4994 | 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] | 4995 | codegen_->AddSlowPath(slow_path); |
| 4996 | if (generate_null_check) { |
| 4997 | __ Cbz(out, slow_path->GetEntryLabel()); |
| 4998 | } |
| 4999 | if (cls->MustGenerateClinitCheck()) { |
| 5000 | GenerateClassInitializationCheck(slow_path, out); |
| 5001 | } else { |
| 5002 | __ Bind(slow_path->GetExitLabel()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5003 | } |
| 5004 | } |
| 5005 | } |
| 5006 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5007 | static MemOperand GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5008 | return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5009 | } |
| 5010 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5011 | void LocationsBuilderARM64::VisitLoadException(HLoadException* load) { |
| 5012 | LocationSummary* locations = |
| 5013 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5014 | locations->SetOut(Location::RequiresRegister()); |
| 5015 | } |
| 5016 | |
| 5017 | void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5018 | __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress()); |
| 5019 | } |
| 5020 | |
| 5021 | void LocationsBuilderARM64::VisitClearException(HClearException* clear) { |
| 5022 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5023 | } |
| 5024 | |
| 5025 | void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5026 | __ Str(wzr, GetExceptionTlsAddress()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5027 | } |
| 5028 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5029 | HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind( |
| 5030 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5031 | switch (desired_string_load_kind) { |
| 5032 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5033 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5034 | break; |
| 5035 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5036 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5037 | break; |
| 5038 | case HLoadString::LoadKind::kBootImageAddress: |
| 5039 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5040 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5041 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5042 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5043 | case HLoadString::LoadKind::kJitTableAddress: |
| 5044 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5045 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5046 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5047 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5048 | } |
| 5049 | return desired_string_load_kind; |
| 5050 | } |
| 5051 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5052 | void LocationsBuilderARM64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5053 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5054 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5055 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5056 | InvokeRuntimeCallingConvention calling_convention; |
| 5057 | locations->SetOut(calling_convention.GetReturnLocation(load->GetType())); |
| 5058 | } else { |
| 5059 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5060 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5061 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5062 | // Rely on the pResolveString and marking to save everything we need. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5063 | locations->AddTemp(FixedTempLocation()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5064 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5065 | InvokeRuntimeCallingConvention calling_convention; |
| 5066 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode())); |
| 5067 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), |
| 5068 | RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot), |
| 5069 | Primitive::kPrimNot).GetCode()); |
| 5070 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5071 | } else { |
| 5072 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5073 | } |
| 5074 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5075 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5076 | } |
| 5077 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5078 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5079 | // move. |
| 5080 | void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5081 | Register out = OutputRegister(load); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5082 | Location out_loc = load->GetLocations()->Out(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5083 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5084 | switch (load->GetLoadKind()) { |
| 5085 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5086 | __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5087 | load->GetStringIndex())); |
| 5088 | return; // No dex cache slow path. |
| 5089 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5090 | // Add ADRP with its PC-relative String patch. |
| 5091 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5092 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5093 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5094 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5095 | codegen_->EmitAdrpPlaceholder(adrp_label, out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5096 | // Add ADD with its PC-relative String patch. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5097 | vixl::aarch64::Label* add_label = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5098 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5099 | codegen_->EmitAddPlaceholder(add_label, out.X(), out.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5100 | return; // No dex cache slow path. |
| 5101 | } |
| 5102 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5103 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5104 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5105 | DCHECK_NE(address, 0u); |
| 5106 | __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5107 | return; // No dex cache slow path. |
| 5108 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5109 | case HLoadString::LoadKind::kBssEntry: { |
| 5110 | // Add ADRP with its PC-relative String .bss entry patch. |
| 5111 | const DexFile& dex_file = load->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5112 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5113 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5114 | Register temp = XRegisterFrom(load->GetLocations()->GetTemp(0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5115 | vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5116 | codegen_->EmitAdrpPlaceholder(adrp_label, temp); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5117 | // Add LDR with its PC-relative String patch. |
| 5118 | vixl::aarch64::Label* ldr_label = |
| 5119 | codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5120 | // /* GcRoot<mirror::String> */ out = *(base_address + offset) /* PC-relative */ |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5121 | GenerateGcRootFieldLoad(load, |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5122 | out_loc, |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5123 | temp, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5124 | /* offset placeholder */ 0u, |
| 5125 | ldr_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5126 | kCompilerReadBarrierOption); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5127 | SlowPathCodeARM64* slow_path = |
| 5128 | new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load, temp, adrp_label); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5129 | codegen_->AddSlowPath(slow_path); |
| 5130 | __ Cbz(out.X(), slow_path->GetEntryLabel()); |
| 5131 | __ Bind(slow_path->GetExitLabel()); |
| 5132 | return; |
| 5133 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5134 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5135 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5136 | load->GetStringIndex(), |
| 5137 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5138 | GenerateGcRootFieldLoad(load, |
| 5139 | out_loc, |
| 5140 | out.X(), |
| 5141 | /* offset */ 0, |
| 5142 | /* fixup_label */ nullptr, |
| 5143 | kCompilerReadBarrierOption); |
| 5144 | return; |
| 5145 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5146 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5147 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5148 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 5149 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5150 | // 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] | 5151 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5152 | DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5153 | __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex().index_); |
Christina Wadsworth | 1fe89ea | 2016-08-31 16:14:38 -0700 | [diff] [blame] | 5154 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 5155 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5156 | } |
| 5157 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5158 | void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) { |
| 5159 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 5160 | locations->SetOut(Location::ConstantLocation(constant)); |
| 5161 | } |
| 5162 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5163 | void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5164 | // Will be generated at use site. |
| 5165 | } |
| 5166 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5167 | void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5168 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5169 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5170 | InvokeRuntimeCallingConvention calling_convention; |
| 5171 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5172 | } |
| 5173 | |
| 5174 | void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 5175 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5176 | instruction, |
| 5177 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5178 | if (instruction->IsEnter()) { |
| 5179 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5180 | } else { |
| 5181 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5182 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5183 | } |
| 5184 | |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5185 | void LocationsBuilderARM64::VisitMul(HMul* mul) { |
| 5186 | LocationSummary* locations = |
| 5187 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 5188 | switch (mul->GetResultType()) { |
| 5189 | case Primitive::kPrimInt: |
| 5190 | case Primitive::kPrimLong: |
| 5191 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5192 | locations->SetInAt(1, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5193 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5194 | break; |
| 5195 | |
| 5196 | case Primitive::kPrimFloat: |
| 5197 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5198 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5199 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5200 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5201 | break; |
| 5202 | |
| 5203 | default: |
| 5204 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5205 | } |
| 5206 | } |
| 5207 | |
| 5208 | void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) { |
| 5209 | switch (mul->GetResultType()) { |
| 5210 | case Primitive::kPrimInt: |
| 5211 | case Primitive::kPrimLong: |
| 5212 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 5213 | break; |
| 5214 | |
| 5215 | case Primitive::kPrimFloat: |
| 5216 | case Primitive::kPrimDouble: |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5217 | __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1)); |
Alexandre Rames | 42d641b | 2014-10-27 14:00:51 +0000 | [diff] [blame] | 5218 | break; |
| 5219 | |
| 5220 | default: |
| 5221 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 5222 | } |
| 5223 | } |
| 5224 | |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5225 | void LocationsBuilderARM64::VisitNeg(HNeg* neg) { |
| 5226 | LocationSummary* locations = |
| 5227 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 5228 | switch (neg->GetResultType()) { |
| 5229 | case Primitive::kPrimInt: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5230 | case Primitive::kPrimLong: |
Serban Constantinescu | 2d35d9d | 2015-02-22 22:08:01 +0000 | [diff] [blame] | 5231 | locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg)); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5232 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5233 | break; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5234 | |
| 5235 | case Primitive::kPrimFloat: |
| 5236 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5237 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5238 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5239 | break; |
| 5240 | |
| 5241 | default: |
| 5242 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5243 | } |
| 5244 | } |
| 5245 | |
| 5246 | void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) { |
| 5247 | switch (neg->GetResultType()) { |
| 5248 | case Primitive::kPrimInt: |
| 5249 | case Primitive::kPrimLong: |
| 5250 | __ Neg(OutputRegister(neg), InputOperandAt(neg, 0)); |
| 5251 | break; |
| 5252 | |
| 5253 | case Primitive::kPrimFloat: |
| 5254 | case Primitive::kPrimDouble: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5255 | __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0)); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5256 | break; |
| 5257 | |
| 5258 | default: |
| 5259 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 5260 | } |
| 5261 | } |
| 5262 | |
| 5263 | void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) { |
| 5264 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5265 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5266 | InvokeRuntimeCallingConvention calling_convention; |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5267 | locations->SetOut(LocationFrom(x0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5268 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5269 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5270 | } |
| 5271 | |
| 5272 | void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5273 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5274 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 5275 | QuickEntrypointEnum entrypoint = |
| 5276 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5277 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5278 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Alexandre Rames | fc19de8 | 2014-11-07 17:13:31 +0000 | [diff] [blame] | 5279 | } |
| 5280 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5281 | void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) { |
| 5282 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5283 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5284 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5285 | if (instruction->IsStringAlloc()) { |
| 5286 | locations->AddTemp(LocationFrom(kArtMethodRegister)); |
| 5287 | } else { |
| 5288 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5289 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5290 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 5291 | } |
| 5292 | |
| 5293 | void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5294 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5295 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5296 | if (instruction->IsStringAlloc()) { |
| 5297 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5298 | Location temp = instruction->GetLocations()->GetTemp(0); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5299 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5300 | __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString))); |
| 5301 | __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value())); |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5302 | |
| 5303 | { |
| 5304 | // Ensure the pc position is recorded immediately after the `blr` instruction. |
| 5305 | ExactAssemblyScope eas(GetVIXLAssembler(), |
| 5306 | kInstructionSize, |
| 5307 | CodeBufferCheckScope::kExactSize); |
| 5308 | __ blr(lr); |
| 5309 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5310 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5311 | } else { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5312 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5313 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5314 | } |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5315 | } |
| 5316 | |
| 5317 | void LocationsBuilderARM64::VisitNot(HNot* instruction) { |
| 5318 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Alexandre Rames | 4e59651 | 2014-11-07 15:56:50 +0000 | [diff] [blame] | 5319 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | fb4e5fa | 2014-11-06 12:41:16 +0000 | [diff] [blame] | 5320 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5321 | } |
| 5322 | |
| 5323 | void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5324 | switch (instruction->GetResultType()) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5325 | case Primitive::kPrimInt: |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5326 | case Primitive::kPrimLong: |
Roland Levillain | 55dcfb5 | 2014-10-24 18:09:09 +0100 | [diff] [blame] | 5327 | __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5328 | break; |
| 5329 | |
| 5330 | default: |
| 5331 | LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType(); |
| 5332 | } |
| 5333 | } |
| 5334 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5335 | void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) { |
| 5336 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5337 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5338 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5339 | } |
| 5340 | |
| 5341 | void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 5342 | __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1)); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5343 | } |
| 5344 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5345 | void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5346 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5347 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5348 | } |
| 5349 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5350 | void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5351 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5352 | return; |
| 5353 | } |
Artem Serov | 914d7a8 | 2017-02-07 14:33:49 +0000 | [diff] [blame] | 5354 | { |
| 5355 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5356 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5357 | Location obj = instruction->GetLocations()->InAt(0); |
| 5358 | __ Ldr(wzr, HeapOperandFrom(obj, Offset(0))); |
| 5359 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5360 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5361 | } |
| 5362 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5363 | void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5364 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5365 | AddSlowPath(slow_path); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5366 | |
| 5367 | LocationSummary* locations = instruction->GetLocations(); |
| 5368 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5369 | |
| 5370 | __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5371 | } |
| 5372 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5373 | void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5374 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5375 | } |
| 5376 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5377 | void LocationsBuilderARM64::VisitOr(HOr* instruction) { |
| 5378 | HandleBinaryOp(instruction); |
| 5379 | } |
| 5380 | |
| 5381 | void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) { |
| 5382 | HandleBinaryOp(instruction); |
| 5383 | } |
| 5384 | |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5385 | void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 5386 | LOG(FATAL) << "Unreachable"; |
| 5387 | } |
| 5388 | |
| 5389 | void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) { |
| 5390 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5391 | } |
| 5392 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5393 | void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) { |
| 5394 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5395 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5396 | if (location.IsStackSlot()) { |
| 5397 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5398 | } else if (location.IsDoubleStackSlot()) { |
| 5399 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5400 | } |
| 5401 | locations->SetOut(location); |
| 5402 | } |
| 5403 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5404 | void InstructionCodeGeneratorARM64::VisitParameterValue( |
| 5405 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5406 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5407 | } |
| 5408 | |
| 5409 | void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5410 | LocationSummary* locations = |
| 5411 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 5412 | locations->SetOut(LocationFrom(kArtMethodRegister)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5413 | } |
| 5414 | |
| 5415 | void InstructionCodeGeneratorARM64::VisitCurrentMethod( |
| 5416 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5417 | // Nothing to do, the method is already at its location. |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5418 | } |
| 5419 | |
| 5420 | void LocationsBuilderARM64::VisitPhi(HPhi* instruction) { |
| 5421 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5422 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5423 | locations->SetInAt(i, Location::Any()); |
| 5424 | } |
| 5425 | locations->SetOut(Location::Any()); |
| 5426 | } |
| 5427 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5428 | void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5429 | LOG(FATAL) << "Unreachable"; |
| 5430 | } |
| 5431 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5432 | void LocationsBuilderARM64::VisitRem(HRem* rem) { |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5433 | Primitive::Type type = rem->GetResultType(); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5434 | LocationSummary::CallKind call_kind = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5435 | Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly |
| 5436 | : LocationSummary::kNoCall; |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5437 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 5438 | |
| 5439 | switch (type) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5440 | case Primitive::kPrimInt: |
| 5441 | case Primitive::kPrimLong: |
| 5442 | locations->SetInAt(0, Location::RequiresRegister()); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5443 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5444 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5445 | break; |
| 5446 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5447 | case Primitive::kPrimFloat: |
| 5448 | case Primitive::kPrimDouble: { |
| 5449 | InvokeRuntimeCallingConvention calling_convention; |
| 5450 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 5451 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 5452 | locations->SetOut(calling_convention.GetReturnLocation(type)); |
| 5453 | |
| 5454 | break; |
| 5455 | } |
| 5456 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5457 | default: |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5458 | LOG(FATAL) << "Unexpected rem type " << type; |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5459 | } |
| 5460 | } |
| 5461 | |
| 5462 | void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) { |
| 5463 | Primitive::Type type = rem->GetResultType(); |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5464 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5465 | switch (type) { |
| 5466 | case Primitive::kPrimInt: |
| 5467 | case Primitive::kPrimLong: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 5468 | GenerateDivRemIntegral(rem); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5469 | break; |
| 5470 | } |
| 5471 | |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5472 | case Primitive::kPrimFloat: |
| 5473 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5474 | QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod; |
| 5475 | codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5476 | if (type == Primitive::kPrimFloat) { |
| 5477 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 5478 | } else { |
| 5479 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 5480 | } |
Serban Constantinescu | 02d81cc | 2015-01-05 16:08:49 +0000 | [diff] [blame] | 5481 | break; |
| 5482 | } |
| 5483 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5484 | default: |
| 5485 | LOG(FATAL) << "Unexpected rem type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5486 | UNREACHABLE(); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5487 | } |
| 5488 | } |
| 5489 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5490 | void LocationsBuilderARM64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 5491 | constructor_fence->SetLocations(nullptr); |
| 5492 | } |
| 5493 | |
| 5494 | void InstructionCodeGeneratorARM64::VisitConstructorFence( |
| 5495 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 5496 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 5497 | } |
| 5498 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5499 | void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 5500 | memory_barrier->SetLocations(nullptr); |
| 5501 | } |
| 5502 | |
| 5503 | void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5504 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5505 | } |
| 5506 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5507 | void LocationsBuilderARM64::VisitReturn(HReturn* instruction) { |
| 5508 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 5509 | Primitive::Type return_type = instruction->InputAt(0)->GetType(); |
Alexandre Rames | a89086e | 2014-11-07 17:13:25 +0000 | [diff] [blame] | 5510 | locations->SetInAt(0, ARM64ReturnLocation(return_type)); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5511 | } |
| 5512 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5513 | void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5514 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5515 | } |
| 5516 | |
| 5517 | void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) { |
| 5518 | instruction->SetLocations(nullptr); |
| 5519 | } |
| 5520 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5521 | void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) { |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5522 | codegen_->GenerateFrameExit(); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5523 | } |
| 5524 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5525 | void LocationsBuilderARM64::VisitRor(HRor* ror) { |
| 5526 | HandleBinaryOp(ror); |
| 5527 | } |
| 5528 | |
| 5529 | void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) { |
| 5530 | HandleBinaryOp(ror); |
| 5531 | } |
| 5532 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5533 | void LocationsBuilderARM64::VisitShl(HShl* shl) { |
| 5534 | HandleShift(shl); |
| 5535 | } |
| 5536 | |
| 5537 | void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) { |
| 5538 | HandleShift(shl); |
| 5539 | } |
| 5540 | |
| 5541 | void LocationsBuilderARM64::VisitShr(HShr* shr) { |
| 5542 | HandleShift(shr); |
| 5543 | } |
| 5544 | |
| 5545 | void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) { |
| 5546 | HandleShift(shr); |
| 5547 | } |
| 5548 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5549 | void LocationsBuilderARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5550 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5551 | } |
| 5552 | |
| 5553 | void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5554 | HandleBinaryOp(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5555 | } |
| 5556 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5557 | void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5558 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5559 | } |
| 5560 | |
| 5561 | void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5562 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5563 | } |
| 5564 | |
| 5565 | void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Alexandre Rames | 09a9996 | 2015-04-15 11:47:56 +0100 | [diff] [blame] | 5566 | HandleFieldSet(instruction); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5567 | } |
| 5568 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5569 | void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5570 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5571 | } |
| 5572 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5573 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet( |
| 5574 | HUnresolvedInstanceFieldGet* instruction) { |
| 5575 | FieldAccessCallingConventionARM64 calling_convention; |
| 5576 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5577 | instruction, instruction->GetFieldType(), calling_convention); |
| 5578 | } |
| 5579 | |
| 5580 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet( |
| 5581 | HUnresolvedInstanceFieldGet* instruction) { |
| 5582 | FieldAccessCallingConventionARM64 calling_convention; |
| 5583 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5584 | instruction->GetFieldType(), |
| 5585 | instruction->GetFieldIndex(), |
| 5586 | instruction->GetDexPc(), |
| 5587 | calling_convention); |
| 5588 | } |
| 5589 | |
| 5590 | void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet( |
| 5591 | HUnresolvedInstanceFieldSet* instruction) { |
| 5592 | FieldAccessCallingConventionARM64 calling_convention; |
| 5593 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5594 | instruction, instruction->GetFieldType(), calling_convention); |
| 5595 | } |
| 5596 | |
| 5597 | void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet( |
| 5598 | HUnresolvedInstanceFieldSet* instruction) { |
| 5599 | FieldAccessCallingConventionARM64 calling_convention; |
| 5600 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5601 | instruction->GetFieldType(), |
| 5602 | instruction->GetFieldIndex(), |
| 5603 | instruction->GetDexPc(), |
| 5604 | calling_convention); |
| 5605 | } |
| 5606 | |
| 5607 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet( |
| 5608 | HUnresolvedStaticFieldGet* instruction) { |
| 5609 | FieldAccessCallingConventionARM64 calling_convention; |
| 5610 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5611 | instruction, instruction->GetFieldType(), calling_convention); |
| 5612 | } |
| 5613 | |
| 5614 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet( |
| 5615 | HUnresolvedStaticFieldGet* instruction) { |
| 5616 | FieldAccessCallingConventionARM64 calling_convention; |
| 5617 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5618 | instruction->GetFieldType(), |
| 5619 | instruction->GetFieldIndex(), |
| 5620 | instruction->GetDexPc(), |
| 5621 | calling_convention); |
| 5622 | } |
| 5623 | |
| 5624 | void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet( |
| 5625 | HUnresolvedStaticFieldSet* instruction) { |
| 5626 | FieldAccessCallingConventionARM64 calling_convention; |
| 5627 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5628 | instruction, instruction->GetFieldType(), calling_convention); |
| 5629 | } |
| 5630 | |
| 5631 | void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet( |
| 5632 | HUnresolvedStaticFieldSet* instruction) { |
| 5633 | FieldAccessCallingConventionARM64 calling_convention; |
| 5634 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5635 | instruction->GetFieldType(), |
| 5636 | instruction->GetFieldIndex(), |
| 5637 | instruction->GetDexPc(), |
| 5638 | calling_convention); |
| 5639 | } |
| 5640 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5641 | void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5642 | LocationSummary* locations = |
| 5643 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Artem Serov | 7957d95 | 2017-04-04 15:44:09 +0100 | [diff] [blame] | 5644 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5645 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5646 | // registers in full width (since the runtime only saves/restores lower part). |
| 5647 | locations->SetCustomSlowPathCallerSaves( |
| 5648 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5649 | } |
| 5650 | |
| 5651 | void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5652 | HBasicBlock* block = instruction->GetBlock(); |
| 5653 | if (block->GetLoopInformation() != nullptr) { |
| 5654 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5655 | // The back edge will generate the suspend check. |
| 5656 | return; |
| 5657 | } |
| 5658 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5659 | // The goto will generate the suspend check. |
| 5660 | return; |
| 5661 | } |
| 5662 | GenerateSuspendCheck(instruction, nullptr); |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 5663 | } |
| 5664 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5665 | void LocationsBuilderARM64::VisitThrow(HThrow* instruction) { |
| 5666 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5667 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5668 | InvokeRuntimeCallingConvention calling_convention; |
| 5669 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5670 | } |
| 5671 | |
| 5672 | void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 22f81d3 | 2016-02-18 16:06:31 +0000 | [diff] [blame] | 5673 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 5674 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5675 | } |
| 5676 | |
| 5677 | void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5678 | LocationSummary* locations = |
| 5679 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 5680 | Primitive::Type input_type = conversion->GetInputType(); |
| 5681 | Primitive::Type result_type = conversion->GetResultType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 5682 | DCHECK_NE(input_type, result_type); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5683 | if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) || |
| 5684 | (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) { |
| 5685 | LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type; |
| 5686 | } |
| 5687 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5688 | if (Primitive::IsFloatingPointType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5689 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5690 | } else { |
| 5691 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5692 | } |
| 5693 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5694 | if (Primitive::IsFloatingPointType(result_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5695 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5696 | } else { |
| 5697 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5698 | } |
| 5699 | } |
| 5700 | |
| 5701 | void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) { |
| 5702 | Primitive::Type result_type = conversion->GetResultType(); |
| 5703 | Primitive::Type input_type = conversion->GetInputType(); |
| 5704 | |
| 5705 | DCHECK_NE(input_type, result_type); |
| 5706 | |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5707 | if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) { |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5708 | int result_size = Primitive::ComponentSize(result_type); |
| 5709 | int input_size = Primitive::ComponentSize(input_type); |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5710 | int min_size = std::min(result_size, input_size); |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5711 | Register output = OutputRegister(conversion); |
| 5712 | Register source = InputRegisterAt(conversion, 0); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5713 | if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) { |
Alexandre Rames | 4dff2fd | 2015-08-20 13:36:35 +0100 | [diff] [blame] | 5714 | // 'int' values are used directly as W registers, discarding the top |
| 5715 | // bits, so we don't need to sign-extend and can just perform a move. |
| 5716 | // We do not pass the `kDiscardForSameWReg` argument to force clearing the |
| 5717 | // top 32 bits of the target register. We theoretically could leave those |
| 5718 | // bits unchanged, but we would have to make sure that no code uses a |
| 5719 | // 32bit input value as a 64bit value assuming that the top 32 bits are |
| 5720 | // zero. |
| 5721 | __ Mov(output.W(), source.W()); |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 5722 | } else if (result_type == Primitive::kPrimChar || |
| 5723 | (input_type == Primitive::kPrimChar && input_size < result_size)) { |
| 5724 | __ Ubfx(output, |
| 5725 | output.IsX() ? source.X() : source.W(), |
| 5726 | 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5727 | } else { |
Alexandre Rames | 3e69f16 | 2014-12-10 10:36:50 +0000 | [diff] [blame] | 5728 | __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5729 | } |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5730 | } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5731 | __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5732 | } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5733 | CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong); |
| 5734 | __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0)); |
Alexandre Rames | 542361f | 2015-01-29 16:57:31 +0000 | [diff] [blame] | 5735 | } else if (Primitive::IsFloatingPointType(result_type) && |
| 5736 | Primitive::IsFloatingPointType(input_type)) { |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5737 | __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0)); |
| 5738 | } else { |
| 5739 | LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type |
| 5740 | << " to " << result_type; |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5741 | } |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5742 | } |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5743 | |
Serban Constantinescu | 02164b3 | 2014-11-13 14:05:07 +0000 | [diff] [blame] | 5744 | void LocationsBuilderARM64::VisitUShr(HUShr* ushr) { |
| 5745 | HandleShift(ushr); |
| 5746 | } |
| 5747 | |
| 5748 | void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) { |
| 5749 | HandleShift(ushr); |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 5750 | } |
| 5751 | |
| 5752 | void LocationsBuilderARM64::VisitXor(HXor* instruction) { |
| 5753 | HandleBinaryOp(instruction); |
| 5754 | } |
| 5755 | |
| 5756 | void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) { |
| 5757 | HandleBinaryOp(instruction); |
| 5758 | } |
| 5759 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5760 | void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5761 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5762 | LOG(FATAL) << "Unreachable"; |
| 5763 | } |
| 5764 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5765 | void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5766 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5767 | LOG(FATAL) << "Unreachable"; |
| 5768 | } |
| 5769 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5770 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5771 | void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5772 | LocationSummary* locations = |
| 5773 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5774 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5775 | } |
| 5776 | |
| 5777 | void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5778 | int32_t lower_bound = switch_instr->GetStartValue(); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5779 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5780 | Register value_reg = InputRegisterAt(switch_instr, 0); |
| 5781 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5782 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5783 | // 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] | 5784 | static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize; |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5785 | // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to |
| 5786 | // make sure we don't emit it if the target may run out of range. |
| 5787 | // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR |
| 5788 | // ranges and emit the tables only as required. |
| 5789 | static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5790 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5791 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5792 | // Current instruction id is an upper bound of the number of HIRs in the graph. |
| 5793 | GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) { |
| 5794 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5795 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5796 | Register temp = temps.AcquireW(); |
| 5797 | __ Subs(temp, value_reg, Operand(lower_bound)); |
| 5798 | |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5799 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 5800 | // Jump to successors[0] if value == lower_bound. |
| 5801 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 5802 | int32_t last_index = 0; |
| 5803 | for (; num_entries - last_index > 2; last_index += 2) { |
| 5804 | __ Subs(temp, temp, Operand(2)); |
| 5805 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 5806 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 5807 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 5808 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 5809 | } |
| 5810 | if (num_entries - last_index == 2) { |
| 5811 | // The last missing case_value. |
| 5812 | __ Cmp(temp, Operand(1)); |
| 5813 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | // And the default for any other value. |
| 5817 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5818 | __ B(codegen_->GetLabelOf(default_block)); |
| 5819 | } |
| 5820 | } else { |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 5821 | JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr); |
Zheng Xu | 3927c8b | 2015-11-18 17:46:25 +0800 | [diff] [blame] | 5822 | |
| 5823 | UseScratchRegisterScope temps(codegen_->GetVIXLAssembler()); |
| 5824 | |
| 5825 | // Below instructions should use at most one blocked register. Since there are two blocked |
| 5826 | // registers, we are free to block one. |
| 5827 | Register temp_w = temps.AcquireW(); |
| 5828 | Register index; |
| 5829 | // Remove the bias. |
| 5830 | if (lower_bound != 0) { |
| 5831 | index = temp_w; |
| 5832 | __ Sub(index, value_reg, Operand(lower_bound)); |
| 5833 | } else { |
| 5834 | index = value_reg; |
| 5835 | } |
| 5836 | |
| 5837 | // Jump to default block if index is out of the range. |
| 5838 | __ Cmp(index, Operand(num_entries)); |
| 5839 | __ B(hs, codegen_->GetLabelOf(default_block)); |
| 5840 | |
| 5841 | // In current VIXL implementation, it won't require any blocked registers to encode the |
| 5842 | // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the |
| 5843 | // register pressure. |
| 5844 | Register table_base = temps.AcquireX(); |
| 5845 | // Load jump offset from the table. |
| 5846 | __ Adr(table_base, jump_table->GetTableStartLabel()); |
| 5847 | Register jump_offset = temp_w; |
| 5848 | __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2)); |
| 5849 | |
| 5850 | // Jump to target block by branching to table_base(pc related) + offset. |
| 5851 | Register target_address = table_base; |
| 5852 | __ Add(target_address, table_base, Operand(jump_offset, SXTW)); |
| 5853 | __ Br(target_address); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5854 | } |
| 5855 | } |
| 5856 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5857 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister( |
| 5858 | HInstruction* instruction, |
| 5859 | Location out, |
| 5860 | uint32_t offset, |
| 5861 | Location maybe_temp, |
| 5862 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5863 | Primitive::Type type = Primitive::kPrimNot; |
| 5864 | Register out_reg = RegisterFrom(out, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5865 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5866 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5867 | if (kUseBakerReadBarrier) { |
| 5868 | // Load with fast path based Baker's read barrier. |
| 5869 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5870 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5871 | out, |
| 5872 | out_reg, |
| 5873 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5874 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5875 | /* needs_null_check */ false, |
| 5876 | /* use_load_acquire */ false); |
| 5877 | } else { |
| 5878 | // Load with slow path based read barrier. |
| 5879 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 5880 | // in the following move operation, as we will need it for the |
| 5881 | // read barrier below. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5882 | Register temp_reg = RegisterFrom(maybe_temp, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5883 | __ Mov(temp_reg, out_reg); |
| 5884 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5885 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5886 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 5887 | } |
| 5888 | } else { |
| 5889 | // Plain load with no read barrier. |
| 5890 | // /* HeapReference<Object> */ out = *(out + offset) |
| 5891 | __ Ldr(out_reg, HeapOperand(out_reg, offset)); |
| 5892 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5893 | } |
| 5894 | } |
| 5895 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5896 | void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters( |
| 5897 | HInstruction* instruction, |
| 5898 | Location out, |
| 5899 | Location obj, |
| 5900 | uint32_t offset, |
| 5901 | Location maybe_temp, |
| 5902 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5903 | Primitive::Type type = Primitive::kPrimNot; |
| 5904 | Register out_reg = RegisterFrom(out, type); |
| 5905 | Register obj_reg = RegisterFrom(obj, type); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5906 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5907 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5908 | if (kUseBakerReadBarrier) { |
| 5909 | // Load with fast path based Baker's read barrier. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5910 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5911 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5912 | out, |
| 5913 | obj_reg, |
| 5914 | offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5915 | maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5916 | /* needs_null_check */ false, |
| 5917 | /* use_load_acquire */ false); |
| 5918 | } else { |
| 5919 | // Load with slow path based read barrier. |
| 5920 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5921 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5922 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 5923 | } |
| 5924 | } else { |
| 5925 | // Plain load with no read barrier. |
| 5926 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 5927 | __ Ldr(out_reg, HeapOperand(obj_reg, offset)); |
| 5928 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 5929 | } |
| 5930 | } |
| 5931 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5932 | void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad( |
| 5933 | HInstruction* instruction, |
| 5934 | Location root, |
| 5935 | Register obj, |
| 5936 | uint32_t offset, |
| 5937 | vixl::aarch64::Label* fixup_label, |
| 5938 | ReadBarrierOption read_barrier_option) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5939 | DCHECK(fixup_label == nullptr || offset == 0u); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5940 | Register root_reg = RegisterFrom(root, Primitive::kPrimNot); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5941 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5942 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5943 | if (kUseBakerReadBarrier) { |
| 5944 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5945 | // Baker's read barrier are used. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5946 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 5947 | !Runtime::Current()->UseJitCompilation()) { |
| 5948 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 5949 | // 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] | 5950 | // load into `temp` (actually IP1) the read barrier mark introspection |
| 5951 | // entrypoint. If `temp` is null, it means that `GetIsGcMarking()` is |
| 5952 | // false, and vice versa. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5953 | // |
| 5954 | // We use link-time generated thunks for the slow path. That thunk |
| 5955 | // checks the reference and jumps to the entrypoint if needed. |
| 5956 | // |
| 5957 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 5958 | // lr = &return_address; |
| 5959 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 5960 | // if (temp != nullptr) { |
| 5961 | // goto gc_root_thunk<root_reg>(lr) |
| 5962 | // } |
| 5963 | // return_address: |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 5964 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5965 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5966 | DCHECK(temps.IsAvailable(ip0)); |
| 5967 | DCHECK(temps.IsAvailable(ip1)); |
| 5968 | temps.Exclude(ip0, ip1); |
| 5969 | uint32_t custom_data = |
| 5970 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierGcRootData(root_reg.GetCode()); |
| 5971 | vixl::aarch64::Label* cbnz_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 5972 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5973 | // ip1 = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 5974 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 5975 | const int32_t entry_point_offset = |
| 5976 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 5977 | __ Ldr(ip1, MemOperand(tr, entry_point_offset)); |
| 5978 | EmissionCheckScope guard(GetVIXLAssembler(), 3 * vixl::aarch64::kInstructionSize); |
| 5979 | vixl::aarch64::Label return_address; |
| 5980 | __ adr(lr, &return_address); |
| 5981 | if (fixup_label != nullptr) { |
| 5982 | __ Bind(fixup_label); |
| 5983 | } |
| 5984 | static_assert(BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 5985 | "GC root LDR must be 2 instruction (8B) before the return address label."); |
| 5986 | __ ldr(root_reg, MemOperand(obj.X(), offset)); |
| 5987 | __ Bind(cbnz_label); |
| 5988 | __ cbnz(ip1, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 5989 | __ Bind(&return_address); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5990 | } else { |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 5991 | // Note that we do not actually check the value of |
| 5992 | // `GetIsGcMarking()` to decide whether to mark the loaded GC |
| 5993 | // root or not. Instead, we load into `temp` the read barrier |
| 5994 | // mark entry point corresponding to register `root`. If `temp` |
| 5995 | // is null, it means that `GetIsGcMarking()` is false, and vice |
| 5996 | // versa. |
| 5997 | // |
| 5998 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 5999 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 6000 | // if (temp != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 6001 | // // Slow path. |
| 6002 | // root = temp(root); // root = ReadBarrier::Mark(root); // Runtime entry point call. |
| 6003 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6004 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6005 | // Slow path marking the GC root `root`. The entrypoint will already be loaded in `temp`. |
| 6006 | Register temp = lr; |
| 6007 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64( |
| 6008 | instruction, root, /* entrypoint */ LocationFrom(temp)); |
| 6009 | codegen_->AddSlowPath(slow_path); |
| 6010 | |
| 6011 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6012 | const int32_t entry_point_offset = |
| 6013 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(root.reg()); |
| 6014 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6015 | // threads are suspended or running a checkpoint. |
| 6016 | __ Ldr(temp, MemOperand(tr, entry_point_offset)); |
| 6017 | |
| 6018 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6019 | if (fixup_label == nullptr) { |
| 6020 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6021 | } else { |
| 6022 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj); |
| 6023 | } |
| 6024 | static_assert( |
| 6025 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6026 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6027 | "have different sizes."); |
| 6028 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6029 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6030 | "have different sizes."); |
| 6031 | |
| 6032 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6033 | // checking GetIsGcMarking. |
| 6034 | __ Cbnz(temp, slow_path->GetEntryLabel()); |
| 6035 | __ Bind(slow_path->GetExitLabel()); |
| 6036 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6037 | } else { |
| 6038 | // GC root loaded through a slow path for read barriers other |
| 6039 | // than Baker's. |
| 6040 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6041 | if (fixup_label == nullptr) { |
| 6042 | __ Add(root_reg.X(), obj.X(), offset); |
| 6043 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6044 | codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6045 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6046 | // /* mirror::Object* */ root = root->Read() |
| 6047 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6048 | } |
| 6049 | } else { |
| 6050 | // Plain GC root load with no read barrier. |
| 6051 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6052 | if (fixup_label == nullptr) { |
| 6053 | __ Ldr(root_reg, MemOperand(obj, offset)); |
| 6054 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6055 | codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6056 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6057 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6058 | // do not have to unpoison `root_reg` here. |
| 6059 | } |
| 6060 | } |
| 6061 | |
| 6062 | void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6063 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6064 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6065 | uint32_t offset, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6066 | Location maybe_temp, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6067 | bool needs_null_check, |
| 6068 | bool use_load_acquire) { |
| 6069 | DCHECK(kEmitCompilerReadBarrier); |
| 6070 | DCHECK(kUseBakerReadBarrier); |
| 6071 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6072 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6073 | !use_load_acquire && |
| 6074 | !Runtime::Current()->UseJitCompilation()) { |
| 6075 | // Note that we do not actually check the value of `GetIsGcMarking()` |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6076 | // to decide whether to mark the loaded reference or not. Instead, we |
| 6077 | // load into `temp` (actually IP1) the read barrier mark introspection |
| 6078 | // entrypoint. If `temp` is null, it means that `GetIsGcMarking()` is |
| 6079 | // false, and vice versa. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6080 | // |
| 6081 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6082 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6083 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6084 | // |
| 6085 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6086 | // lr = &gray_return_address; |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6087 | // if (temp != nullptr) { |
| 6088 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 6089 | // } |
| 6090 | // not_gray_return_address: |
| 6091 | // // Original reference load. If the offset is too large to fit |
| 6092 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6093 | // GcRoot<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6094 | // gray_return_address: |
| 6095 | |
| 6096 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 6097 | Register base = obj; |
| 6098 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6099 | DCHECK(maybe_temp.IsRegister()); |
| 6100 | base = WRegisterFrom(maybe_temp); |
| 6101 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 6102 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 6103 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 6104 | } |
| 6105 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6106 | DCHECK(temps.IsAvailable(ip0)); |
| 6107 | DCHECK(temps.IsAvailable(ip1)); |
| 6108 | temps.Exclude(ip0, ip1); |
| 6109 | uint32_t custom_data = linker::Arm64RelativePatcher::EncodeBakerReadBarrierFieldData( |
| 6110 | base.GetCode(), |
| 6111 | obj.GetCode()); |
| 6112 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6113 | |
| 6114 | // ip1 = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6115 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6116 | const int32_t entry_point_offset = |
| 6117 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6118 | __ Ldr(ip1, MemOperand(tr, entry_point_offset)); |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 6119 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6120 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6121 | vixl::aarch64::Label return_address; |
| 6122 | __ adr(lr, &return_address); |
| 6123 | __ Bind(cbnz_label); |
| 6124 | __ cbnz(ip1, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 6125 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6126 | "Field LDR must be 1 instruction (4B) before the return address label; " |
| 6127 | " 2 instructions (8B) for heap poisoning."); |
| 6128 | Register ref_reg = RegisterFrom(ref, Primitive::kPrimNot); |
| 6129 | __ ldr(ref_reg, MemOperand(base.X(), offset)); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6130 | if (needs_null_check) { |
| 6131 | MaybeRecordImplicitNullCheck(instruction); |
| 6132 | } |
Vladimir Marko | d1ef873 | 2017-04-18 13:55:13 +0100 | [diff] [blame] | 6133 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6134 | __ Bind(&return_address); |
| 6135 | return; |
| 6136 | } |
| 6137 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6138 | // /* HeapReference<Object> */ ref = *(obj + offset) |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 6139 | Register temp = WRegisterFrom(maybe_temp); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6140 | Location no_index = Location::NoLocation(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6141 | size_t no_scale_factor = 0u; |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6142 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6143 | ref, |
| 6144 | obj, |
| 6145 | offset, |
| 6146 | no_index, |
| 6147 | no_scale_factor, |
| 6148 | temp, |
| 6149 | needs_null_check, |
| 6150 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6151 | } |
| 6152 | |
| 6153 | void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6154 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6155 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6156 | uint32_t data_offset, |
| 6157 | Location index, |
| 6158 | Register temp, |
| 6159 | bool needs_null_check) { |
| 6160 | DCHECK(kEmitCompilerReadBarrier); |
| 6161 | DCHECK(kUseBakerReadBarrier); |
| 6162 | |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 6163 | static_assert( |
| 6164 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6165 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6166 | size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 6167 | |
| 6168 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6169 | !Runtime::Current()->UseJitCompilation()) { |
| 6170 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 6171 | // to decide whether to mark the loaded reference or not. Instead, we |
| 6172 | // load into `temp` (actually IP1) the read barrier mark introspection |
| 6173 | // entrypoint. If `temp` is null, it means that `GetIsGcMarking()` is |
| 6174 | // false, and vice versa. |
| 6175 | // |
| 6176 | // We use link-time generated thunks for the slow path. That thunk checks |
| 6177 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 6178 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 6179 | // |
| 6180 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 6181 | // lr = &gray_return_address; |
| 6182 | // if (temp != nullptr) { |
| 6183 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 6184 | // } |
| 6185 | // not_gray_return_address: |
| 6186 | // // Original reference load. If the offset is too large to fit |
| 6187 | // // into LDR, we use an adjusted base register here. |
| 6188 | // GcRoot<mirror::Object> reference = data[index]; |
| 6189 | // gray_return_address: |
| 6190 | |
| 6191 | DCHECK(index.IsValid()); |
| 6192 | Register index_reg = RegisterFrom(index, Primitive::kPrimInt); |
| 6193 | Register ref_reg = RegisterFrom(ref, Primitive::kPrimNot); |
| 6194 | |
| 6195 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6196 | DCHECK(temps.IsAvailable(ip0)); |
| 6197 | DCHECK(temps.IsAvailable(ip1)); |
| 6198 | temps.Exclude(ip0, ip1); |
| 6199 | uint32_t custom_data = |
| 6200 | linker::Arm64RelativePatcher::EncodeBakerReadBarrierArrayData(temp.GetCode()); |
| 6201 | vixl::aarch64::Label* cbnz_label = NewBakerReadBarrierPatch(custom_data); |
| 6202 | |
| 6203 | // ip1 = Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 6204 | DCHECK_EQ(ip0.GetCode(), 16u); |
| 6205 | const int32_t entry_point_offset = |
| 6206 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ip0.GetCode()); |
| 6207 | __ Ldr(ip1, MemOperand(tr, entry_point_offset)); |
| 6208 | __ Add(temp.X(), obj.X(), Operand(data_offset)); |
| 6209 | EmissionCheckScope guard(GetVIXLAssembler(), |
| 6210 | (kPoisonHeapReferences ? 4u : 3u) * vixl::aarch64::kInstructionSize); |
| 6211 | vixl::aarch64::Label return_address; |
| 6212 | __ adr(lr, &return_address); |
| 6213 | __ Bind(cbnz_label); |
| 6214 | __ cbnz(ip1, static_cast<int64_t>(0)); // Placeholder, patched at link-time. |
| 6215 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 6216 | "Array LDR must be 1 instruction (4B) before the return address label; " |
| 6217 | " 2 instructions (8B) for heap poisoning."); |
| 6218 | __ ldr(ref_reg, MemOperand(temp.X(), index_reg.X(), LSL, scale_factor)); |
| 6219 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 6220 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 6221 | __ Bind(&return_address); |
| 6222 | return; |
| 6223 | } |
| 6224 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6225 | // Array cells are never volatile variables, therefore array loads |
| 6226 | // never use Load-Acquire instructions on ARM64. |
| 6227 | const bool use_load_acquire = false; |
| 6228 | |
| 6229 | // /* HeapReference<Object> */ ref = |
| 6230 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6231 | GenerateReferenceLoadWithBakerReadBarrier(instruction, |
| 6232 | ref, |
| 6233 | obj, |
| 6234 | data_offset, |
| 6235 | index, |
| 6236 | scale_factor, |
| 6237 | temp, |
| 6238 | needs_null_check, |
| 6239 | use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6240 | } |
| 6241 | |
| 6242 | void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6243 | Location ref, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 6244 | Register obj, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6245 | uint32_t offset, |
| 6246 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6247 | size_t scale_factor, |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6248 | Register temp, |
| 6249 | bool needs_null_check, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6250 | bool use_load_acquire, |
| 6251 | bool always_update_field) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6252 | DCHECK(kEmitCompilerReadBarrier); |
| 6253 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6254 | // If we are emitting an array load, we should not be using a |
| 6255 | // Load Acquire instruction. In other words: |
| 6256 | // `instruction->IsArrayGet()` => `!use_load_acquire`. |
| 6257 | DCHECK(!instruction->IsArrayGet() || !use_load_acquire); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6258 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6259 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 6260 | // whether we need to enter the slow path to mark the reference. |
| 6261 | // Then, in the slow path, check the gray bit in the lock word of |
| 6262 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 6263 | // not. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6264 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6265 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
| 6266 | // instead, we load into `temp2` the read barrier mark entry point |
| 6267 | // corresponding to register `ref`. If `temp2` is null, it means |
| 6268 | // that `GetIsGcMarking()` is false, and vice versa. |
| 6269 | // |
| 6270 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6271 | // if (temp2 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 6272 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6273 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6274 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6275 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 6276 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 6277 | // if (is_gray) { |
| 6278 | // ref = temp2(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 6279 | // } |
| 6280 | // } else { |
| 6281 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6282 | // } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6283 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6284 | // Slow path marking the object `ref` when the GC is marking. The |
| 6285 | // entrypoint will already be loaded in `temp2`. |
| 6286 | Register temp2 = lr; |
| 6287 | Location temp2_loc = LocationFrom(temp2); |
| 6288 | SlowPathCodeARM64* slow_path; |
| 6289 | if (always_update_field) { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6290 | // LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64 |
| 6291 | // only supports address of the form `obj + field_offset`, where |
| 6292 | // `obj` is a register and `field_offset` is a register. Thus |
| 6293 | // `offset` and `scale_factor` above are expected to be null in |
| 6294 | // this code path. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6295 | DCHECK_EQ(offset, 0u); |
| 6296 | DCHECK_EQ(scale_factor, 0u); /* "times 1" */ |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6297 | Location field_offset = index; |
| 6298 | slow_path = |
| 6299 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM64( |
| 6300 | instruction, |
| 6301 | ref, |
| 6302 | obj, |
| 6303 | offset, |
| 6304 | /* index */ field_offset, |
| 6305 | scale_factor, |
| 6306 | needs_null_check, |
| 6307 | use_load_acquire, |
| 6308 | temp, |
| 6309 | /* entrypoint */ temp2_loc); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6310 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6311 | slow_path = new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM64( |
| 6312 | instruction, |
| 6313 | ref, |
| 6314 | obj, |
| 6315 | offset, |
| 6316 | index, |
| 6317 | scale_factor, |
| 6318 | needs_null_check, |
| 6319 | use_load_acquire, |
| 6320 | temp, |
| 6321 | /* entrypoint */ temp2_loc); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6322 | } |
| 6323 | AddSlowPath(slow_path); |
| 6324 | |
| 6325 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 6326 | const int32_t entry_point_offset = |
| 6327 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref.reg()); |
| 6328 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6329 | // threads are suspended or running a checkpoint. |
| 6330 | __ Ldr(temp2, MemOperand(tr, entry_point_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6331 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6332 | // checking GetIsGcMarking. |
| 6333 | __ Cbnz(temp2, slow_path->GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 6334 | // Fast path: just load the reference. |
| 6335 | GenerateRawReferenceLoad( |
| 6336 | 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] | 6337 | __ Bind(slow_path->GetExitLabel()); |
| 6338 | } |
| 6339 | |
| 6340 | void CodeGeneratorARM64::GenerateRawReferenceLoad(HInstruction* instruction, |
| 6341 | Location ref, |
| 6342 | Register obj, |
| 6343 | uint32_t offset, |
| 6344 | Location index, |
| 6345 | size_t scale_factor, |
| 6346 | bool needs_null_check, |
| 6347 | bool use_load_acquire) { |
| 6348 | DCHECK(obj.IsW()); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6349 | Primitive::Type type = Primitive::kPrimNot; |
| 6350 | Register ref_reg = RegisterFrom(ref, type); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6351 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6352 | // If needed, vixl::EmissionCheckScope guards are used to ensure |
| 6353 | // that no pools are emitted between the load (macro) instruction |
| 6354 | // and MaybeRecordImplicitNullCheck. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6355 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6356 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6357 | // Load types involving an "index": ArrayGet, |
| 6358 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 6359 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6360 | if (use_load_acquire) { |
| 6361 | // UnsafeGetObjectVolatile intrinsic case. |
| 6362 | // Register `index` is not an index in an object array, but an |
| 6363 | // offset to an object reference field within object `obj`. |
| 6364 | DCHECK(instruction->IsInvoke()) << instruction->DebugName(); |
| 6365 | DCHECK(instruction->GetLocations()->Intrinsified()); |
| 6366 | DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile) |
| 6367 | << instruction->AsInvoke()->GetIntrinsic(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6368 | DCHECK_EQ(offset, 0u); |
| 6369 | DCHECK_EQ(scale_factor, 0u); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6370 | DCHECK_EQ(needs_null_check, false); |
| 6371 | // /* HeapReference<mirror::Object> */ ref = *(obj + index) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6372 | MemOperand field = HeapOperand(obj, XRegisterFrom(index)); |
| 6373 | LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6374 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6375 | // ArrayGet and UnsafeGetObject and UnsafeCASObject intrinsics cases. |
| 6376 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6377 | if (index.IsConstant()) { |
| 6378 | uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6379 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6380 | Load(type, ref_reg, HeapOperand(obj, computed_offset)); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6381 | if (needs_null_check) { |
| 6382 | MaybeRecordImplicitNullCheck(instruction); |
| 6383 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6384 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6385 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6386 | Register temp = temps.AcquireW(); |
| 6387 | __ Add(temp, obj, offset); |
| 6388 | { |
| 6389 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6390 | Load(type, ref_reg, HeapOperand(temp, XRegisterFrom(index), LSL, scale_factor)); |
| 6391 | if (needs_null_check) { |
| 6392 | MaybeRecordImplicitNullCheck(instruction); |
| 6393 | } |
| 6394 | } |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6395 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6396 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6397 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6398 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6399 | MemOperand field = HeapOperand(obj, offset); |
| 6400 | if (use_load_acquire) { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6401 | // Implicit null checks are handled by CodeGeneratorARM64::LoadAcquire. |
| 6402 | LoadAcquire(instruction, ref_reg, field, needs_null_check); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6403 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6404 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6405 | Load(type, ref_reg, field); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 6406 | if (needs_null_check) { |
| 6407 | MaybeRecordImplicitNullCheck(instruction); |
| 6408 | } |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6409 | } |
| 6410 | } |
| 6411 | |
| 6412 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6413 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6414 | } |
| 6415 | |
| 6416 | void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6417 | Location out, |
| 6418 | Location ref, |
| 6419 | Location obj, |
| 6420 | uint32_t offset, |
| 6421 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6422 | DCHECK(kEmitCompilerReadBarrier); |
| 6423 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6424 | // Insert a slow path based read barrier *after* the reference load. |
| 6425 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6426 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6427 | // reference will be carried out by the runtime within the slow |
| 6428 | // path. |
| 6429 | // |
| 6430 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6431 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6432 | // not used by the artReadBarrierSlow entry point. |
| 6433 | // |
| 6434 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6435 | SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) |
| 6436 | ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index); |
| 6437 | AddSlowPath(slow_path); |
| 6438 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6439 | __ B(slow_path->GetEntryLabel()); |
| 6440 | __ Bind(slow_path->GetExitLabel()); |
| 6441 | } |
| 6442 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6443 | void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6444 | Location out, |
| 6445 | Location ref, |
| 6446 | Location obj, |
| 6447 | uint32_t offset, |
| 6448 | Location index) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6449 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6450 | // Baker's read barriers shall be handled by the fast path |
| 6451 | // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6452 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6453 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6454 | // by the runtime within the slow path. |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6455 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6456 | } else if (kPoisonHeapReferences) { |
| 6457 | GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out)); |
| 6458 | } |
| 6459 | } |
| 6460 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6461 | void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6462 | Location out, |
| 6463 | Location root) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6464 | DCHECK(kEmitCompilerReadBarrier); |
| 6465 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 6466 | // Insert a slow path based read barrier *after* the GC root load. |
| 6467 | // |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6468 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6469 | // not need to do anything special for this here. |
| 6470 | SlowPathCodeARM64* slow_path = |
| 6471 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root); |
| 6472 | AddSlowPath(slow_path); |
| 6473 | |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 6474 | __ B(slow_path->GetEntryLabel()); |
| 6475 | __ Bind(slow_path->GetExitLabel()); |
| 6476 | } |
| 6477 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6478 | void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6479 | LocationSummary* locations = |
| 6480 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6481 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6482 | locations->SetOut(Location::RequiresRegister()); |
| 6483 | } |
| 6484 | |
| 6485 | void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) { |
| 6486 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6487 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6488 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6489 | instruction->GetIndex(), kArm64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6490 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6491 | MemOperand(XRegisterFrom(locations->InAt(0)), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6492 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6493 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 6494 | instruction->GetIndex(), kArm64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 6495 | __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)), |
| 6496 | mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 6497 | __ Ldr(XRegisterFrom(locations->Out()), |
| 6498 | MemOperand(XRegisterFrom(locations->Out()), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6499 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6500 | } |
| 6501 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6502 | static void PatchJitRootUse(uint8_t* code, |
| 6503 | const uint8_t* roots_data, |
| 6504 | vixl::aarch64::Literal<uint32_t>* literal, |
| 6505 | uint64_t index_in_table) { |
| 6506 | uint32_t literal_offset = literal->GetOffset(); |
| 6507 | uintptr_t address = |
| 6508 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 6509 | uint8_t* data = code + literal_offset; |
| 6510 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 6511 | } |
| 6512 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6513 | void CodeGeneratorARM64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 6514 | for (const auto& entry : jit_string_patches_) { |
| 6515 | const auto& it = jit_string_roots_.find(entry.first); |
| 6516 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6517 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 6518 | } |
| 6519 | for (const auto& entry : jit_class_patches_) { |
| 6520 | const auto& it = jit_class_roots_.find(entry.first); |
| 6521 | DCHECK(it != jit_class_roots_.end()); |
| 6522 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6523 | } |
| 6524 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 6525 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 6526 | #undef __ |
| 6527 | #undef QUICK_ENTRY_POINT |
| 6528 | |
Alexandre Rames | 5319def | 2014-10-23 10:03:10 +0100 | [diff] [blame] | 6529 | } // namespace arm64 |
| 6530 | } // namespace art |